View SampleViewModel.kt
class SampleViewModel : ViewModel() {
val sampleData = UiAsyncLoadLiveData<String> {
value = try {
async(coroutineContext + CommonPool) {
"very long time process!"
}.await()
} catch (e: CancellationException) {
null
}
}
View PagedListGroup.java
import android.arch.paging.AsyncPagedListDiffer;
import android.arch.paging.PagedList;
import android.support.annotation.NonNull;
import android.support.v7.recyclerview.extensions.AsyncDifferConfig;
import android.support.v7.util.DiffUtil;
import android.support.v7.util.ListUpdateCallback;
import com.xwray.groupie.Group;
import com.xwray.groupie.GroupDataObserver;
import com.xwray.groupie.Item;
View NestedCoordinatorLayout.kt
import android.content.Context
import android.support.design.widget.CoordinatorLayout
import android.support.v4.view.NestedScrollingChild
import android.support.v4.view.NestedScrollingChildHelper
import android.util.AttributeSet
import android.view.View
/**
* Propagate nested scroll event to in/out nested coordinator layout
View LatLngUtils.kt
import com.google.android.gms.maps.model.LatLng
// Compute latitude and longitude from current lat lng,
// using Vincenty's direct formulae https://en.wikipedia.org/wiki/Vincenty's_formulae
fun LatLng.computeLatLngByDistanceAndBearing(distance: Double, bearing: Double): LatLng {
val PI = Math.PI / 180.0
val MAXITERS = 20
View DatabindingUtil.kt
import android.app.Activity
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
fun <T : ViewDataBinding> Activity.contentViewBinding(layout: Int): Lazy<T> = lazy {
DataBindingUtil.setContentView<T>(this, layout)
}
View SampleAdapter.kt
class SampleAdapter() : RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
var data: List<String> = emptyList()
var onClick: (String) -> Unit = {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder? {
val binding = ItemListBinding.inflate(LayoutInflater.from(parent.context), parent, false)
binding.root.setOnClickListener {
onClick(data[(parent as RecyclerView).getChildAdapterPosition(it)])
}
return ViewHolder(it)
View CustomTabsHelper.kt
import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.net.Uri
import android.support.customtabs.CustomTabsClient
import android.support.customtabs.CustomTabsIntent
import android.support.customtabs.CustomTabsServiceConnection
View play_service_proj_builder.py
from distutils.spawn import find_executable
import os
import re
import sys
import subprocess
import zipfile
import tempfile
import shutil
View tinyPNG.py
"""
Batch compress PNG images by using TinyPNG
usage:
tinyPNG.py <key> <target-folder> <source-file>...
"""
import os
import glob
import sys
import re
import shutil
View resource_copy.py
"""
Copy image files with dpi suffix to Android resource folder
usage:
resource_copy.py <target-resource-folder> <source-file>...
"""
import os
import glob
import sys
import re