Commits

littledot5566 committed 37508b2

*Finished implementing HoloEverywhere. *Fixed some bugs.

  • Participants
  • Parent commits 9a4f7e7

Comments (0)

Files changed (13)

File AndroidManifest.xml

     <application
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
-        android:theme="@style/AppTheme" >
+        android:theme="@style/Holo.Theme.Sherlock" >
 
         <!--  -->
         <uses-library android:name="com.google.android.maps" />

File project.properties

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

File release/TIL.txt

 X: db.rawQuery("select * from ? where ?=?", new String[]{"profile", "pID", "1"});
 O: db.rawQuery(String.format("select * from %s where %s=%d", "profile", "pID", 1));
 
-> Floating point numbers have a maximum value of 10E9.
+> Floating point numbers have a maximum value of 10E9.
+O: Use $(Type).MAX_VALUE to check (eg: Float.MAX_VALUE, Double.MAX_VALUE)
+
+? SharedPreferences does not get updated after implementing HoloEverywhere.
+> Storage is actually being updated. But instances in different Activities have an inconsistent view of the data.
+O: Implement OnSharedPreferenceChangeListener and use onSharedPreferenceChanged() to get hold of a copy of the updated SharedPreference.

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

 import nctuw.littledot.localtreasure.expedition.DialogManager;
 import nctuw.littledot.util.Echo;
 import nctuw.littledot.util.Leg;
+
+import org.holoeverywhere.app.ProgressDialog;
+
 import android.app.Dialog;
-import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
 		mLM = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 		mSM = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
 		mDB = new Database(this).open(Database.MODE_WRITE);
-		mSP = new SPManager(this);
+		mSP = new SPManager(getBaseContext());
 
 		// initialize map widgets
 		map = (MapView) findViewById(R.id.mapview);
 	@Override
 	protected void onPause() {
 		super.onPause();
-		Leg.a("");
+		Leg.a("[exp]:" + mExpedition);
 
 		// mExpedition.setEndTS(System.currentTimeMillis());
 
 		// save only after destination is confirmed
-		if (mExpedition.getDestLoc() != null)
+		if (mExpedition.getDestLoc() != null) {
 			mDB.updateExpedition(mExpedition);
+			mSP.setActiveExpeditionID(mExpedition.getEID());
+		}
 
 		mDB.close();
 		mLM.removeUpdates(this);
 			// save only after destination is confirmed
 			long eID = mDB.insertExpedition(mExpedition);
 			mExpedition.setEID(eID);
-			mSP.setActiveExpeditionID(eID);
+			// mSP.setActiveExpeditionID(eID);
 
 			startMarker.clearOverlay();
 			startMarker
 		}
 
 		// debug info
-		tvInfo.setText(String.format("Travelled=%f", mExpedition.getTravelled()));
+		Leg.a("expedition=" + mExpedition.toString());
 	}
 
 	public void onProviderDisabled(String provider) {

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

 
 import nctuw.littledot.localtreasure.Const;
 import nctuw.littledot.localtreasure.R;
+
+import org.holoeverywhere.app.Activity;
+
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.widget.EditText;
 import android.widget.Toast;
 
-import com.actionbarsherlock.app.SherlockActivity;
-
-public class ExpeditionConfigActivity extends SherlockActivity {
+public class ExpeditionConfigActivity extends Activity {
 	InputMethodManager imm;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
-		setTheme(Const.THEME);
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.selectdistance_act_layout);
 

File src/nctuw/littledot/localtreasure/components/HistoryActivity.java

 package nctuw.littledot.localtreasure.components;
 
-import nctuw.littledot.localtreasure.Const;
 import nctuw.littledot.localtreasure.R;
+import nctuw.littledot.localtreasure.database.Expedition;
+
+import org.holoeverywhere.app.Activity;
+import org.holoeverywhere.widget.ListView;
+
+import android.content.ContentValues;
 import android.os.Bundle;
-import android.widget.ListView;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.view.Menu;
+import android.view.View;
+import android.widget.AdapterView.AdapterContextMenuInfo;
 
-import com.actionbarsherlock.app.SherlockActivity;
+import com.actionbarsherlock.view.ContextMenu;
+import com.actionbarsherlock.view.MenuItem;
 
-public class HistoryActivity extends SherlockActivity {
+public class HistoryActivity extends Activity {
 	private ListView lvHistory;
 
 	private HistoryActivityAdapter mAdapter;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
-		setTheme(Const.THEME);
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.history_act_layout);
 
 		mAdapter = new HistoryActivityAdapter(this);
 		lvHistory.setAdapter(mAdapter);
+		registerForContextMenu(lvHistory);
 	}
 
 	@Override
 		super.onPause();
 	}
 
+	private static final int CONTINUE = 1;
+	private static final int DELETE = 2;
+
+	@Override
+	public void onCreateContextMenu(ContextMenu menu, View v,
+			ContextMenuInfo menuInfo) {
+		super.onCreateContextMenu(menu, v, menuInfo);
+
+		AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
+		ContentValues kv = mAdapter.getItem(info.position);
+
+		if (kv.getAsLong(Expedition.KEY_END_TIMESTAMP) == 0)
+			menu.add(Menu.NONE, CONTINUE, Menu.NONE, "Continue Expedition");
+		menu.add(Menu.NONE, DELETE, Menu.NONE, "Delete Expedition");
+	}
+
+	@Override
+	public boolean onContextItemSelected(MenuItem item) {
+		int id = item.getItemId();
+
+		if (id == CONTINUE) {
+			return true;
+		} else if (id == DELETE) {
+			return true;
+		}
+
+		return super.onContextItemSelected(item);
+	}
 }

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

 				.setText((l = kv.getAsLong(Expedition.KEY_END_TIMESTAMP)) > 0 ? new Date(
 						l).toLocaleString()
 						: "");
+
 		return view;
 	}
 }

File src/nctuw/littledot/localtreasure/components/MainActivity.java

 
 import nctuw.littledot.localtreasure.Const;
 import nctuw.littledot.localtreasure.R;
-import nctuw.littledot.localtreasure.R.id;
-import nctuw.littledot.localtreasure.R.layout;
 import nctuw.littledot.localtreasure.database.Database;
 import nctuw.littledot.localtreasure.database.Profile;
 import nctuw.littledot.localtreasure.database.SPManager;
 import nctuw.littledot.util.Leg;
+
+import org.holoeverywhere.app.Activity;
+import org.holoeverywhere.app.AlertDialog;
+
 import android.app.Dialog;
 import android.content.Intent;
 import android.os.Bundle;
 import android.widget.Button;
 import android.widget.TextView;
 
-import com.actionbarsherlock.app.SherlockActivity;
 import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
 
-public class MainActivity extends SherlockActivity {
+public class MainActivity extends Activity {
 	public static final String BUN_PROFILE = "bunProfile";
 	public static final String BUN_EID = "bunEID";
 	private TextView tvInfo;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
-		setTheme(Const.THEME);
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.main_act_layout);
 
 		mSPManager = new SPManager(this);
 		mDB = new Database(this).open(Database.MODE_WRITE);
+
+		AlertDialog.Builder b = new AlertDialog.Builder(this);
+		b.setMessage("message");
+		b.setTitle("titties");
+		b.setPositiveButton("hello", null);
+		b.create().show();
 	}
 
 	@Override
 		Leg.a(mProfile.toString());
 
 		// check for active expeditions
-		if ((mActiveEID = mSPManager.getActiveExpeditionID()) > 0) {
-			butContinue.setText("Continue Expedition=" + mActiveEID);
-			butContinue.setVisibility(View.VISIBLE);
-		} else
-			butContinue.setVisibility(View.GONE);
+		mActiveEID = mSPManager.getActiveExpeditionID();
+		Leg.a("activeExp=" + mActiveEID);
+		// if ((mActiveEID = mSPManager.getActiveExpeditionID()) > 0) {
+		butContinue.setText("Continue Expedition=" + mActiveEID);
+		butContinue.setVisibility(View.VISIBLE);
+		// } else
+		// butContinue.setVisibility(View.GONE);
 	}
 
 	@Override

File src/nctuw/littledot/localtreasure/components/ProfileActivity.java

 import nctuw.littledot.localtreasure.database.Database;
 import nctuw.littledot.localtreasure.database.Profile;
 import nctuw.littledot.util.Leg;
+
 import android.os.Bundle;
 import android.support.v4.app.FragmentTransaction;
 import android.view.View;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
-		setTheme(Const.THEME);
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.profile_activity);

File src/nctuw/littledot/localtreasure/components/SplashActivity.java

 package nctuw.littledot.localtreasure.components;
 
-import nctuw.littledot.localtreasure.Const;
 import nctuw.littledot.localtreasure.R;
-import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.widget.TextView;
 
-public class SplashActivity extends Activity {
+import com.actionbarsherlock.app.SherlockActivity;
+
+public class SplashActivity extends SherlockActivity {
 	public static int SPLASH_PAUSE = 1000;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
-		setTheme(Const.THEME);
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.splash_act_layout);
 

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

 	public static final String KEY_TREASURE_NAME = "tName";
 	public static final String KEY_TREASURE_NUM = "tDays";
 
-	/*
-	 * public static final String DBTABLE_PROFILE = "profile"; public static
-	 * final String KEY_PROFILE_ID = "pID"; public static final String
-	 * KEY_PROFILE_NAME = "pName"; public static final String
-	 * KEY_PROFILE_EXPEDITIONS = "pExpeditions"; public static final String
-	 * KEY_PROFILE_DISTANCE_TRAVELED = "pDistanceTraveled";
-	 * 
-	 * /* public static final String DBTABLE_EXPEDITION = "expedition"; public
-	 * static final String KEY_EXPEDITION_ID = "eID"; public static final String
-	 * KEY_EXPEDITION_USER_ID = "ePID"; public static final String
-	 * KEY_EXPEDITION_DISTANCE = "eDistance"; public static final String
-	 * KEY_EXPEDITION_TRAVELED = "eTraveled"; public static final String
-	 * KEY_EXPEDITION_START_LAT = "eStartLat"; public static final String
-	 * KEY_EXPEDITION_START_LONG = "eStartLong"; public static final String
-	 * KEY_EXPEDITION_END_LAT = "eEndLat"; public static final String
-	 * KEY_EXPEDITION_END_LONG = "eEndLong"; public static final String
-	 * KEY_EXPEDITION_START_TIMESTAMP = "eStartTimestamp"; public static final
-	 * String KEY_EXPEDITION_END_TIMESTAMP = "eEndTimestamp"; public static
-	 * final String KEY_EXPEDITION_TIME = "eTime"; public static final String
-	 * KEY_EXPEDITION_TREASURE = "eTreasure";
-	 */
-
-	/*
-	 * private static final String SQL_CREATE_TREASURE =
-	 * "create table if not exists " + DBTABLE_TREASURE + "(" + KEY_TREASURE_ID
-	 * + " integer not null primary key," + KEY_TREASURE_NAME +
-	 * " text default ''," + KEY_TREASURE_NUM + " integer not null default 0" +
-	 * ");";
-	 * 
-	 * /* private static final String SQL_CREATE_PROFILE =
-	 * "create table if not exists " + DBTABLE_PROFILE + "(" + KEY_PROFILE_ID +
-	 * " integer not null primary key autoincrement," + KEY_PROFILE_NAME +
-	 * " text default '<John Doe>'," + KEY_PROFILE_EXPEDITIONS +
-	 * " integer not null default 0," + KEY_PROFILE_DISTANCE_TRAVELED +
-	 * " real not null default 0" + ");";
-	 * 
-	 * /* private static final String SQL_CREATE_EXPEDITION =
-	 * "create table if not exists " + DBTABLE_EXPEDITION + "(" +
-	 * KEY_EXPEDITION_ID + " integer not null primary key autoincrement," +
-	 * KEY_EXPEDITION_USER_ID + " integer not null," + KEY_EXPEDITION_DISTANCE +
-	 * " real not null default 0," + KEY_EXPEDITION_TRAVELED +
-	 * " real default 0," + KEY_EXPEDITION_START_LAT + " real," +
-	 * KEY_EXPEDITION_START_LONG + " real," + KEY_EXPEDITION_END_LAT + " real,"
-	 * + KEY_EXPEDITION_END_LONG + " real," + KEY_EXPEDITION_START_TIMESTAMP +
-	 * " integer," + KEY_EXPEDITION_END_TIMESTAMP + " integer," +
-	 * KEY_EXPEDITION_TIME + " integer," + KEY_EXPEDITION_TREASURE + " integer"
-	 * + ");";
-	 */
-
 	public static final int MODE_READ = 1;
 	public static final int MODE_WRITE = 2;
 
 		return db.rawQuery(sql, null);
 	}
 
-	/*
-	 * public int queryTreasureNum(Treasure treasure) { Cursor cur = rawQuery(
-	 * "select * from ? where ? = ? ", new String[] { DBTABLE_TREASURE,
-	 * KEY_TREASURE_ID, Integer.toString(treasure.getDrawableID()) });
-	 * 
-	 * if (cur.moveToFirst()) return
-	 * cur.getInt(cur.getColumnIndexOrThrow(KEY_TREASURE_NUM)); else return -1;
-	 * }
-	 * 
-	 * public int queryExpeditionNum(int profileID) { Cursor cur =
-	 * rawQuery("select * from ? where ? = ? ", new String[] { DBTABLE_PROFILE,
-	 * KEY_PROFILE_ID, Integer.toString(profileID) });
-	 * 
-	 * if (cur.moveToFirst()) return cur.getInt(cur
-	 * .getColumnIndexOrThrow(KEY_PROFILE_EXPEDITIONS)); else return -1; }
-	 * 
-	 * public double queryDistanceTraveled(int profileID) { Cursor cur =
-	 * rawQuery("select * from ? where ? = ? ", new String[] { DBTABLE_PROFILE,
-	 * KEY_PROFILE_ID, Integer.toString(profileID) });
-	 * 
-	 * if (cur.moveToFirst()) return cur.getDouble(cur
-	 * .getColumnIndexOrThrow(KEY_PROFILE_DISTANCE_TRAVELED)); else return -1; }
-	 */
-
 	public Profile queryProfile(long profileID) {
 		Cursor cur = rawQuery(String
 				.format(
 				null);
 	}
 
-	/*
-	 * /** Increment the number of accumulated treasure by the specified amount.
-	 * 
-	 * @param treasure
-	 * 
-	 * @param increment
-	 * 
-	 * @return public void incrementTreasure(Treasure treasure, int increment) {
-	 * int ret = queryTreasureNum(treasure);
-	 * 
-	 * if (ret == -1) { // do an insert if key does not exist yet
-	 * insert(DBTABLE_TREASURE, new String[] { KEY_TREASURE_NAME,
-	 * KEY_TREASURE_NUM }, new Object[] { treasure, increment }); } else { // do
-	 * an update if key exists int newNum = ret + increment;
-	 * 
-	 * update(DBTABLE_TREASURE, KEY_TREASURE_NUM, newNum, KEY_TREASURE_NAME +
-	 * " = " + treasure); } }
-	 * 
-	 * public void incrementExpeditions(int profileID, int increment) { int ret
-	 * = queryExpeditionNum(profileID);
-	 * 
-	 * if (ret == -1) { insert(DBTABLE_PROFILE, new String[] {
-	 * KEY_PROFILE_EXPEDITIONS, KEY_PROFILE_DISTANCE_TRAVELED }, new Object[] {
-	 * 0, 0 }); } else { int newNum = ret + increment;
-	 * 
-	 * update(DBTABLE_PROFILE, KEY_PROFILE_EXPEDITIONS, newNum, KEY_PROFILE_ID +
-	 * "=" + profileID); } }
-	 * 
-	 * public void incrementDistance(int profileID, double amount) { double ret
-	 * = queryDistanceTraveled(profileID);
-	 * 
-	 * if (ret == -1) { insert(DBTABLE_PROFILE, new String[] {
-	 * KEY_PROFILE_EXPEDITIONS, KEY_PROFILE_DISTANCE_TRAVELED }, new Object[] {
-	 * 0, 0 }); } else { double newNum = ret + amount;
-	 * 
-	 * update(DBTABLE_PROFILE, KEY_PROFILE_DISTANCE_TRAVELED, newNum,
-	 * KEY_PROFILE_ID + "=" + profileID); } }
-	 */
-
 	/*************/
 	/** Deletes **/
 	/*************/
 		return delete(table, whereClaus, null);
 	}
 
-	/*
-	 * public Cursor getEvent(long id) throws SQLException { Cursor cur =
-	 * db.query(true, DBTABLE_EVENT, null, KEY_EVENT_EID + "=" + id, null, null,
-	 * null, null, null); if (cur != null) cur.moveToFirst();
-	 * 
-	 * cursorReader(cur); return cur; }
-	 * 
-	 * public Cursor getEventsForTable(int tid, String[] neededColumns) { Cursor
-	 * mCursor = db.query(true, DBTABLE_EVENT, neededColumns, KEY_TABLE_TID +
-	 * "=" + tid, null, null, null, null, null); if (mCursor != null)
-	 * mCursor.moveToFirst(); return mCursor; }
-	 * 
-	 * public Cursor query(String[] columns, String selection, String[]
-	 * selectionArgs) { Cursor mCursor = db.query(true, DBTABLE_EVENT, columns,
-	 * selection, selectionArgs, null, null, null, null); if (mCursor != null)
-	 * mCursor.moveToFirst(); return mCursor; }
-	 * 
-	 * private void cursorReader(Cursor cur) { while (!cur.isAfterLast()) {
-	 * String log = ""; for (int i = 0; i < cur.getColumnCount(); i++) log +=
-	 * "[" + cur.getColumnName(i) + "]=" + cur.getString(i); //Leg.i( log);
-	 * cur.moveToNext(); } cur.moveToFirst(); }
-	 */
+	public int deleteExpedition(Expedition exp) {
+		return deleteExpedition(exp.getEID());
+	}
+
+	public int deleteExpedition(long id) {
+		return delete(Expedition.TABLE_NAME, Expedition.KEY_ID + "=" + id);
+	}
 
 	/***************/
 	/** Utilities **/

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

 	}
 
 	public String toString() {
-		String sb = "ID=" + eID + " pID=" + pID;
+		String sb = "eID=" + eID + " pID=" + pID;
 
 		if (mStartLoc != null)
 			sb += " stLoc=(" + mStartLoc.getLatitude() + ","
 		Location loc;
 		int i;
 
-		setEID(eID);
+		setEID(cur.getLong(cur.getColumnIndex(Expedition.KEY_ID)));
 		setPID(cur.getLong(cur.getColumnIndex(Expedition.KEY_PID)));
 		setDistance(cur.getDouble(cur.getColumnIndex(Expedition.KEY_DISTANCE)));
 

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

 package nctuw.littledot.localtreasure.database;
 
+import nctuw.littledot.util.Leg;
+
+import org.holoeverywhere.preference.PreferenceManager;
+import org.holoeverywhere.preference.SharedPreferences;
+
 import android.content.Context;
-import android.content.SharedPreferences;
 
 public class SPManager {
 	public static final String DBTABLE_STATS = "statistics";
 
 	public SPManager(Context ctx) {
 		mCtx = ctx;
-
-		mPrefs = mCtx.getSharedPreferences(ctx.getPackageName(),
-				Context.MODE_PRIVATE);
-
+		mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
+		// mPrefs.registerOnSharedPreferenceChangeListener(this);
 		mEditor = mPrefs.edit();
-
-		// editor.putLong(Constants.PREF_LAST_AD_CLICK, cal.getTimeInMillis());
-		// editor.commit();
 	}
 
 	public long getActiveProfileID() {
 	}
 
 	public long getActiveExpeditionID() {
-		return mPrefs.getLong(KEY_ACTIVE_EXPEDITION_ID, 0);
+		long l = mPrefs.getLong(KEY_ACTIVE_EXPEDITION_ID, 0);
+		Leg.a("KEY_ACTIVE_EXPEDITION_ID=" + l);
+		return l;
 	}
 
 	public void setActiveExpeditionID(long id) {
+		Leg.a("KEY_ACTIVE_EXPEDITION_ID=" + id);
 		mEditor.putLong(KEY_ACTIVE_EXPEDITION_ID, id);
 		mEditor.commit();
 	}