Android Digital Clock Demo beta1

  • a3_260034
    了解作者
  • 207.1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-19 01:41
    上传日期
Android Digital Clock Demo 任务: 1.完善布局,兼容各种分辨率和横竖屏切换 2.增加日期和星期信息 3.增加天气信息
AmyClock.rar
内容介绍
package us.eibox.android.amyclock; import java.util.Calendar; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.text.format.DateFormat; import android.util.Log; import android.widget.RemoteViews; public class MainAppWidgetProvider extends AppWidgetProvider { private static final String TAG = "us.eibox.android.amyclock.provider"; private static RemoteViews mRemoteViews; private static AppWidgetManager mAppWidgetManager; private static String str_time; private static Calendar mCalendar; private final static String M12 = "h:mm aa"; private final static String M24 = "k:mm"; @Override public void onEnabled(Context context) { Log.d(TAG, "zhangchi app widget initialled..."); super.onEnabled(context); Context app_ctx = context.getApplicationContext(); app_ctx.registerReceiver(this, new IntentFilter(Intent.ACTION_TIME_TICK)); app_ctx.registerReceiver(this, new IntentFilter(Intent.ACTION_TIME_CHANGED)); app_ctx.registerReceiver(this, new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED)); mAppWidgetManager = AppWidgetManager.getInstance(context); //service enabled // service = new Intent("us.eibox.android.widgetUpdateService"); // context.startService(service); } /** * @return true if clock is set to 24-hour mode */ static boolean get24HourMode(Context context) { return android.text.format.DateFormat.is24HourFormat(context); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); // initial RemoteViews mRemoteViews = new RemoteViews(context.getPackageName(), R.layout.amy_widget_main); // setting time format mCalendar = Calendar.getInstance(); String format = get24HourMode(context) ? M24 : M12; str_time = (mCalendar == null) ? "" : (String)DateFormat.format(format, mCalendar); Log.d(TAG, "str_time=" + str_time + ", mCalendar.M1=" + mCalendar.getTime().getMinutes()); // update widget performent mRemoteViews.setTextViewText(R.id.time, str_time); mAppWidgetManager.updateAppWidget(new ComponentName(context, MainAppWidgetProvider.class), mRemoteViews); } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); Log.d(TAG, "str_time=" + str_time + ", mCalendar.M2=" + mCalendar.getTime().getMinutes()); } @Override public void onDeleted(Context context, int[] appWidgetIds) { super.onDeleted(context, appWidgetIds); } @Override public void onDisabled(Context context) { super.onDisabled(context); } }
评论
    相关推荐