Permalink
Browse files

Added DatabaseAdapter

  • Loading branch information...
1 parent 5f3f1cf commit c6e09ea52af1874cb5745afb10e44685ec535f8c @hiteshsondhi88 hiteshsondhi88 committed Nov 17, 2011
View
@@ -50,6 +50,12 @@
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
></activity>
+ <activity
+ android:name=".FavoriteActivity"
+ android:configChanges="orientation"
+ android:screenOrientation="portrait"
+ android:windowSoftInputMode="adjustPan"
+ ></activity>
</application>
</manifest>
@@ -10,6 +10,7 @@
android:background="@drawable/list_inflated_row_bg"
android:paddingBottom="10dp"
android:paddingTop="10dp"
+ android:id="@+id/expense_listing_inflated_row_listview"
>
<ImageView
@@ -77,4 +78,10 @@
</RelativeLayout>
+ <ImageView
+ android:layout_below="@id/expense_listing_inflated_row_listview"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:background="@drawable/list_inflated_row_divider"/>
+
</RelativeLayout>
@@ -156,7 +156,8 @@
android:layout_height="wrap_content"
android:layout_below="@id/text_voice_camera_voice_details_separator"
android:hint="amount"
- android:layout_marginBottom="20dp"/>
+ android:layout_marginBottom="20dp"
+ android:numeric="decimal"/>
<EditText
android:id="@+id/text_voice_camera_tag"
View
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="unknown">0</string>
+ <string name="text">1</string>
+ <string name="image">2</string>
+ <string name="voice">3</string>
+ <string name="favorite">T</string>
+ <string name="favorite_not">F</string>
+
+</resources>
@@ -1,6 +1,8 @@
package com.vinsol.expensetracker;
import java.io.File;
+
+import com.vinsol.expensetracker.location.LocationLast;
import com.vinsol.expensetracker.utils.CameraFileSave;
import com.vinsol.expensetracker.utils.ImageGet;
@@ -50,6 +52,10 @@ protected void onCreate(Bundle savedInstanceState) {
////////******** Handle Date Bar ********* ////////
new DateHandler(this);
+
+ ////////********* Get Last most accurate location info ********* /////////
+ LocationLast mLocationLast = new LocationLast(this);
+ mLocationLast.getLastLocation();
}
private void startCamera() {
@@ -14,17 +14,17 @@
public class DatabaseAdapter {
//database and table name
- public final String DATABASE_NAME = "ExpenseTrackerDB";
- public final String TABLE_NAME = "ExpenseTrackerTable";
+ private final String DATABASE_NAME = "ExpenseTrackerDB";
+ private final String TABLE_NAME = "ExpenseTrackerTable";
//column index
- public final String KEY_ID="_id";
- public final String KEY_TAG="TAG";
- public final String KEY_AMOUNT="AMOUNT";
- public final String KEY_DATE_TIME="DATE_TIME";
- public final String KEY_LOCATION="LOCATION";
- public final String KEY_FAVORITE="FAVORITE";
- public final String KEY_TYPE = "TYPE";
+ public static final String KEY_ID="_id";
+ public static final String KEY_TAG="TAG";
+ public static final String KEY_AMOUNT="AMOUNT";
+ public static final String KEY_DATE_TIME="DATE_TIME";
+ public static final String KEY_LOCATION="LOCATION";
+ public static final String KEY_FAVORITE="FAVORITE";
+ public static final String KEY_TYPE = "TYPE";
//sql open or create database
private final String DATABASE_CREATE= "create table if not exists "+ TABLE_NAME +"("+
@@ -34,7 +34,7 @@
KEY_DATE_TIME+" VARCHAR(255) NOT NULL,"+
KEY_LOCATION+" TEXT, "+
KEY_FAVORITE+" VARCHAR(1), "+
- KEY_TYPE+" VARCHAR(1) NOT NULL, "+
+ KEY_TYPE+" VARCHAR(1) NOT NULL "+
")";
private SQLiteDatabase db;
@@ -1,14 +1,31 @@
package com.vinsol.expensetracker;
+import com.vinsol.expensetracker.location.LocationLast;
+
import android.app.Activity;
import android.os.Bundle;
+import android.view.Window;
+import android.widget.ListView;
public class ExpenseListing extends Activity{
+ private ListView mListView;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ /////// ****** No Title Bar ********* /////////
+
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.expense_listing);
+
+
+ //////// ********* Get Last most accurate location info ********* /////////
+ LocationLast mLocationLast = new LocationLast(this);
+ mLocationLast.getLastLocation();
+ mListView = (ListView) findViewById(R.id.expense_listing_listview);
+
}
}
@@ -0,0 +1,41 @@
+package com.vinsol.expensetracker;
+
+import com.vinsol.expensetracker.location.LocationLast;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.Window;
+import android.widget.RelativeLayout;
+import android.widget.ScrollView;
+
+public class FavoriteActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ /////// ****** No Title Bar ********* /////////
+
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ setContentView(R.layout.text_voice_camera);
+
+ /////// ******* Hide Main Body of layout and make favorite body visible ******* ///////
+ handleUI();
+
+ /////// ******* Handles Date Bar ******* ////////
+ new DateHandler(this);
+
+ //////// ********* Get Last most accurate location info ********* /////////
+ LocationLast mLocationLast = new LocationLast(this);
+ mLocationLast.getLastLocation();
+ }
+
+ private void handleUI() {
+ /////// ******* Hide Main Body of layout and make favorite body visible ******* ///////
+ ScrollView mScrollView = (ScrollView) findViewById(R.id.text_voice_camera_body);
+ mScrollView.setVisibility(View.GONE);
+ RelativeLayout mRelativeLayout = (RelativeLayout) findViewById(R.id.text_voice_camera_body_favorite);
+ mRelativeLayout.setVisibility(View.VISIBLE);
+ }
+}
@@ -1,11 +1,15 @@
package com.vinsol.expensetracker;
+import java.util.Calendar;
+import java.util.HashMap;
+
import com.vinsol.expensetracker.location.LocationData;
+import com.vinsol.expensetracker.location.LocationLast;
+
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
@@ -49,8 +53,10 @@ public void onCreate(Bundle savedInstanceState) {
-
-
+// DatabaseAdapter adapter =new DatabaseAdapter(this);
+// adapter.open();
+// adapter.drop_table();
+// adapter.close();
////// ********* Adding Click Listeners to MainActivity ********** /////////
@@ -95,7 +101,9 @@ public void onCreate(Bundle savedInstanceState) {
protected void onResume() {
///////// ******** Starts GPS and Check for Location each time Activity Resumes ******* ////////
- new LocationData(this);
+ new LocationData(this);
+ LocationLast mLocationLast = new LocationLast(this);
+ mLocationLast.getLastLocation();
super.onResume();
}
@@ -128,13 +136,28 @@ else if(v.getId() == R.id.main_camera){
////// ******* opens Favorite Activity ******** ///////////
else if(v.getId() == R.id.main_favorite){
- Log.v("Favorite", "Favorite");
+ Intent intentFavorite = new Intent(this, FavoriteActivity.class);
+ startActivity(intentFavorite);
}
- ////// ******* opens SaveReminder Activity ******** ///////////
+ ////// ******* opens List Activity and adds unknown entry to database ******** ///////////
else if(v.getId() == R.id.main_save_reminder){
- Log.v("Save Reminder", "Save Reminder");
+ HashMap<String, String> _list = new HashMap<String, String>();
+ Calendar mCalendar = Calendar.getInstance();
+ _list.put(DatabaseAdapter.KEY_DATE_TIME, mCalendar.getTime().toString());
+
+ if(MainActivity.mCurrentLocation != null){
+ _list.put(DatabaseAdapter.KEY_LOCATION, MainActivity.mCurrentLocation);
+ }
+ _list.put(DatabaseAdapter.KEY_TYPE, getString(R.string.unknown));
+ _list.put(DatabaseAdapter.KEY_FAVORITE, getString(R.string.favorite_not));
+ DatabaseAdapter mDatabaseAdapter = new DatabaseAdapter(this);
+ mDatabaseAdapter.open();
+ mDatabaseAdapter.insert_to_database(_list);
+ mDatabaseAdapter.close();
+ Intent intentListView = new Intent(this, ExpenseListing.class);
+ startActivity(intentListView);
}
@@ -34,6 +34,10 @@ protected void onCreate(Bundle savedInstanceState) {
//////// ******** Handle Date Bar ********* ////////
new DateHandler(this);
+
+ //////// ********* Get Last most accurate location info ********* /////////
+ LocationLast mLocationLast = new LocationLast(this);
+ mLocationLast.getLastLocation();
}
@Override
@@ -1,5 +1,6 @@
package com.vinsol.expensetracker;
+import com.vinsol.expensetracker.location.LocationLast;
import com.vinsol.expensetracker.utils.AudioPlay;
import com.vinsol.expensetracker.utils.DisplayTime;
import com.vinsol.expensetracker.utils.RecordingHelper;
@@ -68,6 +69,9 @@ protected void onCreate(Bundle savedInstanceState) {
mRecordingHelper.startRecording();
+ ////////********* Get Last most accurate location info ********* /////////
+ LocationLast mLocationLast = new LocationLast(this);
+ mLocationLast.getLastLocation();
}
@Override
@@ -104,7 +104,7 @@ public void run() {
//if there are both values use the latest one
if(gps_loc!=null && net_loc!=null){
- if(gps_loc.getAccuracy() < net_loc.getAccuracy()){
+ if(gps_loc.getTime() > net_loc.getTime()){
mLocationResult.gotLocation(gps_loc);
getData(gps_loc);
}
@@ -133,7 +133,7 @@ public void getData(Location location){
try{
Geocoder geocoder = new Geocoder(mContext);
List<Address> list = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
- MainActivity.mCurrentLocation = list.get(0).getFeatureName()+" "+list.get(0).getLocality()+" "+list.get(0).getAdminArea()+" "+list.get(0).getCountryName();
+ MainActivity.mCurrentLocation = list.get(0).getFeatureName()+", "+list.get(0).getLocality()+", "+list.get(0).getAdminArea();
MainActivity.mLocation = location;
Log.v("location", MainActivity.mCurrentLocation);
} catch (Exception e){}
@@ -12,7 +12,6 @@
import android.location.LocationManager;
import android.os.AsyncTask;
import android.util.Log;
-import android.widget.Toast;
public class LocationLast {
@@ -42,7 +41,12 @@ public void getLastLocation(){
}
int accuracy = (int) Math.ceil(mLocation.getAccuracy() - mTempLocation.getAccuracy());
- if(accuracy > 0){
+ if(mLocation.getTime() == mTempLocation.getTime()){
+ if(accuracy > 0 ){
+ mLocation = mTempLocation;
+ }
+ }
+ if(mLocation.getTime() < mTempLocation.getTime()){
mLocation = mTempLocation;
}
}
@@ -70,9 +74,9 @@ protected Void doInBackground(Void... params) {
@Override
protected void onPostExecute(Void result) {
- MainActivity.mCurrentLocation = list.get(0).getFeatureName()+" "+list.get(0).getLocality()+" "+list.get(0).getAdminArea()+" "+list.get(0).getCountryName();
+ MainActivity.mCurrentLocation = list.get(0).getFeatureName()+", "+list.get(0).getLocality()+", "+list.get(0).getAdminArea();
MainActivity.mLocation = mLocation;
- Toast.makeText(mContext, MainActivity.mCurrentLocation, Toast.LENGTH_LONG).show();
+ Log.v("loc last", MainActivity.mCurrentLocation);
super.onPostExecute(result);
}
}

0 comments on commit c6e09ea

Please sign in to comment.