Android 开发小知识(持续更新)
2016-06-07 17:33
483 查看
一、显示一个随系统设置变化的时间(12小时制度下 中文 上午表示为上午、英文环境上午为 AM)
二、 扩大android 中View 的点击区域
1 设置padding 值
2 扩大响应区域(见下)
原理就是在view的onTouchEvent里面
三、获取CU
/**
* 高通芯片 通过反射获取CU,PTS,PTH,BSN参数
*
* @return
*/
public String getCU() {
try {
Class<?> systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method getMethod = systemPropertiesClass.getMethod("get", String.class);
Object object = new Object();
Object obj = getMethod.invoke(object, "ro.tct.curef");
return (obj == null ? "" : (String) obj);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
/** * 获取时间字串,时间随系统时间显示制和时区改变 * * @param context * @return */ public String getSystemTimeStr(Context context) { long now = System.currentTimeMillis(); String timeStr = ""; //判断是否是24小时制 SimpleDateFormat timeformat = null; if (DateFormat.is24HourFormat(context)) { timeformat = new SimpleDateFormat("HH:mm"); } else { timeformat = new SimpleDateFormat("h:mm a"); } //设置随时区变化 timeformat.setTimeZone(TimeZone.getDefault()); timeStr = timeformat.format(now); return timeStr; }时间模式字符串用来指定时间格式。在此模式中,所有的ASCII字母被保留为模式字母,定义如下:
字母 | 描述 | 示例 |
---|---|---|
G | 纪元标记 | AD |
y | 四位年份 | 2001 |
M | 月份 | July or 07 |
d | 一个月的日期 | 10 |
h | A.M./P.M. (1~12)格式小时 | 12 |
H | 一天中的小时 (0~23) | 22 |
m | 分钟数 | 30 |
s | 秒数 | 55 |
S | 微妙数 | 234 |
E | 星期几 | Tuesday |
D | 一年中的日子 | 360 |
F | 一个月中第几周的周几 | 2 (second Wed. in July) |
w | 一年中第几周 | 40 |
W | 一个月中第几周 | 1 |
a | A.M./P.M. 标记 | PM |
k | 一天中的小时(1~24) | 24 |
K | A.M./P.M. (0~11)格式小时 | 10 |
z | 时区 | Eastern Standard Time |
' | 文字定界符 | Delimiter |
" | 单引号 | ` |
1 设置padding 值
2 扩大响应区域(见下)
/** * 扩大View的触摸和点击响应范围,最大不超过其父View范围 * * @param view * @param top * @param bottom * @param left * @param right */ public static void expandViewTouchDelegate(final View view, final int top, final int bottom, final int left, final int right) { ((View) view.getParent()).post(new Runnable() { @Override public void run() { Rect bounds = new Rect(); view.setEnabled(true); view.getHitRect(bounds); bounds.top -= top; bounds.bottom += bottom; bounds.left -= left; bounds.right += right; TouchDelegate touchDelegate = new TouchDelegate(bounds, view); if (View.class.isInstance(view.getParent())) { ((View) view.getParent()).setTouchDelegate(touchDelegate); } } }); }恢复点击区域
/** * 还原View的触摸和点击响应范围,最小不小于View自身范围 * * @param view */ public static void restoreViewTouchDelegate(final View view) { ((View) view.getParent()).post(new Runnable() { @Override public void run() { Rect bounds = new Rect(); bounds.setEmpty(); TouchDelegate touchDelegate = new TouchDelegate(bounds, view); if (View.class.isInstance(view.getParent())) { ((View) view.getParent()).setTouchDelegate(touchDelegate); } } }); }
原理就是在view的onTouchEvent里面
三、获取CU
/**
* 高通芯片 通过反射获取CU,PTS,PTH,BSN参数
*
* @return
*/
public String getCU() {
try {
Class<?> systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method getMethod = systemPropertiesClass.getMethod("get", String.class);
Object object = new Object();
Object obj = getMethod.invoke(object, "ro.tct.curef");
return (obj == null ? "" : (String) obj);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories