From 05e213b0a8d7bcf7d892a37759a36090cc930f7d Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Tue, 18 Nov 2014 04:57:01 +0100 Subject: [PATCH] Removing useless code --- .../information/widget/WidgetIntentService.java | 14 ----- .../weather/information/widget/WidgetProvider.java | 62 +++------------------- 2 files changed, 6 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java index 5497921..b9bbd44 100644 --- a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java +++ b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java @@ -259,7 +259,6 @@ public class WidgetIntentService extends IntentService { final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - // resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK ); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/") ,String.valueOf(appWidgetId)); resultIntent.setData(data); @@ -275,12 +274,6 @@ public class WidgetIntentService extends IntentService { PendingIntent.FLAG_UPDATE_CURRENT ); remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); -// final PendingIntent resultPendingIntent = PendingIntent.getActivity( -// this.getApplicationContext(), -// 0, -// resultIntent, -// PendingIntent.FLAG_UPDATE_CURRENT); -// remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); return remoteView; } @@ -292,7 +285,6 @@ public class WidgetIntentService extends IntentService { final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class); resultIntent.putExtra("actionFromUser", true); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); -// resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK ); // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/") ,String.valueOf(appWidgetId)); resultIntent.setData(data); @@ -308,12 +300,6 @@ public class WidgetIntentService extends IntentService { PendingIntent.FLAG_UPDATE_CURRENT ); remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent); -// final PendingIntent resultPendingIntent = PendingIntent.getActivity( -// this.getApplicationContext(), -// 0, -// resultIntent, -// PendingIntent.FLAG_UPDATE_CURRENT); -// remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent); return remoteView; } diff --git a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetProvider.java b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetProvider.java index c22f01c..acba494 100644 --- a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetProvider.java +++ b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetProvider.java @@ -3,11 +3,9 @@ package name.gumartinm.weather.information.widget; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; -import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.os.Bundle; public class WidgetProvider extends AppWidgetProvider { @@ -39,15 +37,11 @@ public class WidgetProvider extends AppWidgetProvider { } public static void updateAppWidget(final Context context, final int appWidgetId) { - final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext()); - - updateAppWidget(context, appWidgetManager, appWidgetId); - } - public static void refreshAppWidget(final Context context, final int appWidgetId) { - final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context.getApplicationContext()); - - refreshAppWidget(context.getApplicationContext(), appWidgetManager, appWidgetId); + final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class); + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); + intent.putExtra("refreshAppWidget", false); + context.startService(intent); } public static void refreshAllAppWidgets(final Context context) { @@ -56,59 +50,15 @@ public class WidgetProvider extends AppWidgetProvider { final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widgets); for (final int appWidgetId : appWidgetIds) { - refreshAppWidget(context.getApplicationContext(), appWidgetManager, appWidgetId); + refreshAppWidget(context.getApplicationContext(), appWidgetId); } } - private static void refreshAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) { - - int widgetId; - Bundle myOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); - - // Get the value of OPTION_APPWIDGET_HOST_CATEGORY - int category = myOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1); - - // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget - boolean isKeyguard = category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; - - // Once you know the widget's category, you can optionally load a different base layout, set different - // properties, and so on. For example: - //int baseLayout = isKeyguard ? R.layout.keyguard_widget_layout : R.layout.widget_layout; - - // Construct the RemoteViews object. It takes the package name (in our case, it's our - // package, but it needs this because on the other side it's the widget host inflating - // the layout from our package). - //final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget); + public static void refreshAppWidget(final Context context, final int appWidgetId) { final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra("refreshAppWidget", true); context.startService(intent); } - - private static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) { - - int widgetId; - Bundle myOptions = appWidgetManager.getAppWidgetOptions(appWidgetId); - - // Get the value of OPTION_APPWIDGET_HOST_CATEGORY - int category = myOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, -1); - - // If the value is WIDGET_CATEGORY_KEYGUARD, it's a lockscreen widget - boolean isKeyguard = category == AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD; - - // Once you know the widget's category, you can optionally load a different base layout, set different - // properties, and so on. For example: - //int baseLayout = isKeyguard ? R.layout.keyguard_widget_layout : R.layout.widget_layout; - - // Construct the RemoteViews object. It takes the package name (in our case, it's our - // package, but it needs this because on the other side it's the widget host inflating - // the layout from our package). - //final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget); - - final Intent intent = new Intent(context.getApplicationContext(), WidgetIntentService.class); - intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); - intent.putExtra("refreshAppWidget", false); - context.startService(intent); - } } -- 2.1.4