-
Notifications
You must be signed in to change notification settings - Fork 8
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 implementation
- Loading branch information
Showing
45 changed files
with
1,272 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# gift-card-guard | ||
Manage gift cards, their current values, and an image of the most recent receipt | ||
Manage gift cards, their current values, and an image of the most recent receipt. Never forget | ||
how much a gift card is worth, or be unable to use a gift card because the proof of its | ||
value is lost. | ||
|
||
If there is any interest in improving this open source baby monitor, kindly submit a pull request with | ||
proposed changed. | ||
|
||
# Thanks | ||
|
||
App icon originals by [Freepik](https://www.flaticon.com) and distributed under the [CC BY 3.0](http://creativecommons.org/licenses/by/3.0/) license, | ||
and formatted using [Android Asset Studio](https://romannurik.github.io/AndroidAssetStudio/index.html). |
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,32 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "protect.gift_card_guard" | ||
minSdkVersion 17 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
lintOptions { | ||
disable "GoogleAppIndexingWarning" | ||
disable "ButtonStyle" | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
compile 'com.android.support:design:23.1.1' | ||
} |
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/gift_card_guard/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.gift_card_guard; | ||
|
||
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,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="protect.gift_card_guard" | ||
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=".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=".GiftCardViewActivity" | ||
android:theme="@style/AppTheme.NoActionBar" | ||
android:launchMode="singleTop" | ||
android:parentActivityName=".MainActivity"/> | ||
<activity | ||
android:name=".ReceiptViewActivity" | ||
android:theme="@style/AppTheme.NoActionBar" | ||
android:parentActivityName=".GiftCardViewActivity"/> | ||
</application> | ||
|
||
</manifest> |
133 changes: 133 additions & 0 deletions
133
app/src/main/java/protect/gift_card_guard/DBHelper.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,133 @@ | ||
package protect.gift_card_guard; | ||
|
||
|
||
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 = "GiftCardGuard.db"; | ||
public static final int DATABASE_VERSION = 1; | ||
|
||
class GiftCardDbIds | ||
{ | ||
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 VALUE = "value"; | ||
public static final String RECEIPT = "receipt"; | ||
} | ||
|
||
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 " + GiftCardDbIds.TABLE + "(" + | ||
GiftCardDbIds.ID + " INTEGER primary key autoincrement," + | ||
GiftCardDbIds.STORE + " TEXT not null," + | ||
GiftCardDbIds.CARD_ID + " TEXT not null," + | ||
GiftCardDbIds.VALUE + " TEXT not null," + | ||
GiftCardDbIds.RECEIPT + " TEXT not null)"); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) | ||
{ | ||
// Do not support versioning yet | ||
db.execSQL("DROP TABLE IF EXISTS " + GiftCardDbIds.TABLE); | ||
onCreate(db); | ||
} | ||
|
||
public boolean insertGiftCard(final String store, final String cardId, final String value, | ||
final String receipt) | ||
{ | ||
SQLiteDatabase db = getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(GiftCardDbIds.STORE, store); | ||
contentValues.put(GiftCardDbIds.CARD_ID, cardId); | ||
contentValues.put(GiftCardDbIds.VALUE, value); | ||
contentValues.put(GiftCardDbIds.RECEIPT, receipt); | ||
final long newId = db.insert(GiftCardDbIds.TABLE, null, contentValues); | ||
return (newId != 1); | ||
} | ||
|
||
|
||
public boolean updateGiftCard(final int id, final String store, final String cardId, | ||
final String value, final String receipt) | ||
{ | ||
SQLiteDatabase db = getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(GiftCardDbIds.STORE, store); | ||
contentValues.put(GiftCardDbIds.CARD_ID, cardId); | ||
contentValues.put(GiftCardDbIds.VALUE, value); | ||
contentValues.put(GiftCardDbIds.RECEIPT, receipt); | ||
int rowsUpdated = db.update(GiftCardDbIds.TABLE, contentValues, | ||
GiftCardDbIds.ID + "=?", | ||
new String[]{Integer.toString(id)}); | ||
return (rowsUpdated == 1); | ||
} | ||
|
||
public GiftCard getGiftCard(final int id) | ||
{ | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Cursor data = db.rawQuery("select * from " + GiftCardDbIds.TABLE + | ||
" where " + GiftCardDbIds.ID + "=?", new String[]{String.format("%d", id)}); | ||
|
||
GiftCard card = null; | ||
|
||
if(data.getCount() == 1) | ||
{ | ||
data.moveToFirst(); | ||
card = GiftCard.toGiftCard(data); | ||
} | ||
|
||
data.close(); | ||
|
||
return card; | ||
} | ||
|
||
public boolean deleteGiftCard (final int id) | ||
{ | ||
SQLiteDatabase db = getWritableDatabase(); | ||
int rowsDeleted = db.delete(GiftCardDbIds.TABLE, | ||
GiftCardDbIds.ID + " = ? ", | ||
new String[]{String.format("%d", id)}); | ||
return (rowsDeleted == 1); | ||
} | ||
|
||
public Cursor getGiftCardCursor() | ||
{ | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Cursor res = db.rawQuery("select * from " + GiftCardDbIds.TABLE + | ||
" ORDER BY " + GiftCardDbIds.STORE, null); | ||
return res; | ||
} | ||
|
||
public int getGiftCardCount() | ||
{ | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Cursor data = db.rawQuery("SELECT Count(*) FROM " + GiftCardDbIds.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,33 @@ | ||
package protect.gift_card_guard; | ||
|
||
import android.database.Cursor; | ||
|
||
public class GiftCard | ||
{ | ||
public final int id; | ||
public final String store; | ||
public final String cardId; | ||
public final String value; | ||
public final String receipt; | ||
|
||
public GiftCard(final int id, final String store, final String cardId, | ||
final String value, final String receipt) | ||
{ | ||
this.id = id; | ||
this.store = store; | ||
this.cardId = cardId; | ||
this.value = value; | ||
this.receipt = receipt; | ||
} | ||
|
||
public static GiftCard toGiftCard(Cursor cursor) | ||
{ | ||
int id = cursor.getInt(cursor.getColumnIndexOrThrow(DBHelper.GiftCardDbIds.ID)); | ||
String store = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.GiftCardDbIds.STORE)); | ||
String cardId = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.GiftCardDbIds.CARD_ID)); | ||
String value = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.GiftCardDbIds.VALUE)); | ||
String receipt = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.GiftCardDbIds.RECEIPT)); | ||
|
||
return new GiftCard(id, store, cardId, value, receipt); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/protect/gift_card_guard/GiftCardCursorAdapter.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,48 @@ | ||
package protect.gift_card_guard; | ||
|
||
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 GiftCardCursorAdapter extends CursorAdapter | ||
{ | ||
public GiftCardCursorAdapter(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.giftcard_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 valueField = (TextView) view.findViewById(R.id.value); | ||
TextView cardIdField = (TextView) view.findViewById(R.id.cardId); | ||
|
||
// Extract properties from cursor | ||
GiftCard giftCard = GiftCard.toGiftCard(cursor); | ||
|
||
// Populate fields with extracted properties | ||
storeField.setText(giftCard.store); | ||
valueField.setText(giftCard.value); | ||
|
||
String cardIdFormat = view.getResources().getString(R.string.cardIdFormat); | ||
String cardIdLabel = view.getResources().getString(R.string.cardId); | ||
String cardIdText = String.format(cardIdFormat, cardIdLabel, giftCard.cardId); | ||
cardIdField.setText(cardIdText); | ||
} | ||
} |
Oops, something went wrong.