diff options
author | rsudev <rasch@munin-soft.de> | 2014-11-27 21:20:41 +0100 |
---|---|---|
committer | rsudev <rasch@munin-soft.de> | 2014-11-27 21:20:41 +0100 |
commit | b568a4393e9797861dbffaf9b016049c101078ff (patch) | |
tree | 6ecc87d8de1b8acee9a2c383189bc783de2f16d5 | |
parent | ac4e7f683649183d11a1e2f732fc05b5dae9b4f5 (diff) | |
download | cgeo-b568a4393e9797861dbffaf9b016049c101078ff.zip cgeo-b568a4393e9797861dbffaf9b016049c101078ff.tar.gz cgeo-b568a4393e9797861dbffaf9b016049c101078ff.tar.bz2 |
Fix #4247, No action bar on map activities on Android 3.x
Enable 2.x implementation for 3.x. as well.
Additionally fix options menu for 3.x
-rw-r--r-- | main/res/layout-v11/actionbar_maps.xml | 54 | ||||
-rw-r--r-- | main/res/layout-v14/actionbar_maps.xml | 7 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/maps/AbstractMap.java | 12 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 46 |
4 files changed, 107 insertions, 12 deletions
diff --git a/main/res/layout-v11/actionbar_maps.xml b/main/res/layout-v11/actionbar_maps.xml index 3e72717..ee77673 100644 --- a/main/res/layout-v11/actionbar_maps.xml +++ b/main/res/layout-v11/actionbar_maps.xml @@ -1,7 +1,53 @@ <?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + style="@style/action_bar" > - <!-- Empty layout, on 11+ we have a real action bar --> -<merge xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" android:layout_height="match_parent"> + <!-- Add the up chevron to the icon --> -</merge>
\ No newline at end of file + <ImageView + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:src="@drawable/abc_ic_ab_back_holo_dark" /> + + <ImageView + style="@style/action_bar_action" + android:layout_marginLeft="-13dp" + android:onClick="navigateUp" /> + + <View style="@style/action_bar_separator" /> + + <TextView + android:id="@+id/actionbar_title" + style="@style/action_bar_title" + tools:ignore="InconsistentLayout" /> + + <ProgressBar + android:id="@+id/actionbar_progress" + style="@style/action_bar_progress" + android:visibility="gone" + tools:ignore="InconsistentLayout" /> + + <View style="@style/action_bar_separator" /> + + <FrameLayout style="@style/action_bar_action" > + + <CheckBox + android:id="@+id/my_position" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="right" + android:button="@drawable/ic_menu_myposition" + android:checked="false" + tools:ignore="InconsistentLayout" /> + </FrameLayout> + + <View style="@style/action_bar_separator" /> + + <ImageView + android:id="@+id/overflowActionBar" + style="@style/action_bar_action" + android:longClickable="true" + android:src="@drawable/abc_ic_menu_moreoverflow_normal_holo_dark" /> + +</LinearLayout>
\ No newline at end of file diff --git a/main/res/layout-v14/actionbar_maps.xml b/main/res/layout-v14/actionbar_maps.xml new file mode 100644 index 0000000..7ee9b51 --- /dev/null +++ b/main/res/layout-v14/actionbar_maps.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> + + <!-- Empty layout, on 14+ we have a real and working action bar --> +<merge xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" android:layout_height="match_parent"> + +</merge>
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/maps/AbstractMap.java b/main/src/cgeo/geocaching/maps/AbstractMap.java index 2eceadb..f62fb3a 100644 --- a/main/src/cgeo/geocaching/maps/AbstractMap.java +++ b/main/src/cgeo/geocaching/maps/AbstractMap.java @@ -19,7 +19,7 @@ public abstract class AbstractMap { MapActivityImpl mapActivity; - protected AbstractMap(MapActivityImpl activity) { + protected AbstractMap(final MapActivityImpl activity) { mapActivity = activity; } @@ -31,10 +31,10 @@ public abstract class AbstractMap { return mapActivity.getActivity(); } - public void onCreate(Bundle savedInstanceState) { + public void onCreate(final Bundle savedInstanceState) { mapActivity.superOnCreate(savedInstanceState); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mapActivity.getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); } } @@ -55,17 +55,17 @@ public abstract class AbstractMap { mapActivity.superOnDestroy(); } - public boolean onCreateOptionsMenu(Menu menu) { + public boolean onCreateOptionsMenu(final Menu menu) { final boolean result = mapActivity.superOnCreateOptionsMenu(menu); mapActivity.getActivity().getMenuInflater().inflate(R.menu.map_activity, menu); return result; } - public boolean onPrepareOptionsMenu(Menu menu) { + public boolean onPrepareOptionsMenu(final Menu menu) { return mapActivity.superOnPrepareOptionsMenu(menu); } - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(final MenuItem item) { return mapActivity.superOnOptionsItemSelected(item); } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 292808d..2868679 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -67,6 +67,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; @@ -182,6 +183,8 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private boolean centered = false; // if map is already centered private boolean alreadyCentered = false; // -""- for setting my location private static final Set<String> dirtyCaches = new HashSet<>(); + // flag for honeycomb special popup menu handling + private boolean honeycombMenu = false; /** * if live map is enabled, this is the minimum zoom level, independent of the stored setting @@ -476,6 +479,18 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } prepareFilterBar(); + // Check for Honeycomb fake overflow button and attach popup + final View overflowActionBar = ButterKnife.findById(activity, R.id.overflowActionBar); + if (overflowActionBar != null) { + honeycombMenu = true; + overflowActionBar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + showPopupHoneycomb(v); + } + }); + } + if (!app.isLiveMapHintShownInThisSession() && Settings.getLiveMapHintShowCount() <= 3) { LiveMapInfoDialogBuilder.create(activity).show(); } @@ -563,10 +578,37 @@ public class CGeoMap extends AbstractMap implements ViewFactory { } @TargetApi(Build.VERSION_CODES.HONEYCOMB) + private void showPopupHoneycomb(final View view) { + // Inflate the core menu ourselves + final android.widget.PopupMenu popupMenu = new android.widget.PopupMenu(getActivity(), view); + final MenuInflater inflater = new MenuInflater(getActivity()); + inflater.inflate(R.menu.map_activity, popupMenu.getMenu()); + + // continue processing menu items as usual + onCreateOptionsMenu(popupMenu.getMenu()); + + onPrepareOptionsMenu(popupMenu.getMenu()); + + popupMenu.setOnMenuItemClickListener( + new android.widget.PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(final MenuItem item) { + return onOptionsItemSelected(item); + } + } + ); + // display menu + popupMenu.show(); + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public boolean onCreateOptionsMenu(final Menu menu) { // menu inflation happens in Google/Mapsforge specific classes - super.onCreateOptionsMenu(menu); + // skip it for honeycomb - handled specially in @see showPopupHoneycomb + if (!honeycombMenu) { + super.onCreateOptionsMenu(menu); + } MapProviderFactory.addMapviewMenuItems(menu); @@ -574,7 +616,7 @@ public class CGeoMap extends AbstractMap implements ViewFactory { subMenuStrategy.setHeaderTitle(res.getString(R.string.map_strategy_title)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { /* if we have an Actionbar find the my position toggle */ final MenuItem item = menu.findItem(R.id.menu_toggle_mypos); myLocSwitch = new CheckBox(activity); |