LetterTileProvider
*
- * @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 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.
+ * @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)
- {
+ int width, int height, Integer backgroundColor, Integer textColor) {
TextPaint paint = new TextPaint();
paint.setTypeface(Typeface.create("sans-serif-light", Typeface.BOLD));
- if(textColor != null)
- {
+ if (textColor != null) {
paint.setColor(textColor);
- }
- else
- {
+ } else {
paint.setColor(Color.WHITE);
}
paint.setTextAlign(Paint.Align.CENTER);
paint.setAntiAlias(true);
- if(backgroundColor == null)
- {
+ if (backgroundColor == null) {
mColor = getDefaultColor(context, key);
- }
- else
- {
+ } else {
mColor = backgroundColor;
}
@@ -80,7 +72,7 @@ class LetterBitmap
c.setBitmap(mBitmap);
c.drawColor(mColor);
- char [] firstCharArray = new char[1];
+ char[] firstCharArray = new char[1];
firstCharArray[0] = firstChar.toUpperCase().charAt(0);
paint.setTextSize(tileLetterFontSize);
@@ -97,16 +89,14 @@ class LetterBitmap
* alphabet or digit, if there is no letter or digit available, a
* default image is shown instead
*/
- public Bitmap getLetterTile()
- {
+ public Bitmap getLetterTile() {
return mBitmap;
}
/**
* @return background color used for letter title.
*/
- public int getBackgroundColor()
- {
+ public int getBackgroundColor() {
return mColor;
}
@@ -115,8 +105,7 @@ class LetterBitmap
* @return A new or previously chosen color for key used as the
* tile background color
*/
- private static int pickColor(String key, TypedArray colors)
- {
+ 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;
@@ -127,8 +116,7 @@ class LetterBitmap
* Determine the color which the letter tile will use if no default
* color is provided.
*/
- public static int getDefaultColor(Context context, String key)
- {
+ public static int getDefaultColor(Context context, String key) {
final Resources res = context.getResources();
TypedArray colors = res.obtainTypedArray(R.array.letter_tile_colors);
diff --git a/app/src/main/java/protect/card_locker/LoyaltyCard.java b/app/src/main/java/protect/card_locker/LoyaltyCard.java
index 1ec44fa6d..06a0165a5 100644
--- a/app/src/main/java/protect/card_locker/LoyaltyCard.java
+++ b/app/src/main/java/protect/card_locker/LoyaltyCard.java
@@ -35,8 +35,7 @@ public class LoyaltyCard implements Parcelable {
public LoyaltyCard(final int id, final String store, final String note, final Date expiry,
final BigDecimal balance, final Currency balanceType, final String cardId,
@Nullable final String barcodeId, @Nullable final CatimaBarcode barcodeType,
- @Nullable final Integer headerColor, final int starStatus, final long lastUsed,final int zoomLevel)
- {
+ @Nullable final Integer headerColor, final int starStatus, final long lastUsed, final int zoomLevel) {
this.id = id;
this.store = store;
this.note = note;
@@ -88,8 +87,7 @@ public class LoyaltyCard implements Parcelable {
parcel.writeInt(zoomLevel);
}
- public static LoyaltyCard toLoyaltyCard(Cursor cursor)
- {
+ public static LoyaltyCard toLoyaltyCard(Cursor cursor) {
int id = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.ID));
String store = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.STORE));
String note = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.NOTE));
@@ -110,27 +108,23 @@ public class LoyaltyCard implements Parcelable {
Date expiry = null;
Integer headerColor = null;
- if (cursor.isNull(barcodeTypeColumn) == false)
- {
+ if (cursor.isNull(barcodeTypeColumn) == false) {
barcodeType = CatimaBarcode.fromName(cursor.getString(barcodeTypeColumn));
}
- if (cursor.isNull(balanceTypeColumn) == false)
- {
+ if (cursor.isNull(balanceTypeColumn) == false) {
balanceType = Currency.getInstance(cursor.getString(balanceTypeColumn));
}
- if(expiryLong > 0)
- {
+ if (expiryLong > 0) {
expiry = new Date(expiryLong);
}
- if(cursor.isNull(headerColorColumn) == false)
- {
+ if (cursor.isNull(headerColorColumn) == false) {
headerColor = cursor.getInt(headerColorColumn);
}
- return new LoyaltyCard(id, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, starred, lastUsed,zoomLevel);
+ return new LoyaltyCard(id, store, note, expiry, balance, balanceType, cardId, barcodeId, barcodeType, headerColor, starred, lastUsed, zoomLevel);
}
@Override
diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java b/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java
index f259768c1..413028ee1 100644
--- a/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java
+++ b/app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java
@@ -25,7 +25,6 @@ import java.util.ArrayList;
import androidx.core.graphics.BlendModeColorFilterCompat;
import androidx.core.graphics.BlendModeCompat;
import androidx.recyclerview.widget.RecyclerView;
-
import protect.card_locker.preferences.Settings;
public class LoyaltyCardCursorAdapter extends BaseCursorAdapter
* The purpose of this function is to make sure the barcode can be scanned from the phone
* by machines which offer no space to insert the complete device.
*/
@@ -882,6 +881,6 @@ public class LoyaltyCardViewActivity extends CatimaAppCompatActivity implements
);
}
- Log.d("setFullScreen","Is full screen enabled? "+enabled+" Zoom Level = "+barcodeScaler.getProgress());
+ Log.d("setFullScreen", "Is full screen enabled? " + enabled + " Zoom Level = " + barcodeScaler.getProgress());
}
}
diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java
index 787b805a3..9722818f3 100644
--- a/app/src/main/java/protect/card_locker/MainActivity.java
+++ b/app/src/main/java/protect/card_locker/MainActivity.java
@@ -6,7 +6,6 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.res.Configuration;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.os.Bundle;
@@ -31,13 +30,11 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
-import androidx.core.app.ActivityCompat;
import androidx.core.splashscreen.SplashScreen;
import androidx.recyclerview.widget.RecyclerView;
import protect.card_locker.preferences.SettingsActivity;
-public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCardCursorAdapter.CardAdapterListener, GestureDetector.OnGestureListener
-{
+public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCardCursorAdapter.CardAdapterListener, GestureDetector.OnGestureListener {
private static final String TAG = "Catima";
private final DBHelper mDB = new DBHelper(this);
@@ -55,8 +52,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
private View mNoMatchingCardsText;
private View mNoGroupCardsText;
- private ActionMode.Callback mCurrentActionModeCallback = new ActionMode.Callback()
- {
+ private ActionMode.Callback mCurrentActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode inputMode, Menu inputMenu) {
inputMode.getMenuInflater().inflate(R.menu.card_longclick_menu, inputMenu);
@@ -64,8 +60,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
@Override
- public boolean onPrepareActionMode(ActionMode inputMode, Menu inputMenu)
- {
+ public boolean onPrepareActionMode(ActionMode inputMode, Menu inputMenu) {
return false;
}
@@ -109,7 +104,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
inputMode.finish();
return true;
- } else if(inputItem.getItemId() == R.id.action_edit) {
+ } else if (inputItem.getItemId() == R.id.action_edit) {
if (mAdapter.getSelectedItemCount() != 1) {
throw new IllegalArgumentException("Cannot edit more than 1 card at a time");
}
@@ -122,7 +117,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
startActivity(intent);
inputMode.finish();
return true;
- } else if(inputItem.getItemId() == R.id.action_delete) {
+ } else if (inputItem.getItemId() == R.id.action_delete) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// The following may seem weird, but it is necessary to give translators enough flexibility.
// For example, in Russian, Android's plural quantity "one" actually refers to "any number ending on 1 but not ending in 11".
@@ -165,15 +160,12 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
@Override
- public void onDestroyActionMode(ActionMode inputMode)
- {
+ public void onDestroyActionMode(ActionMode inputMode) {
mAdapter.clearSelections();
mCurrentActionMode = null;
- mCardList.post(new Runnable()
- {
+ mCardList.post(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
mAdapter.resetAnimationIndex();
}
});
@@ -181,8 +173,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
};
@Override
- protected void onCreate(Bundle inputSavedInstanceState)
- {
+ protected void onCreate(Bundle inputSavedInstanceState) {
super.onCreate(inputSavedInstanceState);
SplashScreen.installSplashScreen(this);
setTitle(R.string.app_name);
@@ -195,7 +186,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
@Override
public void onTabSelected(TabLayout.Tab tab) {
selectedTab = tab.getPosition();
- Log.d("onTabSelected","Tab Position "+tab.getPosition());
+ Log.d("onTabSelected", "Tab Position " + tab.getPosition());
mGroup = tab.getTag();
updateLoyaltyCardList();
// Store active tab in Shared Preference to restore next app launch
@@ -272,22 +263,18 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
@Override
- protected void onResume()
- {
+ protected void onResume() {
super.onResume();
- if(mCurrentActionMode != null)
- {
+ if (mCurrentActionMode != null) {
mAdapter.clearSelections();
mCurrentActionMode.finish();
}
- if (mMenu != null)
- {
+ if (mMenu != null) {
SearchView searchView = (SearchView) mMenu.findItem(R.id.action_search).getActionView();
- if (!searchView.isIconified())
- {
+ if (!searchView.isIconified()) {
mFilter = searchView.getQuery().toString();
}
}
@@ -307,7 +294,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
try {
mOrder = DBHelper.LoyaltyCardOrder.valueOf(sortPref.getString(getString(R.string.sharedpreference_sort_order), null));
mOrderDirection = DBHelper.LoyaltyCardOrderDirection.valueOf(sortPref.getString(getString(R.string.sharedpreference_sort_direction), null));
- } catch (IllegalArgumentException | NullPointerException ignored) {}
+ } catch (IllegalArgumentException | NullPointerException ignored) {
+ }
mGroup = null;
@@ -345,8 +333,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
// We're coming back from another view so clear the search
// We only do this now to prevent a flash of all entries right after picking one
mFilter = "";
- if (mMenu != null)
- {
+ if (mMenu != null) {
MenuItem searchItem = mMenu.findItem(R.id.action_search);
searchItem.collapseActionView();
}
@@ -357,7 +344,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
BarcodeValues barcodeValues = Utils.parseSetBarcodeActivityResult(requestCode, resultCode, intent, this);
- if(!barcodeValues.isEmpty()) {
+ if (!barcodeValues.isEmpty()) {
Intent newIntent = new Intent(getApplicationContext(), LoyaltyCardEditActivity.class);
Bundle newBundle = new Bundle();
newBundle.putString(LoyaltyCardEditActivity.BUNDLE_BARCODETYPE, barcodeValues.format());
@@ -372,8 +359,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
@Override
- public void onBackPressed()
- {
+ public void onBackPressed() {
if (mMenu != null) {
SearchView searchView = (SearchView) mMenu.findItem(R.id.action_search).getActionView();
@@ -394,20 +380,16 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
mAdapter.swapCursor(mDB.getLoyaltyCardCursor(mFilter, group, mOrder, mOrderDirection));
- if(mDB.getLoyaltyCardCount() > 0)
- {
+ if (mDB.getLoyaltyCardCount() > 0) {
// We want the cardList to be visible regardless of the filtered match count
// to ensure that the noMatchingCardsText doesn't end up being shown below
// the keyboard
mHelpText.setVisibility(View.GONE);
mNoGroupCardsText.setVisibility(View.GONE);
- if(mAdapter.getItemCount() > 0)
- {
+ if (mAdapter.getItemCount() > 0) {
mCardList.setVisibility(View.VISIBLE);
mNoMatchingCardsText.setVisibility(View.GONE);
- }
- else
- {
+ } else {
mCardList.setVisibility(View.GONE);
if (!mFilter.isEmpty()) {
// Actual Empty Search Result
@@ -419,9 +401,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
mNoGroupCardsText.setVisibility(View.VISIBLE);
}
}
- }
- else
- {
+ } else {
mCardList.setVisibility(View.GONE);
mHelpText.setVisibility(View.VISIBLE);
mNoMatchingCardsText.setVisibility(View.GONE);
@@ -433,8 +413,7 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
}
}
- public void updateTabGroups(TabLayout groupsTabLayout)
- {
+ public void updateTabGroups(TabLayout groupsTabLayout) {
final DBHelper db = new DBHelper(this);
List
* Based on https://github.com/journeyapps/zxing-android-embedded/blob/0fdfbce9fb3285e985bad9971c5f7c0a7a334e7b/sample/src/main/java/example/zxing/CustomScannerActivity.java
* originally licensed under Apache 2.0
*/
@@ -54,8 +54,7 @@ public class ScanActivity extends CatimaAppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
- if(actionBar != null)
- {
+ if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
@@ -127,8 +126,7 @@ public class ScanActivity extends CatimaAppCompatActivity {
}
@Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
+ public boolean onCreateOptionsMenu(Menu menu) {
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
getMenuInflater().inflate(R.menu.scan_menu, menu);
}
@@ -139,10 +137,8 @@ public class ScanActivity extends CatimaAppCompatActivity {
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- if (item.getItemId() == android.R.id.home)
- {
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
setResult(Activity.RESULT_CANCELED);
finish();
return true;
@@ -164,8 +160,7 @@ public class ScanActivity extends CatimaAppCompatActivity {
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent intent)
- {
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
BarcodeValues barcodeValues;
diff --git a/app/src/main/java/protect/card_locker/ShortcutHelper.java b/app/src/main/java/protect/card_locker/ShortcutHelper.java
index 29bbff461..8c3ae2e53 100644
--- a/app/src/main/java/protect/card_locker/ShortcutHelper.java
+++ b/app/src/main/java/protect/card_locker/ShortcutHelper.java
@@ -14,8 +14,7 @@ import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.core.graphics.drawable.IconCompat;
-class ShortcutHelper
-{
+class ShortcutHelper {
// Android documentation says that no more than 5 shortcuts
// are supported. However, that may be too many, as not all
// launcher will show all 5. Instead, the number is limited
@@ -30,8 +29,7 @@ class ShortcutHelper
* card exceeds the max number of shortcuts, then the least recently
* used card shortcut is discarded.
*/
- static void updateShortcuts(Context context, LoyaltyCard card)
- {
+ static void updateShortcuts(Context context, LoyaltyCard card) {
LinkedList
* However this is a much, much more cooperative Behaviour than before so
* the callers need to ensure we do NOT rely on forced cancellation and feed less into the
* ThreadPools so we don't OOM/Overload the Users device
- *
+ *
* This assumes single-threaded callers.
*/
public class TaskHandler {
@@ -44,9 +44,10 @@ public class TaskHandler {
/**
* Replaces (or initializes) an Executor with a clean (new) one
+ *
* @param executors Map Reference
- * @param type Which Queue
- * @param flushOld attempt shutdown
+ * @param type Which Queue
+ * @param flushOld attempt shutdown
* @param waitOnOld wait for Termination
*/
private void replaceExecutor(HashMap
* The database's loyalty cards are expected to appear in the CSV data.
* A header is expected for the each table showing the names of the columns.
*/
-public class CatimaImporter implements Importer
-{
+public class CatimaImporter implements Importer {
public void importData(Context context, DBHelper db, InputStream input, char[] password) throws IOException, FormatException, InterruptedException {
InputStream bufferedInputStream = new BufferedInputStream(input);
bufferedInputStream.mark(100);
// First, check if this is a zip file
- ZipInputStream zipInputStream = new ZipInputStream(bufferedInputStream,password);
+ ZipInputStream zipInputStream = new ZipInputStream(bufferedInputStream, password);
boolean isZipFile = false;
@@ -102,41 +99,32 @@ public class CatimaImporter implements Importer
bufferedReader.close();
}
- public void parseV1(Context context, DBHelper db, BufferedReader input) throws IOException, FormatException, InterruptedException
- {
+ public void parseV1(Context context, DBHelper db, BufferedReader input) throws IOException, FormatException, InterruptedException {
final CSVParser parser = new CSVParser(input, CSVFormat.RFC4180.builder().setHeader().build());
SQLiteDatabase database = db.getWritableDatabase();
database.beginTransaction();
- try
- {
- for (CSVRecord record : parser)
- {
+ try {
+ for (CSVRecord record : parser) {
importLoyaltyCard(context, database, db, record);
- if(Thread.currentThread().isInterrupted())
- {
+ if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
}
parser.close();
database.setTransactionSuccessful();
- }
- catch(IllegalArgumentException|IllegalStateException e)
- {
+ } catch (IllegalArgumentException | IllegalStateException e) {
throw new FormatException("Issue parsing CSV data", e);
- }
- finally
- {
+ } finally {
database.endTransaction();
database.close();
}
}
- public void parseV2(Context context, DBHelper db, BufferedReader input) throws IOException, FormatException, InterruptedException
- {
+ public void parseV2(Context context, DBHelper db, BufferedReader input) throws IOException, FormatException, InterruptedException {
SQLiteDatabase database = db.getWritableDatabase();
database.beginTransaction();
@@ -206,8 +194,7 @@ public class CatimaImporter implements Importer
}
}
- public void parseV2Groups(DBHelper db, SQLiteDatabase database, String data) throws IOException, FormatException, InterruptedException
- {
+ public void parseV2Groups(DBHelper db, SQLiteDatabase database, String data) throws IOException, FormatException, InterruptedException {
// Parse groups
final CSVParser groupParser = new CSVParser(new StringReader(data), CSVFormat.RFC4180.builder().setHeader().build());
@@ -232,8 +219,7 @@ public class CatimaImporter implements Importer
}
}
- public void parseV2Cards(Context context, DBHelper db, SQLiteDatabase database, String data) throws IOException, FormatException, InterruptedException
- {
+ public void parseV2Cards(Context context, DBHelper db, SQLiteDatabase database, String data) throws IOException, FormatException, InterruptedException {
// Parse cards
final CSVParser cardParser = new CSVParser(new StringReader(data), CSVFormat.RFC4180.builder().setHeader().build());
@@ -258,8 +244,7 @@ public class CatimaImporter implements Importer
}
}
- public void parseV2CardGroups(DBHelper db, SQLiteDatabase database, String data) throws IOException, FormatException, InterruptedException
- {
+ public void parseV2CardGroups(DBHelper db, SQLiteDatabase database, String data) throws IOException, FormatException, InterruptedException {
// Parse card group mappings
final CSVParser cardGroupParser = new CSVParser(new StringReader(data), CSVFormat.RFC4180.builder().setHeader().build());
@@ -289,13 +274,11 @@ public class CatimaImporter implements Importer
* session.
*/
private void importLoyaltyCard(Context context, SQLiteDatabase database, DBHelper helper, CSVRecord record)
- throws IOException, FormatException
- {
+ throws IOException, FormatException {
int id = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIds.ID, record, false);
String store = CSVHelpers.extractString(DBHelper.LoyaltyCardDbIds.STORE, record, "");
- if(store.isEmpty())
- {
+ if (store.isEmpty()) {
throw new FormatException("No store listed, but is required");
}
@@ -303,12 +286,13 @@ public class CatimaImporter implements Importer
Date expiry = null;
try {
expiry = new Date(CSVHelpers.extractLong(DBHelper.LoyaltyCardDbIds.EXPIRY, record, true));
- } catch (NullPointerException | FormatException e) { }
+ } catch (NullPointerException | FormatException e) {
+ }
BigDecimal balance;
try {
balance = new BigDecimal(CSVHelpers.extractString(DBHelper.LoyaltyCardDbIds.BALANCE, record, null));
- } catch (FormatException _e ) {
+ } catch (FormatException _e) {
// These fields did not exist in versions 1.8.1 and before
// We catch this exception so we can still import old backups
balance = new BigDecimal("0");
@@ -316,33 +300,29 @@ public class CatimaImporter implements Importer
Currency balanceType = null;
String unparsedBalanceType = CSVHelpers.extractString(DBHelper.LoyaltyCardDbIds.BALANCE_TYPE, record, "");
- if(!unparsedBalanceType.isEmpty()) {
+ if (!unparsedBalanceType.isEmpty()) {
balanceType = Currency.getInstance(unparsedBalanceType);
}
String cardId = CSVHelpers.extractString(DBHelper.LoyaltyCardDbIds.CARD_ID, record, "");
- if(cardId.isEmpty())
- {
+ if (cardId.isEmpty()) {
throw new FormatException("No card ID listed, but is required");
}
String barcodeId = CSVHelpers.extractString(DBHelper.LoyaltyCardDbIds.BARCODE_ID, record, "");
- if(barcodeId.isEmpty())
- {
+ if (barcodeId.isEmpty()) {
barcodeId = null;
}
CatimaBarcode barcodeType = null;
String unparsedBarcodeType = CSVHelpers.extractString(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE, record, "");
- if(!unparsedBarcodeType.isEmpty())
- {
+ if (!unparsedBarcodeType.isEmpty()) {
barcodeType = CatimaBarcode.fromName(unparsedBarcodeType);
}
Integer headerColor = null;
- if(record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_COLOR))
- {
+ if (record.isMapped(DBHelper.LoyaltyCardDbIds.HEADER_COLOR)) {
headerColor = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIds.HEADER_COLOR, record, true);
}
@@ -371,8 +351,7 @@ public class CatimaImporter implements Importer
* session.
*/
private void importGroup(SQLiteDatabase database, DBHelper helper, CSVRecord record)
- throws IOException, FormatException
- {
+ throws IOException, FormatException {
String id = CSVHelpers.extractString(DBHelper.LoyaltyCardDbGroups.ID, record, null);
helper.insertGroup(database, id);
@@ -383,8 +362,7 @@ public class CatimaImporter implements Importer
* session.
*/
private void importCardGroupMapping(SQLiteDatabase database, DBHelper helper, CSVRecord record)
- throws IOException, FormatException
- {
+ throws IOException, FormatException {
Integer cardId = CSVHelpers.extractInt(DBHelper.LoyaltyCardDbIdsGroups.cardID, record, false);
String groupId = CSVHelpers.extractString(DBHelper.LoyaltyCardDbIdsGroups.groupID, record, null);
diff --git a/app/src/main/java/protect/card_locker/importexport/DataFormat.java b/app/src/main/java/protect/card_locker/importexport/DataFormat.java
index 26e97e745..fc4fdc531 100644
--- a/app/src/main/java/protect/card_locker/importexport/DataFormat.java
+++ b/app/src/main/java/protect/card_locker/importexport/DataFormat.java
@@ -1,10 +1,8 @@
package protect.card_locker.importexport;
-public enum DataFormat
-{
+public enum DataFormat {
Catima,
Fidme,
Stocard,
- VoucherVault
- ;
+ VoucherVault;
}
diff --git a/app/src/main/java/protect/card_locker/importexport/Exporter.java b/app/src/main/java/protect/card_locker/importexport/Exporter.java
index ad4928030..584572360 100644
--- a/app/src/main/java/protect/card_locker/importexport/Exporter.java
+++ b/app/src/main/java/protect/card_locker/importexport/Exporter.java
@@ -11,11 +11,11 @@ import protect.card_locker.DBHelper;
* Interface for a class which can export the contents of the database
* in a given format.
*/
-public interface Exporter
-{
+public interface Exporter {
/**
* Export the database to the output stream in a given format.
+ *
* @throws IOException
*/
- void exportData(Context context, DBHelper db, OutputStream output,char[] password) throws IOException, InterruptedException;
+ void exportData(Context context, DBHelper db, OutputStream output, char[] password) throws IOException, InterruptedException;
}
diff --git a/app/src/main/java/protect/card_locker/importexport/FidmeImporter.java b/app/src/main/java/protect/card_locker/importexport/FidmeImporter.java
index f5453db67..23c927b8b 100644
--- a/app/src/main/java/protect/card_locker/importexport/FidmeImporter.java
+++ b/app/src/main/java/protect/card_locker/importexport/FidmeImporter.java
@@ -3,8 +3,6 @@ package protect.card_locker.importexport;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
-import com.google.zxing.BarcodeFormat;
-
import net.lingala.zip4j.io.inputstream.ZipInputStream;
import net.lingala.zip4j.model.LocalFileHeader;
@@ -23,12 +21,11 @@ import java.text.ParseException;
import protect.card_locker.CatimaBarcode;
import protect.card_locker.DBHelper;
import protect.card_locker.FormatException;
-import protect.card_locker.Utils;
/**
* Class for importing a database from CSV (Comma Separate Values)
* formatted data.
- *
+ *
* The database's loyalty cards are expected to appear in the CSV data.
* A header is expected for the each table showing the names of the columns.
*/
diff --git a/app/src/main/java/protect/card_locker/importexport/ImportExportResult.java b/app/src/main/java/protect/card_locker/importexport/ImportExportResult.java
index 9a8d71c08..8419d3ebe 100644
--- a/app/src/main/java/protect/card_locker/importexport/ImportExportResult.java
+++ b/app/src/main/java/protect/card_locker/importexport/ImportExportResult.java
@@ -1,9 +1,7 @@
package protect.card_locker.importexport;
-public enum ImportExportResult
-{
+public enum ImportExportResult {
Success,
GenericFailure,
- BadPassword
- ;
+ BadPassword;
}
diff --git a/app/src/main/java/protect/card_locker/importexport/Importer.java b/app/src/main/java/protect/card_locker/importexport/Importer.java
index fe47d05fe..a394e455b 100644
--- a/app/src/main/java/protect/card_locker/importexport/Importer.java
+++ b/app/src/main/java/protect/card_locker/importexport/Importer.java
@@ -15,11 +15,11 @@ import protect.card_locker.FormatException;
* Interface for a class which can import the contents of a stream
* into the database.
*/
-public interface Importer
-{
+public interface Importer {
/**
* Import data from the input stream in a given format into
* the database.
+ *
* @throws IOException
* @throws FormatException
*/
diff --git a/app/src/main/java/protect/card_locker/importexport/MultiFormatExporter.java b/app/src/main/java/protect/card_locker/importexport/MultiFormatExporter.java
index b45cf1eda..c4a3e2dd2 100644
--- a/app/src/main/java/protect/card_locker/importexport/MultiFormatExporter.java
+++ b/app/src/main/java/protect/card_locker/importexport/MultiFormatExporter.java
@@ -8,26 +8,23 @@ import java.io.OutputStream;
import protect.card_locker.DBHelper;
-public class MultiFormatExporter
-{
+public class MultiFormatExporter {
private static final String TAG = "Catima";
/**
* Attempts to export data to the output stream in the
* given format, if possible.
- *
+ *
* The output stream is closed on success.
*
* @return ImportExportResult.Success if the database was successfully exported,
* another ImportExportResult otherwise. If not Success, partial data may have been
* written to the output stream, and it should be discarded.
*/
- public static ImportExportResult exportData(Context context, DBHelper db, OutputStream output, DataFormat format,char[] password)
- {
+ public static ImportExportResult exportData(Context context, DBHelper db, OutputStream output, DataFormat format, char[] password) {
Exporter exporter = null;
- switch(format)
- {
+ switch (format) {
case Catima:
exporter = new CatimaExporter();
break;
@@ -36,26 +33,18 @@ public class MultiFormatExporter
break;
}
- if(exporter != null)
- {
- try
- {
- exporter.exportData(context, db, output,password);
+ if (exporter != null) {
+ try {
+ exporter.exportData(context, db, output, password);
return ImportExportResult.Success;
- }
- catch(IOException e)
- {
+ } catch (IOException e) {
Log.e(TAG, "Failed to export data", e);
- }
- catch(InterruptedException e)
- {
+ } catch (InterruptedException e) {
Log.e(TAG, "Failed to export data", e);
}
return ImportExportResult.GenericFailure;
- }
- else
- {
+ } else {
Log.e(TAG, "Unsupported data format exported: " + format.name());
return ImportExportResult.GenericFailure;
}
diff --git a/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java b/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java
index 3463f1073..21a520f41 100644
--- a/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java
+++ b/app/src/main/java/protect/card_locker/importexport/MultiFormatImporter.java
@@ -14,14 +14,13 @@ import java.text.ParseException;
import protect.card_locker.DBHelper;
import protect.card_locker.FormatException;
-public class MultiFormatImporter
-{
+public class MultiFormatImporter {
private static final String TAG = "Catima";
/**
* Attempts to import data from the input stream of the
* given format into the database.
- *
+ *
* The input stream is not closed, and doing so is the
* responsibility of the caller.
*
@@ -29,12 +28,10 @@ public class MultiFormatImporter
* or another result otherwise. If no Success, no data was written to
* the database.
*/
- public static ImportExportResult importData(Context context, DBHelper db, InputStream input, DataFormat format, char[] password)
- {
+ public static ImportExportResult importData(Context context, DBHelper db, InputStream input, DataFormat format, char[] password) {
Importer importer = null;
- switch(format)
- {
+ switch (format) {
case Catima:
importer = new CatimaImporter();
break;
@@ -49,25 +46,17 @@ public class MultiFormatImporter
break;
}
- if (importer != null)
- {
- try
- {
+ if (importer != null) {
+ try {
importer.importData(context, db, input, password);
return ImportExportResult.Success;
- }
- catch(ZipException e)
- {
+ } catch (ZipException e) {
return ImportExportResult.BadPassword;
- }
- catch(IOException | FormatException | InterruptedException | JSONException | ParseException | NullPointerException e)
- {
+ } catch (IOException | FormatException | InterruptedException | JSONException | ParseException | NullPointerException e) {
Log.e(TAG, "Failed to import data", e);
}
- }
- else
- {
+ } else {
Log.e(TAG, "Unsupported data format imported: " + format.name());
}
diff --git a/app/src/main/java/protect/card_locker/importexport/StocardImporter.java b/app/src/main/java/protect/card_locker/importexport/StocardImporter.java
index 76761b83a..6d46d4045 100644
--- a/app/src/main/java/protect/card_locker/importexport/StocardImporter.java
+++ b/app/src/main/java/protect/card_locker/importexport/StocardImporter.java
@@ -33,22 +33,19 @@ import protect.card_locker.ZipUtils;
/**
* Class for importing a database from CSV (Comma Separate Values)
* formatted data.
- *
+ *
* The database's loyalty cards are expected to appear in the CSV data.
* A header is expected for the each table showing the names of the columns.
*/
-public class StocardImporter implements Importer
-{
+public class StocardImporter implements Importer {
public void importData(Context context, DBHelper db, InputStream input, char[] password) throws IOException, FormatException, JSONException, ParseException {
HashMap
* The database's loyalty cards are expected to appear in the CSV data.
* A header is expected for the each table showing the names of the columns.
*/
-public class VoucherVaultImporter implements Importer
-{
+public class VoucherVaultImporter implements Importer {
public void importData(Context context, DBHelper db, InputStream input, char[] password) throws IOException, FormatException, JSONException, ParseException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
diff --git a/app/src/main/java/protect/card_locker/preferences/Settings.java b/app/src/main/java/protect/card_locker/preferences/Settings.java
index a28ac5f8a..977271ffc 100644
--- a/app/src/main/java/protect/card_locker/preferences/Settings.java
+++ b/app/src/main/java/protect/card_locker/preferences/Settings.java
@@ -12,44 +12,36 @@ import androidx.preference.PreferenceManager;
import protect.card_locker.R;
import protect.card_locker.Utils;
-public class Settings
-{
+public class Settings {
private Context context;
private SharedPreferences settings;
- public Settings(Context context)
- {
+ public Settings(Context context) {
this.context = context;
this.settings = PreferenceManager.getDefaultSharedPreferences(context);
}
- private String getResString(@StringRes int resId)
- {
+ private String getResString(@StringRes int resId) {
return context.getString(resId);
}
- private int getResInt(@IntegerRes int resId)
- {
+ private int getResInt(@IntegerRes int resId) {
return context.getResources().getInteger(resId);
}
- private String getString(@StringRes int keyId, String defaultValue)
- {
+ private String getString(@StringRes int keyId, String defaultValue) {
return settings.getString(getResString(keyId), defaultValue);
}
- private int getInt(@StringRes int keyId, @IntegerRes int defaultId)
- {
+ private int getInt(@StringRes int keyId, @IntegerRes int defaultId) {
return settings.getInt(getResString(keyId), getResInt(defaultId));
}
- private boolean getBoolean(@StringRes int keyId, boolean defaultValue)
- {
+ private boolean getBoolean(@StringRes int keyId, boolean defaultValue) {
return settings.getBoolean(getResString(keyId), defaultValue);
}
- public Locale getLocale()
- {
+ public Locale getLocale() {
String value = getString(R.string.settings_key_locale, "");
if (value.length() == 0) {
@@ -59,69 +51,55 @@ public class Settings
return Utils.stringToLocale(value);
}
- public int getTheme()
- {
+ public int getTheme() {
String value = getString(R.string.settings_key_theme, getResString(R.string.settings_key_system_theme));
- if(value.equals(getResString(R.string.settings_key_light_theme)))
- {
+ if (value.equals(getResString(R.string.settings_key_light_theme))) {
return AppCompatDelegate.MODE_NIGHT_NO;
- }
- else if(value.equals(getResString(R.string.settings_key_dark_theme)))
- {
+ } else if (value.equals(getResString(R.string.settings_key_dark_theme))) {
return AppCompatDelegate.MODE_NIGHT_YES;
}
return AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
}
- public double getFontSizeScale()
- {
+ public double getFontSizeScale() {
return getInt(R.string.settings_key_max_font_size_scale, R.integer.settings_max_font_size_scale_pct) / 100.0;
}
- public int getSmallFont()
- {
+ public int getSmallFont() {
return 14;
}
- public int getMediumFont()
- {
+ public int getMediumFont() {
return 28;
}
- public int getLargeFont()
- {
+ public int getLargeFont() {
return 40;
}
- public int getFontSizeMin(int fontSize)
- {
+ public int getFontSizeMin(int fontSize) {
return (int) (Math.round(fontSize / 2.0) - 1);
}
- public int getFontSizeMax(int fontSize)
- {
+ public int getFontSizeMax(int fontSize) {
return (int) Math.round(fontSize * getFontSizeScale());
}
- public boolean useMaxBrightnessDisplayingBarcode()
- {
+ public boolean useMaxBrightnessDisplayingBarcode() {
return getBoolean(R.string.settings_key_display_barcode_max_brightness, true);
}
- public boolean getLockBarcodeScreenOrientation()
- {
+ public boolean getLockBarcodeScreenOrientation() {
return getBoolean(R.string.settings_key_lock_barcode_orientation, false);
}
- public boolean getKeepScreenOn()
- {
+ public boolean getKeepScreenOn() {
return getBoolean(R.string.settings_key_keep_screen_on, true);
}
- public boolean getDisableLockscreenWhileViewingCard()
- {
+ public boolean getDisableLockscreenWhileViewingCard() {
return getBoolean(R.string.settings_key_disable_lockscreen_while_viewing_card, true);
}
}
diff --git a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java
index 3e88fb87e..7bd73d668 100644
--- a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java
+++ b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java
@@ -24,19 +24,16 @@ import protect.card_locker.CatimaAppCompatActivity;
import protect.card_locker.R;
import protect.card_locker.Utils;
-public class SettingsActivity extends CatimaAppCompatActivity
-{
+public class SettingsActivity extends CatimaAppCompatActivity {
@Override
- protected void onCreate(Bundle savedInstanceState)
- {
+ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.settings);
setContentView(R.layout.settings_activity);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
- if(actionBar != null)
- {
+ if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
@@ -48,12 +45,10 @@ public class SettingsActivity extends CatimaAppCompatActivity
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
+ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
- if(id == android.R.id.home)
- {
+ if (id == android.R.id.home) {
finish();
return true;
}
@@ -61,8 +56,7 @@ public class SettingsActivity extends CatimaAppCompatActivity
return super.onOptionsItemSelected(item);
}
- public static class SettingsFragment extends PreferenceFragmentCompat
- {
+ public static class SettingsFragment extends PreferenceFragmentCompat {
private static final String DIALOG_FRAGMENT_TAG = "SettingsFragment";
@Override