Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
abb8cfa3e8
7 changed files with 268 additions and 55 deletions
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.plus.mapcontextmenu;
|
package net.osmand.plus.mapcontextmenu;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
|
@ -14,11 +15,14 @@ import net.osmand.data.PointDescription;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
|
import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
import net.osmand.plus.mapcontextmenu.sections.AmenityInfoMenuController;
|
import net.osmand.plus.mapcontextmenu.sections.AmenityInfoMenuController;
|
||||||
|
import net.osmand.plus.mapcontextmenu.sections.FavouritePointMenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.sections.MenuController;
|
import net.osmand.plus.mapcontextmenu.sections.MenuController;
|
||||||
import net.osmand.plus.render.RenderingIcons;
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
|
@ -35,8 +39,10 @@ public class MapContextMenu {
|
||||||
private Object object;
|
private Object object;
|
||||||
|
|
||||||
private int leftIconId;
|
private int leftIconId;
|
||||||
|
private Drawable leftIcon;
|
||||||
private String nameStr;
|
private String nameStr;
|
||||||
private String typeStr;
|
private String typeStr;
|
||||||
|
private Drawable secondLineIcon;
|
||||||
private String streetStr;
|
private String streetStr;
|
||||||
|
|
||||||
private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object";
|
private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object";
|
||||||
|
@ -79,9 +85,9 @@ public class MapContextMenu {
|
||||||
typeStr = null;
|
typeStr = null;
|
||||||
streetStr = null;
|
streetStr = null;
|
||||||
|
|
||||||
acquireLeftIcon();
|
acquireIcons();
|
||||||
acquireNameAndType();
|
acquireNameAndType();
|
||||||
if (object != null || Algorithms.isEmpty(pointDescription.getName())) {
|
if (needStreetName()) {
|
||||||
acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -105,6 +111,26 @@ public class MapContextMenu {
|
||||||
fragment.dismissMenu();
|
fragment.dismissMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean needStreetName() {
|
||||||
|
boolean res = object != null || Algorithms.isEmpty(pointDescription.getName());
|
||||||
|
if (res) {
|
||||||
|
if (object != null) {
|
||||||
|
if (object instanceof Amenity) {
|
||||||
|
Amenity a = (Amenity) object;
|
||||||
|
if (a.getSubType() != null && a.getType() != null) {
|
||||||
|
PoiType pt = a.getType().getPoiTypeByKeyName(a.getSubType());
|
||||||
|
if (pt != null && pt.getOsmTag().equals("place")) {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (object instanceof FavouritePoint) {
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
public void refreshMenuTitle() {
|
public void refreshMenuTitle() {
|
||||||
MapContextMenuFragment fragment = findMenuFragment();
|
MapContextMenuFragment fragment = findMenuFragment();
|
||||||
if (fragment != null)
|
if (fragment != null)
|
||||||
|
@ -123,19 +149,35 @@ public class MapContextMenu {
|
||||||
return leftIconId;
|
return leftIconId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Drawable getLeftIcon() {
|
||||||
|
return leftIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable getSecondLineIcon() {
|
||||||
|
return secondLineIcon;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitleStr() {
|
public String getTitleStr() {
|
||||||
return nameStr;
|
return nameStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocationStr() {
|
public String getLocationStr() {
|
||||||
if (Algorithms.isEmpty(streetStr))
|
if (object != null && object instanceof FavouritePoint) {
|
||||||
|
return typeStr;
|
||||||
|
} else {
|
||||||
|
if (Algorithms.isEmpty(streetStr)) {
|
||||||
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
|
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
|
||||||
else
|
} else {
|
||||||
return streetStr;
|
return streetStr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void acquireLeftIcon() {
|
private void acquireIcons() {
|
||||||
leftIconId = 0;
|
leftIconId = 0;
|
||||||
|
leftIcon = null;
|
||||||
|
secondLineIcon = null;
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
if (object instanceof Amenity) {
|
if (object instanceof Amenity) {
|
||||||
String id = null;
|
String id = null;
|
||||||
|
@ -151,10 +193,21 @@ public class MapContextMenu {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
leftIconId = RenderingIcons.getBigIconResourceId(id);
|
leftIconId = RenderingIcons.getBigIconResourceId(id);
|
||||||
}
|
}
|
||||||
|
} else if (object instanceof FavouritePoint) {
|
||||||
|
FavouritePoint fav = (FavouritePoint)object;
|
||||||
|
leftIcon = FavoriteImageDrawable.getOrCreate(mapActivity, fav.getColor(), mapActivity.getMapView().getCurrentRotatedTileBox().getDensity());
|
||||||
|
secondLineIcon = getIcon(R.drawable.ic_small_group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Drawable getIcon(int iconId) {
|
||||||
|
IconsCache iconsCache = app.getIconsCache();
|
||||||
|
boolean light = app.getSettings().isLightContent();
|
||||||
|
return iconsCache.getIcon(iconId,
|
||||||
|
light ? R.color.icon_color : R.color.icon_color_light);
|
||||||
|
}
|
||||||
|
|
||||||
private void acquireNameAndType() {
|
private void acquireNameAndType() {
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
if (object instanceof Amenity) {
|
if (object instanceof Amenity) {
|
||||||
|
@ -169,6 +222,10 @@ public class MapContextMenu {
|
||||||
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
|
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
|
||||||
}
|
}
|
||||||
nameStr = amenity.getName(settings.MAP_PREFERRED_LOCALE.get());
|
nameStr = amenity.getName(settings.MAP_PREFERRED_LOCALE.get());
|
||||||
|
} else if (object instanceof FavouritePoint) {
|
||||||
|
FavouritePoint fav = (FavouritePoint)object;
|
||||||
|
nameStr = fav.getName();
|
||||||
|
typeStr = fav.getCategory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,19 +287,21 @@ public class MapContextMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuController getMenuController(Activity activity) {
|
public MenuController getMenuController(Activity activity) {
|
||||||
|
MenuController menuController = null;
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
if (object instanceof Amenity) {
|
if (object instanceof Amenity) {
|
||||||
MenuController menuController = new AmenityInfoMenuController(app, activity, (Amenity)object);
|
menuController = new AmenityInfoMenuController(app, activity, (Amenity)object);
|
||||||
if (!Algorithms.isEmpty(typeStr)) {
|
if (!Algorithms.isEmpty(typeStr)) {
|
||||||
menuController.addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
|
menuController.addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
|
||||||
}
|
}
|
||||||
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(activity, true).replaceAll("\n", ""));
|
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(activity, true).replaceAll("\n", ""));
|
||||||
return menuController;
|
} else if (object instanceof FavouritePoint) {
|
||||||
|
menuController = new FavouritePointMenuController(app, activity, (FavouritePoint)object);
|
||||||
|
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(activity, true).replaceAll("\n", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return menuController;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buttonNavigatePressed() {
|
public void buttonNavigatePressed() {
|
||||||
|
@ -300,6 +359,6 @@ public class MapContextMenu {
|
||||||
if (streetStrObj != null) {
|
if (streetStrObj != null) {
|
||||||
streetStr = streetStrObj.toString();
|
streetStr = streetStrObj.toString();
|
||||||
}
|
}
|
||||||
acquireLeftIcon();
|
acquireIcons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -318,17 +319,18 @@ public class MapContextMenuFragment extends Fragment {
|
||||||
IconsCache iconsCache = getMyApplication().getIconsCache();
|
IconsCache iconsCache = getMyApplication().getIconsCache();
|
||||||
boolean light = getMyApplication().getSettings().isLightContent();
|
boolean light = getMyApplication().getSettings().isLightContent();
|
||||||
|
|
||||||
int iconId = getCtxMenu().getLeftIconId();
|
|
||||||
|
|
||||||
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
|
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
|
||||||
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
|
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
|
||||||
if (iconId == 0) {
|
Drawable icon = getCtxMenu().getLeftIcon();
|
||||||
iconLayout.setVisibility(View.GONE);
|
int iconId = getCtxMenu().getLeftIconId();
|
||||||
} else {
|
if (icon != null) {
|
||||||
|
iconView.setImageDrawable(icon);
|
||||||
|
} else if (iconId != 0) {
|
||||||
iconView.setImageDrawable(iconsCache.getIcon(iconId,
|
iconView.setImageDrawable(iconsCache.getIcon(iconId,
|
||||||
light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f));
|
light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f));
|
||||||
|
} else {
|
||||||
|
iconLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAddressLocation();
|
setAddressLocation();
|
||||||
|
|
||||||
// Close button
|
// Close button
|
||||||
|
@ -434,6 +436,11 @@ public class MapContextMenuFragment extends Fragment {
|
||||||
// Text line 2
|
// Text line 2
|
||||||
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
||||||
line2.setText(getCtxMenu().getLocationStr());
|
line2.setText(getCtxMenu().getLocationStr());
|
||||||
|
Drawable icon = getCtxMenu().getSecondLineIcon();
|
||||||
|
if (icon != null) {
|
||||||
|
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||||
|
line2.setCompoundDrawablePadding(dpToPx(5f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPosY() {
|
private int getPosY() {
|
||||||
|
|
|
@ -29,7 +29,6 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||||
|
|
||||||
public class AmenityInfoMenuBuilder extends MenuBuilder {
|
public class AmenityInfoMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
boolean firstRow;
|
|
||||||
private final Amenity amenity;
|
private final Amenity amenity;
|
||||||
|
|
||||||
public AmenityInfoMenuBuilder(OsmandApplication app, final Amenity amenity) {
|
public AmenityInfoMenuBuilder(OsmandApplication app, final Amenity amenity) {
|
||||||
|
@ -53,13 +52,13 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
||||||
// Icon
|
// Icon
|
||||||
LinearLayout llIcon = new LinearLayout(view.getContext());
|
LinearLayout llIcon = new LinearLayout(view.getContext());
|
||||||
llIcon.setOrientation(LinearLayout.HORIZONTAL);
|
llIcon.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), firstRow ? dpToPx(48f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(48f)));
|
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), isFirstRow() ? dpToPx(48f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(48f)));
|
||||||
llIcon.setGravity(Gravity.CENTER_VERTICAL);
|
llIcon.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
ll.addView(llIcon);
|
ll.addView(llIcon);
|
||||||
|
|
||||||
ImageView iconView = new ImageView(view.getContext());
|
ImageView iconView = new ImageView(view.getContext());
|
||||||
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
llIconParams.setMargins(dpToPx(16f), firstRow ? dpToPx(12f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP / 2f) : dpToPx(12f), dpToPx(32f), dpToPx(12f));
|
llIconParams.setMargins(dpToPx(16f), isFirstRow() ? dpToPx(12f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP / 2f) : dpToPx(12f), dpToPx(32f), dpToPx(12f));
|
||||||
llIconParams.gravity = Gravity.CENTER_VERTICAL;
|
llIconParams.gravity = Gravity.CENTER_VERTICAL;
|
||||||
iconView.setLayoutParams(llIconParams);
|
iconView.setLayoutParams(llIconParams);
|
||||||
iconView.setScaleType(ImageView.ScaleType.CENTER);
|
iconView.setScaleType(ImageView.ScaleType.CENTER);
|
||||||
|
@ -73,7 +72,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
TextView textView = new TextView(view.getContext());
|
TextView textView = new TextView(view.getContext());
|
||||||
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
llTextParams.setMargins(0, firstRow ? dpToPx(8f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(8f), 0, dpToPx(8f));
|
llTextParams.setMargins(0, isFirstRow() ? dpToPx(8f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(8f), 0, dpToPx(8f));
|
||||||
textView.setLayoutParams(llTextParams);
|
textView.setLayoutParams(llTextParams);
|
||||||
textView.setTextSize(16); // todo: create constant
|
textView.setTextSize(16); // todo: create constant
|
||||||
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
|
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
|
||||||
|
@ -114,7 +113,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
((LinearLayout) view).addView(horizontalLine);
|
((LinearLayout) view).addView(horizontalLine);
|
||||||
|
|
||||||
firstRow = false;
|
rowBuilt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int dpToPx(float dp) {
|
public int dpToPx(float dp) {
|
||||||
|
@ -128,8 +127,8 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build(View view) {
|
public void build(View view) {
|
||||||
|
super.build(view);
|
||||||
|
|
||||||
firstRow = true;
|
|
||||||
boolean hasWiki = false;
|
boolean hasWiki = false;
|
||||||
|
|
||||||
for (PlainMenuItem item : plainMenuItems) {
|
for (PlainMenuItem item : plainMenuItems) {
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
package net.osmand.plus.mapcontextmenu.sections;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.data.FavouritePoint;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||||
|
|
||||||
|
public class FavouritePointMenuBuilder extends MenuBuilder {
|
||||||
|
|
||||||
|
private final FavouritePoint fav;
|
||||||
|
|
||||||
|
public FavouritePointMenuBuilder(OsmandApplication app, final FavouritePoint fav) {
|
||||||
|
super(app);
|
||||||
|
this.fav = fav;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildRow(View view, int iconId, String text, int textColor, boolean isDescription) {
|
||||||
|
buildRow(view, getRowIcon(iconId), text, textColor, isDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildRow(final View view, Drawable icon, String text, int textColor, final boolean isDescription) {
|
||||||
|
boolean light = app.getSettings().isLightContent();
|
||||||
|
|
||||||
|
LinearLayout ll = new LinearLayout(view.getContext());
|
||||||
|
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
//llParams.setMargins(0, dpToPx(14f), 0, dpToPx(14f));
|
||||||
|
ll.setLayoutParams(llParams);
|
||||||
|
|
||||||
|
// Icon
|
||||||
|
LinearLayout llIcon = new LinearLayout(view.getContext());
|
||||||
|
llIcon.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), isFirstRow() ? dpToPx(48f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(48f)));
|
||||||
|
llIcon.setGravity(Gravity.CENTER_VERTICAL);
|
||||||
|
ll.addView(llIcon);
|
||||||
|
|
||||||
|
ImageView iconView = new ImageView(view.getContext());
|
||||||
|
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
llIconParams.setMargins(dpToPx(16f), isFirstRow() ? dpToPx(12f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP / 2f) : dpToPx(12f), dpToPx(32f), dpToPx(12f));
|
||||||
|
llIconParams.gravity = Gravity.CENTER_VERTICAL;
|
||||||
|
iconView.setLayoutParams(llIconParams);
|
||||||
|
iconView.setScaleType(ImageView.ScaleType.CENTER);
|
||||||
|
iconView.setImageDrawable(icon);
|
||||||
|
llIcon.addView(iconView);
|
||||||
|
|
||||||
|
// Text
|
||||||
|
LinearLayout llText = new LinearLayout(view.getContext());
|
||||||
|
llText.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
ll.addView(llText);
|
||||||
|
|
||||||
|
TextView textView = new TextView(view.getContext());
|
||||||
|
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
llTextParams.setMargins(0, isFirstRow() ? dpToPx(8f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(8f), 0, dpToPx(8f));
|
||||||
|
textView.setLayoutParams(llTextParams);
|
||||||
|
textView.setTextSize(16); // todo: create constant
|
||||||
|
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
|
||||||
|
|
||||||
|
textView.setAutoLinkMask(Linkify.ALL);
|
||||||
|
textView.setLinksClickable(true);
|
||||||
|
if (isDescription) {
|
||||||
|
textView.setMinLines(1);
|
||||||
|
textView.setMaxLines(5);
|
||||||
|
}
|
||||||
|
textView.setText(text);
|
||||||
|
if (textColor > 0) {
|
||||||
|
textView.setTextColor(view.getResources().getColor(textColor));
|
||||||
|
}
|
||||||
|
if (isDescription) {
|
||||||
|
textView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//todo: implement edit fav description dialog
|
||||||
|
//POIMapLayer.showDescriptionDialog(view.getContext(), app, fav);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
|
||||||
|
llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
|
||||||
|
llText.setLayoutParams(llTextViewParams);
|
||||||
|
llText.addView(textView);
|
||||||
|
|
||||||
|
((LinearLayout) view).addView(ll);
|
||||||
|
|
||||||
|
View horizontalLine = new View(view.getContext());
|
||||||
|
LinearLayout.LayoutParams llHorLineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1f));
|
||||||
|
llHorLineParams.gravity = Gravity.BOTTOM;
|
||||||
|
horizontalLine.setLayoutParams(llHorLineParams);
|
||||||
|
|
||||||
|
horizontalLine.setBackgroundColor(app.getResources().getColor(light ? R.color.ctx_menu_info_divider_light : R.color.ctx_menu_info_divider_dark));
|
||||||
|
|
||||||
|
((LinearLayout) view).addView(horizontalLine);
|
||||||
|
|
||||||
|
rowBuilt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int dpToPx(float dp) {
|
||||||
|
Resources r = app.getResources();
|
||||||
|
return (int) TypedValue.applyDimension(
|
||||||
|
COMPLEX_UNIT_DIP,
|
||||||
|
dp,
|
||||||
|
r.getDisplayMetrics()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(View view) {
|
||||||
|
super.build(view);
|
||||||
|
|
||||||
|
if (!Algorithms.isEmpty(fav.getDescription())) {
|
||||||
|
buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PlainMenuItem item : plainMenuItems) {
|
||||||
|
buildRow(view, item.getIconId(), item.getText(), 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package net.osmand.plus.mapcontextmenu.sections;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import net.osmand.data.FavouritePoint;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
|
||||||
|
public class FavouritePointMenuController extends MenuController {
|
||||||
|
|
||||||
|
public FavouritePointMenuController(OsmandApplication app, Activity activity, final FavouritePoint fav) {
|
||||||
|
super(new FavouritePointMenuBuilder(app, fav), activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getInitialMenuStatePortrait() {
|
||||||
|
return MenuState.HEADER_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getSupportedMenuStatesPortrait() {
|
||||||
|
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,13 +38,24 @@ public abstract class MenuBuilder {
|
||||||
|
|
||||||
protected OsmandApplication app;
|
protected OsmandApplication app;
|
||||||
protected LinkedList<PlainMenuItem> plainMenuItems;
|
protected LinkedList<PlainMenuItem> plainMenuItems;
|
||||||
|
private boolean firstRow;
|
||||||
|
|
||||||
public MenuBuilder(OsmandApplication app) {
|
public MenuBuilder(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
plainMenuItems = new LinkedList<>();
|
plainMenuItems = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void build(View view);
|
public void build(View view) {
|
||||||
|
firstRow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isFirstRow() {
|
||||||
|
return firstRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void rowBuilt() {
|
||||||
|
firstRow = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void addPlainMenuItem(int iconId, String text) {
|
public void addPlainMenuItem(int iconId, String text) {
|
||||||
plainMenuItems.add(new PlainMenuItem(iconId, text));
|
plainMenuItems.add(new PlainMenuItem(iconId, text));
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package net.osmand.plus.views;
|
package net.osmand.plus.views;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import android.app.AlertDialog;
|
||||||
import java.util.List;
|
import android.app.AlertDialog.Builder;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.PointF;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
import net.osmand.access.AccessibleToast;
|
|
||||||
import net.osmand.data.Amenity;
|
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.LocationPoint;
|
import net.osmand.data.LocationPoint;
|
||||||
|
@ -14,22 +18,14 @@ import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.FavoritesTreeFragment;
|
import net.osmand.plus.activities.FavoritesTreeFragment;
|
||||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
||||||
import net.osmand.util.Algorithms;
|
|
||||||
import android.app.AlertDialog;
|
import java.util.ArrayList;
|
||||||
import android.app.AlertDialog.Builder;
|
import java.util.List;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.PointF;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, MapTextProvider<LocationPoint> {
|
public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, MapTextProvider<LocationPoint> {
|
||||||
|
|
||||||
|
@ -203,8 +199,6 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||||
if (itemId == R.string.favourites_context_menu_edit) {
|
if (itemId == R.string.favourites_context_menu_edit) {
|
||||||
FavoritesTreeFragment.editPoint(view.getContext(), a, null);
|
FavoritesTreeFragment.editPoint(view.getContext(), a, null);
|
||||||
} else if (itemId == R.string.shared_string_show_description) {
|
|
||||||
showDescriptionDialog(a);
|
|
||||||
} else if (itemId == R.string.favourites_context_menu_delete) {
|
} else if (itemId == R.string.favourites_context_menu_delete) {
|
||||||
final Resources resources = view.getContext().getResources();
|
final Resources resources = view.getContext().getResources();
|
||||||
Builder builder = new AlertDialog.Builder(view.getContext());
|
Builder builder = new AlertDialog.Builder(view.getContext());
|
||||||
|
@ -222,10 +216,6 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!Algorithms.isEmpty(a.getDescription())) {
|
|
||||||
adapter.item(R.string.shared_string_show_description).iconColor(R.drawable.ic_action_note_dark)
|
|
||||||
.listen(listener).reg();
|
|
||||||
}
|
|
||||||
adapter.item(R.string.favourites_context_menu_edit).iconColor(R.drawable.ic_action_edit_dark)
|
adapter.item(R.string.favourites_context_menu_edit).iconColor(R.drawable.ic_action_edit_dark)
|
||||||
.listen(listener).reg();
|
.listen(listener).reg();
|
||||||
adapter.item(R.string.favourites_context_menu_delete)
|
adapter.item(R.string.favourites_context_menu_delete)
|
||||||
|
@ -234,14 +224,6 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDescriptionDialog(FavouritePoint a) {
|
|
||||||
Builder bs = new AlertDialog.Builder(view.getContext());
|
|
||||||
bs.setTitle(a.getName(view.getContext()));
|
|
||||||
bs.setMessage(a.getDescription());
|
|
||||||
bs.setPositiveButton(R.string.shared_string_ok, null);
|
|
||||||
bs.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LatLon getTextLocation(LocationPoint o) {
|
public LatLon getTextLocation(LocationPoint o) {
|
||||||
return new LatLon(o.getLatitude(), o.getLongitude());
|
return new LatLon(o.getLatitude(), o.getLongitude());
|
||||||
|
|
Loading…
Reference in a new issue