Android 开发小知识(持续更新)

一、显示一个随系统设置变化的时间(12小时制度下 中文 上午表示为上午、英文环境上午为 AM)

    /**
     * 获取时间字串,时间随系统时间显示制和时区改变
     * 
     * @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
" 单引号 `

二、 扩大android 中View 的点击区域

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 "";
        }
    }



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值