Fixed menu for configure screen.
This commit is contained in:
parent
2c74e887a1
commit
5bde48b2e6
7 changed files with 238 additions and 51 deletions
|
@ -19,11 +19,17 @@
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
tools:src="@drawable/ic_action_gabout_dark"/>
|
tools:src="@drawable/ic_action_gabout_dark"/>
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/text_wrapper"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.v7.widget.AppCompatTextView
|
<android.support.v7.widget.AppCompatTextView
|
||||||
|
@ -41,6 +47,7 @@
|
||||||
tools:text="Some title text"/>
|
tools:text="Some title text"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<android.support.v7.widget.AppCompatImageView
|
<android.support.v7.widget.AppCompatImageView
|
||||||
android:id="@+id/secondary_icon"
|
android:id="@+id/secondary_icon"
|
||||||
|
|
|
@ -118,6 +118,18 @@
|
||||||
<item name="contextMenuButtonColor">@color/map_widget_blue</item>
|
<item name="contextMenuButtonColor">@color/map_widget_blue</item>
|
||||||
|
|
||||||
<item name="color_dialog_buttons">@color/color_dialog_buttons_light</item>
|
<item name="color_dialog_buttons">@color/color_dialog_buttons_light</item>
|
||||||
|
|
||||||
|
<item name="popupMenuStyle">@style/PopupMenuLight</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="PopupMenuLight" parent="@style/Widget.AppCompat.Light.PopupMenu">
|
||||||
|
<item name="overlapAnchor">true</item>'
|
||||||
|
<item name="android:dropDownVerticalOffset">8dip</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="PopupMenuDark" parent="@style/Widget.AppCompat.PopupMenu">
|
||||||
|
<item name="overlapAnchor">true</item>'
|
||||||
|
<item name="android:dropDownVerticalOffset">8dip</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="OsmandLightTheme.NoActionbar">
|
<style name="OsmandLightTheme.NoActionbar">
|
||||||
|
@ -237,6 +249,8 @@
|
||||||
|
|
||||||
<item name="contextMenuButtonColor">@color/osmand_orange</item>
|
<item name="contextMenuButtonColor">@color/osmand_orange</item>
|
||||||
<item name="color_dialog_buttons">@color/color_dialog_buttons_dark</item>
|
<item name="color_dialog_buttons">@color/color_dialog_buttons_dark</item>
|
||||||
|
|
||||||
|
<item name="popupMenuStyle">@style/PopupMenuDark</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="FreeVersionBanner" parent="OsmandDarkTheme">
|
<style name="FreeVersionBanner" parent="OsmandDarkTheme">
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.support.annotation.ColorRes;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||||
|
|
||||||
|
@ -127,6 +128,14 @@ public class IconsCache {
|
||||||
return drawable;
|
return drawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void paintMenuItem(Context context, MenuItem menuItem) {
|
||||||
|
Drawable drawable = menuItem.getIcon();
|
||||||
|
drawable = DrawableCompat.wrap(drawable);
|
||||||
|
drawable.mutate();
|
||||||
|
int color = ContextCompat.getColor(context, getDefaultColorRes(context));
|
||||||
|
DrawableCompat.setTint(drawable, color);
|
||||||
|
}
|
||||||
|
|
||||||
@ColorRes
|
@ColorRes
|
||||||
public static int getDefaultColorRes(Context context) {
|
public static int getDefaultColorRes(Context context) {
|
||||||
final OsmandApplication app = (OsmandApplication) context.getApplicationContext();
|
final OsmandApplication app = (OsmandApplication) context.getApplicationContext();
|
||||||
|
|
|
@ -7,8 +7,6 @@ import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.PopupMenu;
|
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -28,6 +26,7 @@ import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||||
import net.osmand.plus.views.MapInfoLayer;
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
import net.osmand.plus.widgets.IconPopupMenu;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -383,10 +382,15 @@ public class MapWidgetRegistry {
|
||||||
final View view,
|
final View view,
|
||||||
final int itemId,
|
final int itemId,
|
||||||
final int pos) {
|
final int pos) {
|
||||||
PopupMenu popup = new PopupMenu(view.getContext(), view, Gravity.CENTER_VERTICAL);
|
View textWrapper = view.findViewById(R.id.text_wrapper);
|
||||||
|
IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper);
|
||||||
MenuInflater inflater = popup.getMenuInflater();
|
MenuInflater inflater = popup.getMenuInflater();
|
||||||
inflater.inflate(R.menu.vidget_visibility_menu, popup.getMenu());
|
inflater.inflate(R.menu.vidget_visibility_menu, popup.getMenu());
|
||||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_show));
|
||||||
|
IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_hide));
|
||||||
|
IconsCache.paintMenuItem(mapActivity, popup.getMenu().findItem(R.id.action_collapse));
|
||||||
|
popup.setOnMenuItemClickListener(
|
||||||
|
new IconPopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
public boolean onMenuItemClick(MenuItem menuItem) {
|
||||||
|
|
||||||
|
|
|
@ -2,17 +2,10 @@ package net.osmand.plus.widgets;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
@Deprecated
|
||||||
import net.osmand.plus.helpers.FontCache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Alexey Pelykh on 30.01.2015.
|
|
||||||
*/
|
|
||||||
public class ButtonEx extends Button {
|
public class ButtonEx extends Button {
|
||||||
public ButtonEx(Context context) {
|
public ButtonEx(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
167
OsmAnd/src/net/osmand/plus/widgets/IconPopupMenu.java
Normal file
167
OsmAnd/src/net/osmand/plus/widgets/IconPopupMenu.java
Normal file
|
@ -0,0 +1,167 @@
|
||||||
|
package net.osmand.plus.widgets;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.view.SupportMenuInflater;
|
||||||
|
import android.support.v7.view.menu.MenuBuilder;
|
||||||
|
import android.support.v7.view.menu.MenuPopupHelper;
|
||||||
|
import android.support.v7.view.menu.MenuPresenter;
|
||||||
|
import android.support.v7.view.menu.SubMenuBuilder;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copied from android.support.v7.widget.PopupMenu.
|
||||||
|
* "mPopup.setForceShowIcon(true);" in the constructor does the trick :)
|
||||||
|
*
|
||||||
|
* @author maikvlcek
|
||||||
|
* @since 5:00 PM - 1/27/14
|
||||||
|
*/
|
||||||
|
public class IconPopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback {
|
||||||
|
private Context mContext;
|
||||||
|
private MenuBuilder mMenu;
|
||||||
|
private View mAnchor;
|
||||||
|
private MenuPopupHelper mPopup;
|
||||||
|
private OnMenuItemClickListener mMenuItemClickListener;
|
||||||
|
private OnDismissListener mDismissListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback interface used to notify the application that the menu has closed.
|
||||||
|
*/
|
||||||
|
public interface OnDismissListener {
|
||||||
|
/**
|
||||||
|
* Called when the associated menu has been dismissed.
|
||||||
|
*
|
||||||
|
* @param menu The PopupMenu that was dismissed.
|
||||||
|
*/
|
||||||
|
void onDismiss(IconPopupMenu menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new PopupMenu.
|
||||||
|
*
|
||||||
|
* @param context Context for the PopupMenu.
|
||||||
|
* @param anchor Anchor view for this popup. The popup will appear below the anchor if there
|
||||||
|
* is room, or above it if there is not.
|
||||||
|
*/
|
||||||
|
public IconPopupMenu(Context context, View anchor) {
|
||||||
|
mContext = context;
|
||||||
|
mMenu = new MenuBuilder(context);
|
||||||
|
mMenu.setCallback(this);
|
||||||
|
mAnchor = anchor;
|
||||||
|
mPopup = new MenuPopupHelper(context, mMenu, anchor);
|
||||||
|
mPopup.setCallback(this);
|
||||||
|
mPopup.setForceShowIcon(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the {@link android.view.Menu} associated with this popup. Populate the returned Menu with
|
||||||
|
* items before calling {@link #show()}.
|
||||||
|
* @see #show()
|
||||||
|
* @see #getMenuInflater()
|
||||||
|
*/
|
||||||
|
public Menu getMenu() {
|
||||||
|
return mMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a {@link android.view.MenuInflater} that can be used to inflate menu items from XML into the
|
||||||
|
* menu returned by {@link #getMenu()}.
|
||||||
|
* @see #getMenu()
|
||||||
|
*/
|
||||||
|
public MenuInflater getMenuInflater() {
|
||||||
|
return new SupportMenuInflater(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inflate a menu resource into this PopupMenu. This is equivalent to calling
|
||||||
|
* popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu()).
|
||||||
|
*
|
||||||
|
* @param menuRes Menu resource to inflate
|
||||||
|
*/
|
||||||
|
public void inflate(int menuRes) {
|
||||||
|
getMenuInflater().inflate(menuRes, mMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the menu popup anchored to the view specified during construction.
|
||||||
|
*
|
||||||
|
* @see #dismiss()
|
||||||
|
*/
|
||||||
|
public void show() {
|
||||||
|
mPopup.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dismiss the menu popup.
|
||||||
|
*
|
||||||
|
* @see #show()
|
||||||
|
*/
|
||||||
|
public void dismiss() {
|
||||||
|
mPopup.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a listener that will be notified when the user selects an item from the menu.
|
||||||
|
*
|
||||||
|
* @param listener Listener to notify
|
||||||
|
*/
|
||||||
|
public void setOnMenuItemClickListener(OnMenuItemClickListener listener) {
|
||||||
|
mMenuItemClickListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a listener that will be notified when this menu is dismissed.
|
||||||
|
*
|
||||||
|
* @param listener Listener to notify
|
||||||
|
*/
|
||||||
|
public void setOnDismissListener(OnDismissListener listener) {
|
||||||
|
mDismissListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
|
||||||
|
return mMenuItemClickListener != null && mMenuItemClickListener.onMenuItemClick(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
|
||||||
|
if (mDismissListener != null) {
|
||||||
|
mDismissListener.onDismiss(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onOpenSubMenu(MenuBuilder subMenu) {
|
||||||
|
if (subMenu == null) return false;
|
||||||
|
|
||||||
|
if (!subMenu.hasVisibleItems()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Current menu will be dismissed by the normal helper, submenu will be shown in its place.
|
||||||
|
MenuPopupHelper menuPopupHelper = new MenuPopupHelper(mContext, subMenu, mAnchor);
|
||||||
|
menuPopupHelper.show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCloseSubMenu(SubMenuBuilder menu) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onMenuModeChange(MenuBuilder menu) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface responsible for receiving menu item click events if the items themselves
|
||||||
|
* do not have individual item click listeners.
|
||||||
|
*/
|
||||||
|
public interface OnMenuItemClickListener {
|
||||||
|
/**
|
||||||
|
* This method will be invoked when a menu item is clicked if the item itself did
|
||||||
|
* not already handle the event.
|
||||||
|
*
|
||||||
|
* @param item {@link MenuItem} that was clicked
|
||||||
|
* @return <code>true</code> if the event was handled, <code>false</code> otherwise.
|
||||||
|
*/
|
||||||
|
boolean onMenuItemClick(MenuItem item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,17 +2,10 @@ package net.osmand.plus.widgets;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
@Deprecated
|
||||||
import net.osmand.plus.helpers.FontCache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Alexey Pelykh on 02.02.2015.
|
|
||||||
*/
|
|
||||||
public class SwitchEx extends ToggleButton {
|
public class SwitchEx extends ToggleButton {
|
||||||
public SwitchEx(Context context) {
|
public SwitchEx(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
Loading…
Reference in a new issue