时间控制VIEW
来源:互联网 发布:手机淘宝我是商家消失 编辑:程序博客网 时间:2024/06/06 18:27
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Handler;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.widget.DigitalClock;
public class TimeClock extends DigitalClock {
private Calendar calender;
private Runnable runnable;
private Handler handler;
private boolean mt = false;
String timeStr = "";
private ContentResolver cr;
public TimeClock(Context context) {
super(context);
// TODO Auto-generated constructor stub
initClock(context);
}
public TimeClock(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
initClock(context);
}
private void initClock(Context context) {
cr = getContext().getContentResolver();
if (calender == null) {
calender = Calendar.getInstance();
}
}
@Override
protected void onAttachedToWindow() {
// TODO Auto-generated method stub
super.onAttachedToWindow();
mt = false;
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (mt)
return;
calender = Calendar.getInstance(TimeZone.getDefault());
calender.setTimeInMillis(System.currentTimeMillis());
String str = android.provider.Settings.System.getString(cr, android.provider.Settings.System.TIME_12_24);
if (str == null || str.equals("")) {
str = "24";
}
str = "24";
if (str.equals("24")) {
timeStr = new SimpleDateFormat("HH:mm").format(calender.getTime());
} else {
timeStr = new SimpleDateFormat("hh:mm").format(calender.getTime());
}
setText(timeStr);
invalidate();
long now = SystemClock.uptimeMillis();
long next = now + (1000 - now % 1000);
handler.postAtTime(runnable, next);
}
};
runnable.run();
}
@Override
protected void onDetachedFromWindow() {
// TODO Auto-generated method stub
super.onDetachedFromWindow();
mt = true;
}
}
import java.util.Calendar;
import java.util.TimeZone;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Handler;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.widget.DigitalClock;
public class TimeClock extends DigitalClock {
private Calendar calender;
private Runnable runnable;
private Handler handler;
private boolean mt = false;
String timeStr = "";
private ContentResolver cr;
public TimeClock(Context context) {
super(context);
// TODO Auto-generated constructor stub
initClock(context);
}
public TimeClock(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
initClock(context);
}
private void initClock(Context context) {
cr = getContext().getContentResolver();
if (calender == null) {
calender = Calendar.getInstance();
}
}
@Override
protected void onAttachedToWindow() {
// TODO Auto-generated method stub
super.onAttachedToWindow();
mt = false;
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (mt)
return;
calender = Calendar.getInstance(TimeZone.getDefault());
calender.setTimeInMillis(System.currentTimeMillis());
String str = android.provider.Settings.System.getString(cr, android.provider.Settings.System.TIME_12_24);
if (str == null || str.equals("")) {
str = "24";
}
str = "24";
if (str.equals("24")) {
timeStr = new SimpleDateFormat("HH:mm").format(calender.getTime());
} else {
timeStr = new SimpleDateFormat("hh:mm").format(calender.getTime());
}
setText(timeStr);
invalidate();
long now = SystemClock.uptimeMillis();
long next = now + (1000 - now % 1000);
handler.postAtTime(runnable, next);
}
};
runnable.run();
}
@Override
protected void onDetachedFromWindow() {
// TODO Auto-generated method stub
super.onDetachedFromWindow();
mt = true;
}
}
0 0
- 时间控制VIEW
- 精确控制自定义view动画的时间
- 时间控制
- 代码控制UI,View
- view 时间轴
- view时间传递机制
- 时间控制模块
- CIO之时间控制
- 几个时间控制函数
- session过期时间控制
- 关于libevent时间控制
- TIVOLI 时间控制测试
- 控制远程连接时间
- cocos2d animation 时间控制
- AS时间控制类
- 控制到期时间
- Javascript 时间控制
- 控制网站到期时间
- 社説 20150302 民主党大会 見えない岡田代表の再建戦略
- T440P win2008R2 感觉卡,像是硬件加速没打开
- verilog中的timescale
- 五种开源协议的比较(BSD, Apache, GPL, LGPL, MIT)
- 社説 20150302 原発の廃棄物 処分地選定で政府は前に出よ
- 时间控制VIEW
- matlab中使用libsvm
- app 名称 iOS
- Quick-Cocos2d-x初学者游戏教程(三)
- 2015年值得关注的几个WEB技术
- UITextView的使用详解
- html5介绍
- java main函数
- android -- 蓝牙 bluetooth (一) 入门