From 0df411ee963350065402221bbd3b4e535122a405 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sat, 25 Nov 2017 00:13:55 -0500 Subject: [PATCH] Revert "Add widget for directly opening specific card" This is largely unneeded, as shortcuts are directly supported now, and the widget was a hacky replacement for shortcuts. This reverts commit ebe6139a64cc54e092165e4c5cb2f712d215c675. --- app/src/main/AndroidManifest.xml | 14 -- .../card_locker/LoyaltyCardCursorAdapter.java | 2 +- .../appwidget/CardAppWidgetConfigure.java | 130 ------------------ .../appwidget/CardAppWidgetProvider.java | 79 ----------- .../main/res/layout/appwidget_provider.xml | 23 ---- app/src/main/res/values/strings.xml | 1 - app/src/main/res/xml/appwidget_provider.xml | 9 -- 7 files changed, 1 insertion(+), 257 deletions(-) delete mode 100644 app/src/main/java/protect/card_locker/appwidget/CardAppWidgetConfigure.java delete mode 100644 app/src/main/java/protect/card_locker/appwidget/CardAppWidgetProvider.java delete mode 100644 app/src/main/res/layout/appwidget_provider.xml delete mode 100644 app/src/main/res/xml/appwidget_provider.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4b7089152..f9c1e7a43 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,20 +56,6 @@ android:label="" android:configChanges="orientation|screenSize" android:theme="@style/AppTheme.NoActionBar"/> - - - - - - - - - - - - - parent, View view, int position, long id) - { - Context context = CardAppWidgetConfigure.this; - Cursor selected = (Cursor) parent.getItemAtPosition(position); - LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(selected); - - Log.d(TAG, "Saving card " + loyaltyCard.store + "," + loyaltyCard.id + " at " + appWidgetId_); - - // Save the association of the card to the widget - saveIdPref(context, appWidgetId_, loyaltyCard.id); - - // Push widget update to surface with newly set association - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - CardAppWidgetProvider.updateAppWidget(context, appWidgetManager, appWidgetId_); - - // Make sure we pass back the original appWidgetId - Intent resultValue = new Intent(); - resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId_); - setResult(RESULT_OK, resultValue); - finish(); - } - }); - } - - // Write the prefix to the SharedPreferences object for this widget - static void saveIdPref(Context context, int appWidgetId, int id) - { - SharedPreferences.Editor prefs = context.getSharedPreferences(PREFS_NAME, 0).edit(); - prefs.putInt(PREF_PREFIX_KEY + appWidgetId, id); - prefs.commit(); - } - - // Read the prefix from the SharedPreferences object for this widget. - // If there is no preference saved, get the default from a resource - static Integer loadIdPref(Context context, int appWidgetId) - { - SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0); - int id = prefs.getInt(PREF_PREFIX_KEY + appWidgetId, -1); - if(id >= 0) - { - return id; - } - else - { - return null; - } - } -} diff --git a/app/src/main/java/protect/card_locker/appwidget/CardAppWidgetProvider.java b/app/src/main/java/protect/card_locker/appwidget/CardAppWidgetProvider.java deleted file mode 100644 index 162e6ff90..000000000 --- a/app/src/main/java/protect/card_locker/appwidget/CardAppWidgetProvider.java +++ /dev/null @@ -1,79 +0,0 @@ -package protect.card_locker.appwidget; - -import android.app.PendingIntent; -import android.appwidget.AppWidgetManager; -import android.appwidget.AppWidgetProvider; -import android.content.Context; -import android.content.Intent; - -import android.os.Bundle; -import android.util.Log; -import android.widget.RemoteViews; - -import protect.card_locker.DBHelper; -import protect.card_locker.LoyaltyCard; -import protect.card_locker.LoyaltyCardViewActivity; -import protect.card_locker.R; - -public class CardAppWidgetProvider extends AppWidgetProvider -{ - private static final String TAG = "LoyaltyCardLocker"; - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) - { - Log.d(TAG, "CardAppWidgetProvider onUpdate"); - // For each widget that needs an update, get the text that we should display: - // - Create a RemoteViews object for it - // - Set the text in the RemoteViews object - // - Tell the AppWidgetManager to show that views object for the widget. - for (int appWidgetId : appWidgetIds) - { - updateAppWidget(context, appWidgetManager, appWidgetId); - } - } - - static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) - { - Log.d(TAG, "updateAppWidget appWidgetId=" + appWidgetId); - - LoyaltyCard card = null; - DBHelper db = new DBHelper(context); - - Integer id = CardAppWidgetConfigure.loadIdPref(context, appWidgetId); - if(id != null) - { - Log.d(TAG, "updateAppWidget Retrieved id " + id); - card = db.getLoyaltyCard(id); - } - - if(card != null) - { - Log.d(TAG, "updateAppWidget Updating widget " + appWidgetId + " to load " + card.store); - - // 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). - RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); - views.setTextViewText(R.id.title, card.store); - - // Launch the view activity when clicked - Intent intent = new Intent(context, LoyaltyCardViewActivity.class); - Bundle extras = new Bundle(); - extras.putInt("id", id); - extras.putBoolean("view", true); - intent.putExtras(extras); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); - views.setOnClickPendingIntent(R.id.widget, pendingIntent); - - // Tell the widget manager - appWidgetManager.updateAppWidget(appWidgetId, views); - } - else - { - Log.d(TAG, "updateAppWidget, no card ID associated with widget " + appWidgetId - + ", ignoring update"); - } - } -} diff --git a/app/src/main/res/layout/appwidget_provider.xml b/app/src/main/res/layout/appwidget_provider.xml deleted file mode 100644 index 1c8c550e4..000000000 --- a/app/src/main/res/layout/appwidget_provider.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f5e1d29f..62c7039c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,7 +33,6 @@ Add Loyalty Card View Loyalty Card Scan Card\'s Barcode - Select Card Image of card\'s barcode diff --git a/app/src/main/res/xml/appwidget_provider.xml b/app/src/main/res/xml/appwidget_provider.xml deleted file mode 100644 index 24c3b655d..000000000 --- a/app/src/main/res/xml/appwidget_provider.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - \ No newline at end of file