Commits

littledot5566 committed 4eb439c

*Added confirm quit dialog.

Comments (0)

Files changed (1)

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

 import nctuw.littledot.util.Leg;
 
 import org.holoeverywhere.app.Activity;
+import org.holoeverywhere.app.AlertDialog;
 
 import android.app.Dialog;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
+import android.view.KeyEvent;
 import android.view.View;
 import android.widget.Button;
 import android.widget.TextView;
 			startActivity(intent);
 		}
 	}
+
+	@Override
+	public boolean onKeyDown(int keyCode, KeyEvent event) {
+		// Handle the back button
+		if (keyCode == KeyEvent.KEYCODE_BACK && isTaskRoot()) {
+			// Ask the user if they want to quit
+			new AlertDialog.Builder(this)
+					.setTitle("Goodbye  ( ´ ▽ ` )ノ")
+					.setMessage("Would you like to exit the application?")
+					.setPositiveButton("Yes",
+							new DialogInterface.OnClickListener() {
+								public void onClick(DialogInterface dialog, int which) {
+									// Stop the activity
+									finish();
+								}
+							})
+					.setNegativeButton("no", null)
+					.show();
+
+			return true;
+		}
+		return super.onKeyDown(keyCode, event);
+	}
 }