Android 34

How to use synthetic property in Kotlin Android Extension

Issue #555

Synthetic properties generated by Kotlin Android Extensions plugin needs a view for Fragment/Activity to be set before hand.

In your case, for Fragment, you need to use view.btn_K in onViewCreated

override fun onCreateView(inflater: …

How to access view in fragment in Kotlin

Issue #497

Synthetic properties generated by Kotlin Android Extensions plugin needs a view for Fragment/Activity to be set before hand.

In your case, for Fragment, you need to use view.btn_K in onViewCreated

override fun onCreateView(inflater: …

How to show error message like Snack Bar in iOS

Issue #472

Build error view

Use convenient code from Omnia

To make view height dynamic, pin UILabel to edges and center

import UIKit

final class ErrorMessageView: UIView {
    let box: UIView = {
        let view = UIView()
        view. …

How to structure classes

Issue #466

iOS

View Controller -> View Model | Logic Handler -> Data Handler -> Repo

Android

Activity -> Fragment -> View Model | Logic Handler -> Data Handler -> Repo

How to add AdMob to Android app

Issue #431

Use AdMob with Firebase

build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath …

How to do launch screen in Android

Issue #397

We recommend that, rather than disabling the preview window, you follow the common Material Design patterns. You can use the activity’s windowBackground theme attribute to provide a simple custom drawable for the starting activity. …

How to add header to NavigationView in Android

Issue #396

Use app:headerLayout

<com.google.android.material.navigation.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/navigationView" …

How to create bounce animation programmatically in Android

Issue #383

Right click res -> New -> Android Resource Directory, select anim and name it anim Right click res/anim -> New -> Android Resource file, name it bounce

<?xml version="1.0" encoding="utf-8"?>
<set …

How to use point in dp programmatically in Android

Issue #382

import android.content.Context

fun Int.toDp(context: Context?): Int {
    if (context != null) {
        val scale = context.resources.displayMetrics.density
        return (this.toFloat() * scale + 0.5f).toInt()
    } else { …

How to create constraints programmatically with ConstraintLayout in Android

Issue #381

From API < 17, there is ViewCompat.generateViewId() For API 17, there is View.generateViewId()

Note that to use ConstraintSet, all views under ConstraintLayout inside xml must have unique id

val imageView = ImageView(context)
imageView. …

How to use custom font as resource in Android

Issue #380

Downloadable fonts

https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts

Android 8.0 (API level 26) and Android Support Library 26 introduce support for APIs to request fonts from a provider application instead of …

How to get Hacker News top stories using parallel coroutine and Retrofit

Issue #379

interface Api {
    @GET("topstories.json?print=pretty")
    suspend fun getTopStories(): List<Int>

    @GET("item/{id}.json?print=pretty")
    suspend fun getStory(@Path("id") id: Int): Item
}
class Repo { …

How to show generic list in Fragment in Android

Issue #378

After having a generic RecyclerView, if we want to show multiple kinds of data in Fragment, we can use generic.

We may be tempted to use interface or protocol, but should prefer generic.

class FeedFragment() : Fragment() {
    override fun …

How to use Product Hunt GraphQL API with Retrofit

Issue #370

Define response model

import com.squareup.moshi.Json

data class Response(
    @field:Json(name="data") val data: ResponseData
)

data class ResponseData(
    @field:Json(name="posts") val posts: Posts
)

data class Posts( …

How to get trending repos on GitHub using Retrofit

Issue #367

https://api.github.com/search/repositories?sort=stars&order=desc&q=language:javascript,java,swift,kotlin&q=created:>2019-08-21
interface Api {
    @GET("https://api.github.com/search/repositories")
    suspend fun …

How to use Retrofit in Android

Issue #366

Code uses Retrofit 2.6.0 which has Coroutine support

app/build.gradle

implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01"

implementation "com.squareup.moshi:moshi:$Version.moshi"

implementation …

How to use ViewModel and ViewModelsProviders in Android

Issue #363

ViewModels a simple example

https://medium.com/androiddevelopers/viewmodels-a-simple-example-ed5ac416317e

Rotating a device is one of a few configuration changes that an app can go through during its lifetime, including keyboard …

How to inject view model with Koin in Android

Issue #359

app/build.gradle

implementation "org.koin:koin-core:$Version.koin"
implementation "org.koin:koin-androidx-scope:$Version.koin"
implementation "org.koin:koin-androidx-viewmodel:$Version.koin"

MyApplication.kt

import …

How to use coroutine LiveData in Android

Issue #358

app/build.gradle

implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha01"
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import kotlinx.coroutines.Dispatchers

class MainViewModel : ViewModel …

How to declare generic RecyclerView adapter in Android

Issue #357

generic/Adapter.kt

package com.onmyway133.generic

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

abstract class Adapter<T>(var items: …

How to define version property in gradle

Issue #351

From Gradle tips and recipes, Configure project-wide properties

For projects that include multiple modules, it might be useful to define properties at the project level and share them across all modules. You can do this by adding extra …

How to use Navigation component with DrawerLayout in Android

Issue #349

Screenshot_1565169686

build.gradle

dependencies {
    classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha05'
}

app/build.gradle

apply plugin: 'androidx.navigation.safeargs'

dependencies {
    def navigationVersion …

How to use ext in gradle in Android

Issue #338

Gradle uses Groovy and it has ext, also known as ExtraPropertiesExtension

Additional, ad-hoc, properties for Gradle domain objects.

Extra properties extensions allow new properties to be added to existing domain objects. They act like …

How to use Gradle Kotlin DSL in Android

Issue #285

kts

settings.gradle.kts

include(":app")

build.gradle.kts

import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.*
import …

How to run Android apps in Bitrise

Issue #273

Original post https://hackernoon.com/using-bitrise-ci-for-android-apps-fa9c48e301d8


CI, short for Continuous Integration, is a good practice to move fast and confidently where code is integrated into shared repository many times a day. …

How to setup Android projects

Issue #257

checkstyle (Java)

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking …

How to fix ApiException 10 in Flutter for Android

Issue #188

Get error com.google.android.gms.common.api.ApiException: 10 with google_sign_in package.

Read https://developers.google.com/android/guides/client-auth

Certain Google Play services (such as Google Sign-in and App Invites) require you to …

How to fix SSLPeerUnverifiedException in Android

Issue #184

Get error javax.net.ssl.SSLPeerUnverifiedException: No peer certificate in Android API 16 to API 19

Getting started

Read about HTTPS and SSL https://developer.android.com/training/articles/security-ssl Check backend TLS …

Make your own sliding menu on Android tutorial – Part 2

Issue #152

This is the part 2 of the tutorial. If you forget, here is the link to part 1.

Link to Github

In the first part, we learn about the idea, the structure of the project and how MainActivity uses the MainLayout. Now we learn how to actually …

Make your own sliding menu on Android tutorial - Part 1

Issue #151

This post was from long time ago when I did Android


I can’t deny that Facebook is so amazing, they made trends and people want to follow. That is the case of the sliding menu.

Searching many threads on SO, like these create android …

Understanding suspend function in Kotlin Coroutine in Android

Issue #123

Getting to know Coroutine

From https://kotlinlang.org/docs/reference/coroutines.html

To continue the analogy, await() can be a suspending function (hence also callable from within an async {} block) that suspends a coroutine until some …

BuddyBuild and gradle.properties

Issue #109

People advise against storing keys inside build.gradles. We should store them on 1Password and populate our gradle.properties, so don’t track this file in git. Here is .gitignore file

*.iml

/build
/gradle.properties …

Communication between Fragment and Activity

Issue #108

There’s always need for communication, right 😉 Suppose we have OnboardingActivity that has several OnboardingFragment. Each Fragment has a startButton telling that the onboarding flow has finished, and only the last Fragment shows …