Commits

littledot5566 committed b142673

*Fixed FC caused by savedInstanceState in ExpeditionActivity. *Added more logic in dialogs in HistoryActivity. *Lowered treasure bar. *Enabled Proguard.

Comments (0)

Files changed (7)

proguard-project.txt

 #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
 #   public *;
 #}
+
+-assumenosideeffects class nctuw.littledot.Leg 

project.properties

 # project structure.
 #
 # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
 
 # Project target.
 target=Google Inc.:Google APIs:16
 v After completing an Expedition, remove from Active Expedition.
 v Completed Expeditions should not display "Continue Expedition" option.
 * Back button instead of icon.
-* Different excuses when the log is empty. "Had a cold..." "It was raining..." etc.
+* Different excuses when the log is empty. "Had a cold..." "It was raining..." etc.
+* Implement sonar sounds when approaching treasure so that user doesn't have to look at the screen all the time.

res/layout/map_act_layout.xml

         android:apiKey="0-0tVBYzo78FEXFOBhiBi06dI13u00gCOfQnEUA"
         android:clickable="true" />
     <!-- Ubuntu:		0-0tVBYzo78GcruEETjNXCnXjt4rzTKIkzU5HAQ -->
-    <!-- Win7:			0-0-0tVBYzo78FEXFOBhiBi06dI13u00gCOfQnEUA -->
+    <!-- Win7:			0-0tVBYzo78FEXFOBhiBi06dI13u00gCOfQnEUA -->
     <!-- android-dev:	0-0tVBYzo78F-qe7esdacwXkvQC1qjv3vYvBkbA -->
 
 </LinearLayout>

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

 import nctuw.littledot.localtreasure.database.Expedition;
 import nctuw.littledot.localtreasure.database.SPManager;
 import nctuw.littledot.localtreasure.database.Treasure;
-import nctuw.littledot.localtreasure.expedition.DialogManager;
 import nctuw.littledot.util.Echo;
 import nctuw.littledot.util.Leg;
 
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
+import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
 import android.hardware.Sensor;
 import android.hardware.SensorEvent;
 	public static final float LOCATION_ACC_THRESH = 100.0f;
 	public static final int LOCATION_LOCK_DIALOG = 1;
 	public static final int EXPEDITION_COMPLETE_DIALOG = 0;
+	public static final int GIVE_UP_DIALOG = 2;
 
 	public static final String BUND_EXPEDITION = "expedition";
 
 		if (savedInstanceState != null) {
 			mExpedition = savedInstanceState.getParcelable(BUND_EXPEDITION);
 			isCalibrated = true;
-			Echo.a(this, String.format("bundle=%s", mExpedition.toString()));
+			Leg.a(String.format("bundle=%s", mExpedition.toString()));
 
 		} else {
 			// resume or start a new Expedition
 		mSM.unregisterListener(this);
 	}
 
-	// @Override
-	// protected void onSaveInstanceState(Bundle outState) {
-	// super.onSaveInstanceState(outState);
-	// if (isCalibrated) {
-	// // mExpedition.setEndTS(System.currentTimeMillis());
-	// outState.putParcelable(BUND_EXPEDITION, mExpedition);
-	//
-	// // outState.putDouble(BUND_DIST, mDistance);
-	// // outState.putDouble(BUND_DIST_TRAV, mDistanceTraveled);
-	// // outState.putParcelable(BUND_STARTLOC, mStartLocation);
-	// // outState.putParcelable(BUND_DESTLOC, mDestLocation);
-	// }
-	//
-	// Leg.a(String.format("expedition=%s", mExpedition.toString()));
-	// }
+	@Override
+	protected void onSaveInstanceState(Bundle outState) {
+		super.onSaveInstanceState(outState);
+		if (isCalibrated) {
+			outState.putParcelable(BUND_EXPEDITION, mExpedition);
+		}
+
+		Leg.a(String.format("expedition=%s", mExpedition.toString()));
+	}
 
 	public void onClick(View v) {
 		int id = v.getId();
 			finish();
 			return true;
 		} else if (id == MENU_GIVEUP) {
+			showDialog(GIVE_UP_DIALOG);
 		}
 		return super.onOptionsItemSelected(item);
 	}
 				message = String.format(
 						"You have come a long way to complete this expedition!\n\n"
 								+ "Distance travelled: %f meters\n"
+								+ "Distance from destination: %f meters\n"
 								+ "Time taken: %d seconds\n",
-						mExpedition.getTravelled(), seconds);
+						mExpedition.getTravelled(), mExpedition.getDistanceLeft(), seconds);
 			}
 
 			// Use the Builder class for convenient dialog construction
 					});
 
 			return builder.create();
+
+		} else if (id == GIVE_UP_DIALOG) {
+			AlertDialog.Builder builder = new AlertDialog.Builder(this);
+
+			builder.setTitle("It's getting pretty late...")
+					.setMessage("Conclude the expedition?")
+					.setNegativeButton("No", new OnClickListener() {
+						@Override
+						public void onClick(DialogInterface dialog, int which) {
+							dialog.dismiss();
+						}
+					})
+					.setPositiveButton("Yes", new OnClickListener() {
+						@Override
+						public void onClick(DialogInterface dialog, int which) {
+							concludeExpedition();
+							dialog.dismiss();
+							finish();
+						}
+					});
+			return builder.create();
 		}
 
 		return super.onCreateDialog(id, args);
 
 		mExpedition.setLKLocation(location);
 
-		// log remaining distance
-		double distLeft = location.distanceTo(mExpedition.getDestLoc());
-		mExpedition.setDistanceLeft(distLeft);
-
-		// determine if player is close enough to win
-		if (distLeft < mExpedition.getDistance() * 0.05) {
-			Leg.a("apart=" + distLeft + " required=" + mExpedition.getDistance()
-					* 0.05);
-			mExpedition.setEndTS(System.currentTimeMillis());
+		if (isAtDestination(location)) {
 			mExpedition.setPrize(Treasure.generateReward(mExpedition));
-
-			mSP.setActiveExpeditionID(0);
-
-			mLM.removeUpdates(this);
-			mSM.unregisterListener(this);
-
-			isAtDest = true;
-
+			concludeExpedition();
 			showDialog(EXPEDITION_COMPLETE_DIALOG);
 		}
+		// // log remaining distance
+		// double distLeft = location.distanceTo(mExpedition.getDestLoc());
+		// mExpedition.setDistanceLeft(distLeft);
+		//
+		// // determine if player is close enough to win
+		// if (distLeft < mExpedition.getDistance() * 0.05) {
+		// Leg.a("apart=" + distLeft + " required=" + mExpedition.getDistance()
+		// * 0.05);
+		// mExpedition.setEndTS(System.currentTimeMillis());
+		// mExpedition.setPrize(Treasure.generateReward(mExpedition));
+		//
+		// mSP.setActiveExpeditionID(0);
+		//
+		// mLM.removeUpdates(this);
+		// mSM.unregisterListener(this);
+		//
+		// isAtDest = true;
+		//
+		// showDialog(EXPEDITION_COMPLETE_DIALOG);
+		// }
 
 		// debug info
 		Leg.a("expedition=" + mExpedition.toString());
 		return false;
 	}
 
+	/**************/
+	/** Privates **/
+	/**************/
+
+	private boolean isAtDestination(Location location) {
+		// log remaining distance
+		double distLeft = location.distanceTo(mExpedition.getDestLoc());
+		mExpedition.setDistanceLeft(distLeft);
+
+		// determine if player is close enough to win
+		if (distLeft < mExpedition.getDistance() * 0.05) {
+			Leg.a("apart=" + distLeft + " required=" + mExpedition.getDistance()
+					* 0.05);
+
+			// mExpedition.setEndTS(System.currentTimeMillis());
+			// mExpedition.setPrize(Treasure.generateReward(mExpedition));
+
+			// mSP.setActiveExpeditionID(0);
+			//
+			// mLM.removeUpdates(this);
+			// mSM.unregisterListener(this);
+			//
+			// isAtDest = true;
+			// concludeExpedition();
+
+			// showDialog(EXPEDITION_COMPLETE_DIALOG);
+			return true;
+		}
+		return false;
+	}
+
+	private void concludeExpedition() {
+		mExpedition.setEndTS(System.currentTimeMillis());
+		mSP.setActiveExpeditionID(0);
+
+		mLM.removeUpdates(this);
+		mSM.unregisterListener(this);
+
+		isAtDest = true;
+	}
 }

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

 
 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 org.holoeverywhere.widget.Toast;
 
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.view.MenuItem;
-
+import android.content.ContentValues;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.TextView;
 
+import com.actionbarsherlock.app.ActionBar;
+import com.actionbarsherlock.view.MenuItem;
+
 public class HistoryActivity extends Activity {
 
 	private TextView tvExcuse;
 					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();
+							ContentValues expedition = mAdapter.getItem(pos);
+							// expedition has not concluded yet
+							if (expedition.getAsLong(Expedition.KEY_END_TIMESTAMP) == 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
+								Toast.makeText(HistoryActivity.this,
+										"This expedition has concluded and cannot be continued.",
+										Toast.LENGTH_SHORT).show();
 						} else if (which == 1) {
-							mAdapter.deleteExpedition(pos);
+
+							AlertDialog.Builder builder = new AlertDialog.Builder(
+									HistoryActivity.this);
+
+							builder.setTitle("Delete expedition?")
+									.setMessage("Are you sure you want to delete this record?")
+									.setPositiveButton("Yes", new OnClickListener() {
+										@Override
+										public void onClick(DialogInterface dialog, int which) {
+											mAdapter.deleteExpedition(pos);
+											dialog.dismiss();
+										}
+									}).setNegativeButton("No", new OnClickListener() {
+										@Override
+										public void onClick(DialogInterface dialog, int which) {
+											dialog.dismiss();
+										}
+									});
+
+							builder.create().show();
+
+							// mAdapter.deleteExpedition(pos);
 						}
 
 						dialog.dismiss();

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

 	 * @return
 	 */
 	public static Treasure generateReward(Expedition e) {
-		if (e.getTravelled() < 500D)
+		if (e.getTravelled() < 300D)
 			return null;
 
 		Random rand = new Random();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.