Context menu: edit favorites fixes, layout fixes, refactoring
This commit is contained in:
parent
3dafc219a0
commit
f260444904
12 changed files with 324 additions and 246 deletions
|
@ -177,13 +177,13 @@
|
|||
android:id="@+id/context_menu_bottom_scroll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/ctx_menu_info_view_bg"
|
||||
android:fillViewport="true">
|
||||
android:background="?attr/ctx_menu_info_view_bg">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/context_menu_bottom_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/ctx_menu_info_view_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -169,7 +169,7 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:completionThreshold="1"
|
||||
android:editable="false"
|
||||
android:drawableRight="@drawable/ic_action_arrow_drop_down"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.plus.mapcontextmenu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
@ -13,19 +12,14 @@ import net.osmand.data.Amenity;
|
|||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.details.MenuController;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -38,6 +32,7 @@ public class MapContextMenu {
|
|||
|
||||
private PointDescription pointDescription;
|
||||
private Object object;
|
||||
MenuController menuController;
|
||||
|
||||
private int leftIconId;
|
||||
private Drawable leftIcon;
|
||||
|
@ -64,6 +59,10 @@ public class MapContextMenu {
|
|||
return object;
|
||||
}
|
||||
|
||||
public MenuController getMenuController() {
|
||||
return menuController;
|
||||
}
|
||||
|
||||
public MapContextMenu(OsmandApplication app, MapActivity mapActivity) {
|
||||
this.app = app;
|
||||
this.mapActivity = mapActivity;
|
||||
|
@ -71,7 +70,11 @@ public class MapContextMenu {
|
|||
}
|
||||
|
||||
public boolean init(PointDescription pointDescription, Object object) {
|
||||
if (isMenuVisible()) {
|
||||
return init(pointDescription, object, false);
|
||||
}
|
||||
|
||||
public boolean init(PointDescription pointDescription, Object object, boolean reload) {
|
||||
if (!reload && isMenuVisible()) {
|
||||
if (this.object == null || !this.object.equals(object)) {
|
||||
hide();
|
||||
} else {
|
||||
|
@ -82,10 +85,11 @@ public class MapContextMenu {
|
|||
this.pointDescription = pointDescription;
|
||||
this.object = object;
|
||||
leftIconId = 0;
|
||||
nameStr = null;
|
||||
typeStr = null;
|
||||
streetStr = null;
|
||||
nameStr = "";
|
||||
typeStr = "";
|
||||
streetStr = "";
|
||||
|
||||
acquireMenuController();
|
||||
acquireIcons();
|
||||
acquireNameAndType();
|
||||
if (needStreetName()) {
|
||||
|
@ -106,6 +110,14 @@ public class MapContextMenu {
|
|||
}
|
||||
}
|
||||
|
||||
public void refreshMenu(PointDescription pointDescription, Object object) {
|
||||
MapContextMenuFragment fragment = findMenuFragment();
|
||||
if (fragment != null) {
|
||||
init(pointDescription, object, true);
|
||||
fragment.rebuildMenu();
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
MapContextMenuFragment fragment = findMenuFragment();
|
||||
if (fragment != null) {
|
||||
|
@ -113,23 +125,37 @@ public class MapContextMenu {
|
|||
}
|
||||
}
|
||||
|
||||
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() != null && pt.getOsmTag().equals("place")) {
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
res = false;
|
||||
private void acquireMenuController() {
|
||||
menuController = null;
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
menuController = new AmenityMenuController(app, mapActivity, (Amenity)object);
|
||||
if (!Algorithms.isEmpty(typeStr)) {
|
||||
menuController.addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
|
||||
}
|
||||
if (pointDescription != null) {
|
||||
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(mapActivity, true).replaceAll("\n", ""));
|
||||
}
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint)object);
|
||||
if (pointDescription != null) {
|
||||
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(mapActivity, true).replaceAll("\n", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSingleTapOnMap() {
|
||||
if (menuController == null || !menuController.handleSingleTapOnMap()) {
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needStreetName() {
|
||||
boolean res = object != null || Algorithms.isEmpty(pointDescription.getName());
|
||||
if (res && menuController != null) {
|
||||
res = menuController.needStreetName();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -165,7 +191,7 @@ public class MapContextMenu {
|
|||
}
|
||||
|
||||
public String getLocationStr() {
|
||||
if (object != null && object instanceof FavouritePoint) {
|
||||
if (menuController != null && menuController.needTypeStr()) {
|
||||
return typeStr;
|
||||
} else {
|
||||
if (Algorithms.isEmpty(streetStr)) {
|
||||
|
@ -181,55 +207,17 @@ public class MapContextMenu {
|
|||
leftIcon = null;
|
||||
secondLineIcon = null;
|
||||
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
String id = null;
|
||||
Amenity o = (Amenity) object;
|
||||
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
||||
id = st.getIconKeyName();
|
||||
} else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||
id = st.getOsmTag() + "_" + st.getOsmValue();
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
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);
|
||||
}
|
||||
if (menuController != null) {
|
||||
leftIconId = menuController.getLeftIconId();
|
||||
leftIcon = menuController.getLeftIcon();
|
||||
secondLineIcon = menuController.getSecondLineIcon();
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
Amenity amenity = (Amenity) object;
|
||||
|
||||
PoiCategory pc = amenity.getType();
|
||||
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
|
||||
typeStr = amenity.getSubType();
|
||||
if (pt != null) {
|
||||
typeStr = pt.getTranslation();
|
||||
} else if(typeStr != null){
|
||||
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
|
||||
}
|
||||
nameStr = amenity.getName(settings.MAP_PREFERRED_LOCALE.get());
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
FavouritePoint fav = (FavouritePoint)object;
|
||||
nameStr = fav.getName();
|
||||
typeStr = fav.getCategory();
|
||||
}
|
||||
if (menuController != null) {
|
||||
nameStr = menuController.getNameStr();
|
||||
typeStr = menuController.getTypeStr();
|
||||
}
|
||||
|
||||
if (Algorithms.isEmpty(nameStr)) {
|
||||
|
@ -242,7 +230,7 @@ public class MapContextMenu {
|
|||
if (Algorithms.isEmpty(nameStr)) {
|
||||
if (!Algorithms.isEmpty(typeStr)) {
|
||||
nameStr = typeStr;
|
||||
typeStr = null;
|
||||
typeStr = "";
|
||||
} else {
|
||||
nameStr = app.getResources().getString(R.string.address_unknown);
|
||||
}
|
||||
|
@ -260,14 +248,11 @@ public class MapContextMenu {
|
|||
if (object != null) {
|
||||
streetStr = RoutingHelper.formatStreetName(object.getName(settings.MAP_PREFERRED_LOCALE.get()),
|
||||
object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
|
||||
if (streetStr != null && streetStr.trim().length() == 0) {
|
||||
streetStr = null;
|
||||
}
|
||||
|
||||
if (streetStr != null) {
|
||||
if (!Algorithms.isEmpty(streetStr)) {
|
||||
if (getObject() == null) {
|
||||
nameStr = streetStr;
|
||||
streetStr = null;
|
||||
streetStr = "";
|
||||
}
|
||||
mapActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
|
@ -276,7 +261,7 @@ public class MapContextMenu {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
streetStr = null;
|
||||
streetStr = "";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -289,24 +274,6 @@ public class MapContextMenu {
|
|||
});
|
||||
}
|
||||
|
||||
public MenuController getMenuController(Activity activity) {
|
||||
MenuController menuController = null;
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
menuController = new AmenityMenuController(app, activity, (Amenity)object);
|
||||
if (!Algorithms.isEmpty(typeStr)) {
|
||||
menuController.addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
|
||||
}
|
||||
menuController.addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(activity, true).replaceAll("\n", ""));
|
||||
} 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 menuController;
|
||||
}
|
||||
|
||||
public void buttonNavigatePressed() {
|
||||
mapActivity.getMapActions().showNavigationContextMenuPoint(pointDescription.getLat(), pointDescription.getLon());
|
||||
}
|
||||
|
@ -314,10 +281,8 @@ public class MapContextMenu {
|
|||
public void buttonFavoritePressed() {
|
||||
if (object != null && object instanceof FavouritePoint) {
|
||||
mapActivity.getFavoritePointEditor().edit((FavouritePoint)object);
|
||||
//mapActivity.getMapActions().editFavoritePoint((FavouritePoint) object);
|
||||
} else {
|
||||
mapActivity.getFavoritePointEditor().add(pointDescription);
|
||||
//mapActivity.getMapActions().addFavouritePoint(pointDescription.getLat(), pointDescription.getLon());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,36 +302,27 @@ public class MapContextMenu {
|
|||
}
|
||||
|
||||
public void saveMenuState(Bundle bundle) {
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
bundle.putSerializable(KEY_CTX_MENU_OBJECT, (Amenity) object);
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
bundle.putSerializable(KEY_CTX_MENU_OBJECT, (FavouritePoint) object);
|
||||
}
|
||||
if (menuController != null) {
|
||||
menuController.saveEntityState(bundle, KEY_CTX_MENU_OBJECT);
|
||||
}
|
||||
bundle.putSerializable(KEY_CTX_MENU_POINT_DESC, pointDescription);
|
||||
bundle.putSerializable(KEY_CTX_MENU_NAME_STR, nameStr);
|
||||
bundle.putSerializable(KEY_CTX_MENU_TYPE_STR, typeStr);
|
||||
bundle.putSerializable(KEY_CTX_MENU_STREET_STR, streetStr);
|
||||
bundle.putString(KEY_CTX_MENU_NAME_STR, nameStr);
|
||||
bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr);
|
||||
bundle.putString(KEY_CTX_MENU_STREET_STR, streetStr);
|
||||
}
|
||||
|
||||
public void restoreMenuState(Bundle bundle) {
|
||||
object = bundle.getSerializable(KEY_CTX_MENU_OBJECT);
|
||||
Object pDescObj = bundle.getSerializable(KEY_CTX_MENU_POINT_DESC);
|
||||
if (pDescObj != null)
|
||||
pointDescription = (PointDescription)pDescObj;
|
||||
Object nameStrObj = bundle.getSerializable(KEY_CTX_MENU_NAME_STR);
|
||||
if (nameStrObj != null) {
|
||||
nameStr = nameStrObj.toString();
|
||||
}
|
||||
Object typeStrObj = bundle.getSerializable(KEY_CTX_MENU_TYPE_STR);
|
||||
if (typeStrObj != null) {
|
||||
typeStr = typeStrObj.toString();
|
||||
}
|
||||
Object streetStrObj = bundle.getSerializable(KEY_CTX_MENU_STREET_STR);
|
||||
if (streetStrObj != null) {
|
||||
streetStr = streetStrObj.toString();
|
||||
if (pDescObj != null) {
|
||||
pointDescription = (PointDescription) pDescObj;
|
||||
}
|
||||
acquireMenuController();
|
||||
|
||||
nameStr = bundle.getString(KEY_CTX_MENU_NAME_STR);
|
||||
typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR);
|
||||
streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR);
|
||||
|
||||
acquireIcons();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.mapcontextmenu;
|
|||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
@ -25,6 +24,7 @@ import android.view.animation.DecelerateInterpolator;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -98,40 +98,6 @@ public class MapContextMenuFragment extends Fragment {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
/*
|
||||
if(!portrait) {
|
||||
mapActivity.getMapView().setMapPositionX(1);
|
||||
mapActivity.getMapView().refreshMap();
|
||||
}
|
||||
|
||||
if(!AndroidUiHelper.isXLargeDevice(mapActivity)) {
|
||||
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), false);
|
||||
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_left_widgets_panel), false);
|
||||
}
|
||||
if(!portrait) {
|
||||
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin), true);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
|
||||
/*
|
||||
mapActivity.getMapView().setMapPositionX(0);
|
||||
mapActivity.getMapView().refreshMap();
|
||||
|
||||
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin), false);
|
||||
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), true);
|
||||
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_left_widgets_panel), true);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -149,7 +115,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
|
||||
mainView = view.findViewById(R.id.context_menu_main);
|
||||
|
||||
menuController = getCtxMenu().getMenuController(getActivity());
|
||||
menuController = getCtxMenu().getMenuController();
|
||||
if (menuController != null && menuController.isLandscapeLayout()) {
|
||||
mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menuController.getLandscapeWidthDp()), ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
@ -167,7 +133,9 @@ public class MapContextMenuFragment extends Fragment {
|
|||
menuFullHeight = view.findViewById(R.id.context_menu_main).getHeight();
|
||||
|
||||
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight;
|
||||
menuFullHeightMax = menuTitleHeight + (menuBottomViewHeight > 0 ? menuBottomViewHeight + dpToPx(2f) : -dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
|
||||
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
|
||||
|
||||
recalculateFullHeightMax();
|
||||
|
||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||
|
||||
|
@ -316,24 +284,11 @@ public class MapContextMenuFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
// Left icon
|
||||
buildHeader();
|
||||
|
||||
IconsCache iconsCache = getMyApplication().getIconsCache();
|
||||
boolean light = getMyApplication().getSettings().isLightContent();
|
||||
|
||||
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
|
||||
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
|
||||
Drawable icon = getCtxMenu().getLeftIcon();
|
||||
int iconId = getCtxMenu().getLeftIconId();
|
||||
if (icon != null) {
|
||||
iconView.setImageDrawable(icon);
|
||||
} else if (iconId != 0) {
|
||||
iconView.setImageDrawable(iconsCache.getIcon(iconId,
|
||||
light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f));
|
||||
} else {
|
||||
iconLayout.setVisibility(View.GONE);
|
||||
}
|
||||
setAddressLocation();
|
||||
|
||||
// Close button
|
||||
final ImageView closeButtonView = (ImageView)view.findViewById(R.id.context_menu_close_btn_view);
|
||||
closeButtonView.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark,
|
||||
|
@ -387,7 +342,37 @@ public class MapContextMenuFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
// Menu controller
|
||||
buildBottomView();
|
||||
|
||||
getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void recalculateFullHeightMax() {
|
||||
menuFullHeightMax = menuTitleHeight + (menuBottomViewHeight > 0 ? menuBottomViewHeight : -dpToPx(SHADOW_HEIGHT_BOTTOM_DP));
|
||||
}
|
||||
|
||||
private void buildHeader() {
|
||||
IconsCache iconsCache = getMyApplication().getIconsCache();
|
||||
boolean light = getMyApplication().getSettings().isLightContent();
|
||||
|
||||
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
|
||||
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
|
||||
Drawable icon = getCtxMenu().getLeftIcon();
|
||||
int iconId = getCtxMenu().getLeftIconId();
|
||||
if (icon != null) {
|
||||
iconView.setImageDrawable(icon);
|
||||
} else if (iconId != 0) {
|
||||
iconView.setImageDrawable(iconsCache.getIcon(iconId,
|
||||
light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f));
|
||||
} else {
|
||||
iconLayout.setVisibility(View.GONE);
|
||||
}
|
||||
setAddressLocation();
|
||||
}
|
||||
|
||||
private void buildBottomView() {
|
||||
View bottomView = view.findViewById(R.id.context_menu_bottom_view);
|
||||
if (menuController != null) {
|
||||
bottomView.setOnTouchListener(new View.OnTouchListener() {
|
||||
|
@ -398,13 +383,6 @@ public class MapContextMenuFragment extends Fragment {
|
|||
});
|
||||
menuController.build(bottomView);
|
||||
}
|
||||
|
||||
bottomView.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
menuBottomViewHeight = bottomView.getMeasuredHeight();
|
||||
|
||||
getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -413,6 +391,16 @@ public class MapContextMenuFragment extends Fragment {
|
|||
getMapActivity().getMapLayers().getMapControlsLayer().setControlsClickable(true);
|
||||
}
|
||||
|
||||
public void rebuildMenu() {
|
||||
buildHeader();
|
||||
|
||||
LinearLayout bottomLayout = (LinearLayout)view.findViewById(R.id.context_menu_bottom_view);
|
||||
bottomLayout.removeAllViews();
|
||||
buildBottomView();
|
||||
|
||||
recalculateFullHeightMax();
|
||||
}
|
||||
|
||||
private void showOnMap(double latitude, double longitude) {
|
||||
MapActivity ctx = getMapActivity();
|
||||
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
|
||||
|
@ -532,7 +520,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
int slideInAnim = R.anim.slide_in_bottom;
|
||||
int slideOutAnim = R.anim.slide_out_bottom;
|
||||
|
||||
MenuController menuController = mapActivity.getContextMenu().getMenuController(mapActivity);
|
||||
MenuController menuController = mapActivity.getContextMenu().getMenuController();
|
||||
if (menuController != null) {
|
||||
slideInAnim = menuController.getSlideInAnimation();
|
||||
slideOutAnim = menuController.getSlideOutAnimation();
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class AmenityMenuController extends MenuController {
|
||||
|
||||
public AmenityMenuController(OsmandApplication app, Activity activity, final Amenity amenity) {
|
||||
super(new AmenityMenuBuilder(app, amenity), activity);
|
||||
private final Amenity amenity;
|
||||
|
||||
public AmenityMenuController(OsmandApplication app, MapActivity mapActivity, final Amenity amenity) {
|
||||
super(new AmenityMenuBuilder(app, amenity), mapActivity);
|
||||
this.amenity = amenity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,4 +29,54 @@ public class AmenityMenuController extends MenuController {
|
|||
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needStreetName() {
|
||||
if (amenity.getSubType() != null && amenity.getType() != null) {
|
||||
PoiType pt = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||
if (pt != null && pt.getOsmTag() != null && pt.getOsmTag().equals("place")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLeftIconId() {
|
||||
String id = null;
|
||||
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
||||
id = st.getIconKeyName();
|
||||
} else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||
id = st.getOsmTag() + "_" + st.getOsmValue();
|
||||
}
|
||||
}
|
||||
if (id != null) {
|
||||
return RenderingIcons.getBigIconResourceId(id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeStr() {
|
||||
PoiCategory pc = amenity.getType();
|
||||
PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
|
||||
String typeStr = amenity.getSubType();
|
||||
if (pt != null) {
|
||||
typeStr = pt.getTranslation();
|
||||
} else if (typeStr != null) {
|
||||
typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
|
||||
}
|
||||
return typeStr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameStr() {
|
||||
return amenity.getName(getMapActivity().getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEntityState(Bundle bundle, String key) {
|
||||
bundle.putSerializable(key, amenity);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
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(View view, int iconId, String text, int textColor) {
|
||||
buildRow(view, getRowIcon(iconId), text, textColor);
|
||||
}
|
||||
|
||||
private void buildRow(final View view, Drawable icon, String text, int textColor, final boolean isDescription) {
|
||||
private void buildRow(final View view, Drawable icon, String text, int textColor) {
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
|
||||
LinearLayout ll = new LinearLayout(view.getContext());
|
||||
|
@ -65,28 +65,15 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
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.setTextSize(16);
|
||||
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);
|
||||
|
@ -122,11 +109,11 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
super.build(view);
|
||||
|
||||
if (!Algorithms.isEmpty(fav.getDescription())) {
|
||||
buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0, true);
|
||||
buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0);
|
||||
}
|
||||
|
||||
for (PlainMenuItem item : plainMenuItems) {
|
||||
buildRow(view, item.getIconId(), item.getText(), 0, false);
|
||||
buildRow(view, item.getIconId(), item.getText(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment;
|
||||
|
||||
public class FavouritePointMenuController extends MenuController {
|
||||
|
||||
public FavouritePointMenuController(OsmandApplication app, Activity activity, final FavouritePoint fav) {
|
||||
super(new FavouritePointMenuBuilder(app, fav), activity);
|
||||
private FavouritePoint fav;
|
||||
|
||||
public FavouritePointMenuController(OsmandApplication app, MapActivity mapActivity, final FavouritePoint fav) {
|
||||
super(new FavouritePointMenuBuilder(app, fav), mapActivity);
|
||||
this.fav = fav;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,4 +30,52 @@ public class FavouritePointMenuController extends MenuController {
|
|||
protected int getSupportedMenuStatesPortrait() {
|
||||
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSingleTapOnMap() {
|
||||
Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(FavoritePointEditor.TAG);
|
||||
if (fragment != null) {
|
||||
((FavoritePointEditorFragment)fragment).dismiss();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needStreetName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needTypeStr() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getLeftIcon() {
|
||||
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(),
|
||||
fav.getColor(), getMapActivity().getMapView().getCurrentRotatedTileBox().getDensity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getSecondLineIcon() {
|
||||
return getIcon(R.drawable.ic_small_group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeStr() {
|
||||
return fav.getCategory().length() == 0 ?
|
||||
getMapActivity().getString(R.string.shared_string_favorites) : fav.getCategory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameStr() {
|
||||
return fav.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEntityState(Bundle bundle, String key) {
|
||||
bundle.putSerializable(key, fav);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
public abstract class MenuController {
|
||||
|
@ -14,18 +17,24 @@ public abstract class MenuController {
|
|||
public static final int FULL_SCREEN = 4;
|
||||
}
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private MenuBuilder builder;
|
||||
private int currentMenuState;
|
||||
private boolean portraitMode;
|
||||
private boolean largeDevice;
|
||||
|
||||
public MenuController(MenuBuilder builder, Activity activity) {
|
||||
public MenuController(MenuBuilder builder, MapActivity mapActivity) {
|
||||
this.builder = builder;
|
||||
portraitMode = AndroidUiHelper.isOrientationPortrait(activity);
|
||||
largeDevice = AndroidUiHelper.isXLargeDevice(activity);
|
||||
this.mapActivity = mapActivity;
|
||||
portraitMode = AndroidUiHelper.isOrientationPortrait(mapActivity);
|
||||
largeDevice = AndroidUiHelper.isXLargeDevice(mapActivity);
|
||||
this.currentMenuState = getInitialMenuState();
|
||||
}
|
||||
|
||||
public MapActivity getMapActivity() {
|
||||
return mapActivity;
|
||||
}
|
||||
|
||||
public void build(View rootView) {
|
||||
builder.build(rootView);
|
||||
}
|
||||
|
@ -118,7 +127,38 @@ public abstract class MenuController {
|
|||
return .7f;
|
||||
}
|
||||
|
||||
protected Drawable getIcon(int iconId) {
|
||||
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
|
||||
boolean light = mapActivity.getMyApplication().getSettings().isLightContent();
|
||||
return iconsCache.getIcon(iconId,
|
||||
light ? R.color.icon_color : R.color.icon_color_light);
|
||||
}
|
||||
|
||||
public boolean shouldShowButtons() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleSingleTapOnMap() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean needStreetName() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean needTypeStr() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getLeftIconId() { return 0; }
|
||||
|
||||
public Drawable getLeftIcon() { return null; }
|
||||
|
||||
public Drawable getSecondLineIcon() { return null; }
|
||||
|
||||
public String getTypeStr() { return ""; }
|
||||
|
||||
public String getNameStr() { return ""; }
|
||||
|
||||
public abstract void saveEntityState(Bundle bundle, String key);
|
||||
}
|
|
@ -6,6 +6,7 @@ import android.content.DialogInterface;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -15,6 +16,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class FavoritePointEditorFragment extends PointEditorFragment {
|
||||
|
@ -84,7 +86,8 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
|
||||
@Override
|
||||
protected void save(final boolean needDismiss) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), getNameTextValue(), getCategoryTextValue());
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
point.setDescription(getDescriptionTextValue());
|
||||
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
|
||||
|
||||
|
@ -123,10 +126,13 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
dismiss(false);
|
||||
}
|
||||
|
||||
PointDescription pointDescription = favorite.getPointDescription();
|
||||
pointDescription.setLat(favorite.getLatitude());
|
||||
pointDescription.setLon(favorite.getLongitude());
|
||||
getMapActivity().getContextMenu().show(pointDescription, new FavouritePoint(favorite));
|
||||
MapContextMenu menu = getMapActivity().getContextMenu();
|
||||
if (menu.getObject() == favorite) {
|
||||
PointDescription pointDescription = favorite.getPointDescription();
|
||||
pointDescription.setLat(favorite.getLatitude());
|
||||
pointDescription.setLon(favorite.getLongitude());
|
||||
menu.refreshMenu(pointDescription, favorite);
|
||||
}
|
||||
}
|
||||
|
||||
private void doAddFavorite(String name, String category, String description) {
|
||||
|
@ -166,7 +172,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
|
||||
@Override
|
||||
public String getCategoryInitValue() {
|
||||
return favorite.getCategory();
|
||||
return favorite.getCategory().length() == 0 ? getString(R.string.shared_string_favorites) : favorite.getCategory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,14 +15,12 @@ import android.view.LayoutInflater;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -31,8 +29,6 @@ import net.osmand.plus.mapcontextmenu.editors.dialogs.SelectCategoryDialogFragme
|
|||
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
|
||||
public abstract class PointEditorFragment extends Fragment {
|
||||
|
@ -107,29 +103,14 @@ public abstract class PointEditorFragment extends Fragment {
|
|||
nameEdit.setText(getNameInitValue());
|
||||
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) view.findViewById(R.id.category_edit);
|
||||
categoryEdit.setText(getCategoryInitValue());
|
||||
categoryEdit.setThreshold(1);
|
||||
final FavouritesDbHelper helper = getMyApplication().getFavorites();
|
||||
List<FavouritesDbHelper.FavoriteGroup> gs = helper.getFavoriteGroups();
|
||||
String[] list = new String[gs.size()];
|
||||
for(int i = 0; i < list.length; i++) {
|
||||
list[i] =gs.get(i).name;
|
||||
}
|
||||
categoryEdit.setAdapter(new ArrayAdapter<>(getMapActivity(), R.layout.list_textview, list));
|
||||
categoryEdit.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View v, MotionEvent event) {
|
||||
final EditText editText = (EditText) v;
|
||||
final int DRAWABLE_RIGHT = 2;
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (event.getX() >= (editText.getRight()
|
||||
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
||||
- editText.getPaddingRight())) {
|
||||
|
||||
DialogFragment dialogFragment =
|
||||
SelectCategoryDialogFragment.createInstance();
|
||||
dialogFragment.show(getChildFragmentManager(), "SelectCategoryDialogFragment");
|
||||
return true;
|
||||
}
|
||||
DialogFragment dialogFragment =
|
||||
SelectCategoryDialogFragment.createInstance();
|
||||
dialogFragment.show(getChildFragmentManager(), "SelectCategoryDialogFragment");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -193,7 +174,8 @@ public abstract class PointEditorFragment extends Fragment {
|
|||
|
||||
public void setCategory(String name) {
|
||||
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) getView().findViewById(R.id.category_edit);
|
||||
categoryEdit.setText(name);
|
||||
String n = name.length() == 0 ? getString(R.string.shared_string_favorites) : name;
|
||||
categoryEdit.setText(n);
|
||||
ImageView categoryImage = (ImageView) getView().findViewById(R.id.category_image);
|
||||
categoryImage.setImageDrawable(getCategoryIcon());
|
||||
}
|
||||
|
@ -247,7 +229,9 @@ public abstract class PointEditorFragment extends Fragment {
|
|||
|
||||
public String getCategoryTextValue() {
|
||||
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) getView().findViewById(R.id.category_edit);
|
||||
return categoryEdit.getText().toString().trim();
|
||||
String name = categoryEdit.getText().toString().trim();
|
||||
return name.equals(getString(R.string.shared_string_favorites)) ? "" : name;
|
||||
|
||||
}
|
||||
|
||||
public String getDescriptionTextValue() {
|
||||
|
|
|
@ -43,7 +43,8 @@ public class SelectCategoryDialogFragment extends DialogFragment {
|
|||
icon.setImageDrawable(getIcon(getActivity(), R.drawable.ic_action_folder));
|
||||
}
|
||||
Button button = (Button)itemView.findViewById(R.id.button);
|
||||
button.setText(category.name);
|
||||
String name = category.name.length() == 0 ? getString(R.string.shared_string_favorites) : category.name;
|
||||
button.setText(name);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
|
@ -477,7 +477,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
|
||||
activity.getContextMenu().hide();
|
||||
activity.getContextMenu().onSingleTapOnMap();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue