1.DecimalFormat的用法:https://www.jianshu.com/p/b3699d73142e
2.Timer与TimerTask的真正原理&使用介绍:https://blog.csdn.net/xieyuooo/article/details/8607220
3.android中handler使用WeakReference防止内存泄露 https://blog.csdn.net/lanximu/article/details/40522367
4.android中invalidate()的使用小结 https://blog.csdn.net/carlwang100/article/details/19546313
5.颜色转换成int类型,其中第一个参数是context(有时候自定义函数想要传入int类型的颜色的时候可以用)
mLightColor = ContextCompat.getColor(mContext, R.color.date_picker_text_light);
6.判断字符串是否为空
TextUtils.isEmpty(text)
7.得到画笔定义的文字的的信息,fm.top + fm.bottom/2得到的是文字的一半高度,不是坐标,具体居中公式推导看下面网址算法,直接看最后部分
https://www.jianshu.com/p/8b97627b21c4
https://blog.csdn.net/u012551350/article/details/51361778
Paint.FontMetrics fm = mPaint.getFontMetrics();
fm.top + fm.bottom
在看文章之前需要先明白一些基本概念(注意view中y轴正半轴的向下的):
8.时间戳和字符串之间的相互转换
public class DateFormatUtils {
private static final String DATE_FORMAT_PATTERN_YMD = "yyyy-MM-dd";
private static final String DATE_FORMAT_PATTERN_YMD_HM = "yyyy-MM-dd HH:mm";
/**
* 时间戳转字符串
*
* @param timestamp 时间戳
* @param isPreciseTime 是否包含时分
* @return 格式化的日期字符串
*/
public static String long2Str(long timestamp, boolean isPreciseTime) {
return long2Str(timestamp, getFormatPattern(isPreciseTime));
}
private static String long2Str(long timestamp, String pattern) {
return new SimpleDateFormat(pattern, Locale.CHINA).format(new Date(timestamp));
}
/**
* 字符串转时间戳
*
* @param dateStr 日期字符串
* @param isPreciseTime 是否包含时分
* @return 时间戳
*/
public static long str2Long(String dateStr, boolean isPreciseTime) {//在这个方法里执行下一个方法(两个模式两个选择)
return str2Long(dateStr, getFormatPattern(isPreciseTime));
}
private static long str2Long(String dateStr, String pattern) {
try {
return new SimpleDateFormat(pattern, Locale.CHINA).parse(dateStr).getTime();
//第二个参数不管他照着填,这行代码是将str以patter的形式进行解析再用getTime得到需要的时间戳
} catch (Throwable ignored) {
}
return 0;
}
private static String getFormatPattern(boolean showSpecificTime) {
if (showSpecificTime) {
return DATE_FORMAT_PATTERN_YMD_HM;//显示年月日分秒的模式
} else {
return DATE_FORMAT_PATTERN_YMD;//限制年月日的模式,返回的是字符串格式
}
}
}