Compare commits

...

37 Commits
v0.14 ... 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
Branden Archer
7758c61079 Merge pull request #157 from brarcher/pre-v0.15
Pre v0.15
2017-11-25 14:48:27 -05:00
Branden Archer
47b30ca9fb Update for v0.15 2017-11-25 14:41:20 -05:00
Branden Archer
7b4d587b13 Update CHANGELOG for v0.15 2017-11-25 14:40:40 -05:00
Branden Archer
685ee018c6 Merge pull request #155 from brarcher/shortcuts
Add support for shortcuts
2017-11-25 14:40:07 -05:00
Branden Archer
e0915578ba Redraw card info when launched by a shortcut
When a shortcut launches the view activity, if the activity
already exists it will get onNewIntent() called. This needs to
clear out the view items so the next card will be redrawn.
2017-11-25 14:33:59 -05:00
Branden Archer
c733a6c3b9 Start shortcuts with singleTop, but not all launches
This will prevent shortcuts from creating many views, and causing
them to leak. However, do not use singleTop for all launches
of the view activity, else the edit mode cannot be entered.
2017-11-25 14:33:59 -05:00
Branden Archer
ec17255a43 Remove unneeded local variables
The global variables have the same information; no need to look
up the information again.
2017-11-25 14:33:59 -05:00
Branden Archer
1fc7baa5a0 Capture view items in onCreate
Some of these will need to be accessed prior to onResume()
2017-11-25 14:33:59 -05:00
Branden Archer
0df411ee96 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 ebe6139a64.
2017-11-25 14:33:59 -05:00
Branden Archer
23178d9694 Optionally add shortcut when creating/editing a card
When a card is being added or created, a checkbox will now
be presented asking if a shortcut should be made. If selected,
when saving a shortcut will be added to the home screen. The
shortcut will directly launch the given card in view mode.
2017-11-25 14:33:59 -05:00
Branden Archer
94accc951d Let insertLoyaltyCard return the new ID
Card IDs for new cards will soon need to be known once they
are created. This change updates this call to return the
new id.
2017-11-25 14:33:59 -05:00
Branden Archer
0207e12aed Revert "Only let one card viewing activity exist at a time"
This prevented the editing of cards, as the same activity
was used for viewing and editing, but the viewing "instance"
was calling finish(). It is simpler to remove the singleTop
option.

This reverts commit 4e02252b75.
2017-11-25 14:33:59 -05:00
Branden Archer
c760465b3e Merge pull request #156 from brarcher/mimetype
Report accurate mime type when sending backup data
2017-11-25 14:33:44 -05:00
Branden Archer
f480bd0c7e Report the correct mime type for exported data
Technically text/plain is correct-ish, but text/csv is more correct.
2017-11-25 14:25:47 -05:00
Branden Archer
5599560258 Remove unneeded imports 2017-11-25 14:25:47 -05:00
Branden Archer
7b4c119d7d Merge pull request #153 from brarcher/content-imports
Support importing/exporting via content providers
2017-11-21 21:24:52 -05:00
Branden Archer
6144353079 List correct file name on imports 2017-11-21 21:15:42 -05:00
Branden Archer
03a5334961 Export backups using FileProvider
On Android 7+ providing another activity a file:// Uri is
discouraged. This changes instead uses a content provider
backed by a FileProvider to give backup data to other
activities.
2017-11-21 21:14:47 -05:00
Branden Archer
04e0a5716e Flatten error handling when importing from an activity 2017-11-21 21:12:21 -05:00
Branden Archer
91e3f9f785 Support importing content URIs and file URIs
When importing backed up settings other activities may provide
data via a content URI. This is especially likely on Android 7+,
where providing a file URI is flagged as a security issue.
To support such activities, this commit enables supporting
content URIs for importing settings.
2017-11-21 18:15:56 -05:00
Branden Archer
2ebc862e27 Remove file arg from TaskCompleteListener
Soon more than files will be imported, as content URIs will
also be supported. This then makes the File argument for
onTaskComplete() not always useful, as there may not
be a direct file used. To this end, removing the File
argument as the caller should know what was passed
to the ImportExport task anyway.
2017-11-21 16:41:25 -05:00
Branden Archer
5d122affce Merge pull request #150 from brarcher/proguard
do not obfuscate using proguard
2017-10-01 14:32:48 -04:00
Branden Archer
9e09b9052a do not obfuscate using proguard 2017-10-01 13:53:11 -04:00
Branden Archer
2753b8826f Merge pull request #149 from brarcher/singletop
Only let one card viewing activity exist at a time
2017-09-28 12:59:19 -04:00
Branden Archer
4e02252b75 Only let one card viewing activity exist at a time
Now that there are shortcuts which can launch card viewing activities
directly, if a user does not back out of the activity then there will
be a pile up of activities over time. To prevent this, only let
one such view activity exist at a time.
2017-09-28 11:31:00 -04:00
Branden Archer
647ce00e72 Merge pull request #148 from brarcher/text
Capitalize first letter in store and note fields
2017-09-28 10:03:30 -04:00
Branden Archer
86a5f2fb50 Capitalize first letter in store and note fields 2017-09-28 09:46:14 -04:00
Branden Archer
dca5129031 Merge pull request #147 from brarcher/proguard
Do not strip line number info with proguard
2017-09-27 12:14:48 -04:00
Branden Archer
e30eb00bf7 Do not strip line number info with proguard 2017-09-27 11:46:31 -04:00
23 changed files with 319 additions and 360 deletions

View File

@@ -1,3 +1,18 @@
## 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:
- Add support for adding shortcuts to home screen when adding or editing a card. (https://github.com/brarcher/loyalty-card-locker/pull/155)
- Remove widget, as it was a poor substitute for shortcuts. (https://github.com/brarcher/loyalty-card-locker/pull/155)
- Fix exporting backups on Android 7+. (https://github.com/brarcher/loyalty-card-locker/pull/153)
- Report more accurate mime type when exporting backup data. (https://github.com/brarcher/loyalty-card-locker/pull/156)
- Fix bug where a card could not be edited. (https://github.com/brarcher/loyalty-card-locker/pull/155)
## v0.14 (2017-10-26)
Changes:

View File

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

View File

@@ -15,3 +15,10 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
-keepattributes SourceFile,LineNumberTable
# This keep the class and method names the same, for debugging stack traces
-dontobfuscate

View File

@@ -36,7 +36,8 @@
android:name=".LoyaltyCardViewActivity"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="stateHidden"/>
android:windowSoftInputMode="stateHidden"
android:exported="true"/>
<activity
android:name=".BarcodeSelectorActivity"
android:label="@string/selectBarcodeTitle"
@@ -53,20 +54,25 @@
android:label=""
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar"/>
<receiver android:name=".appwidget.CardAppWidgetProvider">
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/appwidget_provider" />
<activity
android:name=".CardShortcutConfigure"
android:label="@string/cardShortcut"
android:configChanges="orientation|screenSize"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
</receiver>
<activity android:name=".appwidget.CardAppWidgetConfigure">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
<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"
android:exported="false"
android:authorities="${applicationId}">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths"/>
</provider>
</application>
</manifest>

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

@@ -51,7 +51,7 @@ public class DBHelper extends SQLiteOpenHelper
}
}
public boolean insertLoyaltyCard(final String store, final String note, final String cardId,
public long insertLoyaltyCard(final String store, final String note, final String cardId,
final String barcodeType)
{
SQLiteDatabase db = getWritableDatabase();
@@ -61,7 +61,7 @@ public class DBHelper extends SQLiteOpenHelper
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
return (newId != -1);
return newId;
}
public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,

View File

@@ -7,12 +7,15 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.OpenableColumns;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
@@ -24,6 +27,9 @@ import android.widget.Button;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
public class ImportExportActivity extends AppCompatActivity
@@ -132,24 +138,34 @@ public class ImportExportActivity extends AppCompatActivity
@Override
public void onClick(View v)
{
startImport(exportFile);
Uri uri = Uri.fromFile(exportFile);
try
{
FileInputStream stream = new FileInputStream(exportFile);
startImport(stream, uri);
}
catch(FileNotFoundException e)
{
Log.e(TAG, "Could not import file " + exportFile.getAbsolutePath(), e);
onImportComplete(false, uri);
}
}
});
}
private void startImport(File target)
private void startImport(final InputStream target, final Uri targetUri)
{
ImportExportTask.TaskCompleteListener listener = new ImportExportTask.TaskCompleteListener()
{
@Override
public void onTaskComplete(boolean success, File file)
public void onTaskComplete(boolean success)
{
onImportComplete(success, file);
onImportComplete(success, targetUri);
}
};
importExporter = new ImportExportTask(ImportExportActivity.this,
true, DataFormat.CSV, target, listener);
DataFormat.CSV, target, listener);
importExporter.execute();
}
@@ -158,14 +174,14 @@ public class ImportExportActivity extends AppCompatActivity
ImportExportTask.TaskCompleteListener listener = new ImportExportTask.TaskCompleteListener()
{
@Override
public void onTaskComplete(boolean success, File file)
public void onTaskComplete(boolean success)
{
onExportComplete(success, file);
onExportComplete(success, exportFile);
}
};
importExporter = new ImportExportTask(ImportExportActivity.this,
false, DataFormat.CSV, exportFile, listener);
DataFormat.CSV, exportFile, listener);
importExporter.execute();
}
@@ -220,7 +236,34 @@ public class ImportExportActivity extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
private void onImportComplete(boolean success, File path)
private String fileNameFromUri(Uri uri)
{
if("file".equals(uri.getScheme()))
{
return uri.getPath();
}
Cursor returnCursor =
getContentResolver().query(uri, null, null, null, null);
if(returnCursor == null)
{
return null;
}
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if(returnCursor.moveToFirst() == false)
{
returnCursor.close();
return null;
}
String name = returnCursor.getString(nameIndex);
returnCursor.close();
return name;
}
private void onImportComplete(boolean success, Uri path)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -236,7 +279,15 @@ public class ImportExportActivity extends AppCompatActivity
int messageId = success ? R.string.importedFrom : R.string.importFailed;
final String template = getResources().getString(messageId);
final String message = String.format(template, path.getAbsolutePath());
// Get the filename of the file being imported
String filename = fileNameFromUri(path);
if(filename == null)
{
filename = "(unknown)";
}
final String message = String.format(template, filename);
builder.setMessage(message);
builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener()
{
@@ -286,10 +337,13 @@ public class ImportExportActivity extends AppCompatActivity
@Override
public void onClick(DialogInterface dialog, int which)
{
Uri outputUri = Uri.fromFile(path);
Uri outputUri = FileProvider.getUriForFile(ImportExportActivity.this, BuildConfig.APPLICATION_ID, path);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, outputUri);
sendIntent.setType("text/plain");
sendIntent.setType("text/csv");
// set flag to give temporary permission to external app to use the FileProvider
sendIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ImportExportActivity.this.startActivity(Intent.createChooser(sendIntent,
sendLabel));
@@ -344,34 +398,28 @@ public class ImportExportActivity extends AppCompatActivity
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == CHOOSE_EXPORT_FILE)
{
String path = null;
Uri uri = data.getData();
if(uri != null && uri.toString().startsWith("/"))
{
uri = Uri.parse("file://" + uri.toString());
}
if(uri != null)
{
path = uri.getPath();
}
if(path != null)
{
Log.e(TAG, "Starting file import with: " + uri.toString());
startImport(new File(path));
}
else
{
Log.e(TAG, "Fail to make sense of URI returned from activity: " + (uri != null ? uri.toString() : "null"));
}
}
else
if (resultCode != RESULT_OK || requestCode != CHOOSE_EXPORT_FILE)
{
Log.w(TAG, "Failed onActivityResult(), result=" + resultCode);
return;
}
Uri uri = data.getData();
if(uri == null)
{
Log.e(TAG, "Activity returned a NULL URI");
return;
}
try
{
InputStream reader = getContentResolver().openInputStream(uri);
Log.e(TAG, "Starting file import with: " + uri.toString());
startImport(reader, uri);
}
catch (FileNotFoundException e)
{
Log.e(TAG, "Failed to import file: " + uri.toString(), e);
}
}
}

View File

@@ -12,6 +12,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
@@ -24,29 +25,46 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
private boolean doImport;
private DataFormat format;
private File target;
private InputStream inputStream;
private TaskCompleteListener listener;
private ProgressDialog progress;
public ImportExportTask(Activity activity, boolean doImport, DataFormat format, File target,
/**
* Constructor which will setup a task for exporting to the given file
*/
ImportExportTask(Activity activity, DataFormat format, File target,
TaskCompleteListener listener)
{
super();
this.activity = activity;
this.doImport = doImport;
this.doImport = false;
this.format = format;
this.target = target;
this.listener = listener;
}
private boolean performImport(File importFile, DBHelper db)
/**
* Constructor which will setup a task for importing from the given InputStream.
*/
ImportExportTask(Activity activity, DataFormat format, InputStream input,
TaskCompleteListener listener)
{
super();
this.activity = activity;
this.doImport = true;
this.format = format;
this.inputStream = input;
this.listener = listener;
}
private boolean performImport(InputStream stream, DBHelper db)
{
boolean result = false;
try
{
FileInputStream fileReader = new FileInputStream(importFile);
InputStreamReader reader = new InputStreamReader(fileReader, Charset.forName("UTF-8"));
InputStreamReader reader = new InputStreamReader(stream, Charset.forName("UTF-8"));
result = MultiFormatImporter.importData(db, reader, format);
reader.close();
}
@@ -55,7 +73,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
Log.e(TAG, "Unable to import file", e);
}
Log.i(TAG, "Import of '" + importFile.getAbsolutePath() + "' result: " + result);
Log.i(TAG, "Import result: " + result);
return result;
}
@@ -105,7 +123,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
if(doImport)
{
result = performImport(target, db);
result = performImport(inputStream, db);
}
else
{
@@ -117,7 +135,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
protected void onPostExecute(Boolean result)
{
listener.onTaskComplete(result, target);
listener.onTaskComplete(result);
progress.dismiss();
Log.i(TAG, (doImport ? "Import" : "Export") + " Complete");
@@ -130,7 +148,7 @@ class ImportExportTask extends AsyncTask<Void, Void, Boolean>
}
interface TaskCompleteListener
{
void onTaskComplete(boolean success, File file);
void onTaskComplete(boolean success);
}
}

View File

@@ -8,7 +8,7 @@ import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;
public class LoyaltyCardCursorAdapter extends CursorAdapter
class LoyaltyCardCursorAdapter extends CursorAdapter
{
public LoyaltyCardCursorAdapter(Context context, Cursor cursor)
{

View File

@@ -22,6 +22,7 @@ import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
@@ -61,6 +62,18 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
DBHelper db;
private void extractIntentFields(Intent intent)
{
final Bundle b = intent.getExtras();
loyaltyCardId = b != null ? b.getInt("id") : 0;
updateLoyaltyCard = b != null && b.getBoolean("update", false);
viewLoyaltyCard = b != null && b.getBoolean("view", false);
Log.d(TAG, "View activity: id=" + loyaltyCardId
+ ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard)
+ ", viewLoyaltyCard=" + Boolean.toString(viewLoyaltyCard));
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
@@ -75,16 +88,37 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
actionBar.setDisplayHomeAsUpEnabled(true);
}
final Bundle b = getIntent().getExtras();
loyaltyCardId = b != null ? b.getInt("id") : 0;
updateLoyaltyCard = b != null && b.getBoolean("update", false);
viewLoyaltyCard = b != null && b.getBoolean("view", false);
Log.d(TAG, "View activity: id=" + loyaltyCardId
+ ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard)
+ ", viewLoyaltyCard=" + Boolean.toString(viewLoyaltyCard));
extractIntentFields(getIntent());
db = new DBHelper(this);
storeFieldEdit = (EditText) findViewById(R.id.storeNameEdit);
storeFieldView = (TextView) findViewById(R.id.storeNameView);
noteFieldEdit = (EditText) findViewById(R.id.noteEdit);
noteFieldView = (TextView) findViewById(R.id.noteView);
cardIdFieldView = (TextView) findViewById(R.id.cardIdView);
cardIdDivider = findViewById(R.id.cardIdDivider);
cardIdTableRow = findViewById(R.id.cardIdTableRow);
barcodeTypeField = (TextView) findViewById(R.id.barcodeType);
barcodeImage = (ImageView) findViewById(R.id.barcode);
barcodeImageLayout = findViewById(R.id.barcodeLayout);
barcodeCaptureLayout = findViewById(R.id.barcodeCaptureLayout);
captureButton = (Button) findViewById(R.id.captureButton);
enterButton = (Button) findViewById(R.id.enterButton);
}
@Override
public void onNewIntent(Intent intent)
{
Log.i(TAG, "Received new intent");
extractIntentFields(intent);
// Reset these fields, so they are re-populated in onResume().
storeFieldEdit.setText("");
noteFieldEdit.setText("");
cardIdFieldView.setText("");
barcodeTypeField.setText("");
}
@Override
@@ -108,21 +142,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
}
}
storeFieldEdit = (EditText) findViewById(R.id.storeNameEdit);
storeFieldView = (TextView) findViewById(R.id.storeNameView);
noteFieldEdit = (EditText) findViewById(R.id.noteEdit);
noteFieldView = (TextView) findViewById(R.id.noteView);
cardIdFieldView = (TextView) findViewById(R.id.cardIdView);
cardIdDivider = findViewById(R.id.cardIdDivider);
cardIdTableRow = findViewById(R.id.cardIdTableRow);
barcodeTypeField = (TextView) findViewById(R.id.barcodeType);
barcodeImage = (ImageView) findViewById(R.id.barcode);
barcodeImageLayout = findViewById(R.id.barcodeLayout);
barcodeCaptureLayout = findViewById(R.id.barcodeCaptureLayout);
captureButton = (Button) findViewById(R.id.captureButton);
enterButton = (Button) findViewById(R.id.enterButton);
if(updateLoyaltyCard || viewLoyaltyCard)
{
final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId);
@@ -296,7 +315,7 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
}
else
{
db.insertLoyaltyCard(store, note, cardId, barcodeType);
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType);
}
finish();
@@ -305,10 +324,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
final Bundle b = getIntent().getExtras();
final boolean updateLoyaltyCard = b != null && b.getBoolean("update", false);
final boolean viewLoyaltyCard = b != null && b.getBoolean("view", false);
if(viewLoyaltyCard)
{
getMenuInflater().inflate(R.menu.card_view_menu, menu);
@@ -332,9 +347,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
{
int id = item.getItemId();
final Bundle b = getIntent().getExtras();
final int loyaltyCardId = b != null ? b.getInt("id") : 0;
switch(id)
{
case android.R.id.home:

View File

@@ -7,10 +7,7 @@ import android.content.ClipboardManager;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
@@ -30,7 +27,6 @@ import android.widget.Toast;
import com.google.common.collect.ImmutableMap;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import protect.card_locker.intro.IntroActivity;

View File

@@ -103,10 +103,16 @@ class ShortcutHelper
{
ShortcutInfo prevShortcut = list.get(index);
Intent shortcutIntent = prevShortcut.getIntent();
// Prevent instances of the view activity from piling up; if one exists let this
// one replace it.
shortcutIntent.setFlags(shortcutIntent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP);
ShortcutInfo updatedShortcut = new ShortcutInfo.Builder(context, prevShortcut.getId())
.setShortLabel(prevShortcut.getShortLabel())
.setLongLabel(prevShortcut.getLongLabel())
.setIntent(prevShortcut.getIntent())
.setIntent(shortcutIntent)
.setIcon(Icon.createWithResource(context, R.drawable.circle))
.setRank(index)
.build();

View File

@@ -1,130 +0,0 @@
package protect.card_locker.appwidget;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
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 protect.card_locker.DBHelper;
import protect.card_locker.LoyaltyCard;
import protect.card_locker.LoyaltyCardCursorAdapter;
import protect.card_locker.R;
/**
* The configuration screen for the CardAppWidgetProvider widget.
*/
public class CardAppWidgetConfigure extends AppCompatActivity
{
static final String TAG = "LoyaltyCardLocker";
private static final String PREFS_NAME
= "protect.card_locker.appwidget.CardAppWidgetProvider";
private static final String PREF_PREFIX_KEY = "prefix_";
int appWidgetId_ = AppWidgetManager.INVALID_APPWIDGET_ID;
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if they press the back button.
setResult(RESULT_CANCELED);
setContentView(R.layout.main_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setVisibility(View.GONE);
setTitle(R.string.selectCardTitle);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null)
{
appWidgetId_ = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (appWidgetId_ == AppWidgetManager.INVALID_APPWIDGET_ID)
{
finish();
}
final DBHelper db = new DBHelper(this);
// If there are no cards, bail
if(db.getLoyaltyCardCount() == 0)
{
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)
{
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;
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -1,13 +1,10 @@
package protect.card_locker.intro;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.v4.app.Fragment;
import com.github.paolorotolo.appintro.AppIntro;
import protect.card_locker.R;
public class IntroActivity extends AppIntro
{

View File

@@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="60.0dip"
android:layout_height="70.0dip">
<ImageView
android:id="@+id/icon"
android:layout_gravity="start"
android:layout_centerHorizontal="true"
android:layout_width="55.0dip"
android:layout_height="55.0dip"
android:gravity="center_horizontal"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/icon"
android:gravity="center_horizontal"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
</RelativeLayout>

View File

@@ -65,6 +65,7 @@
<EditText
android:id="@+id/storeNameEdit"
android:inputType="textCapWords"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="@dimen/inputPadding"
@@ -121,6 +122,7 @@
<EditText
android:id="@+id/noteEdit"
android:inputType="textCapSentences"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="@dimen/inputPadding"

View File

@@ -26,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 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="selectCardTitle">Select Card</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

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="60dp"
android:minHeight="30dp"
android:initialLayout="@layout/appwidget_provider"
android:configure="protect.card_locker.appwidget.CardAppWidgetConfigure"
android:resizeMode="horizontal"
>
</appwidget-provider>

View File

@@ -0,0 +1,3 @@
<paths>
<external-path name="exportPath" path="/" />
</paths>

View File

@@ -36,7 +36,8 @@ public class DatabaseTest
public void addRemoveOneGiftCard()
{
assertEquals(0, db.getLoyaltyCardCount());
boolean result = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
boolean result = (id != -1);
assertTrue(result);
assertEquals(1, db.getLoyaltyCardCount());
@@ -56,7 +57,8 @@ public class DatabaseTest
@Test
public void updateGiftCard()
{
boolean result = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
boolean result = (id != -1);
assertTrue(result);
assertEquals(1, db.getLoyaltyCardCount());
@@ -86,7 +88,8 @@ public class DatabaseTest
@Test
public void emptyGiftCardValues()
{
boolean result = db.insertLoyaltyCard("", "", "", "");
long id = db.insertLoyaltyCard("", "", "", "");
boolean result = (id != -1);
assertTrue(result);
assertEquals(1, db.getLoyaltyCardCount());
@@ -107,8 +110,9 @@ public class DatabaseTest
// that they are sorted
for(int index = CARDS_TO_ADD-1; index >= 0; index--)
{
boolean result = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
long id = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
BarcodeFormat.UPC_A.toString());
boolean result = (id != -1);
assertTrue(result);
}

View File

@@ -17,6 +17,8 @@ import org.robolectric.annotation.Config;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@@ -63,7 +65,8 @@ public class ImportExportTest
{
String storeName = String.format("store, \"%4d", index);
String note = String.format("note, \"%4d", index);
boolean result = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE);
long id = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE);
boolean result = (id != -1);
assertTrue(result);
}
@@ -211,17 +214,15 @@ public class ImportExportTest
class TestTaskCompleteListener implements ImportExportTask.TaskCompleteListener
{
Boolean success;
File file;
public void onTaskComplete(boolean success, File file)
public void onTaskComplete(boolean success)
{
this.success = success;
this.file = file;
}
}
@Test
public void useImportExportTask()
public void useImportExportTask() throws FileNotFoundException
{
final int NUM_CARDS = 10;
@@ -235,7 +236,7 @@ public class ImportExportTest
TestTaskCompleteListener listener = new TestTaskCompleteListener();
// Export to the file
ImportExportTask task = new ImportExportTask(activity, false, format, exportFile, listener);
ImportExportTask task = new ImportExportTask(activity, format, exportFile, listener);
task.execute();
// Actually run the task to completion
@@ -244,8 +245,6 @@ public class ImportExportTest
// Check that the listener was executed
assertNotNull(listener.success);
assertEquals(true, listener.success);
assertNotNull(listener.file);
assertEquals(exportFile, listener.file);
clearDatabase();
@@ -253,7 +252,9 @@ public class ImportExportTest
listener = new TestTaskCompleteListener();
task = new ImportExportTask(activity, true, format, exportFile, listener);
FileInputStream fileStream = new FileInputStream(exportFile);
task = new ImportExportTask(activity, format, fileStream, listener);
task.execute();
// Actually run the task to completion
@@ -262,8 +263,6 @@ public class ImportExportTest
// Check that the listener was executed
assertNotNull(listener.success);
assertEquals(true, listener.success);
assertNotNull(listener.file);
assertEquals(exportFile, listener.file);
assertEquals(NUM_CARDS, db.getLoyaltyCardCount());

View File

@@ -9,6 +9,7 @@ import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
@@ -29,6 +30,7 @@ import org.robolectric.android.controller.ActivityController;
import java.io.IOException;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;