Google 搜索高级技巧

Alt none

Alt none

Alt none

Android 获取当前活动activity的信息

PackageManager mPackageManager = getApplication().getPackageManager();
ActivityManager mActivityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

//get current active activity for user
List<RunningTaskInfo> runningTaskInfos = mActivityManager.getRunningTasks(1);
        RunningTaskInfo taskInfo = runningTaskInfos.get(0);
        ComponentName cn = taskInfo.topActivity;

try {
     ActivityInfo activityInfo = mPackageManger.getActivityInfo(cn, 0);
     //here: something other activity attributes you want
     if((activityInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
         return 0;
     }
} catch (NameNotFoundException e) {
            e.printStackTrace();
}

px、dp、sp转换

public class DensityUtil {

	public static int px2dp(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

	public static int dp2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	public static int px2sp(Context context, float pxValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return (int) (pxValue / fontScale + 0.5f);
	}

	public static int sp2px(Context context, float spValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return (int) (spValue * fontScale + 0.5f);
	}
}

git log 中的 ".." 和 "..."

A: Branch A B: Branch B

git log A.. B

means: 1

git log A... B

means: 2

绘制 9patch

 Bitmap bmp_9patch = BitmapFactory.decodeResource(getResources(), R.drawable.ic_background);
 NinePatch np = new NinePatch(bmp_9patch, bmp_9patch.getNinePatchChunk(), null);
 Rect rect = new Rect(0, 0, 2000, 50);
 np.draw(canvas, rect);