Commits

littledot5566 committed 9ba42b6

*Implementing populating Profile via a Cursor. Need to check SQL for queryProfile.

Comments (0)

Files changed (10)

.classpath

-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="gen"/>
-	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
-	<classpathentry combineaccessrules="false" exported="true" kind="src" path="/Utils"/>
-	<classpathentry exported="true" kind="lib" path="E:/Code/_LIB_/actionbarsherlock-plugin-maps/actionbarsherlock-plugin-maps-4.1.0.jar"/>
-	<classpathentry kind="output" path="bin/classes"/>
-</classpath>

project.properties

 
 # Project target.
 target=Google Inc.:Google APIs:16
-android.library.reference.1=..\\Utils
-android.library.reference.2=../ActionBarSherlock/library
+android.library.reference.1=../ActionBarSherlock/library
+android.library.reference.2=../Utils

src/nctuw/littledot/localtreasure/Geodesy.java

 		double destLat = Math.asin(Math.sin(radLat) * Math.cos(angle)
 				+ Math.cos(radLat) * Math.sin(angle) * Math.cos(radBearing));
 		double destLong = radLong
-				+ Math.atan2(Math.sin(radBearing) * Math.sin(angle) * Math.cos(radLat),
+				+ Math.atan2(
+						Math.sin(radBearing) * Math.sin(angle)
+								* Math.cos(radLat),
 						Math.cos(angle) - Math.sin(radLat) * Math.sin(radLat));
 
 		Location loc = new Location("TreasureHunter");
 	}
 
 	public static Location calculateVincentyDestination(Location curLoc,
-			double bearing, float distance) {// meter
+			double bearing, double distance) {// meter
 		// instantiate the calculator
 		GeodeticCalculator geoCalc = new GeodeticCalculator();
 

src/nctuw/littledot/localtreasure/components/ExpeditionActivity.java

 				mExpedition = new Expedition();
 				mExpedition.setPID(mSP.getActiveProfileID());
 				mExpedition.setStartTS(System.currentTimeMillis());
-				mExpedition.setDistance(extras.getFloat(Const.BUNDLE_DISTANCE, 0));
+				mExpedition.setDistance(extras.getDouble(Const.BUNDLE_DISTANCE,
+						0));
 
 			} else if (source.equals(MainActivity.class.getName())) {
 				// load saved Expedition
 				mExpedition = mDB.queryExpedition(eID);
 
 				startMarker.clearOverlay();
-				startMarker.addLocation(mExpedition.getStartLoc(), "resume-Start",
+				startMarker.addLocation(mExpedition.getStartLoc(),
+						"resume-Start",
 						mExpedition.getStartLoc().toString());
 				destMarker.clearOverlay();
 				destMarker.addLocation(mExpedition.getDestLoc(), "resume-Dest",
 			Leg.a("provider=" + provider);
 
 			mLM.requestLocationUpdates(provider, 0, (float) (mExpedition
-					.getDistance() * 0.05 < 10 ? 10 : mExpedition.getDistance() * 0.05),
+					.getDistance() * 0.05 < 10 ? 10
+					: mExpedition.getDistance() * 0.05),
 					this);
 		}
 
 		// register sensor updates
-		mSM.registerListener(this, mSM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
+		mSM.registerListener(this,
+				mSM.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
 				SensorManager.SENSOR_DELAY_UI);
 		mSM.registerListener(this,
 				mSM.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
 
 		// mCurLocation = location;
 
-		mController.setCenter(new GeoPoint((int) (location.getLatitude() * 1E6),
+		mController.setCenter(new GeoPoint(
+				(int) (location.getLatitude() * 1E6),
 				(int) (location.getLongitude() * 1E6)));
 		playerMarker.clearOverlay();
 		playerMarker.addLocation(location, "CurLoc", location.toString());
 
 			double bearing = Math.random() * 360;
 			mExpedition.setStartLoc(location);
-			mExpedition.setDestLoc(Geodesy.calculateVincentyDestination(location,
-					bearing, mExpedition.getDistance()));
+			mExpedition.setDestLoc(Geodesy.calculateVincentyDestination(
+					location, bearing, mExpedition.getDistance()));
 
 			// save only after destination is confirmed
 			long eID = mDB.insertExpedition(mExpedition);
 			mSP.setActiveExpeditionID(eID);
 
 			startMarker.clearOverlay();
-			startMarker.addLocation(location, "Cali-Start", location.toString());
+			startMarker
+					.addLocation(location, "Cali-Start", location.toString());
 			destMarker.clearOverlay();
-			destMarker.addLocation(mExpedition.getDestLoc(), "Cali-Dest", mExpedition
-					.getDestLoc().toString());
+			destMarker.addLocation(mExpedition.getDestLoc(), "Cali-Dest",
+					mExpedition
+							.getDestLoc().toString());
 
 			isCalibrated = true;
 
 
 		// log traveled distance
 		if (mExpedition.getLKLocation() != null) {
-			float travelled = mExpedition.getLKLocation().distanceTo(location);
+			double travelled = mExpedition.getLKLocation().distanceTo(location);
 			mExpedition.incTravelled(travelled);
 		}
 

src/nctuw/littledot/localtreasure/components/ExpeditionConfigActivity.java

 		Intent intent = new Intent(this, ExpeditionActivity.class);
 
 		switch (v.getId()) {
-			case R.id.distance_but_500m:
-				intent.putExtra(Const.BUNDLE_SOURCE, getClass().getName());
-				intent.putExtra(Const.BUNDLE_DISTANCE, 500F);
-				break;
+		case R.id.distance_but_500m:
+			intent.putExtra(Const.BUNDLE_SOURCE, getClass().getName());
+			intent.putExtra(Const.BUNDLE_DISTANCE, 500F);
+			break;
 		}
 
 		startActivity(intent);
 			but.setText("OK!");
 
 		} else {
-			float d = Float.parseFloat(et.getText().toString());
+			double d = Double.parseDouble(et.getText().toString());
 
 			// cannot > 1/2 * circumference of Earth (40075km)
 			if (d > 20000000) {

src/nctuw/littledot/localtreasure/components/HistoryActivityAdapter.java

 		Cursor cur = mDB.rawQuery(String
 				.format("select * from %s, %s where %s.%s=%s.%s order by %s",
 						Expedition.TABLE_NAME, Profile.TABLE_NAME,
-						Expedition.TABLE_NAME, Expedition.KEY_USER_ID,
+						Expedition.TABLE_NAME, Expedition.KEY_PID,
 						Profile.TABLE_NAME, Profile.KEY_ID,
 						Expedition.KEY_START_TIMESTAMP));
 
 
 		TextView tvTravelled = (TextView) view
 				.findViewById(R.id.hItem_tv_travelled);
-		TextView tvDistance = (TextView) view.findViewById(R.id.hItem_tv_distance);
+		TextView tvDistance = (TextView) view
+				.findViewById(R.id.hItem_tv_distance);
 		TextView tvUser = (TextView) view.findViewById(R.id.hItem_tv_user);
 		TextView tvStTime = (TextView) view.findViewById(R.id.hItem_tv_stTime);
 
 		tvTravelled.setText(NumberFormat.getInstance().format(
-				kv.getAsFloat(Expedition.KEY_TRAVELED)));
+				kv.getAsDouble(Expedition.KEY_TRAVELED)));
 		tvDistance.setText(NumberFormat.getInstance().format(
-				kv.getAsFloat(Expedition.KEY_DISTANCE)));
+				kv.getAsDouble(Expedition.KEY_DISTANCE)));
 		tvUser.setText(kv.getAsString(Profile.KEY_NAME));
 		tvStTime.setText(new Date(kv.getAsLong(Expedition.KEY_START_TIMESTAMP))
 				.toString());

src/nctuw/littledot/localtreasure/database/Database.java

 import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
+import android.database.DatabaseUtils;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 
 	 */
 
 	public Profile queryProfile(long profileID) {
-		Cursor cur = rawQuery(String.format("select * from %s where %s=%d",
-				Profile.TABLE_NAME, Profile.KEY_ID, profileID));
+		Cursor cur = rawQuery(String
+				.format(
+						"select *, %s, %s from %s, %s where %s.%s=%s.%s and %s=%d group by %s",
+						Expedition.SUM_TRAVELED, Expedition.COUNT_ID,
+						Profile.TABLE_NAME, Expedition.TABLE_NAME,
+						Profile.TABLE_NAME, Profile.KEY_ID,
+						Expedition.TABLE_NAME,
+						Expedition.KEY_PID,
+						Profile.KEY_ID, profileID,
+						Profile.KEY_ID));
 
 		if (cur.moveToFirst()) {
-			Leg.dumpCursor(cur);
-			Profile profile = new Profile();
-			profile.setProfileID(profileID);
-			profile.setName(cur.getString(cur.getColumnIndex(Profile.KEY_NAME)));
-			// profile.setTotalExpeditions(cur.getLong(cur
-			// .getColumnIndex(Profile.KEYPROFILE_EXPEDITIONS)));
-			// profile.setTotalDistance(cur.getDouble(cur
-			// .getColumnIndex(KEY_PROFILE_EXPEDITIONS)));
-
+			// Leg.dumpCursor(cur);
+			DatabaseUtils.dumpCurrentRow(cur);
+			Profile profile = new Profile(cur);
 			cur.close();
 
 			return profile;

src/nctuw/littledot/localtreasure/database/Expedition.java

 import java.util.ArrayList;
 import java.util.Date;
 
-import org.json.JSONObject;
-
 import nctuw.littledot.util.Leg;
 import android.content.ContentValues;
 import android.database.Cursor;
 	private long pID = 0;
 	private Location mStartLoc = null;
 	private Location mDestLoc = null;
-	private float mDistance;
-	private float mTravelled;
+	private double mDistance;
+	private double mTravelled;
 
 	private long mStartTS;
 	private long mEndTS;
 		return this;
 	}
 
-	public float getDistance() {
+	public double getDistance() {
 		return mDistance;
 	}
 
-	public Expedition setDistance(float mDistance) {
+	public Expedition setDistance(double mDistance) {
 		this.mDistance = mDistance;
 		return this;
 	}
 
-	public float getTravelled() {
+	public double getTravelled() {
 		return mTravelled;
 	}
 
-	public Expedition setTravelled(float mTravelled) {
+	public Expedition setTravelled(double mTravelled) {
 		this.mTravelled = mTravelled;
 		return this;
 	}
 
-	public Expedition incTravelled(float mTravelled) {
+	public Expedition incTravelled(double mTravelled) {
 		this.mTravelled += mTravelled;
 		return this;
 	}
 
 	public static final String TABLE_NAME = "expedition";
 	public static final String KEY_ID = "eID";
-	public static final String KEY_USER_ID = "ePID";
+	public static final String KEY_PID = "ePID";
 	public static final String KEY_DISTANCE = "eDistance";
 	public static final String KEY_TRAVELED = "eTraveled";
 	public static final String KEY_START_LAT = "eStartLat";
 	public static final String KEY_TIME = "eTime";
 	public static final String KEY_TREASURE = "eTreasure";
 
+	public static final String COUNT_ID = "count(" + KEY_ID + ")";
+	public static final String SUM_TRAVELED = "sum(" + KEY_TRAVELED + ")";
+
 	public static final String SQL_CREATE_EXPEDITION = "create table if not exists "
 			+ TABLE_NAME
 			+ "("
 			+ KEY_ID // long
 			+ " integer not null primary key autoincrement,"
-			+ KEY_USER_ID // long
+			+ KEY_PID // long
 			+ " integer not null,"
-			+ KEY_DISTANCE // float
+			+ KEY_DISTANCE // double
 			+ " integer not null,"
-			+ KEY_TRAVELED // float
+			+ KEY_TRAVELED // double
 			+ " real default 0,"
 			+ KEY_START_LAT // double
 			+ " real,"
 		int i;
 
 		setEID(eID);
-		setPID(cur.getLong(cur.getColumnIndex(Expedition.KEY_USER_ID)));
-		setDistance(cur.getFloat(cur.getColumnIndex(Expedition.KEY_DISTANCE)));
+		setPID(cur.getLong(cur.getColumnIndex(Expedition.KEY_PID)));
+		setDistance(cur.getDouble(cur.getColumnIndex(Expedition.KEY_DISTANCE)));
 
 		if ((i = Database.getIndex(cur, Expedition.KEY_TRAVELED)) > -1)
-			setTravelled(cur.getFloat(i));
+			setTravelled(cur.getDouble(i));
 
 		if ((i = Database.getIndex(cur, Expedition.KEY_START_LAT)) > -1) {
 			loc = new Location("");
 		ArrayList<String> keys = new ArrayList<String>();
 		ArrayList<Object> vals = new ArrayList<Object>();
 
-		keys.add(KEY_USER_ID);
+		keys.add(KEY_PID);
 		vals.add(pID);
 
 		keys.add(KEY_DISTANCE);
 		ContentValues kv = new ContentValues();
 
 		kv.put(KEY_ID, c.getLong(c.getColumnIndex(KEY_ID)));
-		kv.put(KEY_USER_ID, c.getLong(c.getColumnIndex(KEY_USER_ID)));
-		kv.put(KEY_DISTANCE, c.getFloat(c.getColumnIndex(KEY_DISTANCE)));
-		kv.put(KEY_TRAVELED, c.getFloat(c.getColumnIndex(KEY_TRAVELED)));
+		kv.put(KEY_PID, c.getLong(c.getColumnIndex(KEY_PID)));
+		kv.put(KEY_DISTANCE, c.getDouble(c.getColumnIndex(KEY_DISTANCE)));
+		kv.put(KEY_TRAVELED, c.getDouble(c.getColumnIndex(KEY_TRAVELED)));
 		kv.put(KEY_START_LAT, c.getDouble(c.getColumnIndex(KEY_START_LAT)));
 		kv.put(KEY_START_LONG, c.getDouble(c.getColumnIndex(KEY_START_LONG)));
 		kv.put(KEY_END_LAT, c.getDouble(c.getColumnIndex(KEY_END_LAT)));
 		kv.put(KEY_END_LONG, c.getDouble(c.getColumnIndex(KEY_END_LAT)));
 		kv.put(KEY_START_TIMESTAMP,
 				c.getLong(c.getColumnIndex(KEY_START_TIMESTAMP)));
-		kv.put(KEY_END_TIMESTAMP, c.getLong(c.getColumnIndex(KEY_END_TIMESTAMP)));
+		kv.put(KEY_END_TIMESTAMP,
+				c.getLong(c.getColumnIndex(KEY_END_TIMESTAMP)));
 		kv.put(KEY_TIME, c.getLong(c.getColumnIndex(KEY_TIME)));
 		kv.put(KEY_TREASURE, c.getInt(c.getColumnIndex(KEY_TREASURE)));
 
 		dest.writeLong(pID);
 		dest.writeParcelable(mStartLoc, 0);
 		dest.writeParcelable(mDestLoc, 0);
-		dest.writeFloat(mDistance);
-		dest.writeFloat(mTravelled);
+		dest.writeDouble(mDistance);
+		dest.writeDouble(mTravelled);
 		dest.writeLong(mStartTS);
 		dest.writeLong(mEndTS);
 		dest.writeSerializable(mPrize);
 		pID = in.readLong();
 		mStartLoc = in.readParcelable(null);
 		mDestLoc = in.readParcelable(null);
-		mDistance = in.readFloat();
-		mTravelled = in.readFloat();
+		mDistance = in.readDouble();
+		mTravelled = in.readDouble();
 		mStartTS = in.readLong();
 		mEndTS = in.readLong();
 		mPrize = (Treasure) in.readSerializable();

src/nctuw/littledot/localtreasure/database/Profile.java

 			+ ");";
 
 	public Profile(Cursor cur) {
+		mProfileID = cur.getLong(cur.getColumnIndex(KEY_ID));
+		mName = cur.getString(cur.getColumnIndex(KEY_NAME));
+		mTotalDistance = cur.getDouble(cur
+				.getColumnIndex(Expedition.SUM_TRAVELED));
+		mTotalDistance = cur.getInt(cur.getColumnIndex(Expedition.COUNT_ID));
 	}
 
 	public ContentValues toContentValues() {

src/nctuw/littledot/localtreasure/database/SPManager.java

 		mEditor.commit();
 	}
 
-	public float getDistanceTraveled() {
-		return mPrefs.getFloat(KEY_STATS_DIST_TRAV, 0);
-	}
-
-	public void incDistanceTraveled(float inc) {
-		float value = getDistanceTraveled() + inc;
-		mEditor.putFloat(KEY_STATS_DIST_TRAV, value);
-		mEditor.commit();
-	}
-
-	public int getTotalExpeditions() {
-		return mPrefs.getInt(KEY_STATS_EXP_TOTAL, 0);
-	}
-
-	public void incTotalExpeditions(int inc) {
-		int value = getTotalExpeditions() + inc;
-		mEditor.putInt(KEY_STATS_EXP_TOTAL, value);
-		mEditor.commit();
-	}
-
-	public int getSuccessExpeditions() {
-		return mPrefs.getInt(KEY_STATS_EXP_SUCC, 0);
-	}
-
-	public void incSuccessExpeditions(int inc) {
-		int value = getSuccessExpeditions() + inc;
-		mEditor.putInt(KEY_STATS_EXP_SUCC, value);
-		mEditor.commit();
-	}
+	// public float getDistanceTraveled() {
+	// return mPrefs.getFloat(KEY_STATS_DIST_TRAV, 0);
+	// }
+	//
+	// public void incDistanceTraveled(float inc) {
+	// float value = getDistanceTraveled() + inc;
+	// mEditor.putFloat(KEY_STATS_DIST_TRAV, value);
+	// mEditor.commit();
+	// }
+	//
+	// public int getTotalExpeditions() {
+	// return mPrefs.getInt(KEY_STATS_EXP_TOTAL, 0);
+	// }
+	//
+	// public void incTotalExpeditions(int inc) {
+	// int value = getTotalExpeditions() + inc;
+	// mEditor.putInt(KEY_STATS_EXP_TOTAL, value);
+	// mEditor.commit();
+	// }
+	//
+	// public int getSuccessExpeditions() {
+	// return mPrefs.getInt(KEY_STATS_EXP_SUCC, 0);
+	// }
+	//
+	// public void incSuccessExpeditions(int inc) {
+	// int value = getSuccessExpeditions() + inc;
+	// mEditor.putInt(KEY_STATS_EXP_SUCC, value);
+	// mEditor.commit();
+	// }
 }