file.isDirectory() 检查表示此抽象路径名的文件是否是一个目录
file.isFile() 检查表示此抽象路径名的文件是否是一个正常的文件
file.getName() 方法返回的路径名的名称序列的最后一个名字
file.createNewFile()方法自动创建此抽象路径名的新文件
6.0以下相机设置界面关闭时(因为6.0以下无法判断用户是否禁止了拍照功能),所需判断; 6.0以上他法
public boolean cameraIsCanUse() { boolean isCanUse = true; Camera mCamera = null; try { mCamera = Camera.open(); Camera.Parameters mParameters = mCamera.getParameters(); //针对魅族手机 mCamera.setParameters(mParameters); } catch (Exception e) { isCanUse = false; } if (mCamera != null) { try { mCamera.release(); } catch (Exception e) { e.printStackTrace(); return isCanUse; } } return isCanUse; }
System.out.println();因为out是流,没有用缓存,是一个一个的读出,所以尽量用logger或其他的。
markman android切图比较好的测量工具
Root Explorer 数据库查看工具
配置fabric-crashlytics教程(App崩溃,直接将错误日志返给后台)
http://www.mamicode.com/info-detail-470447.html
https://github.com/jarlen/PhotoEditDemo (自定义相机)
Math.min(int a, int b) 返回两个int值中较小的一个。
自定义View控件:
http://blog.csdn.net/harvic880925/article/list/1
//自定义View的属性解释
http://www.imooc.com/video/10768
//理解了xml元素的加载
http://www.imooc.com/learn/247
//五子棋项目,更进一步的了解
http://www.imooc.com/learn/641
=================================================================================
有时,Android系统控件无法满足我们的需求,因此有必要自定义View。具体方法参见官方开发文档:http://developer.android.com/guide/topics/ui/custom-components.html
一般来说,自定义控件都会去重写View的onMeasure方法,因为该方法指定该控件在屏幕上的大小。
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
onMeasure传入的两个参数是由上一层控件传入的大小,有多种情况,重写该方法时需要对计算控件的实际大小,然后调用setMeasuredDimension(int, int)设置实际大小。
onMeasure传入的widthMeasureSpec和heightMeasureSpec不是一般的尺寸数值,而是将模式和尺寸组合在一起的数值。我们需要通过int mode = MeasureSpec.getMode(widthMeasureSpec)得到模式,用int size = MeasureSpec.getSize(widthMeasureSpec)得到尺寸。
onDraw 里面的super.onDraw(canvas)可以删掉,因为父类中的onDraw没做任何操作。(极客学院http://www.jikexueyuan.com/course/1748_1.html又讲)
mode共有三种情况,取值分别为MeasureSpec.UNSPECIFIED, MeasureSpec.EXACTLY, MeasureSpec.AT_MOST。
MeasureSpec.EXACTLY是精确尺寸,当我们将控件的layout_width或layout_height指定为具体数值时如andorid:layout_width="50dip",或者为FILL_PARENT是,都是控件大小已经确定的情况,都是精确尺寸。
MeasureSpec.AT_MOST是最大尺寸,当控件的layout_width或layout_height指定为WRAP_CONTENT时,控件大小一般随着控件的子空间或内容进行变化,此时控件尺寸只要不超过父控件允许的最大尺寸即可。因此,此时的mode是AT_MOST,size给出了父控件允许的最大尺寸。
MeasureSpec.UNSPECIFIED是未指定尺寸,这种情况不多,一般都是父控件是AdapterView,通过measure方法传入的模式。
(慕课网:此属性一般于ScrollView或ListView当中去)
因此,在重写onMeasure方法时要根据模式不同进行尺寸计算。下面代码就是一种比较典型的方式:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getMeasuredLength(widthMeasureSpec, true), getMeasuredLength(heightMeasureSpec, false));
}
private int getMeasuredLength(int length, boolean isWidth) {
int specMode = MeasureSpec.getMode(length);
int specSize = MeasureSpec.getSize(length);
int size;
int padding = isWidth ? getPaddingLeft() + getPaddingRight()
: getPaddingTop() + getPaddingBottom();
if (specMode == MeasureSpec.EXACTLY) {
size = specSize;
} else {
size = isWidth ? padding + mWave.length / 4 : DEFAULT_HEIGHT
+ padding;
if (specMode == MeasureSpec.AT_MOST) {
size = Math.min(size, specSize);
}
}
return size;
}
1. ThreadLocalRandom
在多线程下会产生相同的随机数,需要调用 ThreadLocalRandom.current()
方法。
2. java.util.random
产生的实例来产生随机数是线程安全的,random
使用 CAS 操作保证每次只有一个线程可以获取并更新 seed,失败的线程则需要自旋重试。