Skip to content

Instantly share code, notes, and snippets.

@BCsl
BCsl / HeaderRoundDrawable.java
Created September 19, 2016 06:48
Round Image Drawable
public class HeaderRoundDrawable extends Drawable {
private static final float ROUND_RADIUS = ScreenUtil.dip2px(AppApplication.getContext(), 6);
private final RectF mRect = new RectF(), mBitmapRect;
private final BitmapShader mBitmapShader;
private final Paint mPaint;
private Path mPath = new Path();
private float[] mRadius;
@BCsl
BCsl / ViewStubWidget.java
Created September 20, 2016 03:00
Easy using ViewStub to lazy inflate layout
/**
* Created by chensuilun on 16-9-20.
*/
public abstract class ViewStubWidget {
private ViewGroup mParent;
private int mStubId;
private ViewStub mViewStub;
private View mRoot;
@BCsl
BCsl / BaseFragment.java
Last active March 27, 2017 07:32
在内存重启的时候自动恢复可见状态的Fragment,避免重叠现象,懒加载的Fragment
public abstract class BaseFragment extends Fragment {
public static final String IS_SHOW = "is_show";
protected View mRootView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (BuildConfig.DEBUG) {
Log.d(getClass().getSimpleName(), "onCreate:");
}
@BCsl
BCsl / mx_screen_unlock.sh
Created October 11, 2016 02:31
Adb shell to unlock my Mx4
#!/bin/bash
# power button
adb shell input keyevent 26 &&
adb shell sleep 0.1 &&
# swipe to unlock
adb shell input swipe 655 1774 655 874 &&
adb shell sleep 0.1 &&
# input 2
adb shell input tap 612 726 &&
adb shell sleep 0.1 &&
@BCsl
BCsl / ColorStateGenerator.java
Last active November 1, 2016 10:17
Easy way to generate ColorStateList
class ColorStateGenerate{
// 灰度
public static int greyer(int color) {
int blue = (color & 0x000000FF) >> 0;
int green = (color & 0x0000FF00) >> 8;
int red = (color & 0x00FF0000) >> 16;
int grey = Math.round(red * 0.299f + green * 0.587f + blue * 0.114f);
return Color.argb(0xff, grey, grey, grey);
}
@BCsl
BCsl / app-build.gradle
Created November 3, 2016 07:03
Gradle dependency
def supportLibraryVersion = '24.2.1'
ext.deps = [
supportCompat: "com.android.support:support-compat:$supportLibraryVersion",
]
@BCsl
BCsl / ColorUtil
Created December 29, 2016 11:10 — forked from martintreurnicht/ColorUtil
Lighten and darken colors in android
public static int lighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = lightenColor(red, fraction);
green = lightenColor(green, fraction);
blue = lightenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
/**
* 在内存重启的时候自动恢复可见状态的Fragment,避免重叠现象
* 但同时不要忘了在Activity中判断`savedInstanceState`为null的时候才操作Fragment
* Created by chensuilun on 16-8-9.
*/
public abstract class BaseRestoreFragment extends Fragment {
public static final String IS_SHOW = "is_show";
protected View mRootView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
package com.xinghui.notificationlistenerservicedemo;
import android.app.ActivityManager;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.Process;
@BCsl
BCsl / IMMLeaks.java
Created March 30, 2017 12:20 — forked from pyricau/IMMLeaks.java
"Fix" for InputMethodManager leaking the last focused view: https://code.google.com/p/android/issues/detail?id=171190
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Bundle;
import android.os.Looper;
import android.os.MessageQueue;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;