diff --git a/android/res/menu/main.xml b/android/res/menu/main.xml index 69ad8a23e5..b7846158c0 100644 --- a/android/res/menu/main.xml +++ b/android/res/menu/main.xml @@ -2,8 +2,11 @@ + android:icon="@drawable/ic_menu_about" + android:showAsAction="ifRoom"/> + + android:icon="@android:drawable/ic_menu_preferences" + android:showAsAction="ifRoom"/> diff --git a/android/src/com/mapswithme/maps/ContextMenu.java b/android/src/com/mapswithme/maps/ContextMenu.java new file mode 100644 index 0000000000..d4c53e39e8 --- /dev/null +++ b/android/src/com/mapswithme/maps/ContextMenu.java @@ -0,0 +1,64 @@ +package com.mapswithme.maps; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.webkit.WebView; + + +public class ContextMenu +{ + private static void onAboutDialogClicked(Activity parent) + { + LayoutInflater inflater = LayoutInflater.from(parent); + + View alertDialogView = inflater.inflate(R.layout.about, null); + WebView myWebView = (WebView) alertDialogView.findViewById(R.id.webview_about); + myWebView.loadUrl("file:///android_asset/about.html"); + + new AlertDialog.Builder(parent) + .setView(alertDialogView) + .setTitle(R.string.about) + .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) + { + dialog.cancel(); + } + }) + .show(); + } + + private static void onSettingsClicked(Activity parent) + { + parent.startActivity(new Intent(parent, SettingsActivity.class)); + } + + public static boolean onCreateOptionsMenu(Activity parent, Menu menu) + { + MenuInflater inflater = parent.getMenuInflater(); + inflater.inflate(R.menu.main, menu); + return true; + } + + public static boolean onOptionsItemSelected(Activity parent, MenuItem item) + { + final int id = item.getItemId(); + + if (id == R.id.menuitem_about_dialog) + onAboutDialogClicked(parent); + else if (id == R.id.menuitem_settings_activity) + onSettingsClicked(parent); + else + return false; + + return true; + } +} diff --git a/android/src/com/mapswithme/maps/DownloadUI.java b/android/src/com/mapswithme/maps/DownloadUI.java index 4c6a0189ec..6512a005dd 100644 --- a/android/src/com/mapswithme/maps/DownloadUI.java +++ b/android/src/com/mapswithme/maps/DownloadUI.java @@ -13,6 +13,8 @@ import android.os.StatFs; import android.provider.Settings; import android.util.Log; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; @@ -704,4 +706,19 @@ public class DownloadUI extends ListActivity implements MapStorage.Listener { getDA().onCountryProgress(getListView(), idx, current, total); } + + @Override + public boolean onCreateOptionsMenu(Menu menu) + { + return ContextMenu.onCreateOptionsMenu(this, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) + { + if (ContextMenu.onOptionsItemSelected(this, item)) + return true; + else + return super.onOptionsItemSelected(item); + } } diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 6ca926aa90..c199f9cb79 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -18,12 +18,9 @@ import android.os.Environment; import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.util.Log; -import android.view.LayoutInflater; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.webkit.WebView; import android.widget.LinearLayout; import com.mapswithme.maps.location.LocationService; @@ -622,51 +619,16 @@ public class MWMActivity extends NvEventQueueActivity implements LocationService @Override public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.main, menu); - return true; + return ContextMenu.onCreateOptionsMenu(this, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { - final int id = item.getItemId(); - - if (id == R.id.menuitem_about_dialog) - onAboutDialogClicked(); - else if (id == R.id.menuitem_settings_activity) - onSettingsClicked(); + if (ContextMenu.onOptionsItemSelected(this, item)) + return true; else return super.onOptionsItemSelected(item); - - return true; - } - - private void onAboutDialogClicked() - { - LayoutInflater inflater = LayoutInflater.from(this); - - View alertDialogView = inflater.inflate(R.layout.about, null); - WebView myWebView = (WebView) alertDialogView.findViewById(R.id.webview_about); - myWebView.loadUrl("file:///android_asset/about.html"); - - new AlertDialog.Builder(this) - .setView(alertDialogView) - .setTitle(R.string.about) - .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() - { - @Override - public void onClick(DialogInterface dialog, int which) - { - dialog.cancel(); - } - }) - .show(); - } - - private void onSettingsClicked() - { - startActivity(new Intent(this, SettingsActivity.class)); } // Initialized to invalid combination to force update on the first check