Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3bcd3e273 | ||
|
|
9d1c9c3309 | ||
|
|
61e039c456 | ||
|
|
0e2d725591 | ||
|
|
759d42cfcf | ||
|
|
2312788a57 | ||
|
|
0820be3986 | ||
|
|
8a11953276 | ||
|
|
182b3ff3c0 | ||
|
|
79dad1b0a6 | ||
|
|
04466edb01 | ||
|
|
af3ce5a0ff | ||
|
|
3291185812 | ||
|
|
c9df3bd1d2 | ||
|
|
057c7923a8 | ||
|
|
4195d73c53 | ||
|
|
ed08f0577a | ||
|
|
a1257a1692 | ||
|
|
a51815a172 | ||
|
|
8eee8f6a0f | ||
|
|
1817c184ae | ||
|
|
773d759ef5 | ||
|
|
cbc51cfb73 | ||
|
|
46c3d190d8 | ||
|
|
9951999ca4 | ||
|
|
4843a1093d | ||
|
|
a4bde722a6 | ||
|
|
ff5e5d5833 | ||
|
|
685eaec8b5 | ||
|
|
a3556cc66d | ||
|
|
13543ea9f6 | ||
|
|
d7bf31c308 | ||
|
|
a77a968619 | ||
|
|
70c6ee17cd | ||
|
|
c233f82dc1 | ||
|
|
be0c2507f2 | ||
|
|
abfcf9d6cd | ||
|
|
4d565b3b2f | ||
|
|
27511a4ccd | ||
|
|
12440346fa | ||
|
|
870e4d0c4a | ||
|
|
6e526de087 | ||
|
|
891636b51f | ||
|
|
017d97d08c | ||
|
|
63165ca1a5 | ||
|
|
48f40a51d1 | ||
|
|
3940ba5756 | ||
|
|
b8a36e3c45 | ||
|
|
60deaae8d5 | ||
|
|
a71da8d6dc | ||
|
|
dbbbd128dc | ||
|
|
3275279501 | ||
|
|
2f6516ffb9 | ||
|
|
41c8b78275 | ||
|
|
6ed96393d5 | ||
|
|
3519e03568 | ||
|
|
1aef3f5253 | ||
|
|
c97e80432f | ||
|
|
c6265eb9e3 | ||
|
|
935cd97f99 | ||
|
|
e65d096e76 | ||
|
|
8d38918a12 | ||
|
|
57f2c7acd4 | ||
|
|
7fb6e4a8d3 | ||
|
|
56d20939be | ||
|
|
a3968f8894 | ||
|
|
74dd292f5a | ||
|
|
d7a7528114 | ||
|
|
bffeca9033 | ||
|
|
5a88afb9f3 | ||
|
|
f775f9224b | ||
|
|
17acb8370c | ||
|
|
23766fe9f0 | ||
|
|
f1b0a26591 | ||
|
|
f1b2c0d93d | ||
|
|
4034997d7f | ||
|
|
d3bbaf39f4 | ||
|
|
ae7684921f | ||
|
|
e73974536c | ||
|
|
43072e283f | ||
|
|
a3a70d459b | ||
|
|
edfc91376f | ||
|
|
5fb68055ea | ||
|
|
085a3f10e7 |
@@ -5,7 +5,7 @@ install:
|
||||
- echo y | android update sdk -u -a -t tools
|
||||
- echo y | android update sdk -u -a -t platform-tools
|
||||
- echo y | android update sdk -u -a -t build-tools-26.0.2
|
||||
- echo y | android update sdk -u -a -t android-27
|
||||
- yes | sdkmanager "platforms;android-27"
|
||||
- echo y | android update sdk -u -a -t extra-google-m2repository
|
||||
- echo y | android update sdk -u -a -t extra-android-m2repository
|
||||
|
||||
|
||||
44
CHANGELOG.md
@@ -1,3 +1,47 @@
|
||||
## v0.22 (2018-02-19)
|
||||
|
||||
Changes:
|
||||
- Update translations. (https://github.com/brarcher/loyalty-card-locker/pull/208)
|
||||
- Barcode rendering updates: (https://github.com/brarcher/loyalty-card-locker/pull/209)
|
||||
* Reload card view activity when screen is rotated, so barcode image is correct size.
|
||||
* Render 1D barcodes in a larger space, allowing them to better fill the screen.
|
||||
|
||||
## v0.21 (2018-02-17)
|
||||
|
||||
Changes
|
||||
- Add quiet space at the start/end of barcodes. (https://github.com/brarcher/loyalty-card-locker/pull/200)
|
||||
- Add options to configure the colors used for the store name font and background. (https://github.com/brarcher/loyalty-card-locker/pull/203)
|
||||
- Add options to adjust font sizes on the card listing page and single card page. (https://github.com/brarcher/loyalty-card-locker/pull/204)
|
||||
|
||||
## v0.20 (2018-02-10)
|
||||
|
||||
Changes:
|
||||
- Changes to Card view to display the note, allow the card ID to take multiple lines, and show the store name. (https://github.com/brarcher/loyalty-card-locker/pull/197)
|
||||
|
||||
## v0.19 (2018-02-01)
|
||||
|
||||
Changes:
|
||||
- Improved layout for card list. (https://github.com/brarcher/loyalty-card-locker/pull/188)
|
||||
- Improved layout when viewing a card. (https://github.com/brarcher/loyalty-card-locker/pull/190)
|
||||
|
||||
## v0.18.1 (2018-01-24)
|
||||
|
||||
Changes:
|
||||
- Workaround crash during install on some Android versions (likely Android 5 and below). (https://github.com/brarcher/loyalty-card-locker/pull/184)
|
||||
|
||||
## v0.18 (2018-01-19)
|
||||
|
||||
Changes:
|
||||
- Fix crash when importing certain types of corrupted CSV files. (https://github.com/brarcher/loyalty-card-locker/pull/177)
|
||||
- Fix importing backups directly from the file system. (https://github.com/brarcher/loyalty-card-locker/pull/180)
|
||||
- Fix importing backups from certain types of content providers. (https://github.com/brarcher/loyalty-card-locker/pull/179)
|
||||
|
||||
## v0.17 (2018-01-11)
|
||||
|
||||
Changes:
|
||||
- Fix issue on Android SDK 24+ where using the file chooser import option would cause a crash. (https://github.com/brarcher/loyalty-card-locker/pull/170)
|
||||
- New icon and color scheme. (https://github.com/brarcher/loyalty-card-locker/pull/171)
|
||||
|
||||
## v0.16 (2017-11-29)
|
||||
|
||||
Changes:
|
||||
|
||||
91
CONTRIBUTING.md
Normal file
@@ -0,0 +1,91 @@
|
||||
How to Submit Patches to the Loyalty Card Keychain Project
|
||||
===============================================================================
|
||||
https://github.com/brarcher/budget-watch
|
||||
|
||||
This document is intended to act as a guide to help you contribute to the
|
||||
Loyalty Card Keychain project. It is not perfect, and there will always be exceptions
|
||||
to the rules described here, but by following the instructions below you
|
||||
should have a much easier time getting your work merged with the upstream
|
||||
project.
|
||||
|
||||
## Test Your Code
|
||||
|
||||
There are four possible tests you can run to verify your code. The first
|
||||
is unit tests, which check the basic functionality of the application, and
|
||||
can be run by gradle using:
|
||||
|
||||
# ./gradlew testReleaseUnitTest
|
||||
|
||||
The second and third check for common problems using static analysis.
|
||||
These are the Android lint checker, run using:
|
||||
|
||||
# ./gradlew lintRelease
|
||||
|
||||
and FindBugs, run using:
|
||||
|
||||
# ./gradlew findbugs
|
||||
|
||||
The final check is by testing the application on a live device and verifying
|
||||
the basic functionality works as expected.
|
||||
|
||||
## Make Sure Your Code is Tested
|
||||
|
||||
The Loyalty Card Keychain code uses a fair number of unit tests to verify that
|
||||
the basic functionality is working. Submissions which add functionality
|
||||
or significantly change the existing code should include additional tests
|
||||
to verify the proper operation of the proposed changes.
|
||||
|
||||
## Explain Your Work
|
||||
|
||||
At the top of every patch you should include a description of the problem you
|
||||
are trying to solve, how you solved it, and why you chose the solution you
|
||||
implemented. If you are submitting a bug fix, it is also incredibly helpful
|
||||
if you can describe/include a reproducer for the problem in the description as
|
||||
well as instructions on how to test for the bug and verify that it has been
|
||||
fixed.
|
||||
|
||||
## Sign Your Work
|
||||
|
||||
The sign-off is a simple line at the end of the patch description, which
|
||||
certifies that you wrote it or otherwise have the right to pass it on as an
|
||||
open-source patch. The "Developer's Certificate of Origin" pledge is taken
|
||||
from the Linux Kernel and the rules are pretty simple:
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
|
||||
... then you just add a line to the bottom of your patch description, with
|
||||
your real name, saying:
|
||||
|
||||
Signed-off-by: Random J Developer <random@developer.example.org>
|
||||
|
||||
## Submit Patch(es) for Review
|
||||
|
||||
Finally, you will need to submit your patches so that they can be reviewed
|
||||
and potentially merged into the main Loyalty Card Keychain repository. The preferred
|
||||
way to do this is to submit a Pull Request to the Loyalty Card Keychain project.
|
||||
Changes need to apply cleanly onto the master branch and pass all
|
||||
unit tests and produce no errors during static analysis.
|
||||
12
README.md
@@ -25,13 +25,13 @@ proposed changes.
|
||||
|
||||
# Screenshots
|
||||
|
||||
[<img src="https://user-images.githubusercontent.com/5264535/27416124-79b09162-56d9-11e7-967b-8923177dc228.png" width=250>](https://user-images.githubusercontent.com/5264535/27416124-79b09162-56d9-11e7-967b-8923177dc228.png)
|
||||
[<img src="https://user-images.githubusercontent.com/5264535/27416127-7baea332-56d9-11e7-8a10-5be90bb02225.png" width=250>](https://user-images.githubusercontent.com/5264535/27416127-7baea332-56d9-11e7-8a10-5be90bb02225.png)
|
||||
[<img src="https://user-images.githubusercontent.com/5264535/27416128-7d50f7b2-56d9-11e7-9833-1dd962f9cf66.png" width=250>](https://user-images.githubusercontent.com/5264535/27416128-7d50f7b2-56d9-11e7-9833-1dd962f9cf66.png)
|
||||
[<img src="https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-01.png" width=250>](https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-01.png)
|
||||
[<img src="https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-03.png" width=250>](https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-03.png)
|
||||
[<img src="https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-02.png" width=250>](https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-02.png)
|
||||
|
||||
[<img src="https://user-images.githubusercontent.com/5264535/27416132-7ea6272c-56d9-11e7-9a52-d73424bf902c.png" width=250>](https://user-images.githubusercontent.com/5264535/27416132-7ea6272c-56d9-11e7-9a52-d73424bf902c.png)
|
||||
[<img src="https://user-images.githubusercontent.com/5264535/27416137-800aee90-56d9-11e7-9cc9-2a7dc63bb4fb.png" width=250>](https://user-images.githubusercontent.com/5264535/27416137-800aee90-56d9-11e7-9cc9-2a7dc63bb4fb.png)
|
||||
[<img src="https://user-images.githubusercontent.com/5264535/27416140-82d8211a-56d9-11e7-8031-c71d3077bdc6.png" width=250>](https://user-images.githubusercontent.com/5264535/27416140-82d8211a-56d9-11e7-8031-c71d3077bdc6.png)
|
||||
[<img src="https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-04.png" width=250>](https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-04.png)
|
||||
[<img src="https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-05.png" width=250>](https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-05.png)
|
||||
[<img src="https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-06.png" width=250>](https://github.com/brarcher/loyalty-card-locker/raw/master/metadata/en-US/images/phoneScreenshots/screenshot-06.png)
|
||||
|
||||
# Building
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ android {
|
||||
applicationId "protect.card_locker"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 27
|
||||
versionCode 18
|
||||
versionName "0.17"
|
||||
versionCode 25
|
||||
versionName "0.23"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -27,6 +27,7 @@ android {
|
||||
disable "ButtonStyle"
|
||||
disable "AlwaysShowAction"
|
||||
disable "MissingTranslation"
|
||||
disable "MissingPrefix"
|
||||
}
|
||||
|
||||
// Starting with Android Studio 3 Robolectric is unable to find resources.
|
||||
@@ -45,11 +46,15 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:27.0.2'
|
||||
compile 'com.android.support:design:27.0.2'
|
||||
compile 'com.android.support:support-v4:27.0.2'
|
||||
compile 'com.journeyapps:zxing-android-embedded:3.5.0@aar'
|
||||
compile 'com.google.zxing:core:3.3.0'
|
||||
compile 'org.apache.commons:commons-csv:1.2'
|
||||
compile 'org.apache.commons:commons-csv:1.5'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
compile 'com.jaredrummler:colorpicker:1.0.2'
|
||||
compile group: 'com.google.guava', name: 'guava', version: '20.0'
|
||||
compile 'com.github.apl-devs:appintro:v4.2.0'
|
||||
compile "com.vanniktech:vntnumberpickerpreference:1.0.0"
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile "org.robolectric:robolectric:3.3.2"
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
<activity
|
||||
android:name=".LoyaltyCardViewActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label=""
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:exported="true"/>
|
||||
<activity
|
||||
android:name=".LoyaltyCardEditActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:exported="true"/>
|
||||
@@ -44,6 +50,10 @@
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:windowSoftInputMode="stateHidden"/>
|
||||
<activity
|
||||
android:name=".preferences.SettingsActivity"
|
||||
android:label="@string/settings"
|
||||
android:configChanges="orientation|screenSize"/>
|
||||
<activity
|
||||
android:name=".ImportExportActivity"
|
||||
android:label="@string/importExport"
|
||||
|
||||
@@ -21,7 +21,11 @@ import java.lang.ref.WeakReference;
|
||||
class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
{
|
||||
private static final String TAG = "LoyaltyCardLocker";
|
||||
private static final int MAX_WIDTH = 500;
|
||||
|
||||
// When drawn in a smaller window 1D barcodes for some reason end up
|
||||
// squished, whereas 2D barcodes look fine.
|
||||
private static final int MAX_WIDTH_1D = 1500;
|
||||
private static final int MAX_WIDTH_2D = 500;
|
||||
|
||||
private final WeakReference<ImageView> imageViewReference;
|
||||
private final String cardId;
|
||||
@@ -38,6 +42,8 @@ class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
cardId = cardIdString;
|
||||
format = barcodeFormat;
|
||||
|
||||
final int MAX_WIDTH = getMaxWidth(format);
|
||||
|
||||
if(imageView.getWidth() < MAX_WIDTH)
|
||||
{
|
||||
imageHeight = imageView.getHeight();
|
||||
@@ -52,6 +58,36 @@ class BarcodeImageWriterTask extends AsyncTask<Void, Void, Bitmap>
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaxWidth(BarcodeFormat format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
// 2D barcodes
|
||||
case AZTEC:
|
||||
case DATA_MATRIX:
|
||||
case MAXICODE:
|
||||
case PDF_417:
|
||||
case QR_CODE:
|
||||
return MAX_WIDTH_2D;
|
||||
|
||||
// 1D barcodes:
|
||||
case CODABAR:
|
||||
case CODE_39:
|
||||
case CODE_93:
|
||||
case CODE_128:
|
||||
case EAN_8:
|
||||
case EAN_13:
|
||||
case ITF:
|
||||
case UPC_A:
|
||||
case UPC_E:
|
||||
case RSS_14:
|
||||
case RSS_EXPANDED:
|
||||
case UPC_EAN_EXTENSION:
|
||||
default:
|
||||
return MAX_WIDTH_1D;
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap doInBackground(Void... params)
|
||||
{
|
||||
MultiFormatWriter writer = new MultiFormatWriter();
|
||||
|
||||
@@ -67,7 +67,7 @@ public class BarcodeSelectorActivity extends AppCompatActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.barcode_selector_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar != null)
|
||||
@@ -89,7 +89,7 @@ public class BarcodeSelectorActivity extends AppCompatActivity
|
||||
.put(BarcodeFormat.UPC_A.name(), R.id.upcaBarcode)
|
||||
.build();
|
||||
|
||||
EditText cardId = (EditText) findViewById(R.id.cardId);
|
||||
EditText cardId = findViewById(R.id.cardId);
|
||||
cardId.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
@@ -113,7 +113,7 @@ public class BarcodeSelectorActivity extends AppCompatActivity
|
||||
// Update barcodes
|
||||
for(String key : barcodeViewMap.keySet())
|
||||
{
|
||||
ImageView image = (ImageView)findViewById(barcodeViewMap.get(key));
|
||||
ImageView image = findViewById(barcodeViewMap.get(key));
|
||||
createBarcodeOption(image, key, s.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CardShortcutConfigure extends AppCompatActivity
|
||||
setResult(RESULT_CANCELED);
|
||||
|
||||
setContentView(R.layout.main_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbar.setVisibility(View.GONE);
|
||||
|
||||
final DBHelper db = new DBHelper(this);
|
||||
@@ -41,7 +41,7 @@ public class CardShortcutConfigure extends AppCompatActivity
|
||||
finish();
|
||||
}
|
||||
|
||||
final ListView cardList = (ListView) findViewById(R.id.list);
|
||||
final ListView cardList = findViewById(R.id.list);
|
||||
cardList.setVisibility(View.VISIBLE);
|
||||
|
||||
Cursor cardCursor = db.getLoyaltyCardCursor();
|
||||
|
||||
@@ -23,6 +23,8 @@ public class CsvDatabaseExporter implements DatabaseExporter
|
||||
DBHelper.LoyaltyCardDbIds.STORE,
|
||||
DBHelper.LoyaltyCardDbIds.NOTE,
|
||||
DBHelper.LoyaltyCardDbIds.CARD_ID,
|
||||
DBHelper.LoyaltyCardDbIds.HEADER_COLOR,
|
||||
DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR,
|
||||
DBHelper.LoyaltyCardDbIds.BARCODE_TYPE);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -35,6 +37,8 @@ public class CsvDatabaseExporter implements DatabaseExporter
|
||||
card.store,
|
||||
card.note,
|
||||
card.cardId,
|
||||
card.headerColor,
|
||||
card.headerTextColor,
|
||||
card.barcodeType);
|
||||
|
||||
if(Thread.currentThread().isInterrupted())
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
parser.close();
|
||||
database.setTransactionSuccessful();
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
catch(IllegalArgumentException|IllegalStateException e)
|
||||
{
|
||||
throw new FormatException("Issue parsing CSV data", e);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
* "key" as the key. If no such key exists, or the data is not a valid
|
||||
* int, a FormatException is thrown.
|
||||
*/
|
||||
private int extractInt(String key, CSVRecord record)
|
||||
private Integer extractInt(String key, CSVRecord record, boolean nullIsOk)
|
||||
throws FormatException
|
||||
{
|
||||
if(record.isMapped(key) == false)
|
||||
@@ -91,6 +91,12 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
throw new FormatException("Field not used but expected: " + key);
|
||||
}
|
||||
|
||||
String value = record.get(key);
|
||||
if(value.isEmpty() && nullIsOk)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(record.get(key));
|
||||
@@ -108,7 +114,7 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
private void importLoyaltyCard(SQLiteDatabase database, DBHelper helper, CSVRecord record)
|
||||
throws IOException, FormatException
|
||||
{
|
||||
int id = extractInt(DBHelper.LoyaltyCardDbIds.ID, record);
|
||||
int id = extractInt(DBHelper.LoyaltyCardDbIds.ID, record, false);
|
||||
|
||||
String store = extractString(DBHelper.LoyaltyCardDbIds.STORE, record, "");
|
||||
if(store.isEmpty())
|
||||
@@ -130,6 +136,16 @@ public class CsvDatabaseImporter implements DatabaseImporter
|
||||
throw new FormatException("No barcode type listed, but is required");
|
||||
}
|
||||
|
||||
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType);
|
||||
Integer headerColor = null;
|
||||
Integer headerTextColor = null;
|
||||
|
||||
if(record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_COLOR) &&
|
||||
record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR))
|
||||
{
|
||||
headerColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_COLOR, record, true);
|
||||
headerTextColor = extractInt(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR, record, true);
|
||||
}
|
||||
|
||||
helper.insertLoyaltyCard(database, id, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
{
|
||||
public static final String DATABASE_NAME = "LoyaltyCards.db";
|
||||
public static final int ORIGINAL_DATABASE_VERSION = 1;
|
||||
public static final int DATABASE_VERSION = 2;
|
||||
public static final int DATABASE_VERSION = 3;
|
||||
|
||||
static class LoyaltyCardDbIds
|
||||
{
|
||||
@@ -19,6 +19,8 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
public static final String ID = "_id";
|
||||
public static final String STORE = "store";
|
||||
public static final String NOTE = "note";
|
||||
public static final String HEADER_COLOR = "headercolor";
|
||||
public static final String HEADER_TEXT_COLOR = "headertextcolor";
|
||||
public static final String CARD_ID = "cardid";
|
||||
public static final String BARCODE_TYPE = "barcodetype";
|
||||
}
|
||||
@@ -36,6 +38,8 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
LoyaltyCardDbIds.ID + " INTEGER primary key autoincrement," +
|
||||
LoyaltyCardDbIds.STORE + " TEXT not null," +
|
||||
LoyaltyCardDbIds.NOTE + " TEXT not null," +
|
||||
LoyaltyCardDbIds.HEADER_COLOR + " INTEGER," +
|
||||
LoyaltyCardDbIds.HEADER_TEXT_COLOR + " INTEGER," +
|
||||
LoyaltyCardDbIds.CARD_ID + " TEXT not null," +
|
||||
LoyaltyCardDbIds.BARCODE_TYPE + " TEXT not null)");
|
||||
}
|
||||
@@ -49,10 +53,20 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
|
||||
+ " ADD COLUMN " + LoyaltyCardDbIds.NOTE + " TEXT not null default ''");
|
||||
}
|
||||
|
||||
// Upgrade from version 2 to version 3
|
||||
if(oldVersion < 3 && newVersion >= 3)
|
||||
{
|
||||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
|
||||
+ " ADD COLUMN " + LoyaltyCardDbIds.HEADER_COLOR + " INTEGER");
|
||||
db.execSQL("ALTER TABLE " + LoyaltyCardDbIds.TABLE
|
||||
+ " ADD COLUMN " + LoyaltyCardDbIds.HEADER_TEXT_COLOR + " INTEGER");
|
||||
}
|
||||
}
|
||||
|
||||
public long insertLoyaltyCard(final String store, final String note, final String cardId,
|
||||
final String barcodeType)
|
||||
final String barcodeType, final Integer headerColor,
|
||||
final Integer headerTextColor)
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
@@ -60,13 +74,16 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.NOTE, note);
|
||||
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return newId;
|
||||
}
|
||||
|
||||
public boolean insertLoyaltyCard(final SQLiteDatabase db, final int id,
|
||||
final String store, final String note, final String cardId,
|
||||
final String barcodeType)
|
||||
final String barcodeType, final Integer headerColor,
|
||||
final Integer headerTextColor)
|
||||
{
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(LoyaltyCardDbIds.ID, id);
|
||||
@@ -74,13 +91,16 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.NOTE, note);
|
||||
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues);
|
||||
return (newId != -1);
|
||||
}
|
||||
|
||||
|
||||
public boolean updateLoyaltyCard(final int id, final String store, final String note,
|
||||
final String cardId, final String barcodeType)
|
||||
final String cardId, final String barcodeType,
|
||||
final Integer headerColor, final Integer headerTextColor)
|
||||
{
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
ContentValues contentValues = new ContentValues();
|
||||
@@ -88,6 +108,8 @@ public class DBHelper extends SQLiteOpenHelper
|
||||
contentValues.put(LoyaltyCardDbIds.NOTE, note);
|
||||
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId);
|
||||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_COLOR, headerColor);
|
||||
contentValues.put(LoyaltyCardDbIds.HEADER_TEXT_COLOR, headerTextColor);
|
||||
int rowsUpdated = db.update(LoyaltyCardDbIds.TABLE, contentValues,
|
||||
LoyaltyCardDbIds.ID + "=?",
|
||||
new String[]{Integer.toString(id)});
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.import_export_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar != null)
|
||||
@@ -72,7 +72,7 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
|
||||
Button exportButton = (Button)findViewById(R.id.exportButton);
|
||||
Button exportButton = findViewById(R.id.exportButton);
|
||||
exportButton.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
@@ -86,7 +86,7 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
// Check that there is an activity that can bring up a file chooser
|
||||
final Intent intentPickAction = new Intent(Intent.ACTION_PICK);
|
||||
|
||||
Button importFilesystem = (Button) findViewById(R.id.importOptionFilesystemButton);
|
||||
Button importFilesystem = findViewById(R.id.importOptionFilesystemButton);
|
||||
importFilesystem.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
@@ -110,7 +110,7 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
intentGetContentAction.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intentGetContentAction.setType("*/*");
|
||||
|
||||
Button importApplication = (Button) findViewById(R.id.importOptionApplicationButton);
|
||||
Button importApplication = findViewById(R.id.importOptionApplicationButton);
|
||||
importApplication.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
@@ -131,7 +131,7 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
|
||||
// This option, to import from the fixed location, should always be present
|
||||
|
||||
Button importButton = (Button)findViewById(R.id.importOptionFixedButton);
|
||||
Button importButton = findViewById(R.id.importOptionFixedButton);
|
||||
importButton.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
@@ -235,33 +235,6 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -276,15 +249,10 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
int messageId = success ? R.string.importedFrom : R.string.importFailed;
|
||||
|
||||
final String template = getResources().getString(messageId);
|
||||
|
||||
// Get the filename of the file being imported
|
||||
String filename = fileNameFromUri(path);
|
||||
if(filename == null)
|
||||
{
|
||||
filename = "(unknown)";
|
||||
}
|
||||
String filename = path.toString();
|
||||
|
||||
final String message = String.format(template, filename);
|
||||
builder.setMessage(message);
|
||||
@@ -412,13 +380,24 @@ public class ImportExportActivity extends AppCompatActivity
|
||||
|
||||
try
|
||||
{
|
||||
InputStream reader = getContentResolver().openInputStream(uri);
|
||||
InputStream reader;
|
||||
|
||||
if(uri.getScheme() != null)
|
||||
{
|
||||
reader = getContentResolver().openInputStream(uri);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader = new FileInputStream(new File(uri.toString()));
|
||||
}
|
||||
|
||||
Log.e(TAG, "Starting file import with: " + uri.toString());
|
||||
startImport(reader, uri);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
Log.e(TAG, "Failed to import file: " + uri.toString(), e);
|
||||
onImportComplete(false, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
140
app/src/main/java/protect/card_locker/LetterBitmap.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.TextPaint;
|
||||
|
||||
/**
|
||||
* Original from https://github.com/andOTP/andOTP/blob/master/app/src/main/java/org/shadowice/flocke/andotp/Utilities/LetterBitmap.java
|
||||
* which was originally from http://stackoverflow.com/questions/23122088/colored-boxed-with-letters-a-la-gmail
|
||||
* Used to create a {@link Bitmap} that contains a letter used in the English
|
||||
* alphabet or digit, if there is no letter or digit available, a default image
|
||||
* is shown instead.
|
||||
*/
|
||||
class LetterBitmap
|
||||
{
|
||||
|
||||
/**
|
||||
* The number of available tile colors
|
||||
*/
|
||||
private static final int NUM_OF_TILE_COLORS = 8;
|
||||
/**
|
||||
* The letter bitmap
|
||||
*/
|
||||
private final Bitmap mBitmap;
|
||||
/**
|
||||
* The background color of the letter bitmap
|
||||
*/
|
||||
private final Integer mColor;
|
||||
|
||||
/**
|
||||
* Constructor for <code>LetterTileProvider</code>
|
||||
*
|
||||
* @param context The {@link Context} to use
|
||||
* @param displayName The name used to create the letter for the tile
|
||||
* @param key The key used to generate the background color for the tile
|
||||
* @param tileLetterFontSize The font size used to display the letter
|
||||
* @param width The desired width of the tile
|
||||
* @param height The desired height of the tile
|
||||
* @param backgroundColor (optional) color to use for background.
|
||||
* @param textColor (optional) color to use for text.
|
||||
*/
|
||||
public LetterBitmap(Context context, String displayName, String key, int tileLetterFontSize,
|
||||
int width, int height, Integer backgroundColor, Integer textColor)
|
||||
{
|
||||
TextPaint paint = new TextPaint();
|
||||
paint.setTypeface(Typeface.create("sans-serif-light", Typeface.BOLD));
|
||||
|
||||
if(textColor != null)
|
||||
{
|
||||
paint.setColor(textColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
paint.setColor(Color.WHITE);
|
||||
}
|
||||
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
if(backgroundColor == null)
|
||||
{
|
||||
mColor = getDefaultColor(context, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
mColor = backgroundColor;
|
||||
}
|
||||
|
||||
mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
String firstChar = displayName.substring(0, 1);
|
||||
|
||||
final Canvas c = new Canvas();
|
||||
c.setBitmap(mBitmap);
|
||||
c.drawColor(mColor);
|
||||
|
||||
char [] firstCharArray = new char[1];
|
||||
firstCharArray[0] = firstChar.toUpperCase().charAt(0);
|
||||
paint.setTextSize(tileLetterFontSize);
|
||||
|
||||
// The bounds that enclose the letter
|
||||
Rect bounds = new Rect();
|
||||
|
||||
paint.getTextBounds(firstCharArray, 0, 1, bounds);
|
||||
c.drawText(firstCharArray, 0, 1, width / 2.0f, height / 2.0f
|
||||
+ (bounds.bottom - bounds.top) / 2.0f, paint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A {@link Bitmap} that contains a letter used in the English
|
||||
* alphabet or digit, if there is no letter or digit available, a
|
||||
* default image is shown instead
|
||||
*/
|
||||
public Bitmap getLetterTile()
|
||||
{
|
||||
return mBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return background color used for letter title.
|
||||
*/
|
||||
public int getBackgroundColor()
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key The key used to generate the tile color
|
||||
* @return A new or previously chosen color for <code>key</code> used as the
|
||||
* tile background color
|
||||
*/
|
||||
private static int pickColor(String key, TypedArray colors)
|
||||
{
|
||||
// String.hashCode() is not supposed to change across java versions, so
|
||||
// this should guarantee the same key always maps to the same color
|
||||
final int color = Math.abs(key.hashCode()) % NUM_OF_TILE_COLORS;
|
||||
return colors.getColor(color, Color.BLACK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the color which the letter tile will use if no default
|
||||
* color is provided.
|
||||
*/
|
||||
public static int getDefaultColor(Context context, String key)
|
||||
{
|
||||
final Resources res = context.getResources();
|
||||
|
||||
TypedArray colors = res.obtainTypedArray(R.array.letter_tile_colors);
|
||||
int color = pickColor(key, colors);
|
||||
colors.recycle();
|
||||
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class LoyaltyCard
|
||||
{
|
||||
@@ -10,13 +11,22 @@ public class LoyaltyCard
|
||||
public final String cardId;
|
||||
public final String barcodeType;
|
||||
|
||||
public LoyaltyCard(final int id, final String store, final String note, final String cardId, final String barcodeType)
|
||||
@Nullable
|
||||
public final Integer headerColor;
|
||||
|
||||
@Nullable
|
||||
public final Integer headerTextColor;
|
||||
|
||||
public LoyaltyCard(final int id, final String store, final String note, final String cardId,
|
||||
final String barcodeType, final Integer headerColor, final Integer headerTextColor)
|
||||
{
|
||||
this.id = id;
|
||||
this.store = store;
|
||||
this.note = note;
|
||||
this.cardId = cardId;
|
||||
this.barcodeType = barcodeType;
|
||||
this.headerColor = headerColor;
|
||||
this.headerTextColor = headerTextColor;
|
||||
}
|
||||
|
||||
public static LoyaltyCard toLoyaltyCard(Cursor cursor)
|
||||
@@ -27,6 +37,22 @@ public class LoyaltyCard
|
||||
String cardId = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.CARD_ID));
|
||||
String barcodeType = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE));
|
||||
|
||||
return new LoyaltyCard(id, store, note, cardId, barcodeType);
|
||||
int headerColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_COLOR);
|
||||
int headerTextColorColumn = cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR);
|
||||
|
||||
Integer headerColor = null;
|
||||
Integer headerTextColor = null;
|
||||
|
||||
if(cursor.isNull(headerColorColumn) == false)
|
||||
{
|
||||
headerColor = cursor.getInt(headerColorColumn);
|
||||
}
|
||||
|
||||
if(cursor.isNull(headerTextColorColumn) == false)
|
||||
{
|
||||
headerTextColor = cursor.getInt(headerTextColorColumn);
|
||||
}
|
||||
|
||||
return new LoyaltyCard(id, store, note, cardId, barcodeType, headerColor, headerTextColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,19 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import protect.card_locker.preferences.Settings;
|
||||
|
||||
class LoyaltyCardCursorAdapter extends CursorAdapter
|
||||
{
|
||||
Settings settings;
|
||||
|
||||
public LoyaltyCardCursorAdapter(Context context, Cursor cursor)
|
||||
{
|
||||
super(context, cursor, 0);
|
||||
settings = new Settings(context);
|
||||
}
|
||||
|
||||
// The newView method is used to inflate a new view and return it,
|
||||
@@ -29,25 +35,36 @@ class LoyaltyCardCursorAdapter extends CursorAdapter
|
||||
public void bindView(View view, Context context, Cursor cursor)
|
||||
{
|
||||
// Find fields to populate in inflated template
|
||||
ImageView thumbnail = view.findViewById(R.id.thumbnail);
|
||||
TextView storeField = (TextView) view.findViewById(R.id.store);
|
||||
TextView cardIdField = (TextView) view.findViewById(R.id.cardId);
|
||||
TextView noteField = (TextView) view.findViewById(R.id.note);
|
||||
|
||||
// Extract properties from cursor
|
||||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(cursor);
|
||||
|
||||
// Populate fields with extracted properties
|
||||
String storeAndNote = loyaltyCard.store;
|
||||
storeField.setText(loyaltyCard.store);
|
||||
|
||||
storeField.setTextSize(settings.getCardTitleListFontSize());
|
||||
|
||||
if(loyaltyCard.note.isEmpty() == false)
|
||||
{
|
||||
String storeNameAndNoteFormat = view.getResources().getString(R.string.storeNameAndNoteFormat);
|
||||
storeAndNote = String.format(storeNameAndNoteFormat, loyaltyCard.store, loyaltyCard.note);
|
||||
noteField.setVisibility(View.VISIBLE);
|
||||
noteField.setText(loyaltyCard.note);
|
||||
noteField.setTextSize(settings.getCardNoteListFontSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
noteField.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
storeField.setText(storeAndNote);
|
||||
int tileLetterFontSize = context.getResources().getDimensionPixelSize(R.dimen.tileLetterFontSize);
|
||||
int pixelSize = context.getResources().getDimensionPixelSize(R.dimen.cardThumbnailSize);
|
||||
|
||||
String cardIdFormat = view.getResources().getString(R.string.cardIdFormat);
|
||||
String cardIdLabel = view.getResources().getString(R.string.cardId);
|
||||
String cardIdText = String.format(cardIdFormat, cardIdLabel, loyaltyCard.cardId);
|
||||
cardIdField.setText(cardIdText);
|
||||
Integer letterBackgroundColor = loyaltyCard.headerColor;
|
||||
Integer letterTextColor = loyaltyCard.headerTextColor;
|
||||
LetterBitmap letterBitmap = new LetterBitmap(context, loyaltyCard.store, loyaltyCard.store,
|
||||
tileLetterFontSize, pixelSize, pixelSize, letterBackgroundColor, letterTextColor);
|
||||
thumbnail.setImageBitmap(letterBitmap.getLetterTile());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialog;
|
||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
|
||||
|
||||
public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
{
|
||||
private static final String TAG = "CardLocker";
|
||||
|
||||
private static final int SELECT_BARCODE_REQUEST = 1;
|
||||
|
||||
EditText storeFieldEdit;
|
||||
EditText noteFieldEdit;
|
||||
ImageView headingColorSample;
|
||||
Button headingColorSelectButton;
|
||||
ImageView headingStoreTextColorSample;
|
||||
Button headingStoreTextColorSelectButton;
|
||||
TextView cardIdFieldView;
|
||||
View cardIdDivider;
|
||||
View cardIdTableRow;
|
||||
TextView barcodeTypeField;
|
||||
ImageView barcodeImage;
|
||||
View barcodeImageLayout;
|
||||
View barcodeCaptureLayout;
|
||||
|
||||
Button captureButton;
|
||||
Button enterButton;
|
||||
|
||||
int loyaltyCardId;
|
||||
boolean updateLoyaltyCard;
|
||||
Integer headingColorValue = null;
|
||||
Integer headingStoreTextColorValue = null;
|
||||
|
||||
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);
|
||||
|
||||
Log.d(TAG, "View activity: id=" + loyaltyCardId
|
||||
+ ", updateLoyaltyCard=" + Boolean.toString(updateLoyaltyCard));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.loyalty_card_edit_activity);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar != null)
|
||||
{
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
extractIntentFields(getIntent());
|
||||
|
||||
db = new DBHelper(this);
|
||||
|
||||
storeFieldEdit = findViewById(R.id.storeNameEdit);
|
||||
noteFieldEdit = findViewById(R.id.noteEdit);
|
||||
headingColorSample = findViewById(R.id.headingColorSample);
|
||||
headingColorSelectButton = findViewById(R.id.headingColorSelectButton);
|
||||
headingStoreTextColorSample = findViewById(R.id.headingStoreTextColorSample);
|
||||
headingStoreTextColorSelectButton = findViewById(R.id.headingStoreTextColorSelectButton);
|
||||
cardIdFieldView = findViewById(R.id.cardIdView);
|
||||
cardIdDivider = findViewById(R.id.cardIdDivider);
|
||||
cardIdTableRow = findViewById(R.id.cardIdTableRow);
|
||||
barcodeTypeField = findViewById(R.id.barcodeType);
|
||||
barcodeImage = findViewById(R.id.barcode);
|
||||
barcodeImageLayout = findViewById(R.id.barcodeLayout);
|
||||
barcodeCaptureLayout = findViewById(R.id.barcodeCaptureLayout);
|
||||
|
||||
captureButton = findViewById(R.id.captureButton);
|
||||
enterButton = 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
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
Log.i(TAG, "To view card: " + loyaltyCardId);
|
||||
|
||||
if(updateLoyaltyCard)
|
||||
{
|
||||
final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId);
|
||||
if(loyaltyCard == null)
|
||||
{
|
||||
Log.w(TAG, "Could not lookup loyalty card " + loyaltyCardId);
|
||||
Toast.makeText(this, R.string.noCardExistsError, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if(storeFieldEdit.getText().length() == 0)
|
||||
{
|
||||
storeFieldEdit.setText(loyaltyCard.store);
|
||||
}
|
||||
|
||||
if(noteFieldEdit.getText().length() == 0)
|
||||
{
|
||||
noteFieldEdit.setText(loyaltyCard.note);
|
||||
}
|
||||
|
||||
if(cardIdFieldView.getText().length() == 0)
|
||||
{
|
||||
cardIdFieldView.setText(loyaltyCard.cardId);
|
||||
}
|
||||
|
||||
if(barcodeTypeField.getText().length() == 0)
|
||||
{
|
||||
barcodeTypeField.setText(loyaltyCard.barcodeType);
|
||||
}
|
||||
|
||||
if(headingColorValue == null)
|
||||
{
|
||||
headingColorValue = loyaltyCard.headerColor;
|
||||
if(headingColorValue == null)
|
||||
{
|
||||
headingColorValue = LetterBitmap.getDefaultColor(this, loyaltyCard.store);
|
||||
}
|
||||
headingColorSample.setBackgroundColor(headingColorValue);
|
||||
}
|
||||
|
||||
if(headingStoreTextColorValue == null)
|
||||
{
|
||||
headingStoreTextColorValue = loyaltyCard.headerTextColor;
|
||||
if(headingStoreTextColorValue == null)
|
||||
{
|
||||
headingStoreTextColorValue = Color.WHITE;
|
||||
}
|
||||
headingStoreTextColorSample.setBackgroundColor(headingStoreTextColorValue);
|
||||
}
|
||||
|
||||
setTitle(R.string.editCardTitle);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTitle(R.string.addCardTitle);
|
||||
}
|
||||
|
||||
if(headingColorValue == null)
|
||||
{
|
||||
// Select a random color to start out with.
|
||||
TypedArray colors = getResources().obtainTypedArray(R.array.letter_tile_colors);
|
||||
final int color = (int)(Math.random() * colors.length());
|
||||
headingColorValue = colors.getColor(color, Color.BLACK);
|
||||
colors.recycle();
|
||||
|
||||
headingColorSample.setBackgroundColor(headingColorValue);
|
||||
}
|
||||
|
||||
if(headingStoreTextColorValue == null)
|
||||
{
|
||||
headingStoreTextColorValue = Color.WHITE;
|
||||
headingStoreTextColorSample.setBackgroundColor(headingStoreTextColorValue);
|
||||
}
|
||||
|
||||
headingColorSelectButton.setOnClickListener(new ColorSelectListener(headingColorValue, true));
|
||||
headingStoreTextColorSelectButton.setOnClickListener(new ColorSelectListener(headingStoreTextColorValue, false));
|
||||
|
||||
if(cardIdFieldView.getText().length() > 0 && barcodeTypeField.getText().length() > 0)
|
||||
{
|
||||
String formatString = barcodeTypeField.getText().toString();
|
||||
final BarcodeFormat format = BarcodeFormat.valueOf(formatString);
|
||||
final String cardIdString = cardIdFieldView.getText().toString();
|
||||
|
||||
if(barcodeImage.getHeight() == 0)
|
||||
{
|
||||
Log.d(TAG, "ImageView size is not known known at start, waiting for load");
|
||||
// The size of the ImageView is not yet available as it has not
|
||||
// yet been drawn. Wait for it to be drawn so the size is available.
|
||||
barcodeImage.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new ViewTreeObserver.OnGlobalLayoutListener()
|
||||
{
|
||||
@Override
|
||||
public void onGlobalLayout()
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < 16)
|
||||
{
|
||||
barcodeImage.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
barcodeImage.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
}
|
||||
|
||||
Log.d(TAG, "ImageView size now known");
|
||||
new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "ImageView size known known, creating barcode");
|
||||
new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
|
||||
}
|
||||
|
||||
barcodeImageLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
View.OnClickListener captureCallback = new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
IntentIntegrator integrator = new IntentIntegrator(LoyaltyCardEditActivity.this);
|
||||
integrator.setDesiredBarcodeFormats(BarcodeSelectorActivity.SUPPORTED_BARCODE_TYPES);
|
||||
|
||||
String prompt = getResources().getString(R.string.scanCardBarcode);
|
||||
integrator.setPrompt(prompt);
|
||||
integrator.setBeepEnabled(false);
|
||||
integrator.initiateScan();
|
||||
}
|
||||
};
|
||||
|
||||
captureButton.setOnClickListener(captureCallback);
|
||||
|
||||
enterButton.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent i = new Intent(getApplicationContext(), BarcodeSelectorActivity.class);
|
||||
|
||||
String cardId = cardIdFieldView.getText().toString();
|
||||
if(cardId.length() > 0)
|
||||
{
|
||||
final Bundle b = new Bundle();
|
||||
b.putString("initialCardId", cardId);
|
||||
i.putExtras(b);
|
||||
}
|
||||
|
||||
startActivityForResult(i, SELECT_BARCODE_REQUEST);
|
||||
}
|
||||
});
|
||||
|
||||
if(cardIdFieldView.getText().length() > 0)
|
||||
{
|
||||
cardIdDivider.setVisibility(View.VISIBLE);
|
||||
cardIdTableRow.setVisibility(View.VISIBLE);
|
||||
enterButton.setText(R.string.editCard);
|
||||
}
|
||||
else
|
||||
{
|
||||
cardIdDivider.setVisibility(View.GONE);
|
||||
cardIdTableRow.setVisibility(View.GONE);
|
||||
enterButton.setText(R.string.enterCard);
|
||||
}
|
||||
}
|
||||
|
||||
class ColorSelectListener implements View.OnClickListener
|
||||
{
|
||||
final int defaultColor;
|
||||
final boolean isBackgroundColor;
|
||||
|
||||
ColorSelectListener(int defaultColor, boolean isBackgroundColor)
|
||||
{
|
||||
this.defaultColor = defaultColor;
|
||||
this.isBackgroundColor = isBackgroundColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
ColorPickerDialog dialog = ColorPickerDialog.newBuilder().setColor(defaultColor).create();
|
||||
dialog.setColorPickerDialogListener(new ColorPickerDialogListener()
|
||||
{
|
||||
@Override
|
||||
public void onColorSelected(int dialogId, int color)
|
||||
{
|
||||
if(isBackgroundColor)
|
||||
{
|
||||
headingColorSample.setBackgroundColor(color);
|
||||
headingColorValue = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
headingStoreTextColorSample.setBackgroundColor(color);
|
||||
headingStoreTextColorValue = color;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogDismissed(int dialogId)
|
||||
{
|
||||
// Nothing to do, no change made
|
||||
}
|
||||
});
|
||||
dialog.show(getFragmentManager(), "color-picker-dialog");
|
||||
}
|
||||
}
|
||||
|
||||
private void doSave()
|
||||
{
|
||||
String store = storeFieldEdit.getText().toString();
|
||||
String note = noteFieldEdit.getText().toString();
|
||||
String cardId = cardIdFieldView.getText().toString();
|
||||
String barcodeType = barcodeTypeField.getText().toString();
|
||||
|
||||
if(store.isEmpty())
|
||||
{
|
||||
Snackbar.make(storeFieldEdit, R.string.noStoreError, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(cardId.isEmpty() || barcodeType.isEmpty())
|
||||
{
|
||||
Snackbar.make(cardIdFieldView, R.string.noCardIdError, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(updateLoyaltyCard)
|
||||
{
|
||||
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
|
||||
Log.i(TAG, "Updated " + loyaltyCardId + " to " + cardId);
|
||||
}
|
||||
else
|
||||
{
|
||||
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType, headingColorValue, headingStoreTextColorValue);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
if(updateLoyaltyCard)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.card_update_menu, menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.card_add_menu, menu);
|
||||
}
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
|
||||
case R.id.action_delete:
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.deleteTitle);
|
||||
builder.setMessage(R.string.deleteConfirmation);
|
||||
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
Log.e(TAG, "Deleting card: " + loyaltyCardId);
|
||||
|
||||
DBHelper db = new DBHelper(LoyaltyCardEditActivity.this);
|
||||
db.deleteLoyaltyCard(loyaltyCardId);
|
||||
|
||||
ShortcutHelper.removeShortcut(LoyaltyCardEditActivity.this, loyaltyCardId);
|
||||
|
||||
finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
||||
return true;
|
||||
|
||||
case R.id.action_save:
|
||||
doSave();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent)
|
||||
{
|
||||
String contents = null;
|
||||
String format = null;
|
||||
|
||||
IntentResult result =
|
||||
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||
if (result != null)
|
||||
{
|
||||
Log.i(TAG, "Received barcode information from capture");
|
||||
contents = result.getContents();
|
||||
format = result.getFormatName();
|
||||
}
|
||||
|
||||
if(requestCode == SELECT_BARCODE_REQUEST && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
Log.i(TAG, "Received barcode information from capture");
|
||||
|
||||
contents = intent.getStringExtra(BarcodeSelectorActivity.BARCODE_CONTENTS);
|
||||
format = intent.getStringExtra(BarcodeSelectorActivity.BARCODE_FORMAT);
|
||||
}
|
||||
|
||||
if(contents != null && contents.isEmpty() == false &&
|
||||
format != null && format.isEmpty() == false)
|
||||
{
|
||||
Log.i(TAG, "Read barcode id: " + contents);
|
||||
Log.i(TAG, "Read format: " + format);
|
||||
|
||||
TextView cardIdView = findViewById(R.id.cardIdView);
|
||||
cardIdView.setText(contents);
|
||||
|
||||
final TextView barcodeTypeField = findViewById(R.id.barcodeType);
|
||||
barcodeTypeField.setText(format);
|
||||
onResume();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +1,52 @@
|
||||
package protect.card_locker;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.TextViewCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
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;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
|
||||
import protect.card_locker.preferences.Settings;
|
||||
|
||||
|
||||
public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
{
|
||||
private static final String TAG = "CardLocker";
|
||||
|
||||
private static final int SELECT_BARCODE_REQUEST = 1;
|
||||
|
||||
EditText storeFieldEdit;
|
||||
TextView storeFieldView;
|
||||
EditText noteFieldEdit;
|
||||
TextView noteFieldView;
|
||||
TextView cardIdFieldView;
|
||||
View cardIdDivider;
|
||||
View cardIdTableRow;
|
||||
TextView barcodeTypeField;
|
||||
TextView noteView;
|
||||
View noteViewDivider;
|
||||
TextView storeName;
|
||||
ImageView barcodeImage;
|
||||
View barcodeImageLayout;
|
||||
View barcodeCaptureLayout;
|
||||
|
||||
Button captureButton;
|
||||
Button enterButton;
|
||||
|
||||
View collapsingToolbarLayout;
|
||||
int loyaltyCardId;
|
||||
boolean updateLoyaltyCard;
|
||||
boolean viewLoyaltyCard;
|
||||
|
||||
boolean rotationEnabled;
|
||||
|
||||
DBHelper db;
|
||||
Settings settings;
|
||||
|
||||
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));
|
||||
Log.d(TAG, "View activity: id=" + loyaltyCardId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,8 +54,13 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.loyalty_card_view_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
settings = new Settings(this);
|
||||
|
||||
extractIntentFields(getIntent());
|
||||
|
||||
setContentView(R.layout.loyalty_card_view_layout);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar != null)
|
||||
@@ -88,24 +68,14 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
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);
|
||||
cardIdFieldView = findViewById(R.id.cardIdView);
|
||||
noteView = findViewById(R.id.noteView);
|
||||
noteViewDivider = findViewById(R.id.noteViewDivider);
|
||||
storeName = findViewById(R.id.storeName);
|
||||
barcodeImage = findViewById(R.id.barcode);
|
||||
collapsingToolbarLayout = findViewById(R.id.collapsingToolbarLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,12 +83,6 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
{
|
||||
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
|
||||
@@ -128,90 +92,80 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
|
||||
Log.i(TAG, "To view card: " + loyaltyCardId);
|
||||
|
||||
if(viewLoyaltyCard)
|
||||
// The brightness value is on a scale from [0, ..., 1], where
|
||||
// '1' is the brightest. We attempt to maximize the brightness
|
||||
// to help barcode readers scan the barcode.
|
||||
Window window = getWindow();
|
||||
if(window != null)
|
||||
{
|
||||
// The brightness value is on a scale from [0, ..., 1], where
|
||||
// '1' is the brightest. We attempt to maximize the brightness
|
||||
// to help barcode readers scan the barcode.
|
||||
Window window = getWindow();
|
||||
if(window != null)
|
||||
{
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
attributes.screenBrightness = 1F;
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
attributes.screenBrightness = 1F;
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
|
||||
if(updateLoyaltyCard || viewLoyaltyCard)
|
||||
final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId);
|
||||
if(loyaltyCard == null)
|
||||
{
|
||||
final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId);
|
||||
if(loyaltyCard == null)
|
||||
{
|
||||
Log.w(TAG, "Could not lookup loyalty card " + loyaltyCardId);
|
||||
Toast.makeText(this, R.string.noCardExistsError, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
Log.w(TAG, "Could not lookup loyalty card " + loyaltyCardId);
|
||||
Toast.makeText(this, R.string.noCardExistsError, Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if(storeFieldEdit.getText().length() == 0)
|
||||
{
|
||||
storeFieldEdit.setText(loyaltyCard.store);
|
||||
storeFieldView.setText(loyaltyCard.store);
|
||||
}
|
||||
String formatString = loyaltyCard.barcodeType;
|
||||
final BarcodeFormat format = BarcodeFormat.valueOf(formatString);
|
||||
final String cardIdString = loyaltyCard.cardId;
|
||||
|
||||
if(noteFieldEdit.getText().length() == 0)
|
||||
{
|
||||
noteFieldEdit.setText(loyaltyCard.note);
|
||||
noteFieldView.setText(loyaltyCard.note);
|
||||
}
|
||||
cardIdFieldView.setText(loyaltyCard.cardId);
|
||||
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(cardIdFieldView,
|
||||
getResources().getInteger(R.integer.settings_card_id_min_font_size_sp)-1, settings.getCardIdFontSize(),
|
||||
1, TypedValue.COMPLEX_UNIT_SP);
|
||||
|
||||
if(cardIdFieldView.getText().length() == 0)
|
||||
{
|
||||
cardIdFieldView.setText(loyaltyCard.cardId);
|
||||
}
|
||||
|
||||
if(barcodeTypeField.getText().length() == 0)
|
||||
{
|
||||
barcodeTypeField.setText(loyaltyCard.barcodeType);
|
||||
}
|
||||
|
||||
if(updateLoyaltyCard)
|
||||
{
|
||||
setTitle(R.string.editCardTitle);
|
||||
|
||||
storeFieldView.setVisibility(View.GONE);
|
||||
noteFieldView.setVisibility(View.GONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
barcodeCaptureLayout.setVisibility(View.GONE);
|
||||
captureButton.setVisibility(View.GONE);
|
||||
setTitle(R.string.viewCardTitle);
|
||||
|
||||
storeFieldEdit.setVisibility(View.GONE);
|
||||
noteFieldEdit.setVisibility(View.GONE);
|
||||
}
|
||||
if(loyaltyCard.note.length() > 0)
|
||||
{
|
||||
noteView.setText(loyaltyCard.note);
|
||||
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(noteView,
|
||||
getResources().getInteger(R.integer.settings_card_note_min_font_size_sp)-1,
|
||||
settings.getCardNoteFontSize(), 1, TypedValue.COMPLEX_UNIT_SP);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTitle(R.string.addCardTitle);
|
||||
|
||||
storeFieldView.setVisibility(View.GONE);
|
||||
noteFieldView.setVisibility(View.GONE);
|
||||
noteView.setVisibility(View.GONE);
|
||||
noteViewDivider.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(cardIdFieldView.getText().length() > 0 && barcodeTypeField.getText().length() > 0)
|
||||
{
|
||||
String formatString = barcodeTypeField.getText().toString();
|
||||
final BarcodeFormat format = BarcodeFormat.valueOf(formatString);
|
||||
final String cardIdString = cardIdFieldView.getText().toString();
|
||||
storeName.setText(loyaltyCard.store);
|
||||
storeName.setTextSize(settings.getCardTitleFontSize());
|
||||
|
||||
if(barcodeImage.getHeight() == 0)
|
||||
{
|
||||
Log.d(TAG, "ImageView size is not known known at start, waiting for load");
|
||||
// The size of the ImageView is not yet available as it has not
|
||||
// yet been drawn. Wait for it to be drawn so the size is available.
|
||||
barcodeImage.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
int textColor;
|
||||
if(loyaltyCard.headerTextColor != null)
|
||||
{
|
||||
textColor = loyaltyCard.headerTextColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
textColor = Color.WHITE;
|
||||
}
|
||||
storeName.setTextColor(textColor);
|
||||
|
||||
int backgroundHeaderColor;
|
||||
if(loyaltyCard.headerColor != null)
|
||||
{
|
||||
backgroundHeaderColor = loyaltyCard.headerColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundHeaderColor = LetterBitmap.getDefaultColor(this, loyaltyCard.store);
|
||||
}
|
||||
|
||||
collapsingToolbarLayout.setBackgroundColor(backgroundHeaderColor);
|
||||
|
||||
if(barcodeImage.getHeight() == 0)
|
||||
{
|
||||
Log.d(TAG, "ImageView size is not known known at start, waiting for load");
|
||||
// The size of the ImageView is not yet available as it has not
|
||||
// yet been drawn. Wait for it to be drawn so the size is available.
|
||||
barcodeImage.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||
new ViewTreeObserver.OnGlobalLayoutListener()
|
||||
{
|
||||
@Override
|
||||
@@ -230,112 +184,19 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "ImageView size known known, creating barcode");
|
||||
new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
|
||||
}
|
||||
|
||||
barcodeImageLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
View.OnClickListener captureCallback = new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
IntentIntegrator integrator = new IntentIntegrator(LoyaltyCardViewActivity.this);
|
||||
integrator.setDesiredBarcodeFormats(BarcodeSelectorActivity.SUPPORTED_BARCODE_TYPES);
|
||||
|
||||
String prompt = getResources().getString(R.string.scanCardBarcode);
|
||||
integrator.setPrompt(prompt);
|
||||
integrator.initiateScan();
|
||||
}
|
||||
};
|
||||
|
||||
captureButton.setOnClickListener(captureCallback);
|
||||
|
||||
enterButton.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
Intent i = new Intent(getApplicationContext(), BarcodeSelectorActivity.class);
|
||||
|
||||
String cardId = cardIdFieldView.getText().toString();
|
||||
if(cardId.length() > 0)
|
||||
{
|
||||
final Bundle b = new Bundle();
|
||||
b.putString("initialCardId", cardId);
|
||||
i.putExtras(b);
|
||||
}
|
||||
|
||||
startActivityForResult(i, SELECT_BARCODE_REQUEST);
|
||||
}
|
||||
});
|
||||
|
||||
if(cardIdFieldView.getText().length() > 0)
|
||||
{
|
||||
cardIdDivider.setVisibility(View.VISIBLE);
|
||||
cardIdTableRow.setVisibility(View.VISIBLE);
|
||||
enterButton.setText(R.string.editCard);
|
||||
}
|
||||
else
|
||||
{
|
||||
cardIdDivider.setVisibility(View.GONE);
|
||||
cardIdTableRow.setVisibility(View.GONE);
|
||||
enterButton.setText(R.string.enterCard);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSave()
|
||||
{
|
||||
String store = storeFieldEdit.getText().toString();
|
||||
String note = noteFieldEdit.getText().toString();
|
||||
String cardId = cardIdFieldView.getText().toString();
|
||||
String barcodeType = barcodeTypeField.getText().toString();
|
||||
|
||||
if(store.isEmpty())
|
||||
{
|
||||
Snackbar.make(storeFieldEdit, R.string.noStoreError, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
Log.d(TAG, "ImageView size known known, creating barcode");
|
||||
new BarcodeImageWriterTask(barcodeImage, cardIdString, format).execute();
|
||||
}
|
||||
|
||||
if(cardId.isEmpty() || barcodeType.isEmpty())
|
||||
{
|
||||
Snackbar.make(cardIdFieldView, R.string.noCardIdError, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(updateLoyaltyCard)
|
||||
{
|
||||
db.updateLoyaltyCard(loyaltyCardId, store, note, cardId, barcodeType);
|
||||
Log.i(TAG, "Updated " + loyaltyCardId + " to " + cardId);
|
||||
}
|
||||
else
|
||||
{
|
||||
loyaltyCardId = (int)db.insertLoyaltyCard(store, note, cardId, barcodeType);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
if(viewLoyaltyCard)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.card_view_menu, menu);
|
||||
}
|
||||
else if(updateLoyaltyCard)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.card_update_menu, menu);
|
||||
}
|
||||
else
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.card_add_menu, menu);
|
||||
}
|
||||
getMenuInflater().inflate(R.menu.card_view_menu, menu);
|
||||
|
||||
rotationEnabled = true;
|
||||
|
||||
@@ -353,40 +214,8 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
finish();
|
||||
break;
|
||||
|
||||
case R.id.action_delete:
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.deleteTitle);
|
||||
builder.setMessage(R.string.deleteConfirmation);
|
||||
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
Log.e(TAG, "Deleting card: " + loyaltyCardId);
|
||||
|
||||
DBHelper db = new DBHelper(LoyaltyCardViewActivity.this);
|
||||
db.deleteLoyaltyCard(loyaltyCardId);
|
||||
|
||||
ShortcutHelper.removeShortcut(LoyaltyCardViewActivity.this, loyaltyCardId);
|
||||
|
||||
finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
||||
return true;
|
||||
case R.id.action_edit:
|
||||
Intent intent = new Intent(getApplicationContext(), LoyaltyCardViewActivity.class);
|
||||
Intent intent = new Intent(getApplicationContext(), LoyaltyCardEditActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("id", loyaltyCardId);
|
||||
bundle.putBoolean("update", true);
|
||||
@@ -410,50 +239,8 @@ public class LoyaltyCardViewActivity extends AppCompatActivity
|
||||
}
|
||||
rotationEnabled = !rotationEnabled;
|
||||
return true;
|
||||
|
||||
case R.id.action_save:
|
||||
doSave();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent)
|
||||
{
|
||||
String contents = null;
|
||||
String format = null;
|
||||
|
||||
IntentResult result =
|
||||
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||
if (result != null)
|
||||
{
|
||||
Log.i(TAG, "Received barcode information from capture");
|
||||
contents = result.getContents();
|
||||
format = result.getFormatName();
|
||||
}
|
||||
|
||||
if(requestCode == SELECT_BARCODE_REQUEST && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
Log.i(TAG, "Received barcode information from capture");
|
||||
|
||||
contents = intent.getStringExtra(BarcodeSelectorActivity.BARCODE_CONTENTS);
|
||||
format = intent.getStringExtra(BarcodeSelectorActivity.BARCODE_FORMAT);
|
||||
}
|
||||
|
||||
if(contents != null && contents.isEmpty() == false &&
|
||||
format != null && format.isEmpty() == false)
|
||||
{
|
||||
Log.i(TAG, "Read barcode id: " + contents);
|
||||
Log.i(TAG, "Read format: " + format);
|
||||
|
||||
TextView cardIdView = (TextView)findViewById(R.id.cardIdView);
|
||||
cardIdView.setText(contents);
|
||||
|
||||
final TextView barcodeTypeField = (TextView) findViewById(R.id.barcodeType);
|
||||
barcodeTypeField.setText(format);
|
||||
onResume();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
|
||||
import protect.card_locker.intro.IntroActivity;
|
||||
import protect.card_locker.preferences.SettingsActivity;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
{
|
||||
@@ -40,7 +41,7 @@ public class MainActivity extends AppCompatActivity
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main_activity);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
updateLoyaltyCardList();
|
||||
@@ -62,8 +63,8 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
private void updateLoyaltyCardList()
|
||||
{
|
||||
final ListView cardList = (ListView) findViewById(R.id.list);
|
||||
final TextView helpText = (TextView) findViewById(R.id.helpText);
|
||||
final ListView cardList = findViewById(R.id.list);
|
||||
final TextView helpText = findViewById(R.id.helpText);
|
||||
final DBHelper db = new DBHelper(this);
|
||||
|
||||
if(db.getLoyaltyCardCount() > 0)
|
||||
@@ -96,7 +97,6 @@ public class MainActivity extends AppCompatActivity
|
||||
i.setAction("");
|
||||
final Bundle b = new Bundle();
|
||||
b.putInt("id", loyaltyCard.id);
|
||||
b.putBoolean("view", true);
|
||||
i.putExtras(b);
|
||||
|
||||
ShortcutHelper.updateShortcuts(MainActivity.this, loyaltyCard, i);
|
||||
@@ -121,7 +121,7 @@ public class MainActivity extends AppCompatActivity
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
||||
ListView listView = (ListView) findViewById(R.id.list);
|
||||
ListView listView = findViewById(R.id.list);
|
||||
|
||||
Cursor cardCursor = (Cursor)listView.getItemAtPosition(info.position);
|
||||
LoyaltyCard card = LoyaltyCard.toLoyaltyCard(cardCursor);
|
||||
@@ -153,7 +153,7 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
if (id == R.id.action_add)
|
||||
{
|
||||
Intent i = new Intent(getApplicationContext(), LoyaltyCardViewActivity.class);
|
||||
Intent i = new Intent(getApplicationContext(), LoyaltyCardEditActivity.class);
|
||||
startActivity(i);
|
||||
return true;
|
||||
}
|
||||
@@ -165,6 +165,13 @@ public class MainActivity extends AppCompatActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
if(id == R.id.action_settings)
|
||||
{
|
||||
Intent i = new Intent(getApplicationContext(), SettingsActivity.class);
|
||||
startActivity(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(id == R.id.action_intro)
|
||||
{
|
||||
startIntro();
|
||||
@@ -182,14 +189,15 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
private void displayAboutDialog()
|
||||
{
|
||||
final Map<String, String> USED_LIBRARIES = ImmutableMap.of
|
||||
(
|
||||
"Commons CSV", "https://commons.apache.org/proper/commons-csv/",
|
||||
"Guava", "https://github.com/google/guava",
|
||||
"ZXing", "https://github.com/zxing/zxing",
|
||||
"ZXing Android Embedded", "https://github.com/journeyapps/zxing-android-embedded",
|
||||
"AppIntro", "https://github.com/apl-devs/AppIntro"
|
||||
);
|
||||
final Map<String, String> USED_LIBRARIES = new ImmutableMap.Builder<String, String>()
|
||||
.put("Commons CSV", "https://commons.apache.org/proper/commons-csv/")
|
||||
.put("Guava", "https://github.com/google/guava")
|
||||
.put("ZXing", "https://github.com/zxing/zxing")
|
||||
.put("ZXing Android Embedded", "https://github.com/journeyapps/zxing-android-embedded")
|
||||
.put("AppIntro", "https://github.com/apl-devs/AppIntro")
|
||||
.put("Color Picker", "https://github.com/jaredrummler/ColorPicker")
|
||||
.put("VNTNumberPickerPreference", "https://github.com/vanniktech/VNTNumberPickerPreference")
|
||||
.build();
|
||||
|
||||
final Map<String, String> USED_ASSETS = ImmutableMap.of
|
||||
(
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package protect.card_locker.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.IntegerRes;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import protect.card_locker.R;
|
||||
|
||||
public class Settings
|
||||
{
|
||||
private Context context;
|
||||
private SharedPreferences settings;
|
||||
|
||||
public Settings(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
this.settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
private String getResString(@StringRes int resId)
|
||||
{
|
||||
return context.getString(resId);
|
||||
}
|
||||
|
||||
private int getResInt(@IntegerRes int resId)
|
||||
{
|
||||
return context.getResources().getInteger(resId);
|
||||
}
|
||||
|
||||
private int getInt(@StringRes int keyId, @IntegerRes int defaultId)
|
||||
{
|
||||
return settings.getInt(getResString(keyId), getResInt(defaultId));
|
||||
}
|
||||
|
||||
public int getCardTitleListFontSize()
|
||||
{
|
||||
return getInt(R.string.settings_key_card_title_list_font_size, R.integer.settings_card_title_list_font_size_sp);
|
||||
}
|
||||
|
||||
public int getCardNoteListFontSize()
|
||||
{
|
||||
return getInt(R.string.settings_key_card_note_list_font_size, R.integer.settings_card_note_list_font_size_sp);
|
||||
}
|
||||
|
||||
public int getCardTitleFontSize()
|
||||
{
|
||||
return getInt(R.string.settings_key_card_title_font_size, R.integer.settings_card_title_font_size_sp);
|
||||
}
|
||||
|
||||
public int getCardIdFontSize()
|
||||
{
|
||||
return getInt(R.string.settings_key_card_id_font_size, R.integer.settings_card_id_font_size_sp);
|
||||
}
|
||||
|
||||
public int getCardNoteFontSize()
|
||||
{
|
||||
return getInt(R.string.settings_key_card_note_font_size, R.integer.settings_card_note_font_size_sp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package protect.card_locker.preferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import protect.card_locker.R;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity
|
||||
{
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar != null)
|
||||
{
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
|
||||
if(id == android.R.id.home)
|
||||
{
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragment
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 46 KiB |
@@ -72,14 +72,6 @@
|
||||
android:textSize="@dimen/inputSize"
|
||||
android:layout_toEndOf="@id/storeNameField"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/storeNameView"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="@dimen/inputPadding"
|
||||
android:textSize="@dimen/inputSize"
|
||||
android:textIsSelectable="true"
|
||||
android:layout_toEndOf="@id/storeNameField"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<View
|
||||
@@ -128,16 +120,149 @@
|
||||
android:padding="@dimen/inputPadding"
|
||||
android:textSize="@dimen/inputSize"
|
||||
android:layout_toEndOf="@id/noteField"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<View
|
||||
android:gravity="end"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="@dimen/inputBorderThickness"
|
||||
android:background="@color/inputBorder" />
|
||||
</TableRow>
|
||||
|
||||
<!-- Store Header Background Color -->
|
||||
<View
|
||||
android:layout_height="@dimen/inputBorderThickness"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/inputBorder" />
|
||||
<TableRow
|
||||
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" />
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
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/noteView"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:padding="@dimen/inputPadding"
|
||||
android:id="@+id/headingField"
|
||||
android:text="@string/storeTextBackgroundColorTitle"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:textSize="@dimen/inputSize"
|
||||
android:textIsSelectable="true"
|
||||
android:layout_toEndOf="@id/noteField"/>
|
||||
</RelativeLayout>
|
||||
android:padding="@dimen/inputPadding"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:id="@+id/headingColorSampleBorder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="@dimen/colorSamplePadding"
|
||||
app:layout_constraintStart_toEndOf="@id/headingField"
|
||||
app:layout_constraintEnd_toStartOf="@+id/headingColorSelectButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@android:color/black">
|
||||
<ImageView
|
||||
android:id="@+id/headingColorSample"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="1dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@android:color/white"
|
||||
android:contentDescription="@string/storeNameBackgroundColorDescription"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/headingColorSelectButton"
|
||||
android:text="@string/change"
|
||||
android:padding="@dimen/inputPadding"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_toEndOf="@id/headingColorSampleBorder"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<View
|
||||
android:gravity="end"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="@dimen/inputBorderThickness"
|
||||
android:background="@color/inputBorder" />
|
||||
</TableRow>
|
||||
|
||||
<!-- Store Text Color -->
|
||||
<View
|
||||
android:layout_height="@dimen/inputBorderThickness"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@color/inputBorder" />
|
||||
<TableRow
|
||||
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" />
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
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/storeTextField"
|
||||
android:text="@string/storeTextColorTitle"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:textSize="@dimen/inputSize"
|
||||
android:padding="@dimen/inputPadding"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:id="@+id/headingStoreTextColorSampleBorder"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="@dimen/colorSamplePadding"
|
||||
app:layout_constraintStart_toEndOf="@id/storeTextField"
|
||||
app:layout_constraintEnd_toStartOf="@+id/headingStoreTextColorSelectButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@android:color/black">
|
||||
<ImageView
|
||||
android:id="@+id/headingStoreTextColorSample"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="1dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@android:color/white"
|
||||
android:contentDescription="@string/storeNameColorDescription"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/headingStoreTextColorSelectButton"
|
||||
android:text="@string/change"
|
||||
android:padding="@dimen/inputPadding"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_toEndOf="@id/headingStoreTextColorSampleBorder"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<View
|
||||
android:gravity="end"
|
||||
@@ -1,32 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:padding="10.0dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:padding="5.0dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="true">
|
||||
<TextView android:textSize="20.0sp"
|
||||
android:id="@+id/store"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.0"
|
||||
android:maxLines="1"/>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:baselineAligned="false"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_width="@dimen/cardThumbnailSize"
|
||||
android:layout_height="@dimen/cardThumbnailSize"
|
||||
android:layout_marginEnd="@dimen/activity_margin"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
android:contentDescription="@string/thumbnailDescription"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/valueLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/store"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/storeNameTextSize"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/note"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textSize="@dimen/noteTextSize"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:padding="5.0dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="true">
|
||||
<TextView android:textSize="20.0sp"
|
||||
android:layout_gravity="start"
|
||||
android:id="@+id/cardId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
142
app/src/main/res/layout/loyalty_card_view_layout.xml
Normal file
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
>
|
||||
|
||||
<FrameLayout
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.constraint.Guideline
|
||||
android:id="@+id/centerGuideline"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintGuide_percent="0.5"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/barcode"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="20.0dip"
|
||||
android:layout_marginBottom="10.0dip"
|
||||
android:layout_marginStart="15.0dip"
|
||||
android:layout_marginEnd="15.0dip"
|
||||
app:layout_constraintBottom_toTopOf="@+id/centerGuideline"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:contentDescription="@string/barcodeImageDescription"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/cardIdView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginLeft="10.0dip"
|
||||
android:layout_marginRight="10.0dip"
|
||||
app:layout_constraintTop_toBottomOf="@id/centerGuideline"
|
||||
app:layout_constraintBottom_toTopOf="@+id/noteViewDivider"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:textAlignment="center"
|
||||
app:autoSizeTextType="uniform"
|
||||
app:autoSizeMinTextSize="@dimen/singleCardCardIdTextSizeMin"
|
||||
app:autoSizeMaxTextSize="@dimen/singleCardCardIdTextSizeMax"
|
||||
android:ellipsize="end"
|
||||
android:textIsSelectable="true"/>
|
||||
|
||||
<View
|
||||
android:id="@id/noteViewDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/black"
|
||||
app:layout_constraintTop_toBottomOf="@id/cardIdView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/noteView"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@id/noteView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10.0dip"
|
||||
android:ellipsize="end"
|
||||
android:layout_gravity="bottom"
|
||||
app:layout_constraintTop_toBottomOf="@id/noteViewDivider"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:autoSizeTextType="uniform"
|
||||
app:autoSizeMinTextSize="@dimen/singleCardNoteTextSizeMin"
|
||||
app:autoSizeMaxTextSize="@dimen/singleCardNoteTextSizeMax"
|
||||
android:textIsSelectable="true"/>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/drop_shadow_actionbar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="5.0dip"
|
||||
android:layout_gravity="top"/>
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar_layout"
|
||||
android:background="@android:color/transparent"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:weightSum="1.0"
|
||||
android:fitsSystemWindows="true">
|
||||
<android.support.design.widget.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsingToolbarLayout"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="56.0dip"
|
||||
android:layout_weight="1.0"
|
||||
app:expandedTitleMarginStart="48dp"
|
||||
app:expandedTitleMarginEnd="64dp"
|
||||
app:contentScrim="?colorPrimary"
|
||||
app:expandedTitleGravity="top">
|
||||
<TextView
|
||||
android:id="@+id/storeName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="40sp"
|
||||
android:textAlignment="center"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="?actionBarSize"
|
||||
android:layout_marginBottom="?actionBarSize"
|
||||
app:layout_collapseMode="parallax"
|
||||
android:fitsSystemWindows="true"/>
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@id/toolbar"
|
||||
android:background="@android:color/transparent"
|
||||
android:theme="@style/CardView.ActionBarTheme"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="?actionBarSize"
|
||||
app:contentInsetStart="72.0dip"
|
||||
app:layout_collapseMode="pin" />
|
||||
</android.support.design.widget.CollapsingToolbarLayout>
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
@@ -12,6 +12,10 @@
|
||||
android:icon="@drawable/ic_import_export_white_24dp"
|
||||
android:title="@string/importExport"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/action_intro"
|
||||
android:title="@string/startIntro"
|
||||
|
||||
@@ -13,24 +13,34 @@
|
||||
|
||||
<string name="cancel">Abbrechen</string>
|
||||
<string name="save">Speichern</string>
|
||||
<string name="capture">Karte erfassen</string>
|
||||
<string name="enterCard">Karte einfügen</string>
|
||||
<string name="capture">Karte scannen</string>
|
||||
<string name="enterCard">Manuell eingeben</string>
|
||||
<string name="editCard">Karte bearbeiten</string>
|
||||
<string name="edit">Bearbeiten</string>
|
||||
<string name="delete">Löschen</string>
|
||||
<string name="confirm">Bestätigen</string>
|
||||
<string name="lockScreen">Rotation blockieren</string>
|
||||
<string name="unlockScreen">Rotation zulassen</string>
|
||||
<string name="deleteTitle">Karte entfernen</string>
|
||||
<string name="deleteConfirmation">Bitte bestätigen Sie, dass diese Karte gelöscht werden soll.</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="copy_to_clipboard">Kopiere die Nummer in die Zwischenablage</string>
|
||||
<string name="sendLabel">Senden…</string>
|
||||
<string name="addedShortcut">Zum Home Screen hinzugefügt</string>
|
||||
|
||||
<string name="editCardTitle">Kundenkarte bearbeiten</string>
|
||||
<string name="addCardTitle">Neue Kundenkarte</string>
|
||||
<string name="viewCardTitle">Kundenkarte anzeigen</string>
|
||||
<string name="scanCardBarcode">Barcode scannen</string>
|
||||
<string name="cardShortcut">Shortcut zu einer Karte</string>
|
||||
<string name="noCardsMessage">Es ist noch keine Karte vorhanden, bitte zuerst eine hinzufügen</string>
|
||||
|
||||
<string name="barcodeImageDescription">Bild des Barcodes</string>
|
||||
|
||||
<string name="noStoreError">Kein Geschäft angegeben</string>
|
||||
<string name="noCardIdError">Keine Kartennummer angegeben</string>
|
||||
<string name="noCardExistsError">Karte konnte nicht gefunden werden</string>
|
||||
|
||||
<string name="cardIdFormat">%1$s: %2$s</string>
|
||||
<string name="importExport">Import/Export</string>
|
||||
<string name="importName">Import</string>
|
||||
@@ -86,4 +96,5 @@
|
||||
<string name="intro5Description">Sie können selbstverständlich Backups anlegen. Um Karten zu exportieren oder importieren wählen Sie Import/Export im Menü auf dem Hauptbildschirm.\n\n</string>
|
||||
<string name="intro6Title">Feedback\n</string>
|
||||
<string name="intro6Description">Diese App enthält keine Werbung, und ist freie und quelloffene Software. Für Details berühren Sie Über im Menü auf der Hauptseite.\n\nHinterlassen Sie uns ein Feedback im App-Store (:</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
|
||||
<string name="copy_to_clipboard_toast">Numéro de carte copié dans le presse-papier</string>
|
||||
|
||||
<string name="thumbnailDescription">Vignette pour la carte</string>
|
||||
|
||||
<string name="startIntro">Présentation</string>
|
||||
<string name="intro1Title">Bienvenue dans\nLoyalty Card Keychain\n</string>
|
||||
<string name="intro1Description">Gérez vos cartes de fidélité\nsur votre téléphone !\n\n</string>
|
||||
@@ -96,4 +98,5 @@
|
||||
<string name="intro5Description">Les cartes peuvent être sauvegardées. Touchez \'Importer/Exporter\' sur l\'écran principal pour restaurer ou sauvegarder les cartes.\n\n</string>
|
||||
<string name="intro6Title">Votre avis\n</string>
|
||||
<string name="intro6Description">Cette application est gratuite, sans publicité, et son code est ouvert. Découvrez-en plus en touchant \'à propos\' sur l\'écran principal.\n\nLaissez un commentaire sur votre magasin d\'applications (:</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -94,4 +94,5 @@
|
||||
<string name="intro5Description">I dati delle tessere possono essere salvati. Per esportare o importare tessere premi Importa/Esporta nel menù nella schermata principale.\n\n</string>
|
||||
<string name="intro6Title">Feedback\n</string>
|
||||
<string name="intro6Description">Questa app è gratuita, priva di pubblicità e open source. Guarda i dettagli premendo su Informazioni nella schermata principale.\n\nPer favore, lascia un feedback nell\'app store! (:</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<string name="debug_version_fmt">Versie: <xliff:g id="version">%s</xliff:g></string>
|
||||
<string name="app_revision_fmt">Revisieïnformatie: <xliff:g id="app_revision_url">%s</xliff:g></string>
|
||||
<string name="app_libraries"><xliff:g id="app_name">%s</xliff:g> gebruikt de volgende bibliotheken van derden: <xliff:g id="app_libraries_list">%s</xliff:g></string>
|
||||
<string name="app_resources"><xliff:g id="app_name">%s</xliff:g> gebruikt de volgende bronnen van derden: <xliff:g id="app_resources_list\">%s</xliff:g></string>
|
||||
<string name="app_resources"><xliff:g id="app_name">%s</xliff:g> gebruikt de volgende bronnen van derden: <xliff:g id="app_resources_list">%s</xliff:g></string>
|
||||
|
||||
<string name="selectBarcodeTitle">Selecteer barcode</string>
|
||||
<string name="enterBarcodeInstructions">Voer de waarde van de barcode in en kies daarna de afbeelding die de barcode die je wil gebruiken representeert</string>
|
||||
@@ -96,4 +96,5 @@
|
||||
<string name="intro5Description">De kaarten kunnen worden geback-upt. Om te kaarten te exporteren of importeren, raak in het menu in het hoofdscherm Importeer/Exporteer aan.\n\n</string>
|
||||
<string name="intro6Title">Terugkoppeling\n</string>
|
||||
<string name="intro6Description">Deze app is gratis, vrije van advertenties en opensource. Zie details door Over aan te raken in het menu op het hoofdscher,.\n\nBeschrijft je ervaring in de app store! (:</string>
|
||||
|
||||
</resources>
|
||||
|
||||
45
app/src/main/res/values-ru/strings.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<resources
|
||||
xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
|
||||
<string name="app_name">Брелок карт лояльности</string>
|
||||
<string name="action_add">Добавить</string>
|
||||
|
||||
<string name="noGiftCards">На данный момент у Вас нет ни одной карты лояльности. Нажмите на кнопку «+» (плюс) вверху, чтобы добавить первую карту.\n\n «Брелок карт лояльности» позволит Вам хранить скидочные карты в Вашем телефоне, чтобы они всегда были под рукой.</string>
|
||||
|
||||
<string name="storeName">Организация</string>
|
||||
<string name="note">Заметка</string>
|
||||
<string name="cardId">ID карты</string>
|
||||
<string name="barcodeType">Тип штрих-кода</string>
|
||||
|
||||
<string name="cancel">Отмена</string>
|
||||
<string name="save">Сохранить</string>
|
||||
<string name="capture">Просканировать карту</string>
|
||||
<string name="enterCard">Ввести вручную</string>
|
||||
<string name="editCard">Редактировать карту</string>
|
||||
<string name="edit">Редактировать</string>
|
||||
<string name="delete">Удалить</string>
|
||||
<string name="confirm">Подтвердить</string>
|
||||
<string name="deleteTitle">Удалить карту лояльности</string>
|
||||
<string name="deleteConfirmation">Вы действительно хотите удалить эту карту?</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="copy_to_clipboard">Скопировать идентификатор в буфер обмена</string>
|
||||
<string name="sendLabel">Отправить…</string>
|
||||
<string name="addedShortcut">Карта добавлена на главный экран.</string>
|
||||
|
||||
<string name="editCardTitle">Редактировать карточку лояльности</string>
|
||||
<string name="addCardTitle">Добавить карточку лояльности</string>
|
||||
<string name="thumbnailDescription">Логорип карты</string>
|
||||
|
||||
<string name="startIntro">Введение</string>
|
||||
<string name="intro1Title">Добро пожаловать в программу «Брелок карт лояльности»\n</string>
|
||||
<string name="intro2Title">Добавление карт\n</string>
|
||||
<string name="intro2Description">Добавьте новую карту, коснувшись кнопки плюса на главной странице.\n\n</string>
|
||||
<string name="intro3Title">Добавление карт\n</string>
|
||||
<string name="intro4Title">Показать карточку\n</string>
|
||||
<string name="intro4Description">Чтобы перейти к просмотру карты, нажмите на название организации на главной странице.\n\n</string>
|
||||
<string name="intro5Title">Резервное копирование\n</string>
|
||||
<string name="intro5Description">Вы можете сохранить карты во внешнее хранилище. Чтобы экспортировать или импортировать данные карты, нажмите «Импорт/Экспорт» в меню на главной странице.\n\n</string>
|
||||
<string name="intro6Title">Обратная связь\n</string>
|
||||
<string name="intro6Description">Это бесплатное приложение, не обремененное рекламой и с открытым исходным кодом. Подробнее см. в разделе «О программе» в меню на главной странице.\n\nПожалуйста, оставьте отзыв в магазине приложений! (:</string>
|
||||
|
||||
</resources>
|
||||
@@ -11,9 +11,27 @@
|
||||
<dimen name="text_size_medium">18sp</dimen>
|
||||
<dimen name="text_size_large">22sp</dimen>
|
||||
|
||||
<dimen name="storeNameTextSize">28sp</dimen>
|
||||
<dimen name="noteTextSize">14sp</dimen>
|
||||
|
||||
<dimen name="singleCardCardIdTextSizeMin">15sp</dimen>
|
||||
<dimen name="singleCardCardIdTextSizeMax">50sp</dimen>
|
||||
<dimen name="singleCardNoteTextSizeMin">25sp</dimen>
|
||||
<dimen name="singleCardNoteTextSizeMax">50sp</dimen>
|
||||
|
||||
<dimen name="inputBorderThickness">2dip</dimen>
|
||||
<dimen name="inputBorderDividerThickness">4dip</dimen>
|
||||
<dimen name="inputPadding">20dip</dimen>
|
||||
<dimen name="colorSamplePadding">10dip</dimen>
|
||||
<dimen name="inputSize">18sp</dimen>
|
||||
|
||||
<dimen name="cardThumbnailSize">46dp</dimen>
|
||||
<dimen name="cardThumbnailSizeLarge">200dp</dimen>
|
||||
|
||||
<dimen name="activity_margin_small">8dp</dimen>
|
||||
<dimen name="activity_margin">16dp</dimen>
|
||||
|
||||
<!-- The default letter tile text size -->
|
||||
<dimen name="tileLetterFontSize">33sp</dimen>
|
||||
<dimen name="cardViewLetterFontSize">100sp</dimen>
|
||||
</resources>
|
||||
|
||||
32
app/src/main/res/values/settings.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<array name="letter_tile_colors">
|
||||
<item>#f16364</item>
|
||||
<item>#f58559</item>
|
||||
<item>#f9a43e</item>
|
||||
<item>#e4c62e</item>
|
||||
<item>#67bf74</item>
|
||||
<item>#59a2be</item>
|
||||
<item>#2093cd</item>
|
||||
<item>#ad62a7</item>
|
||||
</array>
|
||||
|
||||
<!-- Default values -->
|
||||
<integer name="settings_card_title_list_font_size_sp">28</integer>
|
||||
<integer name="settings_card_note_list_font_size_sp">14</integer>
|
||||
<integer name="settings_card_title_font_size_sp">40</integer>
|
||||
<integer name="settings_card_id_font_size_sp">50</integer>
|
||||
<integer name="settings_card_note_font_size_sp">50</integer>
|
||||
|
||||
<!-- Constraints -->
|
||||
<integer name="settings_card_title_list_max_font_size_sp">40</integer>
|
||||
<integer name="settings_card_title_list_min_font_size_sp">16</integer>
|
||||
<integer name="settings_card_note_list_max_font_size_sp">25</integer>
|
||||
<integer name="settings_card_note_list_min_font_size_sp">10</integer>
|
||||
<integer name="settings_card_title_max_font_size_sp">50</integer>
|
||||
<integer name="settings_card_title_min_font_size_sp">16</integer>
|
||||
<integer name="settings_card_id_max_font_size_sp">50</integer>
|
||||
<integer name="settings_card_id_min_font_size_sp">16</integer>
|
||||
<integer name="settings_card_note_max_font_size_sp">50</integer>
|
||||
<integer name="settings_card_note_min_font_size_sp">26</integer>
|
||||
</resources>
|
||||
@@ -85,6 +85,8 @@
|
||||
|
||||
<string name="copy_to_clipboard_toast">Card ID copied to clipboard</string>
|
||||
|
||||
<string name="thumbnailDescription">Thumbnail for card</string>
|
||||
|
||||
<string name="startIntro">Start Intro</string>
|
||||
<string name="intro1Title">Welcome to Loyalty Card Keychain\n</string>
|
||||
<string name="intro1Description">Manage your barcode-based store/loyalty cards on your phone!\n\n</string>
|
||||
@@ -98,4 +100,24 @@
|
||||
<string name="intro5Description">The cards can be backed-up. To export or import card data touch Import/Export in the menu on the main page.\n\n</string>
|
||||
<string name="intro6Title">Feedback\n</string>
|
||||
<string name="intro6Description">This app is free, ad-free, and open source. See details by touching About in the menu on the main page.\n\nPlease leave feedback in the app store! (:</string>
|
||||
|
||||
<string name="change">Change</string>
|
||||
<string name="storeTextColorTitle">Store Text Color</string>
|
||||
<string name="storeTextBackgroundColorTitle">Heading Color</string>
|
||||
<string name="storeNameBackgroundColorDescription">Color for store text background</string>
|
||||
<string name="storeNameColorDescription">Color for store text</string>
|
||||
|
||||
<string name="settings">Settings</string>
|
||||
<string name="settings_category_title_ui">User interface</string>
|
||||
<string name="settings_card_title_list_font_size">Card title list font size</string>
|
||||
<string name="settings_key_card_title_list_font_size" translatable="false">pref_card_title_list_font_size_sp</string>
|
||||
<string name="settings_card_note_list_font_size">Card note list font size</string>
|
||||
<string name="settings_key_card_note_list_font_size" translatable="false">pref_card_note_list_font_size_sp</string>
|
||||
<string name="settings_card_title_font_size">Card title font size</string>
|
||||
<string name="settings_key_card_title_font_size" translatable="false">pref_card_title_font_size_sp</string>
|
||||
<string name="settings_card_id_font_size">Card ID font size</string>
|
||||
<string name="settings_key_card_id_font_size" translatable="false">pref_card_id_font_size_sp</string>
|
||||
<string name="settings_card_note_font_size">Card note font size</string>
|
||||
<string name="settings_key_card_note_font_size" translatable="false">pref_card_note_font_size_sp</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||
|
||||
<style name="CardView.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||
<!-- THIS is where you can color the arrow! -->
|
||||
<item name="colorControlNormal">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.TextView.NoData" parent="AppTheme">
|
||||
<item name="android:layout_centerHorizontal">true</item>
|
||||
<item name="android:layout_centerVertical">true</item>
|
||||
|
||||
46
app/src/main/res/xml/preferences.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_category_title_ui">
|
||||
|
||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
||||
android:key="@string/settings_key_card_title_list_font_size"
|
||||
android:title="@string/settings_card_title_list_font_size"
|
||||
android:defaultValue="@integer/settings_card_title_list_font_size_sp"
|
||||
app:vnt_maxValue="@integer/settings_card_title_list_max_font_size_sp"
|
||||
app:vnt_minValue="@integer/settings_card_title_list_min_font_size_sp" />
|
||||
|
||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
||||
android:key="@string/settings_key_card_note_list_font_size"
|
||||
android:title="@string/settings_card_note_list_font_size"
|
||||
android:defaultValue="@integer/settings_card_note_list_font_size_sp"
|
||||
app:vnt_maxValue="@integer/settings_card_note_list_max_font_size_sp"
|
||||
app:vnt_minValue="@integer/settings_card_note_list_min_font_size_sp" />
|
||||
|
||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
||||
android:key="@string/settings_key_card_title_font_size"
|
||||
android:title="@string/settings_card_title_font_size"
|
||||
android:defaultValue="@integer/settings_card_title_font_size_sp"
|
||||
app:vnt_maxValue="@integer/settings_card_title_max_font_size_sp"
|
||||
app:vnt_minValue="@integer/settings_card_title_min_font_size_sp"/>
|
||||
|
||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
||||
android:key="@string/settings_key_card_id_font_size"
|
||||
android:title="@string/settings_card_id_font_size"
|
||||
android:defaultValue="@integer/settings_card_id_font_size_sp"
|
||||
app:vnt_maxValue="@integer/settings_card_id_max_font_size_sp"
|
||||
app:vnt_minValue="@integer/settings_card_id_min_font_size_sp" />
|
||||
|
||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
||||
android:key="@string/settings_key_card_note_font_size"
|
||||
android:title="@string/settings_card_note_font_size"
|
||||
android:defaultValue="@integer/settings_card_note_font_size_sp"
|
||||
app:vnt_maxValue="@integer/settings_card_note_max_font_size_sp"
|
||||
app:vnt_minValue="@integer/settings_card_note_min_font_size_sp" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -4,6 +4,7 @@ import android.app.Activity;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
@@ -25,6 +26,9 @@ public class DatabaseTest
|
||||
{
|
||||
private DBHelper db;
|
||||
|
||||
private static final Integer DEFAULT_HEADER_COLOR = Color.BLACK;
|
||||
private static final Integer DEFAULT_HEADER_TEXT_COLOR = Color.WHITE;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
@@ -36,7 +40,7 @@ public class DatabaseTest
|
||||
public void addRemoveOneGiftCard()
|
||||
{
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
@@ -57,12 +61,12 @@ public class DatabaseTest
|
||||
@Test
|
||||
public void updateGiftCard()
|
||||
{
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
long id = db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
result = db.updateLoyaltyCard(1, "store1", "note1", "cardId1", BarcodeFormat.AZTEC.toString());
|
||||
result = db.updateLoyaltyCard(1, "store1", "note1", "cardId1", BarcodeFormat.AZTEC.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
@@ -80,7 +84,7 @@ public class DatabaseTest
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
boolean result = db.updateLoyaltyCard(1, "store1", "note1", "cardId1",
|
||||
BarcodeFormat.UPC_A.toString());
|
||||
BarcodeFormat.UPC_A.toString(), DEFAULT_HEADER_COLOR, DEFAULT_HEADER_TEXT_COLOR);
|
||||
assertEquals(false, result);
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
}
|
||||
@@ -88,7 +92,7 @@ public class DatabaseTest
|
||||
@Test
|
||||
public void emptyGiftCardValues()
|
||||
{
|
||||
long id = db.insertLoyaltyCard("", "", "", "");
|
||||
long id = db.insertLoyaltyCard("", "", "", "", null, null);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
@@ -111,7 +115,7 @@ public class DatabaseTest
|
||||
for(int index = CARDS_TO_ADD-1; index >= 0; index--)
|
||||
{
|
||||
long id = db.insertLoyaltyCard("store" + index, "note" + index, "cardId" + index,
|
||||
BarcodeFormat.UPC_A.toString());
|
||||
BarcodeFormat.UPC_A.toString(), index, index*2);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
@@ -130,7 +134,10 @@ public class DatabaseTest
|
||||
assertEquals("store"+index, cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STORE)));
|
||||
assertEquals("note"+index, cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.NOTE)));
|
||||
assertEquals("cardId"+index, cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.CARD_ID)));
|
||||
assertEquals("cardId"+index, cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.CARD_ID)));
|
||||
assertEquals(BarcodeFormat.UPC_A.toString(), cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE)));
|
||||
assertEquals(index, cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_COLOR)));
|
||||
assertEquals(index*2, cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR)));
|
||||
|
||||
cursor.moveToNext();
|
||||
}
|
||||
@@ -184,6 +191,8 @@ public class DatabaseTest
|
||||
assertEquals("cardId", card.cardId);
|
||||
assertEquals(BarcodeFormat.UPC_A.toString(), card.barcodeType);
|
||||
assertEquals("", card.note);
|
||||
assertEquals(null, card.headerColor);
|
||||
assertEquals(null, card.headerTextColor);
|
||||
|
||||
database.close();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Environment;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
import org.apache.tools.ant.filters.StringInputStream;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -22,10 +23,12 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Calendar;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -65,7 +68,7 @@ public class ImportExportTest
|
||||
{
|
||||
String storeName = String.format("store, \"%4d", index);
|
||||
String note = String.format("note, \"%4d", index);
|
||||
long id = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE);
|
||||
long id = db.insertLoyaltyCard(storeName, note, BARCODE_DATA, BARCODE_TYPE, index, index*2);
|
||||
boolean result = (id != -1);
|
||||
assertTrue(result);
|
||||
}
|
||||
@@ -94,6 +97,8 @@ public class ImportExportTest
|
||||
assertEquals(expectedNote, card.note);
|
||||
assertEquals(BARCODE_DATA, card.cardId);
|
||||
assertEquals(BARCODE_TYPE, card.barcodeType);
|
||||
assertEquals(Integer.valueOf(index), card.headerColor);
|
||||
assertEquals(Integer.valueOf(index*2), card.headerTextColor);
|
||||
|
||||
index++;
|
||||
}
|
||||
@@ -198,7 +203,11 @@ public class ImportExportTest
|
||||
|
||||
clearDatabase();
|
||||
|
||||
String corruptEntry = "ThisStringIsLikelyNotPartOfAnyFormat";
|
||||
// commons-csv would throw a RuntimeException if an entry was quotes but had
|
||||
// content after. For example:
|
||||
// abc,def,""abc,abc
|
||||
// ^ after the quote there should only be a , \n or EOF
|
||||
String corruptEntry = "ThisStringIsLikelyNotPartOfAnyFormat,\"\"a";
|
||||
|
||||
ByteArrayInputStream inData = new ByteArrayInputStream((outData.toString() + corruptEntry).getBytes());
|
||||
InputStreamReader inStream = new InputStreamReader(inData);
|
||||
@@ -272,4 +281,86 @@ public class ImportExportTest
|
||||
clearDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importWithoutColors() throws IOException
|
||||
{
|
||||
String csvText = "";
|
||||
csvText += DBHelper.LoyaltyCardDbIds.ID + "," +
|
||||
DBHelper.LoyaltyCardDbIds.STORE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.NOTE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.CARD_ID + "," +
|
||||
DBHelper.LoyaltyCardDbIds.BARCODE_TYPE + "\n";
|
||||
csvText += "1,store,note,12345,type";
|
||||
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(csvText.getBytes(StandardCharsets.UTF_8));
|
||||
InputStreamReader inStream = new InputStreamReader(inputStream);
|
||||
|
||||
// Import the CSV data
|
||||
boolean result = MultiFormatImporter.importData(db, inStream, DataFormat.CSV);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
assertEquals("store", card.store);
|
||||
assertEquals("note", card.note);
|
||||
assertEquals("12345", card.cardId);
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertNull(card.headerColor);
|
||||
assertNull(card.headerTextColor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importWithoutNullColors() throws IOException
|
||||
{
|
||||
String csvText = "";
|
||||
csvText += DBHelper.LoyaltyCardDbIds.ID + "," +
|
||||
DBHelper.LoyaltyCardDbIds.STORE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.NOTE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.CARD_ID + "," +
|
||||
DBHelper.LoyaltyCardDbIds.BARCODE_TYPE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.HEADER_COLOR + "," +
|
||||
DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR + "\n";
|
||||
csvText += "1,store,note,12345,type,,";
|
||||
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(csvText.getBytes(StandardCharsets.UTF_8));
|
||||
InputStreamReader inStream = new InputStreamReader(inputStream);
|
||||
|
||||
// Import the CSV data
|
||||
boolean result = MultiFormatImporter.importData(db, inStream, DataFormat.CSV);
|
||||
assertTrue(result);
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
assertEquals("store", card.store);
|
||||
assertEquals("note", card.note);
|
||||
assertEquals("12345", card.cardId);
|
||||
assertEquals("type", card.barcodeType);
|
||||
assertNull(card.headerColor);
|
||||
assertNull(card.headerTextColor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importWithoutInvalidColors() throws IOException
|
||||
{
|
||||
String csvText = "";
|
||||
csvText += DBHelper.LoyaltyCardDbIds.ID + "," +
|
||||
DBHelper.LoyaltyCardDbIds.STORE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.NOTE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.CARD_ID + "," +
|
||||
DBHelper.LoyaltyCardDbIds.BARCODE_TYPE + "," +
|
||||
DBHelper.LoyaltyCardDbIds.HEADER_COLOR + "," +
|
||||
DBHelper.LoyaltyCardDbIds.HEADER_TEXT_COLOR + "\n";
|
||||
csvText += "1,store,note,12345,type,not a number,invalid";
|
||||
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(csvText.getBytes(StandardCharsets.UTF_8));
|
||||
InputStreamReader inStream = new InputStreamReader(inputStream);
|
||||
|
||||
// Import the CSV data
|
||||
boolean result = MultiFormatImporter.importData(db, inStream, DataFormat.CSV);
|
||||
assertEquals(false, result);
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package protect.card_locker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -22,12 +25,22 @@ public class LoyaltyCardCursorAdapterTest
|
||||
{
|
||||
private Activity activity;
|
||||
private DBHelper db;
|
||||
private SharedPreferences settings;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
activity = Robolectric.setupActivity(MainActivity.class);
|
||||
db = new DBHelper(activity);
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
}
|
||||
|
||||
private void setFontSizes(int storeFontSize, int noteFontSize)
|
||||
{
|
||||
settings.edit()
|
||||
.putInt(activity.getResources().getString(R.string.settings_key_card_title_list_font_size), storeFontSize)
|
||||
.putInt(activity.getResources().getString(R.string.settings_key_card_note_list_font_size), noteFontSize)
|
||||
.apply();
|
||||
}
|
||||
|
||||
private View createView(Cursor cursor)
|
||||
@@ -40,20 +53,37 @@ public class LoyaltyCardCursorAdapterTest
|
||||
return view;
|
||||
}
|
||||
|
||||
private void checkView(final View view, final String store, final String cardId)
|
||||
private void checkView(final View view, final String store, final String note, boolean checkFontSizes)
|
||||
{
|
||||
final TextView storeField = (TextView) view.findViewById(R.id.store);
|
||||
assertEquals(store, storeField.getText().toString());
|
||||
final TextView storeField = view.findViewById(R.id.store);
|
||||
final TextView noteField = view.findViewById(R.id.note);
|
||||
|
||||
final TextView cardIdField = (TextView) view.findViewById(R.id.cardId);
|
||||
assertEquals(cardId, cardIdField.getText().toString());
|
||||
if(checkFontSizes)
|
||||
{
|
||||
int storeFontSize = settings.getInt(activity.getResources().getString(R.string.settings_key_card_title_list_font_size), 0);
|
||||
int noteFontSize = settings.getInt(activity.getResources().getString(R.string.settings_key_card_note_list_font_size), 0);
|
||||
|
||||
assertEquals(storeFontSize, (int)storeField.getTextSize());
|
||||
assertEquals(noteFontSize, (int)noteField.getTextSize());
|
||||
}
|
||||
|
||||
assertEquals(store, storeField.getText().toString());
|
||||
if(note.isEmpty() == false)
|
||||
{
|
||||
assertEquals(View.VISIBLE, noteField.getVisibility());
|
||||
assertEquals(note, noteField.getText().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEquals(View.GONE, noteField.getVisibility());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void TestCursorAdapterEmptyNote()
|
||||
{
|
||||
db.insertLoyaltyCard("store", "", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
db.insertLoyaltyCard("store", "", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -61,17 +91,13 @@ public class LoyaltyCardCursorAdapterTest
|
||||
|
||||
View view = createView(cursor);
|
||||
|
||||
final String cardIdLabel = activity.getResources().getString(R.string.cardId);
|
||||
final String cardIdFormat = activity.getResources().getString(R.string.cardIdFormat);
|
||||
String cardIdText = String.format(cardIdFormat, cardIdLabel, card.cardId);
|
||||
|
||||
checkView(view, card.store, cardIdText);
|
||||
checkView(view, card.store, card.note, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCursorAdapterWithNote()
|
||||
{
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
@@ -79,13 +105,24 @@ public class LoyaltyCardCursorAdapterTest
|
||||
|
||||
View view = createView(cursor);
|
||||
|
||||
final String storeNameAndNoteFormat = activity.getResources().getString(R.string.storeNameAndNoteFormat);
|
||||
String storeAndNoteText = String.format(storeNameAndNoteFormat, card.store, card.note);
|
||||
checkView(view, card.store, card.note, false);
|
||||
}
|
||||
|
||||
final String cardIdLabel = activity.getResources().getString(R.string.cardId);
|
||||
final String cardIdFormat = activity.getResources().getString(R.string.cardIdFormat);
|
||||
String cardIdText = String.format(cardIdFormat, cardIdLabel, card.cardId);
|
||||
@Test
|
||||
public void TestCursorAdapterFontSizes()
|
||||
{
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
checkView(view, storeAndNoteText, cardIdText);
|
||||
Cursor cursor = db.getLoyaltyCardCursor();
|
||||
cursor.moveToFirst();
|
||||
|
||||
setFontSizes(1, 2);
|
||||
View view = createView(cursor);
|
||||
checkView(view, card.store, card.note, true);
|
||||
|
||||
setFontSizes(30, 31);
|
||||
view = createView(cursor);
|
||||
checkView(view, card.store, card.note, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ package protect.card_locker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.widget.TextViewCompat;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -30,7 +33,6 @@ 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;
|
||||
@@ -103,10 +105,10 @@ public class LoyaltyCardViewActivityTest
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
}
|
||||
|
||||
final EditText storeField = (EditText) activity.findViewById(R.id.storeNameEdit);
|
||||
final EditText noteField = (EditText) activity.findViewById(R.id.noteEdit);
|
||||
final TextView cardIdField = (TextView) activity.findViewById(R.id.cardIdView);
|
||||
final TextView barcodeTypeField = (TextView) activity.findViewById(R.id.barcodeType);
|
||||
final EditText storeField = activity.findViewById(R.id.storeNameEdit);
|
||||
final EditText noteField = activity.findViewById(R.id.noteEdit);
|
||||
final TextView cardIdField = activity.findViewById(R.id.cardIdView);
|
||||
final TextView barcodeTypeField = activity.findViewById(R.id.barcodeType);
|
||||
|
||||
storeField.setText(store);
|
||||
noteField.setText(note);
|
||||
@@ -124,6 +126,8 @@ public class LoyaltyCardViewActivityTest
|
||||
assertEquals(note, card.note);
|
||||
assertEquals(cardId, card.cardId);
|
||||
assertEquals(barcodeType, card.barcodeType);
|
||||
assertNotNull(card.headerColor);
|
||||
assertNotNull(card.headerTextColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +137,7 @@ public class LoyaltyCardViewActivityTest
|
||||
private void captureBarcodeWithResult(final Activity activity, final int buttonId, final boolean success) throws IOException
|
||||
{
|
||||
// Start image capture
|
||||
final Button captureButton = (Button) activity.findViewById(buttonId);
|
||||
final Button captureButton = activity.findViewById(buttonId);
|
||||
captureButton.performClick();
|
||||
|
||||
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).peekNextStartedActivityForResult();
|
||||
@@ -178,27 +182,31 @@ public class LoyaltyCardViewActivityTest
|
||||
private void checkAllFields(final Activity activity, ViewMode mode,
|
||||
final String store, final String note, final String cardId, final String barcodeType)
|
||||
{
|
||||
int captureVisibility = (mode == ViewMode.UPDATE_CARD || mode == ViewMode.ADD_CARD) ? View.VISIBLE : View.GONE;
|
||||
if(mode == ViewMode.VIEW_CARD)
|
||||
{
|
||||
checkFieldProperties(activity, R.id.cardIdView, View.VISIBLE, cardId);
|
||||
}
|
||||
else
|
||||
{
|
||||
int captureVisibility = (mode == ViewMode.UPDATE_CARD || mode == ViewMode.ADD_CARD) ? View.VISIBLE : View.GONE;
|
||||
|
||||
int viewVisibility = (mode == ViewMode.VIEW_CARD) ? View.VISIBLE : View.GONE;
|
||||
int editVisibility = (mode != ViewMode.VIEW_CARD) ? View.VISIBLE : View.GONE;
|
||||
int editVisibility = View.VISIBLE;
|
||||
|
||||
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.noteView, viewVisibility, note);
|
||||
checkFieldProperties(activity, R.id.cardIdView, View.VISIBLE, cardId);
|
||||
checkFieldProperties(activity, R.id.cardIdDivider, cardId.isEmpty() ? View.GONE : View.VISIBLE, null);
|
||||
checkFieldProperties(activity, R.id.cardIdTableRow, cardId.isEmpty() ? View.GONE : View.VISIBLE, null);
|
||||
checkFieldProperties(activity, R.id.barcodeType, View.GONE, barcodeType);
|
||||
checkFieldProperties(activity, R.id.captureButton, captureVisibility, null);
|
||||
checkFieldProperties(activity, R.id.barcode, View.VISIBLE, null);
|
||||
checkFieldProperties(activity, R.id.storeNameEdit, editVisibility, store);
|
||||
checkFieldProperties(activity, R.id.noteEdit, editVisibility, note);
|
||||
checkFieldProperties(activity, R.id.cardIdView, View.VISIBLE, cardId);
|
||||
checkFieldProperties(activity, R.id.cardIdDivider, cardId.isEmpty() ? View.GONE : View.VISIBLE, null);
|
||||
checkFieldProperties(activity, R.id.cardIdTableRow, cardId.isEmpty() ? View.GONE : View.VISIBLE, null);
|
||||
checkFieldProperties(activity, R.id.barcodeType, View.GONE, barcodeType);
|
||||
checkFieldProperties(activity, R.id.captureButton, captureVisibility, null);
|
||||
checkFieldProperties(activity, R.id.barcode, View.VISIBLE, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithoutParametersCheckFieldsAvailable()
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class).create();
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
@@ -211,7 +219,7 @@ public class LoyaltyCardViewActivityTest
|
||||
@Test
|
||||
public void startWithoutParametersCannotCreateLoyaltyCard()
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class).create();
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
@@ -221,9 +229,9 @@ public class LoyaltyCardViewActivityTest
|
||||
DBHelper db = new DBHelper(activity);
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
final EditText storeField = (EditText) activity.findViewById(R.id.storeNameEdit);
|
||||
final EditText noteField = (EditText) activity.findViewById(R.id.noteEdit);
|
||||
final TextView cardIdField = (TextView) activity.findViewById(R.id.cardIdView);
|
||||
final EditText storeField = activity.findViewById(R.id.storeNameEdit);
|
||||
final EditText noteField = activity.findViewById(R.id.noteEdit);
|
||||
final TextView cardIdField = activity.findViewById(R.id.cardIdView);
|
||||
|
||||
shadowActivity.clickMenuItem(R.id.action_save);
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
@@ -244,7 +252,7 @@ public class LoyaltyCardViewActivityTest
|
||||
@Test
|
||||
public void startWithoutParametersBack()
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class).create();
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
@@ -261,7 +269,7 @@ public class LoyaltyCardViewActivityTest
|
||||
{
|
||||
registerMediaStoreIntentHandler();
|
||||
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class).create();
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
@@ -282,7 +290,7 @@ public class LoyaltyCardViewActivityTest
|
||||
@Test
|
||||
public void startWithoutParametersCaptureBarcodeFailure() throws IOException
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class).create();
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
@@ -300,7 +308,7 @@ public class LoyaltyCardViewActivityTest
|
||||
@Test
|
||||
public void startWithoutParametersCaptureBarcodeCancel() throws IOException
|
||||
{
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class).create();
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
@@ -326,18 +334,22 @@ public class LoyaltyCardViewActivityTest
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt("id", 1);
|
||||
|
||||
Class clazz;
|
||||
|
||||
if(editMode)
|
||||
{
|
||||
bundle.putBoolean("update", true);
|
||||
clazz = LoyaltyCardEditActivity.class;
|
||||
}
|
||||
else
|
||||
{
|
||||
bundle.putBoolean("view", true);
|
||||
clazz = LoyaltyCardViewActivity.class;
|
||||
}
|
||||
|
||||
intent.putExtras(bundle);
|
||||
|
||||
return Robolectric.buildActivity(LoyaltyCardViewActivity.class).withIntent(intent).create();
|
||||
return Robolectric.buildActivity(clazz).withIntent(intent).create();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -347,7 +359,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -363,7 +375,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -379,7 +391,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE);
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -400,7 +412,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE);
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -426,7 +438,7 @@ public class LoyaltyCardViewActivityTest
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
@@ -461,4 +473,97 @@ public class LoyaltyCardViewActivityTest
|
||||
activityController.stop();
|
||||
activityController.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithoutParametersViewBack()
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
assertEquals(false, activity.isFinishing());
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWithoutColors()
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
assertEquals(false, activity.isFinishing());
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startLoyaltyCardWithoutColorsSave() throws IOException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, null, null);
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
// Save and check the gift card
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, BARCODE_TYPE, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startCheckFontSizes()
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(false);
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE);
|
||||
|
||||
final int STORE_FONT_SIZE = 50;
|
||||
final int CARD_FONT_SIZE = 40;
|
||||
final int NOTE_FONT_SIZE = 30;
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
settings.edit()
|
||||
.putInt(activity.getResources().getString(R.string.settings_key_card_title_font_size), STORE_FONT_SIZE)
|
||||
.putInt(activity.getResources().getString(R.string.settings_key_card_id_font_size), CARD_FONT_SIZE)
|
||||
.putInt(activity.getResources().getString(R.string.settings_key_card_note_font_size), NOTE_FONT_SIZE)
|
||||
.apply();
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
assertEquals(false, activity.isFinishing());
|
||||
|
||||
TextView storeName = activity.findViewById(R.id.storeName);
|
||||
TextView cardIdFieldView = activity.findViewById(R.id.cardIdView);
|
||||
TextView noteView = activity.findViewById(R.id.noteView);
|
||||
|
||||
TextViewCompat.getAutoSizeMaxTextSize(storeName);
|
||||
TextViewCompat.getAutoSizeMaxTextSize(storeName);
|
||||
assertEquals(STORE_FONT_SIZE, (int)storeName.getTextSize());
|
||||
assertEquals(CARD_FONT_SIZE, TextViewCompat.getAutoSizeMaxTextSize(cardIdFieldView));
|
||||
assertEquals(NOTE_FONT_SIZE, TextViewCompat.getAutoSizeMaxTextSize(noteView));
|
||||
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
@@ -49,10 +50,10 @@ public class MainActivityTest
|
||||
Activity activity = Robolectric.setupActivity(MainActivity.class);
|
||||
assertTrue(activity != null);
|
||||
|
||||
TextView helpText = (TextView)activity.findViewById(R.id.helpText);
|
||||
TextView helpText = activity.findViewById(R.id.helpText);
|
||||
assertEquals(View.VISIBLE, helpText.getVisibility());
|
||||
|
||||
ListView list = (ListView)activity.findViewById(R.id.list);
|
||||
ListView list = activity.findViewById(R.id.list);
|
||||
assertEquals(View.GONE, list.getVisibility());
|
||||
}
|
||||
|
||||
@@ -65,16 +66,17 @@ public class MainActivityTest
|
||||
assertTrue(menu != null);
|
||||
|
||||
// The settings and add button should be present
|
||||
assertEquals(menu.size(), 4);
|
||||
assertEquals(menu.size(), 5);
|
||||
|
||||
assertEquals("Add", menu.findItem(R.id.action_add).getTitle().toString());
|
||||
assertEquals("Import/Export", menu.findItem(R.id.action_import_export).getTitle().toString());
|
||||
assertEquals("Start Intro", menu.findItem(R.id.action_intro).getTitle().toString());
|
||||
assertEquals("About", menu.findItem(R.id.action_about).getTitle().toString());
|
||||
assertEquals("Settings", menu.findItem(R.id.action_settings).getTitle().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickAddLaunchesLoyaltyCardViewActivity()
|
||||
public void clickAddLaunchesLoyaltyCardEditActivity()
|
||||
{
|
||||
final MainActivity activity = Robolectric.setupActivity(MainActivity.class);
|
||||
|
||||
@@ -82,7 +84,7 @@ public class MainActivityTest
|
||||
|
||||
Intent intent = shadowOf(activity).peekNextStartedActivityForResult().intent;
|
||||
|
||||
assertEquals(new ComponentName(activity, LoyaltyCardViewActivity.class), intent.getComponent());
|
||||
assertEquals(new ComponentName(activity, LoyaltyCardEditActivity.class), intent.getComponent());
|
||||
assertNull(intent.getExtras());
|
||||
}
|
||||
|
||||
@@ -95,13 +97,13 @@ public class MainActivityTest
|
||||
activityController.start();
|
||||
activityController.resume();
|
||||
|
||||
TextView helpText = (TextView)mainActivity.findViewById(R.id.helpText);
|
||||
ListView list = (ListView)mainActivity.findViewById(R.id.list);
|
||||
TextView helpText = mainActivity.findViewById(R.id.helpText);
|
||||
ListView list = mainActivity.findViewById(R.id.list);
|
||||
|
||||
assertEquals(0, list.getCount());
|
||||
|
||||
DBHelper db = new DBHelper(mainActivity);
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString());
|
||||
db.insertLoyaltyCard("store", "note", "cardId", BarcodeFormat.UPC_A.toString(), Color.BLACK, Color.WHITE);
|
||||
|
||||
assertEquals(View.VISIBLE, helpText.getVisibility());
|
||||
assertEquals(View.GONE, list.getVisibility());
|
||||
|
||||
@@ -15,4 +15,9 @@
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
# org.gradle.parallel=true
|
||||
|
||||
# The aapt2 tool creates an APK which fails to install on Android 5 and below if it contains
|
||||
# a bug. Build tools 27.0.1 has a mitigation. Avoiding aapt2 also avoids hitting the bug.
|
||||
# See: https://issuetracker.google.com/issues/64434571
|
||||
android.enableAapt2=false
|
||||
|
||||
BIN
metadata/en-US/images/featureGraphic.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 62 KiB |