Context menu fixes (337)

This commit is contained in:
Alexey Kulish 2015-11-16 18:56:41 +03:00
parent 0cfbd24e22
commit 03dedbf037
9 changed files with 178 additions and 168 deletions

View file

@ -85,7 +85,7 @@
android:id="@+id/context_menu_close_btn_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="66dp"
android:minWidth="76dp"
android:orientation="horizontal">
<Button
@ -136,7 +136,7 @@
android:id="@+id/compass_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="66dp"
android:minWidth="76dp"
android:orientation="horizontal">
<ImageView

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="copied_to_clipboard">Copied to clipboard</string>
<string name="release_2_2">
\u2022 New context-sensitive UI for tapping locations on the map and on other screens\n\n
\u2022 Map screen is now launched directly unless \'Show Dashboard on app start\' is selected\n\n

View file

@ -427,6 +427,12 @@ public class MapContextMenu extends MenuTitleController {
}
}
public void openMenuFullScreen() {
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null)
fragmentRef.get().openMenuFullScreen();
}
public boolean slideUp() {
return menuController != null && menuController.slideUp();
}
@ -537,6 +543,10 @@ public class MapContextMenu extends MenuTitleController {
}
}
public boolean hasHiddenBottomInfo() {
return getCurrentMenuState() == MenuState.HEADER_ONLY;
}
public LatLon getMyLocation() {
return myLocation;
}

View file

@ -303,95 +303,13 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
velocity.recycle();
boolean skipHalfScreenState = Math.abs(currentY - dyMain) > skipHalfScreenStateLimit;
boolean needCloseMenu = false;
int oldMenuState = menu.getCurrentMenuState();
if (menuBottomViewHeight > 0 && slidingUp) {
menu.slideUp();
if (skipHalfScreenState) {
menu.slideUp();
}
} else if (slidingDown) {
needCloseMenu = !menu.slideDown();
if (!needCloseMenu && skipHalfScreenState) {
menu.slideDown();
}
}
int newMenuState = menu.getCurrentMenuState();
boolean needMapAdjust = oldMenuState != newMenuState && newMenuState != MenuState.FULL_SCREEN;
if (newMenuState != oldMenuState) {
doBeforeMenuStateChange(oldMenuState, newMenuState);
}
applyPosY(currentY, needCloseMenu, needMapAdjust, oldMenuState, newMenuState);
changeMenuState(currentY, skipHalfScreenState, slidingUp, slidingDown);
break;
}
return true;
}
private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust,
final int previousMenuState, final int newMenuState) {
final int posY = getPosY(needCloseMenu);
if (currentY != posY) {
if (posY < currentY) {
updateMainViewLayout(posY);
}
if (!oldAndroid()) {
mainView.animate().y(posY)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
if (needCloseMenu) {
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
@Override
public void onAnimationEnd(Animator animation) {
if (needCloseMenu) {
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
})
.start();
fabView.animate().y(getFabY(posY))
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.start();
if (needMapAdjust) {
adjustMapPosition(posY, true);
}
} else {
setViewY(posY, false, needMapAdjust);
if (needCloseMenu) {
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
}
}
};
View topView = view.findViewById(R.id.context_menu_top_view);
@ -484,6 +402,97 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
return view;
}
public void openMenuFullScreen() {
changeMenuState(getViewY(), true, true, false);
}
private void changeMenuState(int currentY, boolean skipHalfScreenState,
boolean slidingUp, boolean slidingDown) {
boolean needCloseMenu = false;
int oldMenuState = menu.getCurrentMenuState();
if (menuBottomViewHeight > 0 && slidingUp) {
menu.slideUp();
if (skipHalfScreenState) {
menu.slideUp();
}
} else if (slidingDown) {
needCloseMenu = !menu.slideDown();
if (!needCloseMenu && skipHalfScreenState) {
menu.slideDown();
}
}
int newMenuState = menu.getCurrentMenuState();
boolean needMapAdjust = oldMenuState != newMenuState && newMenuState != MenuState.FULL_SCREEN;
if (newMenuState != oldMenuState) {
doBeforeMenuStateChange(oldMenuState, newMenuState);
}
applyPosY(currentY, needCloseMenu, needMapAdjust, oldMenuState, newMenuState);
}
private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust,
final int previousMenuState, final int newMenuState) {
final int posY = getPosY(needCloseMenu);
if (currentY != posY) {
if (posY < currentY) {
updateMainViewLayout(posY);
}
if (!oldAndroid()) {
mainView.animate().y(posY)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
if (needCloseMenu) {
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
@Override
public void onAnimationEnd(Animator animation) {
if (needCloseMenu) {
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
})
.start();
fabView.animate().y(getFabY(posY))
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.start();
if (needMapAdjust) {
adjustMapPosition(posY, true);
}
} else {
setViewY(posY, false, needMapAdjust);
if (needCloseMenu) {
menu.close();
} else {
updateMainViewLayout(posY);
if (previousMenuState != 0 && newMenuState != 0 && previousMenuState != newMenuState) {
doAfterMenuStateChange(previousMenuState, newMenuState);
}
}
}
}
}
public void updateMapCenter(LatLon mapCenter) {
customMapCenter = true;
menu.setMapCenter(mapCenter);

View file

@ -1,10 +1,12 @@
package net.osmand.plus.mapcontextmenu;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.ClipboardManager;
import android.text.util.Linkify;
import android.util.TypedValue;
import android.view.Gravity;
@ -15,6 +17,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
@ -103,7 +106,7 @@ public class MenuBuilder {
return buildRow(view, getRowIcon(iconId), text, textColor, needLinks, textLinesLimit);
}
protected View buildRow(final View view, Drawable icon, String text, int textColor, boolean needLinks, int textLinesLimit) {
protected View buildRow(final View view, Drawable icon, final String text, int textColor, boolean needLinks, int textLinesLimit) {
if (!isFirstRow()) {
buildRowDivider(view, false);
@ -113,17 +116,25 @@ public class MenuBuilder {
ll.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ll.setLayoutParams(llParams);
ll.setBackgroundResource(resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
ll.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
copyToClipboard(text, view.getContext());
return true;
}
});
// 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.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), 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.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(32f), dpToPx(12f));
llIconParams.gravity = Gravity.CENTER_VERTICAL;
iconView.setLayoutParams(llIconParams);
iconView.setScaleType(ImageView.ScaleType.CENTER);
@ -137,7 +148,7 @@ public class MenuBuilder {
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));
llTextParams.setMargins(0, dpToPx(8f), 0, dpToPx(8f));
textView.setLayoutParams(llTextParams);
textView.setTextSize(16);
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
@ -168,6 +179,13 @@ public class MenuBuilder {
return ll;
}
protected void copyToClipboard(String text, Context ctx) {
((ClipboardManager) app.getSystemService(Activity.CLIPBOARD_SERVICE)).setText(text);
Toast.makeText(ctx,
ctx.getResources().getString(R.string.copied_to_clipboard) + ":\n" + text,
Toast.LENGTH_SHORT).show();
}
protected void buildButtonRow(final View view, Drawable buttonIcon, String text, OnClickListener onClickListener) {
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);
@ -178,7 +196,7 @@ public class MenuBuilder {
// Empty
LinearLayout llIcon = new LinearLayout(view.getContext());
llIcon.setOrientation(LinearLayout.HORIZONTAL);
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(62f), isFirstRow() ? dpToPx(58f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(58f)));
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(62f), dpToPx(58f)));
llIcon.setGravity(Gravity.CENTER_VERTICAL);
ll.addView(llIcon);

View file

@ -45,21 +45,36 @@ public class AmenityMenuBuilder extends MenuBuilder {
buildRowDivider(view, false);
}
final String txt;
if (!Algorithms.isEmpty(textPrefix)) {
txt = textPrefix + ": " + text;
} else {
txt = text;
}
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ll.setLayoutParams(llParams);
ll.setBackgroundResource(resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
ll.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
copyToClipboard(txt, view.getContext());
return true;
}
});
// 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.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), 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.setMargins(dpToPx(16f), dpToPx(12f), dpToPx(32f), dpToPx(12f));
llIconParams.gravity = Gravity.CENTER_VERTICAL;
iconView.setLayoutParams(llIconParams);
iconView.setScaleType(ImageView.ScaleType.CENTER);
@ -73,7 +88,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
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));
llTextParams.setMargins(0, dpToPx(8f), 0, dpToPx(8f));
textView.setLayoutParams(llTextParams);
textView.setTextSize(16);
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
@ -90,11 +105,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
textView.setMinLines(1);
textView.setMaxLines(10);
}
if (!Algorithms.isEmpty(textPrefix)) {
textView.setText(textPrefix + ": " + text);
} else {
textView.setText(text);
}
textView.setText(txt);
if (textColor > 0) {
textView.setTextColor(view.getResources().getColor(textColor));
}
@ -114,7 +125,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
POIMapLayer.showWikipediaDialog(view.getContext(), app, amenity);
}
});
} else if (isText) {
} else if (isText && text.length() > 200) {
ll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -191,6 +191,8 @@ public class MapMultiSelectionMenu extends BaseMenuController {
selectedObjects.remove(menuObject.getObject());
}
hide();
getMapActivity().getMapViewTrackingUtilities().locationChanged(menuObject.getLatLon().getLatitude(),
menuObject.getLatLon().getLongitude(), this);
getMapActivity().getContextMenu()
.show(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject());
}

View file

@ -1,13 +1,6 @@
package net.osmand.plus.osmedit;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
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.plus.OsmandApplication;
import net.osmand.plus.R;
@ -24,78 +17,20 @@ public class EditPOIMenuBuilder extends MenuBuilder {
this.osmPoint = osmPoint;
}
private void buildRow(View view, int iconId, String text) {
buildRow(view, getRowIcon(iconId), text);
}
protected void buildRow(final View view, Drawable icon, String text) {
boolean light = app.getSettings().isLightContent();
if (!isFirstRow()) {
buildRowDivider(view, false);
}
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
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);
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setText(text);
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);
rowBuilt();
}
@Override
public void buildInternal(View view) {
if (osmPoint instanceof OsmNotesPoint) {
OsmNotesPoint notes = (OsmNotesPoint) osmPoint;
buildRow(view, R.drawable.ic_action_note_dark, notes.getText());
buildRow(view, R.drawable.ic_group, notes.getAuthor());
buildRow(view, R.drawable.ic_action_note_dark, notes.getText(), 0, false, 0);
buildRow(view, R.drawable.ic_group, notes.getAuthor(), 0, false, 0);
} else if (osmPoint instanceof OpenstreetmapPoint) {
OpenstreetmapPoint point = (OpenstreetmapPoint) osmPoint;
for (Map.Entry<String, String> e : point.getEntity().getTags().entrySet()) {
String text = e.getKey() + "=" + e.getValue();
buildRow(view, R.drawable.ic_action_info_dark, text);
buildRow(view, R.drawable.ic_action_info_dark, text, 0, false, 0);
}
}
}

View file

@ -6,6 +6,7 @@ import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
@ -13,8 +14,10 @@ import net.osmand.CallbackWithObject;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
@ -98,6 +101,24 @@ public class ContextMenuLayer extends OsmandMapLayer {
this.selectOnMap = selectOnMap;
}
@Override
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if (menu.hasHiddenBottomInfo()) {
ContextMenuAdapter.OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.shared_string_show_description) {
menu.openMenuFullScreen();
}
return true;
}
};
adapter.item(R.string.shared_string_show_description)
.iconColor(R.drawable.ic_action_note_dark).listen(listener)
.reg();
}
}
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (disableLongPressOnMap()) {
@ -130,6 +151,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
latLon = getLatLon(point, tileBox);
}
hideVisibleMenues();
activity.getMapViewTrackingUtilities().locationChanged(latLon.getLatitude(), latLon.getLongitude(), this);
menu.show(latLon, pointDescription, selectedObj);
return true;
@ -139,7 +161,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
} else if (showUnknownLocation) {
hideVisibleMenues();
menu.show(getLatLon(point, tileBox), null, null);
LatLon latLon = getLatLon(point, tileBox);
activity.getMapViewTrackingUtilities().locationChanged(latLon.getLatitude(), latLon.getLongitude(), this);
menu.show(latLon, null, null);
return true;
}
return false;