Permalink
Browse files

add option menu

  • Loading branch information...
1 parent 82cfea4 commit e081dec96402b420df4089b487a6735a222af120 @jubal committed Apr 6, 2012
View
@@ -25,18 +25,19 @@
</intent-filter>
</activity>
<activity
- android:name="DriverMainActivity">
+ android:name=".DriverMainActivity">
<intent-filter >
<action android:name="android.intent.action.DriverMainView"/>
+ <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
- android:name="PassengerMainActivity">
+ android:name=".PassengerMainActivity">
<intent-filter >
<action android:name="android.intent.action.PassengerMainView"/>
</intent-filter>
</activity>
- <activity android:name="SettingActivity">
+ <activity android:name=".SettingActivity">
<intent-filter >
<action android:name="android.intent.action.CARSHARINGSETTING"/>
</intent-filter>
@@ -18,6 +18,7 @@
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:text="@string/driver"
/>
<ListView
android:id="@android:id/list"
@@ -12,6 +12,8 @@
<string name="passenger">乘客</string>
<string name="add_passenger">添加乘客</string>
<string name="about">关于</string>
+ <string name="close">关闭</string>
<string name="key_app_mode">AppMode</string>
+ <string name="statement">作者:胡海雷\n单位:盛大文学\n工号:018578\n电话:15214351226</string>
</resources>
@@ -2,13 +2,16 @@
import android.app.Activity;
import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;
@@ -20,11 +23,16 @@
private String mTagString;
private Context mApplicationContext;
- protected static final int MODE_DRIVER = 91;
+ //
+ // option menu tag
+ protected static final int MENU_ABOUT = 91;
+
+ protected static final int MODE_DRIVER = 624;
protected static final int MODE_PASSENGER = MODE_DRIVER + 1;
- protected static final int DIALOG_MODE_SELECTION = 929;
+ protected static final int DIALOG_MODE_SELECTION = 825;
protected static final int DIALOG_EXIT_CONFIRM = DIALOG_MODE_SELECTION + 1;
+ protected static final int DIALOG_ABOUT = DIALOG_EXIT_CONFIRM + 1;
public final static int REQUEST_CODE = 1;
public final static int RESULT_CODE = REQUEST_CODE + 1;
@@ -71,6 +79,25 @@ public void onDestroy(){
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu){
+ menu.add(0, MENU_ABOUT, 0, R.string.about);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu){
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item){
+ if(item.getItemId() == MENU_ABOUT) {
+ showAbout();
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
protected Dialog onCreateDialog(int id){
switch (id) {
case DIALOG_MODE_SELECTION:{
@@ -95,6 +122,20 @@ else if (which == 1){
});
return builder.create();
}
+ case DIALOG_ABOUT:{
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.app_name);
+ builder.setMessage(R.string.statement);
+ builder.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // TODO Auto-generated method stub
+ dismissDialog(DIALOG_ABOUT);
+ }
+ });
+ return builder.create();
+ }
default:
break;
}
@@ -115,7 +156,10 @@ public boolean onKeyDown(int keyCode, KeyEvent event){
log("Back button pressed");
backButtonPressed();
}
- return true;
+
+ //
+ // shoud return false to let it continue to transfer
+ return false;
}
public void backButtonPressed(){
@@ -147,6 +191,10 @@ public void showToast(String content, int duration){
Toast.makeText(getApplicationContext(), content, duration).show();
}
+ public void showAbout() {
+ showDialog(DIALOG_ABOUT);
+ }
+
/*
* Return user's phone number
*/
@@ -4,6 +4,7 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
+import android.view.Menu;
import android.widget.LinearLayout;
import com.google.ads.AdRequest;
@@ -7,8 +7,7 @@
public class DriverMainActivity extends BaseActivity {
- private final int MENU_ADD = 91;
- private final int MENU_ABOUT = MENU_ADD + 1;
+ private final int MENU_ADD = MENU_ABOUT + 1;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -27,21 +26,23 @@ public void backButtonPressed(){
@Override
public boolean onCreateOptionsMenu(Menu menu){
- showToast("Menu button pressed");
menu.add(0, MENU_ADD, 0, R.string.add_passenger);
- menu.add(0, MENU_ABOUT, 0, R.string.about);
return super.onCreateOptionsMenu(menu);
}
@Override
+ public boolean onPrepareOptionsMenu(Menu menu){
+ log("Menu button pressed");
+ return super.onPrepareOptionsMenu(menu);
+ }
+
+ @Override
public boolean onOptionsItemSelected(MenuItem item){
+ log("Options item selected " + item.getItemId());
if (item.getItemId() == MENU_ADD) {
}
- else if(item.getItemId() == MENU_ABOUT) {
-
- }
- return true;
+ return super.onOptionsItemSelected(item);
}
}

0 comments on commit e081dec

Please sign in to comment.