From fafb3b6b37297ecdcbdd209118211e6e7816b253 Mon Sep 17 00:00:00 2001 From: lotharlanger Date: Tue, 20 Dec 2011 22:42:41 +0100 Subject: [PATCH 01/16] fdfgghhkljk;lmnn --- CashPoint/.classpath | 7 + CashPoint/.project | 33 +++ CashPoint/default.properties | 11 + CashPoint/proguard.cfg | 40 ++++ CashPoint/res/drawable-hdpi/icon.png | Bin 0 -> 4147 bytes CashPoint/res/drawable-ldpi/icon.png | Bin 0 -> 1723 bytes CashPoint/res/drawable-mdpi/icon.png | Bin 0 -> 2574 bytes CashPoint/res/layout/main.xml | 6 + CashPoint/res/values/strings.xml | 5 + CashPoint/src/app/learn/CashPoint.java | 23 +++ CashPoint/src/app/learn/DbAdapter.java | 77 +++++++ CashPoint/src/app/learn/NotesDbAdapter.java | 188 ++++++++++++++++++ .../TripCostCalculation - eine Studie.ods | Bin 0 -> 9790 bytes CashPoint/trip/cashpoint.sh | 11 + CashPoint/trip/cashpoint.sql | 39 ++++ CashPoint/trip/cashpoint2.sql | 45 +++++ CashPoint/trip/tables.sql | 23 +++ CashPoint/trip/test.db | Bin 0 -> 2048 bytes 18 files changed, 508 insertions(+) create mode 100755 CashPoint/.classpath create mode 100755 CashPoint/.project create mode 100755 CashPoint/default.properties create mode 100755 CashPoint/proguard.cfg create mode 100755 CashPoint/res/drawable-hdpi/icon.png create mode 100755 CashPoint/res/drawable-ldpi/icon.png create mode 100755 CashPoint/res/drawable-mdpi/icon.png create mode 100755 CashPoint/res/layout/main.xml create mode 100755 CashPoint/res/values/strings.xml create mode 100755 CashPoint/src/app/learn/CashPoint.java create mode 100755 CashPoint/src/app/learn/DbAdapter.java create mode 100755 CashPoint/src/app/learn/NotesDbAdapter.java create mode 100755 CashPoint/trip/TripCostCalculation - eine Studie.ods create mode 100755 CashPoint/trip/cashpoint.sh create mode 100755 CashPoint/trip/cashpoint.sql create mode 100755 CashPoint/trip/cashpoint2.sql create mode 100755 CashPoint/trip/tables.sql create mode 100755 CashPoint/trip/test.db diff --git a/CashPoint/.classpath b/CashPoint/.classpath new file mode 100755 index 0000000..6efcbb7 --- /dev/null +++ b/CashPoint/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CashPoint/.project b/CashPoint/.project new file mode 100755 index 0000000..ffa801c --- /dev/null +++ b/CashPoint/.project @@ -0,0 +1,33 @@ + + + CashPoint + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/CashPoint/default.properties b/CashPoint/default.properties new file mode 100755 index 0000000..b74c488 --- /dev/null +++ b/CashPoint/default.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-4 diff --git a/CashPoint/proguard.cfg b/CashPoint/proguard.cfg new file mode 100755 index 0000000..b1cdf17 --- /dev/null +++ b/CashPoint/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native ; +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/CashPoint/res/drawable-hdpi/icon.png b/CashPoint/res/drawable-hdpi/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..8074c4c571b8cd19e27f4ee5545df367420686d7 GIT binary patch literal 4147 zcmV-35X|q1P)OwvMs$Q8_8nISM!^>PxsujeDCl4&hPxrxkp%Qc^^|l zp6LqAcf3zf1H4aA1Gv-O6ha)ktct9Y+VA@N^9i;p0H%6v>ZJZYQ`zEa396z-gi{r_ zDz)D=vgRv62GCVeRjK{15j7V@v6|2nafFX6W7z2j1_T0a zLyT3pGTubf1lB5)32>bl0*BflrA!$|_(WD2)iJIfV}37=ZKAC zSe3boYtQ=;o0i>)RtBvsI#iT{0!oF1VFeW`jDjF2Q4aE?{pGCAd>o8Kg#neIh*AMY zLl{;F!vLiem7s*x0<9FKAd6LoPz3~G32P+F+cuGOJ5gcC@pU_?C2fmix7g2)SUaQO$NS07~H)#fn!Q<}KQWtX}wW`g2>cMld+`7Rxgq zChaey66SG560JhO66zA!;sK1cWa2AG$9k~VQY??6bOmJsw9@3uL*z;WWa7(Nm{^TA zilc?y#N9O3LcTo2c)6d}SQl-v-pE4^#wb=s(RxaE28f3FQW(yp$ulG9{KcQ7r>7mQ zE!HYxUYex~*7IinL+l*>HR*UaD;HkQhkL(5I@UwN%Wz504M^d!ylo>ANvKPF_TvA< zkugG5;F6x}$s~J8cnev->_(Ic7%lGQgUi3n#XVo36lUpcS9s z)ympRr7}@|6WF)Ae;D{owN1;aZSR50al9h~?-WhbtKK%bDd zhML131oi1Bu1&Qb$Cp199LJ#;j5d|FhW8_i4KO1OI>}J^p2DfreMSVGY9aFlr&90t zyI2FvxQiKMFviSQeP$Ixh#70qj5O%I+O_I2t2XHWqmh2!1~tHpN3kA4n=1iHj?`@c<~3q^X6_Q$AqTDjBU`|!y<&lkqL|m5tG(b z8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);q>w`bxts_4} znKHg?X==JDkQl3Y>Ckt%`s{n?Nq-1Fw5~%Mq$CAsi-`yu_bKm zxs#QdE7&vgJD%M84f4SNzSDv)S|V?|$!d5a#lhT5>>YWE4NGqa9-fbmV$=)@k&32kdEYetna>=j@0>V8+wRsL;po!3ivVwh<9tn z2S<1u9DAAQ>x1Sn=fk`)At|quvleV($B|#Kap_lB-F^*yV=wZ{9baUu(uXfokr95^ zA*!*W=5a>$2Ps`-F^+qRQT^{*cN>vipT*4!r#p%{(#I7s z0NN94*q?ib$KJjfDI_sjHNdmEVp5wB&j54O#VoFqBwy)gfA$%)4d_X4q${L9Xom2R3xy&ZBSNgt4a1d7K^CDWa9r zVb-_52m}Vp)`9;ZSKd#|U4ZYj5}Gp49{4utST|=c`~(#>KHF6}CCov1iHYw zt{bWo)A@yF2$~c(nR$rSAaFQ$(Wh{vkG1AlutDMw=mM`C`T=X&|Ad9fb5Od}ROt1z zOpczHqrb4Jo^rSCiW#&o(m7jFamnrsTpQb;*h4o8r#$aZ}2RaT-x2u^^ z%u@YyIv$U^u~@9(XGbSwU@fk6SikH>j+D1jQrYTKGJpW%vUT{!d}7THI5&Sa?~MKy zS0-mvMl+BOcroEJ@hN!2H_?coTEJ5Q<;Nd?yx;eIj4{$$E2?YUO|NtNPJ-PdDf;s} zab;}Mz0kbOI}5*w@3gROcnl#5)wQnEhDBfn!Xhy`u>C}*E~vWpO^HS)FC>8^umI=+ z&H;LW6w#;EF`}vQd_9Muru`KnQVPI9U?(sD)&Dg-0j3#(!fNKVZ_GoYH{la~d*1Yh$TI-TL>mI4vpNb@sU2=IZ8vL%AXUx0 zz{K0|nK(yizLHaeW#ZhRfQXoK^}1$=$#1{Yn002ovPDHLkV1n#w+^+xt literal 0 HcmV?d00001 diff --git a/CashPoint/res/drawable-ldpi/icon.png b/CashPoint/res/drawable-ldpi/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..1095584ec21f71cd0afc9e0993aa2209671b590c GIT binary patch literal 1723 zc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Gsl2{qY0%a7J?uICWgHuLfj+MB z=GkAN1&ifT#2u}B+2S#~$5jA(Qn^;H%CCmIae4AE-Dsng|Hl*Ov!z72k3ZnJs{pp| z+pW`DDueC#mEWOf=ucJ!dTL}hzOeiS-i?m2E;`EKz4<&Lu~NnW?peqVU^@<+T3KKu z{yrI%Qy-Z%HEvLUz}n^~m?7x`xuCtNR#L2En!T>dQtIKdS#V-Hzt3RtwTeYtmQ&dR z6qXZvac*oc@BUYEH%@Ylv_1&tSjkbzzU6*h1(3^C`;1z;g_SmOtclS?KWk2VYE zM*oS<=C483XckW?GN|1jfh3Ro(h + \ No newline at end of file diff --git a/CashPoint/res/values/strings.xml b/CashPoint/res/values/strings.xml new file mode 100755 index 0000000..4c14d2d --- /dev/null +++ b/CashPoint/res/values/strings.xml @@ -0,0 +1,5 @@ + + + This is CashPoint ! + Cash Point + diff --git a/CashPoint/src/app/learn/CashPoint.java b/CashPoint/src/app/learn/CashPoint.java new file mode 100755 index 0000000..b448494 --- /dev/null +++ b/CashPoint/src/app/learn/CashPoint.java @@ -0,0 +1,23 @@ +package app.learn; + +import android.app.Activity; +import android.os.Bundle; +import android.content.Context; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import junit.framework.Assert; + + +public class CashPoint extends Activity { + /** Called when the activity is first created. */ + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.main); + } + + +} \ No newline at end of file diff --git a/CashPoint/src/app/learn/DbAdapter.java b/CashPoint/src/app/learn/DbAdapter.java new file mode 100755 index 0000000..4603286 --- /dev/null +++ b/CashPoint/src/app/learn/DbAdapter.java @@ -0,0 +1,77 @@ +package app.learn; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +public class DbAdapter extends SQLiteOpenHelper { + + private static final String TAG = "DbAdapter"; + + private static final String DATABASE_NAME = "data"; + private static final String DATABASE_TABLE = "cashpoint"; + private static final int DATABASE_VERSION = 2; + + public DbAdapter(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + mDb = getWritableDatabase(); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL("create table " + DATABASE_TABLE + " (" + + " entry integer not null," + // unique for the inputs, reference for the distributions + " name text not null," + // the person involved + " amount real not null," + // the amount of money, negative for distributions + " currency text," + // if null it's the default currency (Euro or Dollar or ...) + " date numeric," + // if null it's a distribution + " comment text" + // optional, for recognition + " );" + ); + + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + + newVersion + ", which will destroy all old data"); + db.execSQL("DROP TABLE IF EXISTS cashpoint"); + onCreate(db); + + } + + private SQLiteDatabase mDb; + + public int getEntryId() { + Cursor cursor = mDb.rawQuery("select max(entry) from " + DATABASE_TABLE, null); + if (cursor.getCount() < 1) + return 1; + else { + cursor.moveToFirst(); + return cursor.getInt(0); + } + } + + public int createEntry(String name, double amount, String currency, String comment) { + int entryId = getEntryId(); + + ContentValues values = new ContentValues(); + values.put("entry", "" + entryId); + values.put("name", name); + values.put("amount", amount); + values.put("currency", currency); +// values.put("date", datetime('now','localtime')); + values.put("comment", comment); + + long rowId = mDb.insert(DATABASE_TABLE, null, values); + if (rowId < 0) + return -1; + else { + return entryId; + } + } +} \ No newline at end of file diff --git a/CashPoint/src/app/learn/NotesDbAdapter.java b/CashPoint/src/app/learn/NotesDbAdapter.java new file mode 100755 index 0000000..403c250 --- /dev/null +++ b/CashPoint/src/app/learn/NotesDbAdapter.java @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package app.learn; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +/** + * Simple notes database access helper class. Defines the basic CRUD operations + * for the notepad example, and gives the ability to list all notes as well as + * retrieve or modify a specific note. + * + * This has been improved from the first version of this tutorial through the + * addition of better error handling and also using returning a Cursor instead + * of using a collection of inner classes (which is less scalable and not + * recommended). + */ +public class NotesDbAdapter { + + public static final String KEY_TITLE = "title"; + public static final String KEY_BODY = "body"; + public static final String KEY_ROWID = "_id"; + + private static final String TAG = "NotesDbAdapter"; + private DatabaseHelper mDbHelper; + private SQLiteDatabase mDb; + + /** + * Database creation sql statement + */ + private static final String DATABASE_CREATE = + "create table notes (_id integer primary key autoincrement, " + + "title text not null, body text not null);"; + + private static final String DATABASE_NAME = "data"; + private static final String DATABASE_TABLE = "notes"; + private static final int DATABASE_VERSION = 2; + + private final Context mCtx; + + private static class DatabaseHelper extends SQLiteOpenHelper { + + DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + + db.execSQL(DATABASE_CREATE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + + newVersion + ", which will destroy all old data"); + db.execSQL("DROP TABLE IF EXISTS notes"); + onCreate(db); + } + } + + /** + * Constructor - takes the context to allow the database to be + * opened/created + * + * @param ctx the Context within which to work + */ + public NotesDbAdapter(Context ctx) { + this.mCtx = ctx; + } + + /** + * Open the notes database. If it cannot be opened, try to create a new + * instance of the database. If it cannot be created, throw an exception to + * signal the failure + * + * @return this (self reference, allowing this to be chained in an + * initialization call) + * @throws SQLException if the database could be neither opened or created + */ + public NotesDbAdapter open() throws SQLException { + mDbHelper = new DatabaseHelper(mCtx); + mDb = mDbHelper.getWritableDatabase(); + return this; + } + + public void close() { + mDbHelper.close(); + } + + + /** + * Create a new note using the title and body provided. If the note is + * successfully created return the new rowId for that note, otherwise return + * a -1 to indicate failure. + * + * @param title the title of the note + * @param body the body of the note + * @return rowId or -1 if failed + */ + public long createNote(String title, String body) { + ContentValues initialValues = new ContentValues(); + initialValues.put(KEY_TITLE, title); + initialValues.put(KEY_BODY, body); + + return mDb.insert(DATABASE_TABLE, null, initialValues); + } + + /** + * Delete the note with the given rowId + * + * @param rowId id of note to delete + * @return true if deleted, false otherwise + */ + public boolean deleteNote(long rowId) { + + return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0; + } + + /** + * Return a Cursor over the list of all notes in the database + * + * @return Cursor over all notes + */ + public Cursor fetchAllNotes() { + + return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, + KEY_BODY}, null, null, null, null, null); + } + + /** + * Return a Cursor positioned at the note that matches the given rowId + * + * @param rowId id of note to retrieve + * @return Cursor positioned to matching note, if found + * @throws SQLException if note could not be found/retrieved + */ + public Cursor fetchNote(long rowId) throws SQLException { + + Cursor mCursor = + + mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, + KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId, null, + null, null, null, null); + if (mCursor != null) { + mCursor.moveToFirst(); + } + return mCursor; + + } + + /** + * Update the note using the details provided. The note to be updated is + * specified using the rowId, and it is altered to use the title and body + * values passed in + * + * @param rowId id of note to update + * @param title value to set note title to + * @param body value to set note body to + * @return true if the note was successfully updated, false otherwise + */ + public boolean updateNote(long rowId, String title, String body) { + ContentValues args = new ContentValues(); + args.put(KEY_TITLE, title); + args.put(KEY_BODY, body); + + return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0; + } +} diff --git a/CashPoint/trip/TripCostCalculation - eine Studie.ods b/CashPoint/trip/TripCostCalculation - eine Studie.ods new file mode 100755 index 0000000000000000000000000000000000000000..fc6f88172ea55e3435840de2c12bdf2714a883ee GIT binary patch literal 9790 zcmdsdcU%)o_kIwhBSnfz@6r-_2~B$MAks?+5riZpp-BwSOs{r7iZ^Vyv_&zUo4XJ?*0v-(=Nc+>y@ApnqxyeA*xA{7Y) z005^4wg}+rB^84&#J?gFN64K!hFI2@OObp>PKT#N8DN#{kht6x7ZE zeH{wL=>NrL;AQ&FBwPUC^!R2Iim?NFxw^>6V}DpYpeQufsw|rjP>_uU3Wp#ZoZv87 zHWOo20ZBG_Ibs=vqoWf93jWcM0M;Wr7AzEw27j-TWphWt!QWg0!|hz5XfOr>{?#|| zuiD^m4Sg^1a&dy+kY&4$!63mPkf*07&{G76K*2ylQc_Z&Z?$ZHH01#KQxEBma`~p^ z00BW=pr^e@gM@%WpdY%Y9{yXWPIZ5E34uWT+0bbpzIX9kbHajxqM+~BKU#vJ92{K! z)c>UeSX~hi4CG*ku@mrcf_k#EvHTIoUji=7Cif${r*6o}d~?PL?u2o&a}j`G?qMl@k^e5)u#+6c83R7L){wNnrnhVnTly z_^ax7I1CDhqP{ojWRHUCeY@`<5uhlC3EatxMf+!=4HAWLhC(nP5m7-`Ar3`%Cl?0+ zQ9_`B|(;~kB`wt~huL0G|5UNy_G(+wfJN|d$ShE6uz-x8`}2XS zR;xH=q#6qk-)b?lJBg)=Gqn{l-f*1j{iE*1X7tehp<2w&E(?c>oLDF~ZZ^TVLel2v zfl3Rj-LHa^J^s?IU7=vxswF%o$v~ci86NCX;n{EwU7!slOfd34fo&{e2PPP0^cQe9(J*nPXP0 zJMA^?&v|{P*!?q5bWBZMcLJa9#eNVOt$qE7*p9GxfZx22ZXIv+TkY&dIm|hFs_%cHK4Nrs__kNWDO7A*qKMt?{J~<@60A10=@8 zb+oq|Sa0%0_2sLmWqt`h>phUXgw!`Ba3C?j9P=DJ=Blh~UI!^`-S&xU3qV40lmRVm zXUSu>R7Ow?!_TU(GHhz0G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?d00001 diff --git a/CashPoint/trip/cashpoint.sh b/CashPoint/trip/cashpoint.sh new file mode 100755 index 0000000..68d0582 --- /dev/null +++ b/CashPoint/trip/cashpoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash +pwd +sqlite3 test.db "drop table if exists cashpoint;" +sqlite3 test.db "create table cashpoint ( + entry integer not null, -- unique for the inputs, reference for the distributions + name text not null, -- the person involved + amount real not null, -- the amount of money, negative for distributions + currency text, -- if null it's the default currency (Euro or Dollar or ...) + date numeric, -- if null it's a distribution + comment text -- optional, for recognition +);" diff --git a/CashPoint/trip/cashpoint.sql b/CashPoint/trip/cashpoint.sql new file mode 100755 index 0000000..738b08c --- /dev/null +++ b/CashPoint/trip/cashpoint.sql @@ -0,0 +1,39 @@ +drop table if exists cashpoint; +create table cashpoint ( + entry integer not null, -- unique for the inputs, reference for the distributions + name text not null, -- the person involved + amount real not null, -- the amount of money, negative for distributions + currency text, -- if null it's the default currency (Euro or Dollar or ...) + date numeric, -- if null it's a distribution + comment text -- optional, for recognition +); + +-- the following insert represents an input to cashpoint +insert into cashpoint (entry,name,amount,date,comment) values (1,'Bob',100.0,'12/24/11','gas'); +-- the next two inserts represent distributions referring to the above input +insert into cashpoint (entry,name,amount) values (1,'Bob',-100.0/3); +insert into cashpoint (entry,name,amount) values (1,'Tom',-100.0/3); +insert into cashpoint (entry,name,amount) values (1,'Sue',-100.0/3); + +-- the following insert represents an input to cashpoint +insert into cashpoint (entry,name,amount,date,comment) + values (2,'Sue',70.0,'12/23/11','groceries'); +-- the next two inserts represent distributions referring to the above input +insert into cashpoint (entry,name,amount) values (2,'Bob',-70.0/3); +insert into cashpoint (entry,name,amount) values (2,'Tom',-70.0/3); +insert into cashpoint (entry,name,amount) values (2,'Sue',-70.0/3); + +.header on +.mode column +select * from cashpoint; +select sum(amount) as expenses from cashpoint where date not null; +select count(name) as names from (select distinct name from cashpoint); +select name,balance from + (select name,sum(amount) as balance from cashpoint where name='Bob' union + select name,sum(amount) as balance from cashpoint where name='Tom' union + select name,sum(amount) as balance from cashpoint where name='Sue'); + +-- the following doesn 't work unfortunately +-- select expenses/names as 'per person' from +-- (select sum(amount) as expenses from cashpoint where date not null) join +-- (select count(name) as names from (select distinct name from cashpoint); diff --git a/CashPoint/trip/cashpoint2.sql b/CashPoint/trip/cashpoint2.sql new file mode 100755 index 0000000..0ca0e44 --- /dev/null +++ b/CashPoint/trip/cashpoint2.sql @@ -0,0 +1,45 @@ +drop table if exists cashpoint; +create table cashpoint ( + entry integer not null, -- unique for the inputs, reference for the distributions + name text not null, -- the person involved + amount real not null, -- the amount of money, negative for distributions + currency text, -- if null it's the default currency (Euro or Dollar or ...) + date numeric, -- if null it's a distribution + comment text -- optional, for recognition +); + +-- the following insert represents an input to cashpoint +insert into cashpoint (entry,name,amount,date,comment) + values (1,'Bob',100.0,'12/24/11','gas'); +-- the next two inserts represent ditributions referring to the above input +insert into cashpoint (entry,name,amount) values (1,'Bob',-100.0/3); +insert into cashpoint (entry,name,amount) values (1,'Tom',-100.0/3); +insert into cashpoint (entry,name,amount) values (1,'Sue',-100.0/3); + +-- the following insert represents an input to cashpoint +insert into cashpoint (entry,name,amount,date,comment) + values (2,'Sue',70.0,'12/23/11','groceries'); +-- the next two inserts represent ditributions referring to the above input +insert into cashpoint (entry,name,amount) values (2,'Bob',-70.0/3); +insert into cashpoint (entry,name,amount) values (2,'Tom',-70.0/3); +insert into cashpoint (entry,name,amount) values (2,'Sue',-70.0/3); + +.header on +.mode column +select * from cashpoint; +select sum(amount) as expenses from cashpoint where date not null; +select count(name) as numOfNames from (select distinct name from cashpoint); +select distinct comment as purposes from cashpoint where comment not null; +select name,balance from + (select name,sum(amount) as balance from cashpoint group by name); + -- following syntax is not required, 'group by ' gives the same effect + -- (select name,sum(amount) as balance from cashpoint where name='Bob' union + -- select name,sum(amount) as balance from cashpoint where name='Tom'union + -- select name,sum(amount) as balance from cashpoint where name='Sue'); + + + +-- the following doesn 't work unfortunately +-- select expenses/names as 'per person' from +-- (select sum(amount) as expenses from cashpoint where date not null) join +-- (select count(name) as names from (select distinct name from cashpoint); diff --git a/CashPoint/trip/tables.sql b/CashPoint/trip/tables.sql new file mode 100755 index 0000000..0f1b851 --- /dev/null +++ b/CashPoint/trip/tables.sql @@ -0,0 +1,23 @@ +drop table credits; +create table credits ( + date text not null, + creditor text not null, + amount integer not null, + purpose text not null); + +drop table debits; +create table debits ( + ENTRY integer not null, + debitor text not null, + share integer not null); + +insert into credits (ROWID,date,creditor,amount,purpose) values (1,'12/24/11','Bob',100.0,'gas'); +insert into debits (ENTRY,debitor,share) values (1,'Tom',-100.0/3); +insert into debits (ENTRY,debitor,share) values (1,'Sue',-100.0/3); +insert into credits (ROWID,date,creditor,amount,purpose) values (2,'12/23/11','Sue',70.0,'groceries'); +insert into debits (ENTRY,debitor,share) values (2,'Bob',-70.0/3); +insert into debits (ENTRY,debitor,share) values (2,'Tom',-70.0/3); + +.header on +.mode column +select * from credits JOIN debits where credits.ROWID=debits.ENTRY; diff --git a/CashPoint/trip/test.db b/CashPoint/trip/test.db new file mode 100755 index 0000000000000000000000000000000000000000..001c72082b8e7e02fc0dc61d5375f7c7724bb258 GIT binary patch literal 2048 zcmeHGK~BRk5OfL>N-EAAyPRmHv==@=f!ull`T;lDw3ZxiaMl$)Bk@pPf*oimugd0Hq&D9Kim;Z~fBC=z!7LWrS11Aq2)=0UW7Il>3+KX53fpQFn_9xR1_ z`Z|FG-Y3z;)o2ubT(ewh%w@BwNg3|I;Ndx&FEd!q?-v<#Z5Ssp8n!#|WL%>KLkz}g zoyOBCIHO)&`>O(P&~s|XO$ruEv}p3*n?f~g)ylCV(n>!mmYu8%01E{hc1{B{kt$Tr` zbef@~jx%Qo$igFOEp0%v*=&-;h4f2mT!mKU|Ft9>dM9yCRpo Date: Tue, 20 Dec 2011 22:46:47 +0100 Subject: [PATCH 02/16] hgjcfhkljkl; --- CashPoint/AndroidManifest.xml | 18 +++++ CashPointTest/.classpath | 8 +++ CashPointTest/.project | 34 ++++++++++ CashPointTest/AndroidManifest.xml | 12 ++++ CashPointTest/default.properties | 11 +++ CashPointTest/proguard.cfg | 40 +++++++++++ CashPointTest/res/drawable-hdpi/icon.png | Bin 0 -> 4147 bytes CashPointTest/res/drawable-ldpi/icon.png | Bin 0 -> 1723 bytes CashPointTest/res/drawable-mdpi/icon.png | Bin 0 -> 2574 bytes CashPointTest/res/layout/main.xml | 12 ++++ CashPointTest/res/values/strings.xml | 5 ++ .../src/app/learn/test/CashPointTest.java | 63 ++++++++++++++++++ 12 files changed, 203 insertions(+) create mode 100755 CashPoint/AndroidManifest.xml create mode 100755 CashPointTest/.classpath create mode 100755 CashPointTest/.project create mode 100755 CashPointTest/AndroidManifest.xml create mode 100755 CashPointTest/default.properties create mode 100755 CashPointTest/proguard.cfg create mode 100755 CashPointTest/res/drawable-hdpi/icon.png create mode 100755 CashPointTest/res/drawable-ldpi/icon.png create mode 100755 CashPointTest/res/drawable-mdpi/icon.png create mode 100755 CashPointTest/res/layout/main.xml create mode 100755 CashPointTest/res/values/strings.xml create mode 100755 CashPointTest/src/app/learn/test/CashPointTest.java diff --git a/CashPoint/AndroidManifest.xml b/CashPoint/AndroidManifest.xml new file mode 100755 index 0000000..fac3969 --- /dev/null +++ b/CashPoint/AndroidManifest.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CashPointTest/.classpath b/CashPointTest/.classpath new file mode 100755 index 0000000..b8aba73 --- /dev/null +++ b/CashPointTest/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/CashPointTest/.project b/CashPointTest/.project new file mode 100755 index 0000000..b0c2fd8 --- /dev/null +++ b/CashPointTest/.project @@ -0,0 +1,34 @@ + + + CashPointTest + + + CashPoint + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/CashPointTest/AndroidManifest.xml b/CashPointTest/AndroidManifest.xml new file mode 100755 index 0000000..5b65a33 --- /dev/null +++ b/CashPointTest/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/CashPointTest/default.properties b/CashPointTest/default.properties new file mode 100755 index 0000000..b74c488 --- /dev/null +++ b/CashPointTest/default.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-4 diff --git a/CashPointTest/proguard.cfg b/CashPointTest/proguard.cfg new file mode 100755 index 0000000..b1cdf17 --- /dev/null +++ b/CashPointTest/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native ; +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/CashPointTest/res/drawable-hdpi/icon.png b/CashPointTest/res/drawable-hdpi/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..8074c4c571b8cd19e27f4ee5545df367420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)At|quvleV($B|#Kap_lB-F^*yV=wZ{9baUu(uXfokr95^ zA*!*W=5a>$2Ps`-F^+qRQT^{*cN>vipT*4!r#p%{(#I7s z0NN94*q?ib$KJjfDI_sjHNdmEVp5wB&j54O#VoFqBwy)gfA$%)4d_X4q${L9Xom2R3xy&ZBSNgt4a1d7K^CDWa9r zVb-_52m}Vp)`9;ZSKd#|U4ZYj5}Gp49{4utST|=c`~(#>KHF6}CCov1iHYw zt{bWo)A@yF2$~c(nR$rSAaFQ$(Wh{vkG1AlutDMw=mM`C`T=X&|Ad9fb5Od}ROt1z zOpczHqrb4Jo^rSCiW#&o(m7jFamnrsTpQb;*h4o8r#$aZ}2RaT-x2u^^ z%u@YyIv$U^u~@9(XGbSwU@fk6SikH>j+D1jQrYTKGJpW%vUT{!d}7THI5&Sa?~MKy zS0-mvMl+BOcroEJ@hN!2H_?coTEJ5Q<;Nd?yx;eIj4{$$E2?YUO|NtNPJ-PdDf;s} zab;}Mz0kbOI}5*w@3gROcnl#5)wQnEhDBfn!Xhy`u>C}*E~vWpO^HS)FC>8^umI=+ z&H;LW6w#;EF`}vQd_9Muru`KnQVPI9U?(sD)&Dg-0j3#(!fNKVZ_GoYH{la~d*1Yh$TI-TL>mI4vpNb@sU2=IZ8vL%AXUx0 zz{K0|nK(yizLHaeW#ZhRfQXoK^}1$=$#1{Yn002ovPDHLkV1n#w+^+xt literal 0 HcmV?d00001 diff --git a/CashPointTest/res/drawable-ldpi/icon.png b/CashPointTest/res/drawable-ldpi/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..1095584ec21f71cd0afc9e0993aa2209671b590c GIT binary patch literal 1723 zcmV;s21NOZP)AReP91Tc8>~sHP8V>Ys(CF=aT`Sk=;|pS}XrJPb~T1dys{sdO&0YpQBSz*~us zcN*3-J_EnE1cxrXiq*F~jZje~rkAe3vf3>;eR)3?Ox=jK*jEU7Do|T`2NqP{56w(* zBAf)rvPB_7rsfeKd0^!CaR%BHUC$tsP9m8a!i@4&Txx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}n^~m?7x`xuCtNR#L2En!T>dQtIKdS#V-Hzt3RtwTeYtmQ&dR z6qXZvac*oc@BUYEH%@Ylv_1&tSjkbzzU6*h1(3^C`;1z;g_SmOtclS?KWk2VYE zM*oS<=C483XckW?GN|1jfh3Ro(h + + + diff --git a/CashPointTest/res/values/strings.xml b/CashPointTest/res/values/strings.xml new file mode 100755 index 0000000..b57801c --- /dev/null +++ b/CashPointTest/res/values/strings.xml @@ -0,0 +1,5 @@ + + + Hello World! + CashPointTest + diff --git a/CashPointTest/src/app/learn/test/CashPointTest.java b/CashPointTest/src/app/learn/test/CashPointTest.java new file mode 100755 index 0000000..5c48fa2 --- /dev/null +++ b/CashPointTest/src/app/learn/test/CashPointTest.java @@ -0,0 +1,63 @@ +package app.learn.test; + +import app.learn.*; + +import android.test.*; +import android.widget.TextView; +import android.database.Cursor; +import android.database.sqlite.*; +import junit.framework.Assert; + +public class CashPointTest extends ActivityInstrumentationTestCase2 { // AndroidTestCase + public CashPointTest() { + super("app.learn", CashPoint.class); + } + + private CashPoint mActivity; + private TextView mView; + private String resourceString; + + + @Override + protected void setUp() throws Exception { + super.setUp(); + mActivity = this.getActivity(); + mView = (TextView) mActivity.findViewById(app.learn.R.id.textview); + resourceString = mActivity.getString(app.learn.R.string.hello); + } + + public void testPreconditions() { + assertNotNull(mView); + } + + public void testText() { + assertEquals(resourceString,(String)mView.getText()); + } + + public void testDbInOut() { + + DbAdapter dbAdapter = new DbAdapter(mActivity); +// int entry = dbAdapter.createEntry("Bob", 100.0, null, "gas"); +// assertTrue(0 < entry); + +// db.execSQL("insert into cashpoint (entry,name,amount,date,comment) values (1,'Bob',100.0,'12/24/11','gas');"); +// +// Cursor outputCursor = db.query("cashpoint", new String[]{"name"}, "where entry = 1", null, null, null, null); +// assertEquals("Bob", outputCursor.getString(0)); + dbAdapter.close(); + + } + + private NotesDbAdapter mDbHelper; + + public void testNotesDbInOut() { + mDbHelper = new NotesDbAdapter(mActivity); + mDbHelper.open(); + + mDbHelper.createNote("Note1", "bla bla"); + Cursor c = mDbHelper.fetchAllNotes(); + assertTrue(c.getCount() > 0); + + mDbHelper.close(); + } +} From d52e4fec2ce7221abe49884529404d7ab5eff8c9 Mon Sep 17 00:00:00 2001 From: lotharla Date: Sat, 7 Jan 2012 14:39:30 +0100 Subject: [PATCH 03/16] commit 1: testDbInout --- CashPoint/.classpath | 3 ++- CashPoint/default.properties | 11 ----------- CashPoint/src/app/learn/DbAdapter.java | 16 +++++++++++----- CashPointTest/.classpath | 3 ++- CashPointTest/default.properties | 11 ----------- .../src/app/learn/test/CashPointTest.java | 11 +++++------ 6 files changed, 20 insertions(+), 35 deletions(-) delete mode 100755 CashPoint/default.properties delete mode 100755 CashPointTest/default.properties diff --git a/CashPoint/.classpath b/CashPoint/.classpath index 6efcbb7..4160c21 100755 --- a/CashPoint/.classpath +++ b/CashPoint/.classpath @@ -3,5 +3,6 @@ - + + diff --git a/CashPoint/default.properties b/CashPoint/default.properties deleted file mode 100755 index b74c488..0000000 --- a/CashPoint/default.properties +++ /dev/null @@ -1,11 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "build.properties", and override values to adapt the script to your -# project structure. - -# Project target. -target=android-4 diff --git a/CashPoint/src/app/learn/DbAdapter.java b/CashPoint/src/app/learn/DbAdapter.java index 4603286..000b20f 100755 --- a/CashPoint/src/app/learn/DbAdapter.java +++ b/CashPoint/src/app/learn/DbAdapter.java @@ -48,12 +48,18 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public int getEntryId() { Cursor cursor = mDb.rawQuery("select max(entry) from " + DATABASE_TABLE, null); - if (cursor.getCount() < 1) - return 1; - else { + int retval = 0; + if (cursor.getCount() > 0) { cursor.moveToFirst(); - return cursor.getInt(0); + retval = cursor.getInt(0); } + cursor.close(); + return ++retval; + } + + public void refreshCashpoint() { + mDb.execSQL("DROP TABLE IF EXISTS cashpoint"); + onCreate(mDb); } public int createEntry(String name, double amount, String currency, String comment) { @@ -64,7 +70,7 @@ public int createEntry(String name, double amount, String currency, String comme values.put("name", name); values.put("amount", amount); values.put("currency", currency); -// values.put("date", datetime('now','localtime')); +// values.put("date", datetime("now","localtime")); values.put("comment", comment); long rowId = mDb.insert(DATABASE_TABLE, null, values); diff --git a/CashPointTest/.classpath b/CashPointTest/.classpath index b8aba73..d6e06c3 100755 --- a/CashPointTest/.classpath +++ b/CashPointTest/.classpath @@ -4,5 +4,6 @@ - + + diff --git a/CashPointTest/default.properties b/CashPointTest/default.properties deleted file mode 100755 index b74c488..0000000 --- a/CashPointTest/default.properties +++ /dev/null @@ -1,11 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "build.properties", and override values to adapt the script to your -# project structure. - -# Project target. -target=android-4 diff --git a/CashPointTest/src/app/learn/test/CashPointTest.java b/CashPointTest/src/app/learn/test/CashPointTest.java index 5c48fa2..1c05560 100755 --- a/CashPointTest/src/app/learn/test/CashPointTest.java +++ b/CashPointTest/src/app/learn/test/CashPointTest.java @@ -5,8 +5,6 @@ import android.test.*; import android.widget.TextView; import android.database.Cursor; -import android.database.sqlite.*; -import junit.framework.Assert; public class CashPointTest extends ActivityInstrumentationTestCase2 { // AndroidTestCase public CashPointTest() { @@ -35,10 +33,11 @@ public void testText() { } public void testDbInOut() { - DbAdapter dbAdapter = new DbAdapter(mActivity); -// int entry = dbAdapter.createEntry("Bob", 100.0, null, "gas"); -// assertTrue(0 < entry); +// dbAdapter.refreshCashpoint(); + + int entry = dbAdapter.createEntry("Bob", 100.0, null, "gas"); + assertTrue(-1 < entry); // db.execSQL("insert into cashpoint (entry,name,amount,date,comment) values (1,'Bob',100.0,'12/24/11','gas');"); // @@ -50,7 +49,7 @@ public void testDbInOut() { private NotesDbAdapter mDbHelper; - public void testNotesDbInOut() { + public void _testNotesDbInOut() { mDbHelper = new NotesDbAdapter(mActivity); mDbHelper.open(); From 9cf4bd02da882a95366c33fd9c49835f58e85cd8 Mon Sep 17 00:00:00 2001 From: Lotharla Date: Wed, 11 Jan 2012 19:19:31 +0100 Subject: [PATCH 04/16] 11jan2012 --- .../.settings/org.eclipse.jdt.core.prefs | 5 ++ CashPoint/project.properties | 11 +++++ CashPoint/res/layout-finger/nameview.xml | 6 +++ CashPoint/res/layout/main.xml | 22 +++++++-- CashPoint/res/values/strings.xml | 3 +- CashPoint/src/app/learn/CashPoint.java | 5 -- CashPoint/src/app/learn/DbAdapter.java | 46 ++++++++++++++----- .../.settings/org.eclipse.jdt.core.prefs | 5 ++ CashPointTest/project.properties | 11 +++++ .../src/app/learn/test/CashPointTest.java | 44 ++++++++---------- 10 files changed, 112 insertions(+), 46 deletions(-) create mode 100644 CashPoint/.settings/org.eclipse.jdt.core.prefs create mode 100644 CashPoint/project.properties create mode 100644 CashPoint/res/layout-finger/nameview.xml create mode 100644 CashPointTest/.settings/org.eclipse.jdt.core.prefs create mode 100644 CashPointTest/project.properties diff --git a/CashPoint/.settings/org.eclipse.jdt.core.prefs b/CashPoint/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e5239a2 --- /dev/null +++ b/CashPoint/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Sun Dec 25 14:05:34 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/CashPoint/project.properties b/CashPoint/project.properties new file mode 100644 index 0000000..c957743 --- /dev/null +++ b/CashPoint/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-4 diff --git a/CashPoint/res/layout-finger/nameview.xml b/CashPoint/res/layout-finger/nameview.xml new file mode 100644 index 0000000..f5e5154 --- /dev/null +++ b/CashPoint/res/layout-finger/nameview.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/CashPoint/res/layout/main.xml b/CashPoint/res/layout/main.xml index 80d6faa..d9eff27 100755 --- a/CashPoint/res/layout/main.xml +++ b/CashPoint/res/layout/main.xml @@ -1,6 +1,18 @@ - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/CashPoint/res/values/strings.xml b/CashPoint/res/values/strings.xml index 4c14d2d..832833b 100755 --- a/CashPoint/res/values/strings.xml +++ b/CashPoint/res/values/strings.xml @@ -1,5 +1,6 @@ This is CashPoint ! - Cash Point + Cashpoint + Name diff --git a/CashPoint/src/app/learn/CashPoint.java b/CashPoint/src/app/learn/CashPoint.java index b448494..d6c3a6d 100755 --- a/CashPoint/src/app/learn/CashPoint.java +++ b/CashPoint/src/app/learn/CashPoint.java @@ -2,11 +2,6 @@ import android.app.Activity; import android.os.Bundle; -import android.content.Context; -import android.database.Cursor; -import android.database.SQLException; -import android.database.sqlite.SQLiteDatabase; -import junit.framework.Assert; public class CashPoint extends Activity { diff --git a/CashPoint/src/app/learn/DbAdapter.java b/CashPoint/src/app/learn/DbAdapter.java index 000b20f..71e8cec 100755 --- a/CashPoint/src/app/learn/DbAdapter.java +++ b/CashPoint/src/app/learn/DbAdapter.java @@ -1,5 +1,8 @@ package app.learn; +import java.util.Date; +import java.text.SimpleDateFormat; + import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -39,14 +42,22 @@ public void onCreate(SQLiteDatabase db) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); - db.execSQL("DROP TABLE IF EXISTS cashpoint"); - onCreate(db); + recreate(db); } + + public void recreate(SQLiteDatabase db) { + db.execSQL("DROP TABLE IF EXISTS cashpoint"); + onCreate(db); + } private SQLiteDatabase mDb; - public int getEntryId() { + public SQLiteDatabase getDb() { + return mDb; + } + + public int getNewEntryId() { Cursor cursor = mDb.rawQuery("select max(entry) from " + DATABASE_TABLE, null); int retval = 0; if (cursor.getCount() > 0) { @@ -57,22 +68,22 @@ public int getEntryId() { return ++retval; } - public void refreshCashpoint() { - mDb.execSQL("DROP TABLE IF EXISTS cashpoint"); - onCreate(mDb); - } + private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - public int createEntry(String name, double amount, String currency, String comment) { - int entryId = getEntryId(); + public String getDateFormat(Date date) { + return mDateFormat.format(date); + } + + public int createEntry(String name, double amount, String currency, String comment) { + int entryId = getNewEntryId(); ContentValues values = new ContentValues(); values.put("entry", "" + entryId); values.put("name", name); values.put("amount", amount); values.put("currency", currency); -// values.put("date", datetime("now","localtime")); + values.put("date", getDateFormat(new Date())); values.put("comment", comment); - long rowId = mDb.insert(DATABASE_TABLE, null, values); if (rowId < 0) return -1; @@ -80,4 +91,17 @@ public int createEntry(String name, double amount, String currency, String comme return entryId; } } + + public Cursor fetchEntry(int entry) throws SQLException { + + Cursor mCursor = mDb.query(true, DATABASE_TABLE, + new String[] {"entry", "name", "amount", "currency", "date", "comment"}, + "entry=" + entry, + null, null, null, null, null); + if (mCursor != null) { + mCursor.moveToFirst(); + } + return mCursor; + + } } \ No newline at end of file diff --git a/CashPointTest/.settings/org.eclipse.jdt.core.prefs b/CashPointTest/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..abfc958 --- /dev/null +++ b/CashPointTest/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Sun Dec 25 14:05:52 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/CashPointTest/project.properties b/CashPointTest/project.properties new file mode 100644 index 0000000..c957743 --- /dev/null +++ b/CashPointTest/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-4 diff --git a/CashPointTest/src/app/learn/test/CashPointTest.java b/CashPointTest/src/app/learn/test/CashPointTest.java index 1c05560..a4a7067 100755 --- a/CashPointTest/src/app/learn/test/CashPointTest.java +++ b/CashPointTest/src/app/learn/test/CashPointTest.java @@ -1,10 +1,13 @@ package app.learn.test; +import java.util.Date; + import app.learn.*; import android.test.*; import android.widget.TextView; import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; public class CashPointTest extends ActivityInstrumentationTestCase2 { // AndroidTestCase public CashPointTest() { @@ -12,7 +15,7 @@ public CashPointTest() { } private CashPoint mActivity; - private TextView mView; + private TextView mTextView; private String resourceString; @@ -20,43 +23,36 @@ public CashPointTest() { protected void setUp() throws Exception { super.setUp(); mActivity = this.getActivity(); - mView = (TextView) mActivity.findViewById(app.learn.R.id.textview); - resourceString = mActivity.getString(app.learn.R.string.hello); } public void testPreconditions() { - assertNotNull(mView); + mTextView = (TextView) mActivity.findViewById(app.learn.R.id.nameLabel); + assertNotNull(mTextView); } public void testText() { - assertEquals(resourceString,(String)mView.getText()); + resourceString = mActivity.getString(app.learn.R.string.nameLabelText); + assertEquals(resourceString,(String)mTextView.getText()); } public void testDbInOut() { DbAdapter dbAdapter = new DbAdapter(mActivity); -// dbAdapter.refreshCashpoint(); - int entry = dbAdapter.createEntry("Bob", 100.0, null, "gas"); - assertTrue(-1 < entry); + int entry = dbAdapter.createEntry("Bob", 100.5, null, "gas"); + assertEquals(dbAdapter.getNewEntryId() - 1, entry); + + Cursor outputCursor = dbAdapter.fetchEntry(entry); + assertEquals("Bob", outputCursor.getString(1)); + assertEquals("" + 100.5, outputCursor.getString(2)); + assertEquals(null, outputCursor.getString(3)); + String now = dbAdapter.getDateFormat(new Date()); + assertEquals(now.substring(0, 16), + outputCursor.getString(4).substring(0, 16)); + assertEquals("gas", outputCursor.getString(5)); + outputCursor.close(); -// db.execSQL("insert into cashpoint (entry,name,amount,date,comment) values (1,'Bob',100.0,'12/24/11','gas');"); -// -// Cursor outputCursor = db.query("cashpoint", new String[]{"name"}, "where entry = 1", null, null, null, null); -// assertEquals("Bob", outputCursor.getString(0)); dbAdapter.close(); } - private NotesDbAdapter mDbHelper; - - public void _testNotesDbInOut() { - mDbHelper = new NotesDbAdapter(mActivity); - mDbHelper.open(); - - mDbHelper.createNote("Note1", "bla bla"); - Cursor c = mDbHelper.fetchAllNotes(); - assertTrue(c.getCount() > 0); - - mDbHelper.close(); - } } From dbd31071edb60c33aff145c1e0458ab98fae35e9 Mon Sep 17 00:00:00 2001 From: Lotharla Date: Wed, 11 Jan 2012 19:30:45 +0100 Subject: [PATCH 05/16] 11jan2012 --- TripCostCalculator/.classpath | 3 ++- TripCostCalculator/default.properties | 11 ----------- 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 TripCostCalculator/default.properties diff --git a/TripCostCalculator/.classpath b/TripCostCalculator/.classpath index 6efcbb7..4160c21 100644 --- a/TripCostCalculator/.classpath +++ b/TripCostCalculator/.classpath @@ -3,5 +3,6 @@ - + + diff --git a/TripCostCalculator/default.properties b/TripCostCalculator/default.properties deleted file mode 100644 index b74c488..0000000 --- a/TripCostCalculator/default.properties +++ /dev/null @@ -1,11 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "build.properties", and override values to adapt the script to your -# project structure. - -# Project target. -target=android-4 From a6e23a2839213a99a85b5f20dc6ae1a9f4c61544 Mon Sep 17 00:00:00 2001 From: Lotharla Date: Thu, 12 Jan 2012 23:39:33 +0100 Subject: [PATCH 06/16] 12jan12 : distribution + test --- CashPoint/src/app/learn/DbAdapter.java | 93 +++++++++++++------ .../src/app/learn/test/ActivityTest.java | 33 +++++++ .../src/app/learn/test/CashPointTest.java | 64 +++++++------ 3 files changed, 133 insertions(+), 57 deletions(-) create mode 100644 CashPointTest/src/app/learn/test/ActivityTest.java diff --git a/CashPoint/src/app/learn/DbAdapter.java b/CashPoint/src/app/learn/DbAdapter.java index 71e8cec..152e588 100755 --- a/CashPoint/src/app/learn/DbAdapter.java +++ b/CashPoint/src/app/learn/DbAdapter.java @@ -1,6 +1,6 @@ package app.learn; -import java.util.Date; +import java.util.*; import java.text.SimpleDateFormat; import android.content.ContentValues; @@ -17,7 +17,7 @@ public class DbAdapter extends SQLiteOpenHelper { private static final String DATABASE_NAME = "data"; private static final String DATABASE_TABLE = "cashpoint"; - private static final int DATABASE_VERSION = 2; + private static final int DATABASE_VERSION = 1; public DbAdapter(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -27,7 +27,7 @@ public DbAdapter(Context context) { @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table " + DATABASE_TABLE + " (" + - " entry integer not null," + // unique for the inputs, reference for the distributions + " entry integer not null," + // unique for the entries, reference for the distributions " name text not null," + // the person involved " amount real not null," + // the amount of money, negative for distributions " currency text," + // if null it's the default currency (Euro or Dollar or ...) @@ -42,12 +42,12 @@ public void onCreate(SQLiteDatabase db) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); - recreate(db); + recreate(db); } public void recreate(SQLiteDatabase db) { - db.execSQL("DROP TABLE IF EXISTS cashpoint"); + db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE); onCreate(db); } @@ -57,6 +57,24 @@ public SQLiteDatabase getDb() { return mDb; } + String[] getFieldNames() { + return new String[] {"entry", "name", "amount", "currency", "date", "comment"}; + } + + ContentValues putValues(int entry, String name, float amount, String currency, String timeStamp, String comment) { + ContentValues values = new ContentValues(); + + String[] fields = getFieldNames(); + values.put(fields[0], entry); + values.put(fields[1], name); + values.put(fields[2], amount); + values.put(fields[3], currency); + values.put(fields[4], timeStamp); + values.put(fields[5], comment); + + return values; + } + public int getNewEntryId() { Cursor cursor = mDb.rawQuery("select max(entry) from " + DATABASE_TABLE, null); int retval = 0; @@ -70,38 +88,57 @@ public int getNewEntryId() { private SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - public String getDateFormat(Date date) { + public String getTimeStamp(Date date) { return mDateFormat.format(date); } - - public int createEntry(String name, double amount, String currency, String comment) { + + public int addEntry(String name, float amount, String currency, String comment) { int entryId = getNewEntryId(); - - ContentValues values = new ContentValues(); - values.put("entry", "" + entryId); - values.put("name", name); - values.put("amount", amount); - values.put("currency", currency); - values.put("date", getDateFormat(new Date())); - values.put("comment", comment); - long rowId = mDb.insert(DATABASE_TABLE, null, values); + + long rowId = mDb.insert(DATABASE_TABLE, null, + putValues(entryId, name, amount, + currency, getTimeStamp(new Date()), comment)); if (rowId < 0) return -1; - else { + else return entryId; - } } - public Cursor fetchEntry(int entry) throws SQLException { - - Cursor mCursor = mDb.query(true, DATABASE_TABLE, - new String[] {"entry", "name", "amount", "currency", "date", "comment"}, - "entry=" + entry, + public Cursor fetchEntry(int entryId) { + Cursor cursor = mDb.query(true, DATABASE_TABLE, + getFieldNames(), + "entry=" + entryId, null, null, null, null, null); - if (mCursor != null) { - mCursor.moveToFirst(); - } - return mCursor; + if (cursor != null) + cursor.moveToFirst(); + return cursor; + } + + public boolean doDistribution(int entryId, Map shares) { + Cursor cursor = fetchEntry(entryId); + if (cursor == null) + return false; + + String entrant = cursor.getString(cursor.getColumnIndex("name")); + float amount = cursor.getFloat(cursor.getColumnIndex("amount")); + String currency = cursor.getString(cursor.getColumnIndex("currency")); + + for (String name : shares.keySet()) + if (!entrant.equals(name)) { + float share = shares.get(name).floatValue(); + + if (mDb.insert(DATABASE_TABLE, null, + putValues(entryId, name, -share, currency, null, null)) < 0) + return false; + + amount -= share; + } + if (mDb.insert(DATABASE_TABLE, null, + putValues(entryId, entrant, -amount, currency, null, null)) < 0) + return false; + + return true; } + } \ No newline at end of file diff --git a/CashPointTest/src/app/learn/test/ActivityTest.java b/CashPointTest/src/app/learn/test/ActivityTest.java new file mode 100644 index 0000000..ef74bae --- /dev/null +++ b/CashPointTest/src/app/learn/test/ActivityTest.java @@ -0,0 +1,33 @@ +package app.learn.test; + +import android.test.*; +import android.widget.*; + +import app.learn.CashPoint; + +public class ActivityTest extends ActivityInstrumentationTestCase2 { + public ActivityTest() { + super("app.learn", CashPoint.class); + } + + private CashPoint mActivity; + private TextView mTextView; + private String resourceString; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mActivity = this.getActivity(); + mTextView = (TextView) mActivity.findViewById(app.learn.R.id.nameLabel); + } + + public void testPreconditions() { + assertNotNull(mTextView); + } + + public void testText() { + resourceString = mActivity.getString(app.learn.R.string.nameLabelText); + assertEquals(resourceString,(String)mTextView.getText()); + } + +} diff --git a/CashPointTest/src/app/learn/test/CashPointTest.java b/CashPointTest/src/app/learn/test/CashPointTest.java index a4a7067..f269a1e 100755 --- a/CashPointTest/src/app/learn/test/CashPointTest.java +++ b/CashPointTest/src/app/learn/test/CashPointTest.java @@ -1,58 +1,64 @@ package app.learn.test; -import java.util.Date; - -import app.learn.*; +import java.util.*; import android.test.*; -import android.widget.TextView; import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -public class CashPointTest extends ActivityInstrumentationTestCase2 { // AndroidTestCase +import app.learn.*; + +public class CashPointTest extends ActivityInstrumentationTestCase2 { public CashPointTest() { super("app.learn", CashPoint.class); } private CashPoint mActivity; - private TextView mTextView; - private String resourceString; - + private DbAdapter dbAdapter; @Override protected void setUp() throws Exception { super.setUp(); mActivity = this.getActivity(); + dbAdapter = new DbAdapter(mActivity); } + + @Override + protected void tearDown() throws Exception { + dbAdapter.close(); + super.tearDown(); + } - public void testPreconditions() { - mTextView = (TextView) mActivity.findViewById(app.learn.R.id.nameLabel); - assertNotNull(mTextView); - } - - public void testText() { - resourceString = mActivity.getString(app.learn.R.string.nameLabelText); - assertEquals(resourceString,(String)mTextView.getText()); - } - - public void testDbInOut() { - DbAdapter dbAdapter = new DbAdapter(mActivity); - - int entry = dbAdapter.createEntry("Bob", 100.5, null, "gas"); - assertEquals(dbAdapter.getNewEntryId() - 1, entry); + public void testEntry() { + int entryId = dbAdapter.addEntry("Bob", 100.5f, null, "gas"); + assertEquals(dbAdapter.getNewEntryId() - 1, entryId); - Cursor outputCursor = dbAdapter.fetchEntry(entry); + Cursor outputCursor = dbAdapter.fetchEntry(entryId); assertEquals("Bob", outputCursor.getString(1)); - assertEquals("" + 100.5, outputCursor.getString(2)); + assertEquals(100.5f, outputCursor.getFloat(2)); assertEquals(null, outputCursor.getString(3)); - String now = dbAdapter.getDateFormat(new Date()); + String now = dbAdapter.getTimeStamp(new Date()); assertEquals(now.substring(0, 16), outputCursor.getString(4).substring(0, 16)); assertEquals("gas", outputCursor.getString(5)); outputCursor.close(); + } + + public void testDistribution() { + float amount = 100.2f; + int entryId = dbAdapter.addEntry("Bob", amount, null, "gas"); + HashMap shares = new HashMap(); + shares.put("Sue", amount / 3); + shares.put("Tom", amount / 3); + assertTrue(dbAdapter.doDistribution(entryId, shares)); - dbAdapter.close(); - + Cursor cursor = dbAdapter.fetchEntry(entryId); + assertEquals(4, cursor.getCount()); + float sum = 0f; + do { + sum += cursor.getFloat(cursor.getColumnIndex("amount")); + } while (cursor.moveToNext()); + assertFalse("distribution leaks", Math.abs(sum) > 0.001); + cursor.close(); } } From 8059cf754dcd79525b07f06080f9a210481480fe Mon Sep 17 00:00:00 2001 From: Lotharla Date: Wed, 18 Jan 2012 20:20:34 +0100 Subject: [PATCH 07/16] 18jan2012 : Transactor, Impex --- .../src/app/learn/test/CashPointTest.java | 150 ++++++++++++++++-- 1 file changed, 133 insertions(+), 17 deletions(-) diff --git a/CashPointTest/src/app/learn/test/CashPointTest.java b/CashPointTest/src/app/learn/test/CashPointTest.java index f269a1e..bffeec4 100755 --- a/CashPointTest/src/app/learn/test/CashPointTest.java +++ b/CashPointTest/src/app/learn/test/CashPointTest.java @@ -1,25 +1,46 @@ package app.learn.test; +import java.io.*; import java.util.*; +import junit.framework.Test; +import junit.framework.TestSuite; + +import android.os.Environment; import android.test.*; +import android.test.suitebuilder.TestSuiteBuilder; + import android.database.Cursor; import app.learn.*; -public class CashPointTest extends ActivityInstrumentationTestCase2 { +public class CashPointTest extends ActivityInstrumentationTestCase2 +{ + public static void main(String[] args) { +// TestSuite suite = new TestSuite(CashPointTest.class); +// InstrumentationTestRunner.run(suite); + } + + public static Test suite() { + return new TestSuiteBuilder(CashPointTest.class). + includePackages("app.learn.test.CashPointTest").build(); + } + public CashPointTest() { super("app.learn", CashPoint.class); } private CashPoint mActivity; private DbAdapter dbAdapter; + private Transactor transactor; @Override protected void setUp() throws Exception { super.setUp(); + mActivity = this.getActivity(); - dbAdapter = new DbAdapter(mActivity); + transactor = new Transactor(mActivity); + dbAdapter = (DbAdapter)transactor; } @Override @@ -28,37 +49,132 @@ protected void tearDown() throws Exception { super.tearDown(); } + public void assertZero(String message, float number) { + assertFalse(message, Math.abs(number) > 0.001f); + } + + public void assertAmountEquals(String message, Number expected, Number actual) { + String sexp = String.format("%.2f", expected.floatValue()); + String sact = String.format("%.2f", actual.floatValue()); + assertEquals(message, sexp, sact); + } + + String[] participants = new String[] {"Sue", "Bob", "Tom"}; + + public void testClear() { + dbAdapter.recreate(dbAdapter.getDb()); + } + public void testEntry() { int entryId = dbAdapter.addEntry("Bob", 100.5f, null, "gas"); assertEquals(dbAdapter.getNewEntryId() - 1, entryId); - Cursor outputCursor = dbAdapter.fetchEntry(entryId); - assertEquals("Bob", outputCursor.getString(1)); - assertEquals(100.5f, outputCursor.getFloat(2)); - assertEquals(null, outputCursor.getString(3)); + Cursor cursor = dbAdapter.fetchEntry(entryId); + assertNotNull(cursor); + assertEquals("Bob", cursor.getString(1)); + assertEquals(100.5f, cursor.getFloat(2)); + assertEquals(null, cursor.getString(3)); String now = dbAdapter.getTimeStamp(new Date()); assertEquals(now.substring(0, 16), - outputCursor.getString(4).substring(0, 16)); - assertEquals("gas", outputCursor.getString(5)); - outputCursor.close(); + cursor.getString(4).substring(0, 16)); + assertEquals("gas", cursor.getString(5)); + cursor.close(); + + assertEquals(1, dbAdapter.removeEntry(entryId)); + assertEquals(0, dbAdapter.fetchEntry(entryId).getCount()); + } + + void assertSize(int expected, int entry) { + Cursor cursor = dbAdapter.fetchEntry(entry); + assertNotNull(cursor); + assertEquals(expected, cursor.getCount()); + cursor.close(); } - public void testDistribution() { + public void testDistribution() throws Exception { float amount = 100.2f; int entryId = dbAdapter.addEntry("Bob", amount, null, "gas"); + HashMap shares = new HashMap(); - shares.put("Sue", amount / 3); + shares.put("Sue", amount / 4); shares.put("Tom", amount / 3); assertTrue(dbAdapter.doDistribution(entryId, shares)); - Cursor cursor = dbAdapter.fetchEntry(entryId); - assertEquals(4, cursor.getCount()); - float sum = 0f; + assertSize(4, entryId); + assertZero("distribution leaking", dbAdapter.getSum("entry=" + entryId)); + + assertNotNull("timestamp missing", dbAdapter.fetchTimestamp(entryId)); + + Set names = dbAdapter.getNames(); + assertTrue("some name missing", names.containsAll(Arrays.asList(participants))); + + assertEquals(4, dbAdapter.removeEntry(entryId)); + assertEquals(0, dbAdapter.fetchEntry(entryId).getCount()); + } + + public void testNames() { + File dbFile = new File(Environment.getDataDirectory(), "data/app.learn/databases/data"); + assertTrue(dbFile.exists()); + + assertEquals(new TreeSet(Arrays.asList(participants)), dbAdapter.getNames()); + } + + void expenseTest(String submitter, float amount, String purpose) { + Map shares = transactor.sharesFor(participants, amount); + int entry = transactor.performExpense(submitter, amount, null, purpose, shares); + Cursor cursor = transactor.fetchEntry(entry); + assertNotNull(cursor); + assertEquals(cursor.getCount(), 1 + shares.keySet().size()); + for (String name : shares.keySet()) + if (!name.equals(submitter)) { + float share = shares.get(name).floatValue(); + do { + if (name.equals(cursor.getString(cursor.getColumnIndex("name")))) { + assertZero("sharing violated", share + cursor.getFloat(cursor.getColumnIndex("amount"))); + } + } while (cursor.moveToNext()); + cursor.moveToFirst(); + } + cursor.close(); + } + + float[] balances = new float[] {43.33f, 13.33f, -56.67f}; + + public void testExpenses() { + testClear(); + expenseTest("Bob", 100f, "gas"); + expenseTest("Sue", 70f, "groceries"); + + Cursor cursor = transactor.queryBalances(); + assertEquals(balances.length, cursor.getCount()); + cursor.moveToFirst(); + int i = 0; do { - sum += cursor.getFloat(cursor.getColumnIndex("amount")); + assertAmountEquals(cursor.getString(0) + "'s balance wrong", balances[i], cursor.getFloat(1)); + i++; } while (cursor.moveToNext()); - assertFalse("distribution leaks", Math.abs(sum) > 0.001); - cursor.close(); + cursor.close(); + + assertAmountEquals("total of expenses wrong", 170f, transactor.totalExpenses()); + } + + void transferTest(String submitter, String receiver) throws Exception { + float amount = 312.50f; + int entryId = transactor.performTransfer(submitter, amount, null, "ring transfer", receiver); + assertSize(2, entryId); + assertZero("transfer leaking", transactor.getSum("entry=" + entryId)); + } + + public void testTransfer() throws Exception { + Set names = transactor.getNames(); + Iterator it = names.iterator(); + String submitter = it.next(); + while (it.hasNext()) { + String receiver = it.next(); + transferTest(submitter, receiver); + submitter = receiver; + } + transferTest(submitter, names.iterator().next()); } } From 71aba92f2eb684b4d5a701ae3dfb0f12e844206b Mon Sep 17 00:00:00 2001 From: Lotharla Date: Wed, 18 Jan 2012 20:21:18 +0100 Subject: [PATCH 08/16] 18jan2012 : Transactor, Impex --- CashPoint/AndroidManifest.xml | 1 + CashPoint/res/layout/main.xml | 12 ++ CashPoint/res/values/strings.xml | 4 +- CashPoint/src/app/learn/CashPoint.java | 127 ++++++++++++- CashPoint/src/app/learn/DbAdapter.java | 113 +++++++++--- CashPoint/src/app/learn/NotesDbAdapter.java | 188 -------------------- CashPoint/src/app/learn/Transactor.java | 68 +++++++ CashPoint/trip/cashpoint2.sql | 4 +- 8 files changed, 301 insertions(+), 216 deletions(-) delete mode 100755 CashPoint/src/app/learn/NotesDbAdapter.java create mode 100644 CashPoint/src/app/learn/Transactor.java diff --git a/CashPoint/AndroidManifest.xml b/CashPoint/AndroidManifest.xml index fac3969..cb4a676 100755 --- a/CashPoint/AndroidManifest.xml +++ b/CashPoint/AndroidManifest.xml @@ -4,6 +4,7 @@ android:versionCode="1" android:versionName="1.0"> + +