Compare commits

...

8 Commits
v0.15 ... v0.16

Author SHA1 Message Date
Branden Archer
7eeb87578f Merge pull request #164 from brarcher/pre-v0.16
Update for v0.16
2017-11-29 20:23:57 -05:00
Branden Archer
badba551d0 Update CHANGELOG 2017-11-29 20:18:12 -05:00
Branden Archer
49abf8a918 Update for v0.16 2017-11-29 20:15:10 -05:00
Branden Archer
5fba338223 Merge pull request #163 from brarcher/shortcut
Remove support for adding shortcuts from within the app
2017-11-29 20:12:25 -05:00
Branden Archer
388a0723dc Remove support for adding shortcuts from within the app
The preferred way to create a shortcut is through the launcher.
Although it is possible for an app to create shortcuts, there is
concern that allowing the app to do so may not be desirable
due to potentials for abuse.

As there is support now for adding shortcuts through the launcher,
this app do not need to also support creating them itself.
2017-11-29 19:03:34 -05:00
Branden Archer
e14da63d06 Merge pull request #161 from brarcher/add-shortcuts-from-launcher
Add shortcuts from launcher
2017-11-27 14:56:44 -05:00
Branden Archer
1673c0229a 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.
2017-11-27 14:50:18 -05:00
Branden Archer
22afeddcbc Add activity for handling shortcut add requests 2017-11-26 20:50:15 -05:00
9 changed files with 105 additions and 190 deletions

View File

@@ -1,3 +1,9 @@
## v0.16 (2017-11-29)
Changes:
- Add support for adding loyalty card shortcuts from the launcher/homescreen. (https://github.com/brarcher/loyalty-card-locker/pull/161)
- Remove support for adding loyalty card shortcuts from the app itself. This removes the need for the shortcut permission. (https://github.com/brarcher/loyalty-card-locker/pull/163)
## v0.15 (2017-11-25)
Changes:

View File

@@ -14,8 +14,8 @@ android {
applicationId "protect.card_locker"
minSdkVersion 17
targetSdkVersion 25
versionCode 16
versionName "0.15"
versionCode 17
versionName "0.16"
}
buildTypes {
release {

View File

@@ -8,8 +8,6 @@
android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-feature
android:name="android.hardware.camera"
@@ -56,6 +54,16 @@
android:label=""
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name=".CardShortcutConfigure"
android:label="@string/cardShortcut"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"

View File

@@ -0,0 +1,83 @@
package protect.card_locker;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
/**
* The configuration screen for creating a shortcut.
*/
public class CardShortcutConfigure extends AppCompatActivity
{
static final String TAG = "LoyaltyCardLocker";
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
// Set the result to CANCELED. This will cause nothing to happen if the
// aback button is pressed.
setResult(RESULT_CANCELED);
setContentView(R.layout.main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setVisibility(View.GONE);
final DBHelper db = new DBHelper(this);
// If there are no cards, bail
if(db.getLoyaltyCardCount() == 0)
{
Toast.makeText(this, R.string.noCardsMessage, Toast.LENGTH_LONG).show();
finish();
}
final ListView cardList = (ListView) findViewById(R.id.list);
cardList.setVisibility(View.VISIBLE);
Cursor cardCursor = db.getLoyaltyCardCursor();
final LoyaltyCardCursorAdapter adapter = new LoyaltyCardCursorAdapter(this, cardCursor);
cardList.setAdapter(adapter);
cardList.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> 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();
}
});
}
}

View File

@@ -43,9 +43,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
TextView storeFieldView;
EditText noteFieldEdit;
TextView noteFieldView;
CheckBox shortcutCheckbox;
View shortcutBorder;
View shortcutTablerow;
TextView cardIdFieldView;
View cardIdDivider;
View cardIdTableRow;
@@ -99,9 +96,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
storeFieldView = (TextView) findViewById(R.id.storeNameView);
noteFieldEdit = (EditText) findViewById(R.id.noteEdit);
noteFieldView = (TextView) findViewById(R.id.noteView);
shortcutCheckbox = (CheckBox) findViewById(R.id.shortcutCheckbox);
shortcutBorder = findViewById(R.id.shortcutBorder);
shortcutTablerow = findViewById(R.id.shortcutTablerow);
cardIdFieldView = (TextView) findViewById(R.id.cardIdView);
cardIdDivider = findViewById(R.id.cardIdDivider);
cardIdTableRow = findViewById(R.id.cardIdTableRow);
@@ -206,9 +200,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
noteFieldView.setVisibility(View.GONE);
}
shortcutBorder.setVisibility(viewLoyaltyCard ? View.GONE : View.VISIBLE);
shortcutTablerow.setVisibility(viewLoyaltyCard ? View.GONE : View.VISIBLE);
if(cardIdFieldView.getText().length() > 0 && barcodeTypeField.getText().length() > 0)
{
String formatString = barcodeTypeField.getText().toString();
@@ -302,7 +293,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
{
String store = storeFieldEdit.getText().toString();
String note = noteFieldEdit.getText().toString();
boolean shouldAddShortcut = shortcutCheckbox.isChecked();
String cardId = cardIdFieldView.getText().toString();
String barcodeType = barcodeTypeField.getText().toString();
@@ -328,39 +318,9 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType);
}
if(shouldAddShortcut)
{
addShortcut(loyaltyCardId, store);
}
finish();
}
private void addShortcut(int id, String name)
{
Intent shortcutIntent = new Intent(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", id);
bundle.putBoolean("view", true);
shortcutIntent.putExtras(bundle);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
.fromContext(this, R.mipmap.ic_launcher));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
// Do not duplicate the shortcut if it is already there
intent.putExtra("duplicate", false);
getApplicationContext().sendBroadcast(intent);
Toast.makeText(this, R.string.addedShortcut, Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{

View File

@@ -146,55 +146,6 @@
android:background="@color/inputBorder" />
</TableRow>
<!-- Add Shortcut -->
<View
android:id="@+id/shortcutBorder"
android:layout_height="@dimen/inputBorderThickness"
android:layout_width="match_parent"
android:background="@color/inputBorder" />
<TableRow
android:id="@+id/shortcutTablerow"
android:background="@color/inputBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:gravity="start"
android:layout_height="match_parent"
android:layout_width="@dimen/inputBorderThickness"
android:background="@color/inputBorder" />
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/inputPadding"
android:paddingEnd="@dimen/inputPadding">
<TextView
android:id="@+id/shortcutField"
android:text="@string/addShortcut"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:textSize="@dimen/inputSize"
android:padding="@dimen/inputPadding"
android:layout_alignParentStart="true"/>
<CheckBox
android:id="@+id/shortcutCheckbox"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="@dimen/inputPadding"
android:textSize="@dimen/inputSize"
android:layout_toEndOf="@id/shortcutField"/>
</RelativeLayout>
<View
android:gravity="end"
android:layout_height="match_parent"
android:layout_width="@dimen/inputBorderThickness"
android:background="@color/inputBorder" />
</TableRow>
<!-- Card ID -->
<View
android:id="@+id/cardIdDivider"

View File

@@ -8,7 +8,6 @@
<string name="storeName">Store</string>
<string name="note">Note</string>
<string name="addShortcut">Add Shortcut</string>
<string name="cardId">Card ID</string>
<string name="barcodeType">Barcode Type</string>
@@ -27,12 +26,14 @@
<string name="ok">OK</string>
<string name="copy_to_clipboard">Copy ID to clipboard</string>
<string name="sendLabel">Send&#8230;</string>
<string name="addedShortcut">Added shortcut</string>
<string name="addedShortcut">Added to Home Screen</string>
<string name="editCardTitle">Edit Loyalty Card</string>
<string name="addCardTitle">Add Loyalty Card</string>
<string name="viewCardTitle">View Loyalty Card</string>
<string name="scanCardBarcode">Scan Card\'s Barcode</string>
<string name="cardShortcut">Card Shortcut</string>
<string name="noCardsMessage">There are no cards, add one first</string>
<string name="barcodeImageDescription">Image of card\'s barcode</string>

View File

@@ -89,7 +89,6 @@ public class LoyaltyCardViewActivityTest
*/
private void saveLoyaltyCardWithArguments(final Activity activity,
final String store, final String note,
final boolean addShortcut,
final String cardId,
final String barcodeType,
boolean creatingNewCard)
@@ -106,25 +105,18 @@ public class LoyaltyCardViewActivityTest
final EditText storeField = (EditText) activity.findViewById(R.id.storeNameEdit);
final EditText noteField = (EditText) activity.findViewById(R.id.noteEdit);
final CheckBox shortcutCheckbox = (CheckBox) activity.findViewById(R.id.shortcutCheckbox);
final TextView cardIdField = (TextView) activity.findViewById(R.id.cardIdView);
final TextView barcodeTypeField = (TextView) activity.findViewById(R.id.barcodeType);
storeField.setText(store);
noteField.setText(note);
shortcutCheckbox.setChecked(addShortcut);
cardIdField.setText(cardId);
barcodeTypeField.setText(barcodeType);
ShortcutAddedReceiver shortcutAddedReceiver = new ShortcutAddedReceiver();
shortcutAddedReceiver.registerReceiver(activity);
assertEquals(false, activity.isFinishing());
shadowOf(activity).clickMenuItem(R.id.action_save);
assertEquals(true, activity.isFinishing());
shortcutAddedReceiver.unregisterReceiver(activity);
assertEquals(1, db.getLoyaltyCardCount());
LoyaltyCard card = db.getLoyaltyCard(1);
@@ -132,28 +124,6 @@ public class LoyaltyCardViewActivityTest
assertEquals(note, card.note);
assertEquals(cardId, card.cardId);
assertEquals(barcodeType, card.barcodeType);
Intent shortcutRequest = shortcutAddedReceiver.lastRequest();
if(addShortcut)
{
assertNotNull(shortcutRequest);
String name = shortcutRequest.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
assertEquals(card.store, name);
Intent startIntent = shortcutRequest.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
assertNotNull(startIntent);
Bundle startBundle = startIntent.getExtras();
assertNotNull(startBundle);
assertEquals(card.id, startBundle.getInt("id", -1));
assertEquals(true, startBundle.getBoolean("view", false));
}
else
{
assertNull(shortcutRequest);
}
}
/**
@@ -216,8 +186,6 @@ public class LoyaltyCardViewActivityTest
checkFieldProperties(activity, R.id.storeNameEdit, editVisibility, store);
checkFieldProperties(activity, R.id.storeNameView, viewVisibility, store);
checkFieldProperties(activity, R.id.noteEdit, editVisibility, note);
checkFieldProperties(activity, R.id.shortcutBorder, editVisibility, null);
checkFieldProperties(activity, R.id.shortcutTablerow, editVisibility, null);
checkFieldProperties(activity, R.id.noteView, viewVisibility, note);
checkFieldProperties(activity, R.id.cardIdView, View.VISIBLE, cardId);
checkFieldProperties(activity, R.id.cardIdDivider, cardId.isEmpty() ? View.GONE : View.VISIBLE, null);
@@ -308,30 +276,7 @@ public class LoyaltyCardViewActivityTest
checkAllFields(activity, ViewMode.ADD_CARD, "", "", BARCODE_DATA, BARCODE_TYPE);
// Save and check the gift card
saveLoyaltyCardWithArguments(activity, "store", "note", false, BARCODE_DATA, BARCODE_TYPE, true);
}
@Test
public void startWithoutParametersCaptureBarcodeCreateLoyaltyCardSaveShortcut() throws IOException
{
registerMediaStoreIntentHandler();
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
activityController.start();
activityController.visible();
activityController.resume();
Activity activity = (Activity)activityController.get();
checkAllFields(activity, ViewMode.ADD_CARD, "", "", "", "");
// Complete barcode capture successfully
captureBarcodeWithResult(activity, R.id.captureButton, true);
checkAllFields(activity, ViewMode.ADD_CARD, "", "", BARCODE_DATA, BARCODE_TYPE);
// Save and check the gift card
saveLoyaltyCardWithArguments(activity, "store", "note", true, BARCODE_DATA, BARCODE_TYPE, true);
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, BARCODE_TYPE, true);
}
@Test

View File

@@ -1,39 +0,0 @@
package protect.card_locker;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
public class ShortcutAddedReceiver extends BroadcastReceiver
{
public static final String SHORTCUT_ADD_REQUEST = "com.android.launcher.action.INSTALL_SHORTCUT";
private Intent _request = null;
@Override
public void onReceive(Context context, Intent intent)
{
_request = intent;
}
public void registerReceiver(Context context)
{
context.registerReceiver(this, new IntentFilter(SHORTCUT_ADD_REQUEST));
}
public void unregisterReceiver(Context context)
{
context.unregisterReceiver(this);
}
public Intent lastRequest()
{
return _request;
}
public void reset()
{
_request = null;
}
}