forked from upstream-mirrors/OpenTracks
add onEnabled to reinitialize the widget after reboot
This commit is contained in:
@@ -82,15 +82,30 @@ public class TrackWidgetProvider extends AppWidgetProvider {
|
|||||||
|| context.getString(R.string.track_stopped_broadcast_action).equals(action)
|
|| context.getString(R.string.track_stopped_broadcast_action).equals(action)
|
||||||
|| context.getString(R.string.track_update_broadcast_action).equals(action)) {
|
|| context.getString(R.string.track_update_broadcast_action).equals(action)) {
|
||||||
long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L);
|
long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L);
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
updateAllWidgets(context, trackId);
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
}
|
||||||
new ComponentName(context, TrackWidgetProvider.class));
|
}
|
||||||
for (int appWidgetId : appWidgetIds) {
|
|
||||||
int size = ApiAdapterFactory.getApiAdapter()
|
@Override
|
||||||
.getAppWidgetSize(appWidgetManager, appWidgetId);
|
public void onEnabled(Context context) {
|
||||||
RemoteViews remoteViews = getRemoteViews(context, trackId, size);
|
// Need to update all widgets after phone reboot
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
updateAllWidgets(context, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates all widgets.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param trackId track id
|
||||||
|
*/
|
||||||
|
private void updateAllWidgets(Context context, long trackId) {
|
||||||
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
||||||
|
new ComponentName(context, TrackWidgetProvider.class));
|
||||||
|
for (int appWidgetId : appWidgetIds) {
|
||||||
|
int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
|
||||||
|
RemoteViews remoteViews = getRemoteViews(context, trackId, size);
|
||||||
|
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user