forked from upstream-mirrors/OpenTracks
Update widget on software update.
This commit is contained in:
+1
-1
@@ -86,7 +86,7 @@ public class TrackWidgetConfigActivity extends Activity {
|
|||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(
|
||||||
TrackWidgetConfigActivity.this);
|
TrackWidgetConfigActivity.this);
|
||||||
TrackWidgetProvider.updateAppWidget(
|
TrackWidgetProvider.updateAppWidget(
|
||||||
TrackWidgetConfigActivity.this, appWidgetManager, appWidgetId);
|
TrackWidgetConfigActivity.this, appWidgetManager, appWidgetId, -1L);
|
||||||
PreferencesUtils.setInt(TrackWidgetConfigActivity.this, R.string.track_widget_item1,
|
PreferencesUtils.setInt(TrackWidgetConfigActivity.this, R.string.track_widget_item1,
|
||||||
item1.getSelectedItemPosition());
|
item1.getSelectedItemPosition());
|
||||||
PreferencesUtils.setInt(TrackWidgetConfigActivity.this, R.string.track_widget_item2,
|
PreferencesUtils.setInt(TrackWidgetConfigActivity.this, R.string.track_widget_item2,
|
||||||
|
|||||||
@@ -89,23 +89,15 @@ public class TrackWidgetProvider extends AppWidgetProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnabled(Context context) {
|
public void onEnabled(Context context) {
|
||||||
super.onEnabled(context);
|
super.onEnabled(context);
|
||||||
// Need to update all widgets after phone reboot
|
// Need to update all app widgets after phone reboot
|
||||||
updateAllAppWidgets(context, -1L);
|
updateAllAppWidgets(context, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Updates all app widgets.
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
*
|
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
||||||
* @param context the context
|
// Need to update all app widgets after software update
|
||||||
* @param trackId track id
|
updateAllAppWidgets(context, -1L);
|
||||||
*/
|
|
||||||
private void updateAllAppWidgets(Context context, long trackId) {
|
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
|
||||||
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
|
||||||
new ComponentName(context, TrackWidgetProvider.class));
|
|
||||||
for (int appWidgetId : appWidgetIds) {
|
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(16)
|
@TargetApi(16)
|
||||||
@@ -135,7 +127,7 @@ public class TrackWidgetProvider extends AppWidgetProvider {
|
|||||||
int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
|
int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
|
||||||
if (size != newSize) {
|
if (size != newSize) {
|
||||||
ApiAdapterFactory.getApiAdapter().setAppWidgetSize(appWidgetManager, appWidgetId, newSize);
|
ApiAdapterFactory.getApiAdapter().setAppWidgetSize(appWidgetManager, appWidgetId, newSize);
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId);
|
updateAppWidget(context, appWidgetManager, appWidgetId, -1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,14 +138,30 @@ public class TrackWidgetProvider extends AppWidgetProvider {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
* @param appWidgetManager the app widget manager
|
* @param appWidgetManager the app widget manager
|
||||||
* @param appWidgetId the app widget id
|
* @param appWidgetId the app widget id
|
||||||
|
* @param trackId the track id. -1L to not specify one
|
||||||
*/
|
*/
|
||||||
public static void updateAppWidget(
|
public static void updateAppWidget(
|
||||||
Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
|
Context context, AppWidgetManager appWidgetManager, int appWidgetId, long trackId) {
|
||||||
int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
|
int size = ApiAdapterFactory.getApiAdapter().getAppWidgetSize(appWidgetManager, appWidgetId);
|
||||||
RemoteViews remoteViews = getRemoteViews(context, -1L, size);
|
RemoteViews remoteViews = getRemoteViews(context, trackId, size);
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates all app widgets.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
* @param trackId track id
|
||||||
|
*/
|
||||||
|
private static void updateAllAppWidgets(Context context, long trackId) {
|
||||||
|
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
|
||||||
|
new ComponentName(context, TrackWidgetProvider.class));
|
||||||
|
for (int appWidgetId : appWidgetIds) {
|
||||||
|
updateAppWidget(context, appWidgetManager, appWidgetId, trackId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the remote views.
|
* Gets the remote views.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user