Skip to content

Instantly share code, notes, and snippets.

@wyon
wyon / ScaleBitmap.java
Created January 25, 2016 08:40
android中如何使用一张图片适配不同尺寸的APP引导页(http://blog.csdn.net/sahadev_/article/details/48475217)
private static void scaleImage(final Activity activity, final View view, int drawableResId) {
// 获取屏幕的高宽
Point outSize = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
activity.getWindow().getWindowManager().getDefaultDisplay().getSize(outSize);
} else {
outSize.x = activity.getWindow().getWindowManager().getDefaultDisplay().getWidth();
outSize.y = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight();
}
@wyon
wyon / isMainApplicationContext
Created April 19, 2016 09:07
判断当前进程是否是app主进程中
ActivityManager am = ((ActivityManager)mAppContext.getSystemService(Context.ACTIVITY_SERVICE));
List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
String mainProcessName = mAppContext.getPackageName();
int myPid = Process.myPid();
for (ActivityManager.RunningAppProcessInfo info : processInfos) {
if (info.pid == myPid && mainProcessName.equals(info.processName)) {
return true;
}
}
return false;
@wyon
wyon / MimeTypeUtil
Created June 3, 2016 07:21
获取MimeType
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension("txt");
if (mime == null) {
mime = "application/octet-stream";
}
@wyon
wyon / BST.js
Last active October 26, 2016 07:43
some js code
// 二叉树
// 节点construct
function Node(data, left, right) {
this.data = data;
this.left = left;
this.right = right;
this.show = show;
}
@wyon
wyon / Tools.java
Created January 19, 2017 07:47
printMotionEvent
public static StringBuilder printMotionEvent(MotionEvent event, StringBuilder stringBuilder) {
if (stringBuilder == null) {
stringBuilder = new StringBuilder();
}
stringBuilder.append("[RawAction:0x").append(Integer.toHexString(event.getAction()))
.append("");
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
stringBuilder.append("(down)");
@wyon
wyon / RoundCornerImageView.java
Created July 19, 2017 07:51
RoundCornerImageView 带圆角的ImageView
public class RoundCornerImageView extends ImageView {
private final RectF mTmpRectF = new RectF();
private int topLeftRadius;
private int topRightRadius;
private int bottomLeftRadius;
private int bottomRightRadius;
// todo canvas.clipPath(Round Rect)?
@wyon
wyon / CenterBottomRoundImageView.java
Created July 19, 2017 07:52
CenterCrop的imageview,水平、垂直方向如果有放大会在该方向移动以居中显示;这里CenterBottomRoundImageView效果如同CenterCrop,并保持水平方向居中能力,但是垂直方向则距底显示。
public class CenterBottomRoundImageView extends RoundCornerImageView {
private Matrix mMatrix;
public CenterBottomRoundImageView(Context context) {
super(context);
init();
}
public CenterBottomRoundImageView(Context context, @Nullable AttributeSet attrs) {
@wyon
wyon / DividerDecoration.java
Created July 24, 2017 09:17
RecycleView item 边框、阴影
private static class DividerDecoration extends RecyclerView.ItemDecoration {
final int bottomOffset = DisplayUtil.dip2px(15);
final int hOffset = DisplayUtil.dip2px(7);
final ShadowHelper mShadowHelper;
DividerDecoration(Context context) {
mShadowHelper = new ShadowHelper(context);
}
@wyon
wyon / FrameAnalyze.java
Created July 28, 2017 03:25
帧分析工具类,一个打印帧率和丢帧情况log的工具类,原理是利用Choreographer的FrameCallback。
package com.wyon.util;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.Choreographer;
/**
* 功能:分析丢帧情况和帧绘制耗时
* 描述:需要分析的代码前后加上 FrameAnalyze.start(), FrameAnalyze.stop()
@wyon
wyon / BlockDetect.java
Last active February 25, 2021 05:56
检测应用在UI线程的卡顿,打印出卡顿时调用堆栈。
public class BlockDetect {
// BlockDetectByPrinter
public static void start() {
Looper.getMainLooper().setMessageLogging(new Printer() {
private static final String START = ">>>>> Dispatching";
private static final String END = "<<<<< Finished";
@Override