Weather APP: desktop clock witget, app desktop clock witget
Component development of desktop clock:
The process is as follows:
Demo: www.github.com/xufeifandj
Service + component + broadcast real-time background Update Time
(1) When a broadcast listener is started, the time for dynamically registering a broadcast to listen changes immediately after the service is started.
IntentFilter intentFilter = new IntentFilter ();
IntentFilter. addAction (Intent. ACTION_TIME_TICK); // time change
IntentFilter. addAction (Intent. ACTION_TIME_CHANGED );//
IntentFilter. addAction (Intent. ACTION_DATE_CHANGED); // modify the date.
IntentFilter. addAction (Intent. ACTION_TIMEZONE_CHANGED); // Time Zone Modification
This. getBaseContext (). registerReceiver (widgetsUpdateReceiver, intentFilter );
(2) When the broadcast listening time changes, you can update the component.
Class UpdateReceiver extends BroadcastReceiver {
@ Override
Public void onReceive (Context context, Intent intent ){
UpdateWidget ();
}
}
// Send a broadcast to update the component.
Public synchronized void updateWidget (){
SendBroadcast (new Intent ("com. android. FERRIS_UPDATE_WIDGET "));
}
(3) WeatherWidget_time inherited from AppWidgetProvider is actually a broadcast. We have registered some updated actions here.
// Update the component when it changes.
Public void onUpdate (Context context, AppWidgetManager appWidgetManager,
Int [] appWidgetIds ){
For (int I = 0; I <appWidgetIds. length; I ++ ){
RemoteViews updateView = lewaBuildUpdate (context, appWidgetIds [I], false, true, true );
AppWidgetManager. updateAppWidget (appWidgetIds [I], updateView );
}
Super. onUpdate (context, appWidgetManager, appWidgetIds );
}
@ Override
Public void onReceive (final Context context, Intent intent ){
If (intent. getAction (). equals (Intent. ACTION_BOOT_COMPLETED) {// start upon startup
// Start time backend service, dynamically register Broadcast
Intent service = new Intent (context, WidgetTimeService. class );
Context. startService (service );
UpdateTimeAlarm (context); // update the clock
} Else if (intent. getAction (). equals ("com. android. FERRIS_UPDATE_WIDGET") {// listen to time changes and update wiget
UpdateTimeAlarm (context );
}
Super. onReceive (context, intent );
}
(4) Update Time
Public synchronized void updateTimeAlarm (Context context ){
// AppWidgetManager appWidgetManger = AppWidgetManager
//. GetInstance (context );
// Int [] appIds = appWidgetManger. getAppWidgetIds (new ComponentName (
// Context, WeatherWidgetV5_time.class ));
//
ComponentName provider = new ComponentName (context, context. getPackageName () + ". WeatherWidget_time ");
AppWidgetManager gm = AppWidgetManager. getInstance (context );
Int [] appWidgetIds;
AppWidgetIds = gm. getAppWidgetIds (provider );
For (int I = 0; I <appWidgetIds. length; I ++) {// iterate to update
RemoteViews updateView = lewaBuildUpdate (context, appWidgetIds [I], false, true, true); // update the UI component. The parameters are date, week, and so on. Update?
Gm. updateAppWidget (appWidgetIds [I], updateView );
}
}
Mobile desktop clock weather app
Last time, Hunan Satellite TV introduced an APP called 'moji weather 'on the daily program. The response was good. You can try it.
Software that includes desktop clock, weather, and calendar
Yes. Go to the next multi-function desktop clock. I am now using the old ship ticket multi-function desktop clock. It is quite easy to use.