package com.sun.clock;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import com.sun.clockwidget.R;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.RemoteViews;
public class ClockWidget extends AppWidgetProvider {
public static final String TAG = "DigitalClockWidget";
private Context mContext;
private AppWidgetManager mAppWigetManager;
private Calendar cal;
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 0x1) {
cal = Calendar.getInstance();
RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.clock);
ContentResolver cv = mContext.getContentResolver();
String strTimeFormat = android.provider.Settings.System.getString(cv,
android.provider.Settings.System.TIME_12_24);
if(strTimeFormat.equals("24"))
{
if(cal.get(Calendar.AM_PM)==1){
remoteViews.setTextViewText(R.id.hour, cal.get(Calendar.HOUR)+12+"");
}else{
remoteViews.setTextViewText(R.id.hour, cal.get(Calendar.HOUR)+"");
}
}else{
remoteViews.setTextViewText(R.id.hour, cal.get(Calendar.HOUR)+"");
}
remoteViews.setTextViewText(R.id.minute, cal.get(Calendar.MINUTE)+"");
remoteViews.setTextViewText(R.id.second, cal.get(Calendar.SECOND)+"");
ComponentName componentName = new ComponentName(mContext, ClockWidget.class);
mAppWigetManager.updateAppWidget(componentName, remoteViews);
}
}
};
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "...onReceive");
super.onReceive(context, intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Log.i(TAG, "...onUpdate");
this.mContext = context;
this.mAppWigetManager = appWidgetManager;
new Timer().schedule(new TimerTask() {
@Override
public void run() {
handler.sendEmptyMessage(0x1);
}
}, 0, 1000);
//super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
Log.i(TAG, "...onDeleted");
super.onDeleted(context, appWidgetIds);
}
@Override
public void onEnabled(Context context) {
Log.i(TAG, "...onEnabled");
super.onEnabled(context);
}
@Override
public void onDisabled(Context context) {
Log.i(TAG, "...onDisabled");
super.onDisabled(context);
}
}

释寒
- 粉丝: 3
- 资源: 9
最新资源
- 【毕业设计-java】springboot-vue基于工程教育认证的计算机课程管理平台源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue基于用户兴趣的影视推荐系统设计与实现源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue基于微服务的分布式新生报到系统源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue机动车号牌管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
- Maven的Springboot搭建初始项目
- 机器学习_Python_JupyterNotebooks_教_1741402036.zip
- 数据科学_Python基础_数据分析_学习资源.zip
- 人工智能_Python学习历程_代码仓库_教育记录_1741402216.zip
- 【毕业设计-java】springboot-vue基于智能推荐的卫生健康系统源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue疾病防控综合系统的设计与实现源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue计算机学院校友网源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue家具销售平台实现源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue家居日用小百货交易网站实现源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue家具销售电商平台实现源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue健身房管理系统源码(完整前后端+mysql+说明文档+LunW).zip
- 【毕业设计-java】springboot-vue家政服务平台实现源码(完整前后端+mysql+说明文档+LunW).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
- 3
前往页