Skip to content

Instantly share code, notes, and snippets.

View chowaikong's full-sized avatar

KNOX chowaikong

  • China
View GitHub Profile
allprojects { project ->
project.plugins.withType(com.android.build.gradle.LibraryPlugin) { plugin ->
project.android.libraryVariants.all { variant ->
// TODO replace with https://issuetracker.google.com/issues/72050365 once released.
variant.generateBuildConfigProvider.configure { task ->
task.enabled = false
}
}
}
}
@chowaikong
chowaikong / LifecycleHelper
Last active August 4, 2017 01:28
A helper to define is there a running foreground activity based on ActivityLifecycleCallbacks
class LifecycleHelper: Application.ActivityLifecycleCallbacks {
private var resumed: Int = 0
private var paused: Int = 0
private var started: Int = 0
private var stopped: Int = 0
override fun onActivityPaused(activity: Activity?) {
++paused
}
class NonScrollViewPager : ViewPager {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
override fun onTouchEvent(event: MotionEvent): Boolean {
return false
}
class EmojiExcludedEditText : EditText {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs,
class WaveView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private val mAbovePath: Path = Path()
private val mBelowWavePath: Path = Path()
private val mAboveWavePaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val mBelowWavePaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val mDrawFilter: DrawFilter = PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
private var φ: Float = 0.toFloat()
public class RxBus {
private final FlowableProcessor<Object> bus = PublishProcessor.create().toSerialized();
private RxBus() {
}
private static class InstanceHolder {
private static final RxBus sInstance = new RxBus();
}
public class DataBindingViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
private T mBinding;
public DataBindingViewHolder(T binding) {
super(binding.getRoot());
this.mBinding = binding;
}
public T getBinding() {
public abstract class BaseRVAdapter<T extends ViewDataBinding, M>
extends RecyclerView.Adapter<DataBindingViewHolder<T>> {
List<M> mDataList;
public BaseRVAdapter(List<M> mDataList) {
this.mDataList = mDataList;
}
@Override public int getItemCount() {
public class Singleton {
private Singleton() {
}
public static Singleton getInstance() {
return SingletonViewHolder.sInsatnce;
}
private static class SingletonHolder {
@chowaikong
chowaikong / DimenUtil
Last active December 23, 2016 07:02
DimenUtil
public int dp2px(float dp) {
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
return Math.round(dp * (displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT));
}