From 22afeddcbcb93876f65be4a90165b1a18f8b5e2a Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sun, 26 Nov 2017 17:25:24 -0500 Subject: [PATCH 1/2] Add activity for handling shortcut add requests --- app/src/main/AndroidManifest.xml | 10 +++ .../card_locker/CardShortcutConfigure.java | 83 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 3 files changed, 95 insertions(+) create mode 100644 app/src/main/java/protect/card_locker/CardShortcutConfigure.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f9c1e7a43..e80d163c3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -56,6 +56,16 @@ android:label="" android:configChanges="orientation|screenSize" android:theme="@style/AppTheme.NoActionBar"/> + + + + + + parent, View view, int position, long id) + { + Cursor selected = (Cursor) parent.getItemAtPosition(position); + LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(selected); + + Log.d(TAG, "Creating shortcut for card " + loyaltyCard.store + "," + loyaltyCard.id); + + Intent shortcutIntent = new Intent(CardShortcutConfigure.this, LoyaltyCardViewActivity.class); + shortcutIntent.setAction(Intent.ACTION_MAIN); + // Prevent instances of the view activity from piling up; if one exists let this + // one replace it. + shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); + Bundle bundle = new Bundle(); + bundle.putInt("id", loyaltyCard.id); + bundle.putBoolean("view", true); + shortcutIntent.putExtras(bundle); + + Parcelable icon = Intent.ShortcutIconResource.fromContext(CardShortcutConfigure.this, R.mipmap.ic_launcher); + Intent intent = new Intent(); + intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); + intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, loyaltyCard.store); + intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); + setResult(RESULT_OK, intent); + + finish(); + } + }); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 62c7039c2..d89b6bbc3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,6 +33,8 @@ Add Loyalty Card View Loyalty Card Scan Card\'s Barcode + Card Shortcut + There are no cards, add one first Image of card\'s barcode From 1673c0229a452ffe65e59d9e3fb8ca4fd59e1062 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Mon, 27 Nov 2017 14:50:18 -0500 Subject: [PATCH 2/2] Update strings around adding shortcuts Chrome uses the wording "Add to home screen" when adding a shortcut. https://developer.chrome.com/multidevice/android/installtohomescreen That sounds more direct that this app's wording. Updating to match. --- app/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d89b6bbc3..3d7c07dfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -8,7 +8,7 @@ Store Note - Add Shortcut + Add to Home Screen Card ID Barcode Type @@ -27,7 +27,7 @@ OK Copy ID to clipboard Send… - Added shortcut + Added to Home Screen Edit Loyalty Card Add Loyalty Card