Skip to content

Instantly share code, notes, and snippets.

@wyon
wyon / URLUtil.java
Last active September 21, 2017 08:02
url:String,拼接query:String
public static void main(String[] args) throws ParseException {
String query = "hello=world";
List<String> list = new ArrayList<>();
String url;
url = "http://www.baidu.com"; // no ?, no #
list.add(url); url = "http://www.baidu.com?"; // has ?, no # : just ?
list.add(url); url = "http://www.baidu.com?&"; // has ?, no # : ?&
list.add(url); url = "http://www.baidu.com?query"; // has ?, no # : ?query
list.add(url); url = "http://www.baidu.com?query&"; // has ?, no # : ?query&
list.add(url); url = "http://www.baidu.com#e"; // no ?, has # : #e
@wyon
wyon / WeekParse.java
Created September 21, 2017 07:00
获取一段时间之间,所有的周
public static List<WeekBean> parseNatureWeek(long startMs, long endMs) {
if (startMs > endMs) {
return Collections.emptyList();
}
Calendar calendar = Calendar.getInstance();
// end date
calendar.setTimeInMillis(endMs);
clearTime(calendar);
endMs = calendar.getTimeInMillis();
@wyon
wyon / MultiXLCall.java
Created September 11, 2017 12:09
MultiXLCall
public class MultiXLCall<R> {
@SuppressWarnings("unchecked")
public static <T1, T2, R> MultiXLCall<R> wrap(@NonNull XLCall<T1> call1, @NonNull XLCall<T2> call2, @NonNull Zip2<T1, T2, R> zip) {
return new MultiXLCall<>(fromZip2(zip), new XLCall[]{call1, call2});
}
@SuppressWarnings("unchecked")
public static <T1, T2, T3, R> MultiXLCall<R> wrap(@NonNull XLCall<T1> call1, @NonNull XLCall<T2> call2, @NonNull XLCall<T3> call3, @NonNull Zip3<T1, T2, T3, R> zip) {
return new MultiXLCall<>(fromZip3(zip), new XLCall[]{call1, call2, call3});
@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
@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 / 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 / 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 / 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 / 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 / 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;
}