Skip to content

Instantly share code, notes, and snippets.

public static int resolveSizeAndState(int desireSize, int measureSpec) {
int result = desireSize;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
switch (specMode) {
case MeasureSpec.UNSPECIFIED:
result = desireSize;
break;
case MeasureSpec.AT_MOST:
if (specSize < desireSize) {
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
@BCsl
BCsl / ModuleBuild.xml
Created May 7, 2016 02:26
Gradle Signed
final Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ["archives"]
pkg {
repo = "maven"
@BCsl
BCsl / MachineUtils.java
Created May 23, 2016 06:33
MultiProcess
/**
* 获取当前进程名
* @param context
* @return
*/
public static String getCurrProcessName(Context context) {
try {
final int currProcessId = android.os.Process.myPid();
final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
@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;
/**
@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 / 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 / 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 / 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 / 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;