Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / DragLinearLayout.java
Created September 7, 2016 03:17
DragLinearLayout
/**
* copy from github:https://github.com/justasm/DragLinearLayout
* <p/>
* Edited by @author chensuilun
* add support for HORIZONTAL , simplify code , some useful callback ,add OverScroll constrain , long click to drag support
*/
public class DragLinearLayout extends LinearLayout {
private static final String TAG = DragLinearLayout.class.getSimpleName();
private static final long NOMINAL_SWITCH_DURATION = 150;
private static final long MIN_SWITCH_DURATION = NOMINAL_SWITCH_DURATION;
@BCsl
BCsl / ParallaxListView.java
Created June 30, 2016 06:27
实现OverScroller效果
public class ParallaxListView extends ListView {
private ImageView iv_header;
/**图片的高度*/
private int drawableHeight;
/**ImageView的原始高度*/
private int originalHeight;
public ParallaxListView(Context context) {
super(context);
@BCsl
BCsl / configuration
Created June 29, 2016 07:29
some useful configuration for custom view
final ViewConfiguration configuration = ViewConfiguration.get(mContext);
mTouchSlop = configuration.getScaledTouchSlop();
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
mOverscrollDistance = configuration.getScaledOverscrollDistance();
mOverflingDistance = configuration.getScaledOverflingDistance();
@BCsl
BCsl / Rotate3dAnimation.java
Last active May 31, 2016 02:02
如何实现3D动画和Cemera API的使用
/**
* An animation that rotates the view on the Y axis between two specified angles.
* This animation also adds a translation on the Z axis (depth) to improve the effect.
*/
public class Rotate3dAnimation extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ;
@BCsl
BCsl / VerticalFlipReceiver.java
Created May 30, 2016 03:24
监听程序翻转
public class VerticalFlipReceiver implements SensorEventListener {
private static final String TAG = "VerticalFlipReceiver";
private static final float CRITICAL_DOWN_ANGLE = -6.75f;
private static final float CRITICAL_UP_ANGLE = 6.75f;
private static final int Z_ORATIATION = 2;
private static final int SCREEN_FLIP_UP = 0;
private static final int SCREEN_FLIP_DOWN = 1;
private int mReverseDownFlg = -1;
private Context mContext;
private SensorManager mSensorManager;
@BCsl
BCsl / StatusBarCompat.java
Last active April 13, 2018 11:01
状态栏着色工具类,不需要再繁琐的配style
/**
* https://github.com/niorgai/StatusBarCompat
* */
public class StatusBarCompat {
private static final int COLOR_TRANSLUCENT = Color.parseColor("#00000000");
public static final int DEFAULT_COLOR_ALPHA = 112;
/**