-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from brarcher/initial
Initial commit of application
- Loading branch information
Showing
51 changed files
with
1,748 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "protect.card_locker" | ||
minSdkVersion 17 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "0.1" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
lintOptions { | ||
disable "GoogleAppIndexingWarning" | ||
disable "ButtonStyle" | ||
disable "AlwaysShowAction" | ||
} | ||
|
||
// This is for Robolectric support for SDK 23 | ||
useLibrary 'org.apache.http.legacy' | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
compile 'com.android.support:design:23.1.1' | ||
compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar' | ||
compile 'com.google.zxing:core:3.2.0' | ||
testCompile 'junit:junit:4.12' | ||
testCompile "org.robolectric:robolectric:3.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/brarcher/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
15 changes: 15 additions & 0 deletions
15
app/src/androidTest/java/protect/card_locker/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package protect.card_locker; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> | ||
{ | ||
public ApplicationTest() | ||
{ | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="protect.card_locker" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-feature android:required="true" android:name="android.hardware.camera"/> | ||
<uses-permission android:maxSdkVersion="18" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
|
||
<application | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name="protect.card_locker.MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".LoyaltyCardViewActivity" | ||
android:theme="@style/AppTheme.NoActionBar" | ||
android:configChanges="orientation|screenSize" | ||
android:parentActivityName="protect.card_locker.MainActivity"/> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package protect.card_locker; | ||
|
||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
public class DBHelper extends SQLiteOpenHelper | ||
{ | ||
public static final String DATABASE_NAME = "LoyaltyCards.db"; | ||
public static final int DATABASE_VERSION = 1; | ||
|
||
class LoyaltyCardDbIds | ||
{ | ||
public static final String TABLE = "cards"; | ||
public static final String ID = "_id"; | ||
public static final String STORE = "store"; | ||
public static final String CARD_ID = "cardid"; | ||
public static final String BARCODE_TYPE = "barcodetype"; | ||
} | ||
|
||
public DBHelper(Context context) | ||
{ | ||
super(context, DATABASE_NAME, null, DATABASE_VERSION); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) | ||
{ | ||
// create table for gift cards | ||
db.execSQL("create table " + LoyaltyCardDbIds.TABLE + "(" + | ||
LoyaltyCardDbIds.ID + " INTEGER primary key autoincrement," + | ||
LoyaltyCardDbIds.STORE + " TEXT not null," + | ||
LoyaltyCardDbIds.CARD_ID + " TEXT not null," + | ||
LoyaltyCardDbIds.BARCODE_TYPE + " TEXT not null)"); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) | ||
{ | ||
// Do not support versioning yet | ||
db.execSQL("DROP TABLE IF EXISTS " + LoyaltyCardDbIds.TABLE); | ||
onCreate(db); | ||
} | ||
|
||
public boolean insertLoyaltyCard(final String store, final String cardId, final String barcodeType) | ||
{ | ||
SQLiteDatabase db = getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(LoyaltyCardDbIds.STORE, store); | ||
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId); | ||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType); | ||
final long newId = db.insert(LoyaltyCardDbIds.TABLE, null, contentValues); | ||
return (newId != -1); | ||
} | ||
|
||
|
||
public boolean updateLoyaltyCard(final int id, final String store, final String cardId, | ||
final String barcodeType) | ||
{ | ||
SQLiteDatabase db = getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(LoyaltyCardDbIds.STORE, store); | ||
contentValues.put(LoyaltyCardDbIds.CARD_ID, cardId); | ||
contentValues.put(LoyaltyCardDbIds.BARCODE_TYPE, barcodeType); | ||
int rowsUpdated = db.update(LoyaltyCardDbIds.TABLE, contentValues, | ||
LoyaltyCardDbIds.ID + "=?", | ||
new String[]{Integer.toString(id)}); | ||
return (rowsUpdated == 1); | ||
} | ||
|
||
public LoyaltyCard getLoyaltyCard(final int id) | ||
{ | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Cursor data = db.rawQuery("select * from " + LoyaltyCardDbIds.TABLE + | ||
" where " + LoyaltyCardDbIds.ID + "=?", new String[]{String.format("%d", id)}); | ||
|
||
LoyaltyCard card = null; | ||
|
||
if(data.getCount() == 1) | ||
{ | ||
data.moveToFirst(); | ||
card = LoyaltyCard.toLoyaltyCard(data); | ||
} | ||
|
||
data.close(); | ||
|
||
return card; | ||
} | ||
|
||
public boolean deleteLoyaltyCard (final int id) | ||
{ | ||
SQLiteDatabase db = getWritableDatabase(); | ||
int rowsDeleted = db.delete(LoyaltyCardDbIds.TABLE, | ||
LoyaltyCardDbIds.ID + " = ? ", | ||
new String[]{String.format("%d", id)}); | ||
return (rowsDeleted == 1); | ||
} | ||
|
||
public Cursor getLoyaltyCardCursor() | ||
{ | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Cursor res = db.rawQuery("select * from " + LoyaltyCardDbIds.TABLE + | ||
" ORDER BY " + LoyaltyCardDbIds.STORE, null); | ||
return res; | ||
} | ||
|
||
public int getLoyaltyCardCount() | ||
{ | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Cursor data = db.rawQuery("SELECT Count(*) FROM " + LoyaltyCardDbIds.TABLE, null); | ||
|
||
int numItems = 0; | ||
|
||
if(data.getCount() == 1) | ||
{ | ||
data.moveToFirst(); | ||
numItems = data.getInt(0); | ||
} | ||
|
||
data.close(); | ||
|
||
return numItems; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package protect.card_locker; | ||
|
||
import android.database.Cursor; | ||
|
||
public class LoyaltyCard | ||
{ | ||
public final int id; | ||
public final String store; | ||
public final String cardId; | ||
public final String barcodeType; | ||
|
||
public LoyaltyCard(final int id, final String store, final String cardId, final String barcodeType) | ||
{ | ||
this.id = id; | ||
this.store = store; | ||
this.cardId = cardId; | ||
this.barcodeType = barcodeType; | ||
} | ||
|
||
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 cardId = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.CARD_ID)); | ||
String barcodeType = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.LoyaltyCardDbIds.BARCODE_TYPE)); | ||
|
||
return new LoyaltyCard(id, store, cardId, barcodeType); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/protect/card_locker/LoyaltyCardCursorAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package protect.card_locker; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CursorAdapter; | ||
import android.widget.TextView; | ||
|
||
class LoyaltyCardCursorAdapter extends CursorAdapter | ||
{ | ||
public LoyaltyCardCursorAdapter(Context context, Cursor cursor) | ||
{ | ||
super(context, cursor, 0); | ||
} | ||
|
||
// The newView method is used to inflate a new view and return it, | ||
// you don't bind any data to the view at this point. | ||
@Override | ||
public View newView(Context context, Cursor cursor, ViewGroup parent) | ||
{ | ||
return LayoutInflater.from(context).inflate(R.layout.loyalty_card_layout, parent, false); | ||
} | ||
|
||
// The bindView method is used to bind all data to a given view | ||
// such as setting the text on a TextView. | ||
@Override | ||
public void bindView(View view, Context context, Cursor cursor) | ||
{ | ||
// Find fields to populate in inflated template | ||
TextView storeField = (TextView) view.findViewById(R.id.store); | ||
TextView cardIdField = (TextView) view.findViewById(R.id.cardId); | ||
|
||
// Extract properties from cursor | ||
LoyaltyCard loyaltyCard = LoyaltyCard.toLoyaltyCard(cursor); | ||
|
||
// Populate fields with extracted properties | ||
storeField.setText(loyaltyCard.store); | ||
|
||
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); | ||
} | ||
} |
Oops, something went wrong.