Commits

littledot5566 committed 10e090c

*Completed Continue and Delete Expedition options from HistoryActivity.

Comments (0)

Files changed (6)

 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.
-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.
+> How to find the limits for Floats and Doubles?
+O: Use $(Type).MAX_VALUE to check (eg: Float.MAX_VALUE, Double.MAX_VALUE)

res/layout/map_act_layout.xml

     <!-- Win7:			0-0-0tVBYzo78FEXFOBhiBi06dI13u00gCOfQnEUA -->
     <!-- android-dev:	0-0tVBYzo78F-qe7esdacwXkvQC1qjv3vYvBkbA -->
 
-    <LinearLayout
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:orientation="horizontal" >
-
-        <TextView
-            android:id="@+id/map_tv_info"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:visibility="gone" />
-
-        <Button
-            android:id="@+id/map_but_debug"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:onClick="onClick"
-            android:text="debug bundle" />
-    </LinearLayout>
-
 </LinearLayout>

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

 import nctuw.littledot.util.Leg;
 
 import org.holoeverywhere.app.ProgressDialog;
+import org.holoeverywhere.widget.Toast;
 
 import android.app.Dialog;
 import android.content.Context;
 	private Database mDB;
 	private SPManager mSP;
 
-	private TextView tvInfo;
 	private MapView map;
 
 	private ProgressDialog pdLock;
 		super.onCreate(savedInstanceState);
 
 		setContentView(R.layout.map_act_layout);
-		tvInfo = (TextView) findViewById(R.id.map_tv_info);
 
 		// mLI = (LayoutInflater)
 		// getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 				mExpedition.setDistance(extras.getDouble(Const.BUNDLE_DISTANCE,
 						0));
 
-			} else if (source.equals(MainActivity.class.getName())) {
+			} else if (source.equals(MainActivity.class.getName())
+					|| source.equals(HistoryActivity.class.getName())) {
 				// load saved Expedition
 				long eID = extras.getLong(Const.BUNDLE_EID);
 				mExpedition = mDB.queryExpedition(eID);
 				destMarker.addLocation(mExpedition.getDestLoc(), "resume-Dest",
 						mExpedition.getDestLoc().toString());
 
+				mController.setCenter(new GeoPoint(
+						(int) (mExpedition.getDestLoc().getLatitude() * 1E6),
+						(int) (mExpedition.getDestLoc().getLongitude() * 1E6)));
+				mController.setZoom(11);
+
 				isCalibrated = true;
+
+				Toast.makeText(this,
+						"Please walk around so that the GPS can get a fix",
+						Toast.LENGTH_LONG).show();
 			}
 			Leg.a(mExpedition.toString());
 
 		if (id == R.id.hunt_but_showmap) {
 			Intent showmap = new Intent(this, HuntingMapActivity.class);
 			startActivity(showmap);
-		} else if (id == R.id.map_but_debug) {
-			Intent test = new Intent(this, TestBundleActivity.class);
-			mExpedition.setEndTS(System.currentTimeMillis());
-			test.putExtra(BUND_EXPEDITION, mExpedition);
-			Leg.a(mExpedition.toString());
-			startActivity(test);
 		}
 	}
 

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 nctuw.littledot.util.Leg;
 
 import org.holoeverywhere.app.Activity;
+import org.holoeverywhere.app.AlertDialog;
+import org.holoeverywhere.app.Dialog;
 import org.holoeverywhere.widget.ListView;
 
-import android.content.ContentValues;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
 import android.os.Bundle;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.Menu;
 import android.view.View;
-import android.widget.AdapterView.AdapterContextMenuInfo;
-
-import com.actionbarsherlock.view.ContextMenu;
-import com.actionbarsherlock.view.MenuItem;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
 
 public class HistoryActivity extends Activity {
-	private ListView lvHistory;
 
+	private ListView lvHistory;
 	private HistoryActivityAdapter mAdapter;
+	private DialogManager mDM = new DialogManager();;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 
 		mAdapter = new HistoryActivityAdapter(this);
 		lvHistory.setAdapter(mAdapter);
-		registerForContextMenu(lvHistory);
+
+		lvHistory.setOnItemClickListener(new OnItemClickListener() {
+			@Override
+			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
+					long arg3) {
+				Leg.a("arg2=" + arg2 + " arg3=" + arg3);
+				mDM.deleteExpeditionDialog(HistoryActivity.this, arg2).show();
+			}
+		});
+
 	}
 
 	@Override
 	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);
+	private class DialogManager {
+
+		public Dialog deleteExpeditionDialog(Context ctx, final int pos) {
+			AlertDialog.Builder b = new AlertDialog.Builder(ctx);
+			b.setTitle("hello");
+			b.setItems(new CharSequence[] { "Continue", "Delete" },
+					new OnClickListener() {
+						@Override
+						public void onClick(DialogInterface dialog, int which) {
+							Leg.a("which=" + which);
+							if (which == 0) {
+								Intent intent = new Intent(HistoryActivity.this,
+										ExpeditionActivity.class);
+								intent.putExtra(Const.BUNDLE_SOURCE, HistoryActivity.this
+										.getClass().getName());
+								intent.putExtra(Const.BUNDLE_EID, mAdapter.getItemId(pos));
+								startActivity(intent);
+
+								finish();
+							} else if (which == 1) {
+								mAdapter.deleteExpedition(pos);
+							}
+
+							dialog.dismiss();
+						}
+					});
+
+			return b.create();
 
-		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);
 	}
+
 }

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

 		mDB.close();
 	}
 
+	public void deleteExpedition(int pos) {
+		mDB.open(Database.MODE_WRITE);
+
+		if (mDB.deleteExpedition(getItemId(pos)) == 1)
+			mData.remove(pos);
+
+		notifyDataSetChanged();
+
+		mDB.close();
+	}
+
 	public int getCount() {
 		return mData.size();
 	}

src/nctuw/littledot/localtreasure/expedition/DialogManager.java

 package nctuw.littledot.localtreasure.expedition;
 
 import nctuw.littledot.localtreasure.database.Expedition;
-import android.app.AlertDialog;
-import android.app.Dialog;
+
+import org.holoeverywhere.app.AlertDialog;
+import org.holoeverywhere.app.Dialog;
+
 import android.content.Context;
 import android.content.DialogInterface;
 
 		// Create the AlertDialog object and return it
 		return builder.create();
 	}
+
+	// public static Dialog deleteExpeditionDialog(Context ctx, long eid) {
+	//
+	// AlertDialog.Builder b = new AlertDialog.Builder(ctx);
+	//
+	// b.setTitle("hello");
+	//
+	// b.setItems(new CharSequence[] { "Continue", "Delete" },
+	// new OnClickListener() {
+	//
+	// @Override
+	// public void onClick(DialogInterface dialog, int which) {
+	// Leg.a("which=" + which);
+	// if (which == 1) {
+	// } else if (which == 2) {
+	// }
+	//
+	// dialog.dismiss();
+	// }
+	// });
+	//
+	// return b.create();
+	//
+	// }
 }