Fix context menu scroll
This commit is contained in:
parent
3dfed6f29e
commit
dafe7e8fdc
6 changed files with 93 additions and 42 deletions
|
@ -51,7 +51,7 @@ public abstract class BaseMenuController {
|
|||
}
|
||||
|
||||
public float getHalfScreenMaxHeightKoef() {
|
||||
return .7f;
|
||||
return .75f;
|
||||
}
|
||||
|
||||
public int getSlideInAnimation() {
|
||||
|
|
|
@ -521,6 +521,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}, timeout);
|
||||
}
|
||||
|
||||
public void updateLayout() {
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
|
||||
if (fragmentRef != null) {
|
||||
fragmentRef.get().updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMenuUI() {
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
|
||||
if (fragmentRef != null) {
|
||||
|
|
|
@ -98,6 +98,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
private int markerPaddingPx;
|
||||
private int markerPaddingXPx;
|
||||
private int topScreenPosY;
|
||||
|
||||
private OsmandMapTileView map;
|
||||
private LatLon mapCenter;
|
||||
|
@ -112,7 +113,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
private boolean wasDrawerDisabled;
|
||||
private boolean zoomIn;
|
||||
|
||||
private float skipHalfScreenStateLimit;
|
||||
private float skipScreenStateLimit;
|
||||
|
||||
private int screenOrientation;
|
||||
private boolean created;
|
||||
|
@ -125,6 +126,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
markerPaddingPx = dpToPx(MARKER_PADDING_DP);
|
||||
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
|
||||
topScreenPosY = -dpToPx(SHADOW_HEIGHT_TOP_DP);
|
||||
|
||||
menu = getMapActivity().getContextMenu();
|
||||
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
|
||||
|
@ -327,8 +329,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
velocity.recycle();
|
||||
|
||||
boolean skipHalfScreenState = Math.abs(currentY - dyMain) > skipHalfScreenStateLimit;
|
||||
changeMenuState(currentY, skipHalfScreenState, slidingUp, slidingDown);
|
||||
boolean skipScreenState = Math.abs(currentY - dyMain) > skipScreenStateLimit;
|
||||
changeMenuState(currentY, skipScreenState, slidingUp, slidingDown);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -487,7 +489,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
detailsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
menu.openMenuFullScreen();
|
||||
openMenuHalfScreen();
|
||||
}
|
||||
});
|
||||
TextView directionsButton = (TextView) view.findViewById(R.id.context_menu_directions_button);
|
||||
|
@ -543,7 +545,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
if (showShowHideButton) {
|
||||
openMenuHeaderOnly();
|
||||
} else {
|
||||
openMenuFullScreen();
|
||||
openMenuHalfScreen();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -575,7 +577,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
private void processScreenHeight(ViewParent parent) {
|
||||
View container = (View)parent;
|
||||
screenHeight = container.getHeight() + AndroidUtils.getStatusBarHeight(getActivity());
|
||||
skipHalfScreenStateLimit = screenHeight * SKIP_HALF_SCREEN_STATE_KOEF;
|
||||
skipScreenStateLimit = screenHeight * SKIP_HALF_SCREEN_STATE_KOEF;
|
||||
viewHeight = screenHeight - AndroidUtils.getStatusBarHeight(getMapActivity());
|
||||
}
|
||||
|
||||
|
@ -596,19 +598,22 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
|
||||
private void changeMenuState(int currentY, boolean skipHalfScreenState,
|
||||
private void changeMenuState(int currentY, boolean skipScreenState,
|
||||
boolean slidingUp, boolean slidingDown) {
|
||||
boolean needCloseMenu = false;
|
||||
|
||||
int oldMenuState = menu.getCurrentMenuState();
|
||||
if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN && currentY < topScreenPosY) {
|
||||
slidingDown = false;
|
||||
}
|
||||
if (menuBottomViewHeight > 0 && slidingUp) {
|
||||
menu.slideUp();
|
||||
if (skipHalfScreenState) {
|
||||
if (skipScreenState) {
|
||||
menu.slideUp();
|
||||
}
|
||||
} else if (slidingDown) {
|
||||
needCloseMenu = !menu.slideDown();
|
||||
if (!needCloseMenu && skipHalfScreenState) {
|
||||
if (!needCloseMenu && skipScreenState) {
|
||||
menu.slideDown();
|
||||
}
|
||||
}
|
||||
|
@ -1240,6 +1245,19 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
|
||||
private void updateZoomButtonsVisibility(int menuState) {
|
||||
boolean zoomButtonsVisible = menu.zoomButtonsVisible() && menuState == MenuState.HEADER_ONLY;
|
||||
if (zoomButtonsVisible) {
|
||||
if (zoomButtonsView.getVisibility() != View.VISIBLE) {
|
||||
zoomButtonsView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
if (zoomButtonsView.getVisibility() == View.VISIBLE) {
|
||||
zoomButtonsView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getPosY() {
|
||||
return getPosY(CURRENT_Y_UNDEFINED, false);
|
||||
}
|
||||
|
@ -1256,22 +1274,23 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
minHalfY = viewHeight - (int) (viewHeight * menu.getHalfScreenMaxHeightKoef());
|
||||
} else {
|
||||
destinationState = MenuState.HEADER_ONLY;
|
||||
minHalfY = viewHeight;
|
||||
minHalfY = viewHeight - (int) (viewHeight * .75f);
|
||||
}
|
||||
|
||||
updateZoomButtonsVisibility(destinationState);
|
||||
|
||||
int posY = 0;
|
||||
switch (destinationState) {
|
||||
case MenuState.HEADER_ONLY:
|
||||
posY = viewHeight - menuTitleHeight;
|
||||
break;
|
||||
case MenuState.HALF_SCREEN:
|
||||
posY = viewHeight - menuFullHeightMax;
|
||||
posY = Math.max(posY, minHalfY);
|
||||
posY = minHalfY;
|
||||
break;
|
||||
case MenuState.FULL_SCREEN:
|
||||
if (currentY != CURRENT_Y_UNDEFINED) {
|
||||
int maxPosY = viewHeight - menuFullHeightMax;
|
||||
int minPosY = Math.max(maxPosY, minHalfY);
|
||||
int minPosY = addStatusBarHeightIfNeeded(topScreenPosY);
|
||||
if (maxPosY > minPosY) {
|
||||
maxPosY = minPosY;
|
||||
}
|
||||
|
@ -1283,8 +1302,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
posY = currentY;
|
||||
}
|
||||
} else {
|
||||
posY = -dpToPx(SHADOW_HEIGHT_TOP_DP);
|
||||
posY = addStatusBarHeightIfNeeded(posY);
|
||||
posY = addStatusBarHeightIfNeeded(topScreenPosY);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -1417,7 +1435,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
private void doLayoutMenu() {
|
||||
final int posY = getPosY();
|
||||
final int posY = getPosY(getViewY(), false);
|
||||
setViewY(posY, true, !initLayout || !centered);
|
||||
updateMainViewLayout(posY);
|
||||
}
|
||||
|
@ -1432,6 +1450,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
|
||||
public void updateLayout() {
|
||||
runLayoutListener();
|
||||
}
|
||||
|
||||
public void refreshTitle() {
|
||||
setAddressLocation();
|
||||
runLayoutListener();
|
||||
|
|
|
@ -95,10 +95,16 @@ public class MenuBuilder {
|
|||
private CardsRowBuilder onlinePhotoCardsRow;
|
||||
private List<AbstractCard> onlinePhotoCards;
|
||||
|
||||
private CollapseExpandListener collapseExpandListener;
|
||||
|
||||
private String preferredMapLang;
|
||||
private String preferredMapAppLang;
|
||||
private boolean transliterateNames;
|
||||
|
||||
public interface CollapseExpandListener {
|
||||
void onCollapseExpand(boolean collapsed);
|
||||
}
|
||||
|
||||
public class PlainMenuItem {
|
||||
private int iconId;
|
||||
private String buttonText;
|
||||
|
@ -158,22 +164,22 @@ public class MenuBuilder {
|
|||
public static class CollapsableView {
|
||||
|
||||
private View contenView;
|
||||
private MenuBuilder menuBuilder;
|
||||
private OsmandPreference<Boolean> collapsedPref;
|
||||
private boolean collapsed;
|
||||
private OnCollExpListener onCollExpListener;
|
||||
private CollapseExpandListener collapseExpandListener;
|
||||
|
||||
public interface OnCollExpListener {
|
||||
void onCollapseExpand(boolean collapsed);
|
||||
}
|
||||
|
||||
public CollapsableView(@NonNull View contenView, @NonNull OsmandPreference<Boolean> collapsedPref) {
|
||||
public CollapsableView(@NonNull View contenView, @NonNull MenuBuilder menuBuilder,
|
||||
@NonNull OsmandPreference<Boolean> collapsedPref) {
|
||||
this.contenView = contenView;
|
||||
this.menuBuilder = menuBuilder;
|
||||
this.collapsedPref = collapsedPref;
|
||||
}
|
||||
|
||||
public CollapsableView(@NonNull View contenView, boolean collapsed) {
|
||||
public CollapsableView(@NonNull View contenView, @NonNull MenuBuilder menuBuilder, boolean collapsed) {
|
||||
this.contenView = contenView;
|
||||
this.collapsed = collapsed;
|
||||
this.menuBuilder = menuBuilder;
|
||||
}
|
||||
|
||||
public View getContenView() {
|
||||
|
@ -194,17 +200,20 @@ public class MenuBuilder {
|
|||
} else {
|
||||
this.collapsed = collapsed;
|
||||
}
|
||||
if (onCollExpListener != null) {
|
||||
onCollExpListener.onCollapseExpand(collapsed);
|
||||
if (collapseExpandListener != null) {
|
||||
collapseExpandListener.onCollapseExpand(collapsed);
|
||||
}
|
||||
if (menuBuilder.collapseExpandListener != null) {
|
||||
menuBuilder.collapseExpandListener.onCollapseExpand(collapsed);
|
||||
}
|
||||
}
|
||||
|
||||
public OnCollExpListener getOnCollExpListener() {
|
||||
return onCollExpListener;
|
||||
public CollapseExpandListener getCollapseExpandListener() {
|
||||
return collapseExpandListener;
|
||||
}
|
||||
|
||||
public void setOnCollExpListener(OnCollExpListener onCollExpListener) {
|
||||
this.onCollExpListener = onCollExpListener;
|
||||
public void setCollapseExpandListener(CollapseExpandListener collapseExpandListener) {
|
||||
this.collapseExpandListener = collapseExpandListener;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,6 +230,10 @@ public class MenuBuilder {
|
|||
transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
|
||||
}
|
||||
|
||||
public void setCollapseExpandListener(CollapseExpandListener collapseExpandListener) {
|
||||
this.collapseExpandListener = collapseExpandListener;
|
||||
}
|
||||
|
||||
public void setRoutes(List<TransportStopRoute> routes) {
|
||||
this.routes = routes;
|
||||
}
|
||||
|
@ -378,9 +391,9 @@ public class MenuBuilder {
|
|||
boolean needUpdateOnly = onlinePhotoCardsRow != null && onlinePhotoCardsRow.getMenuBuilder() == this;
|
||||
onlinePhotoCardsRow = new CardsRowBuilder(this, view, false);
|
||||
onlinePhotoCardsRow.build();
|
||||
CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(),
|
||||
CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(), this,
|
||||
app.getSettings().ONLINE_PHOTOS_ROW_COLLAPSED);
|
||||
collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() {
|
||||
collapsableView.setCollapseExpandListener(new CollapseExpandListener() {
|
||||
@Override
|
||||
public void onCollapseExpand(boolean collapsed) {
|
||||
if (!collapsed && onlinePhotoCards == null) {
|
||||
|
@ -584,13 +597,13 @@ public class MenuBuilder {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (collapsableView.getContenView().getVisibility() == View.VISIBLE) {
|
||||
collapsableView.setCollapsed(true);
|
||||
collapsableView.getContenView().setVisibility(View.GONE);
|
||||
iconViewCollapse.setImageDrawable(getCollapseIcon(true));
|
||||
collapsableView.setCollapsed(true);
|
||||
} else {
|
||||
collapsableView.setCollapsed(false);
|
||||
collapsableView.getContenView().setVisibility(View.VISIBLE);
|
||||
iconViewCollapse.setImageDrawable(getCollapseIcon(false));
|
||||
collapsableView.setCollapsed(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -844,7 +857,7 @@ public class MenuBuilder {
|
|||
buildTransportRouteRow(view, r, listener, showDivider);
|
||||
}
|
||||
|
||||
return new CollapsableView(view, collapsed);
|
||||
return new CollapsableView(view, this, collapsed);
|
||||
}
|
||||
|
||||
protected CollapsableView getCollapsableTextView(Context context, boolean collapsed, String text) {
|
||||
|
@ -857,7 +870,7 @@ public class MenuBuilder {
|
|||
textView.setTextSize(16);
|
||||
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
|
||||
textView.setText(text);
|
||||
return new CollapsableView(textView, collapsed);
|
||||
return new CollapsableView(textView, this, collapsed);
|
||||
}
|
||||
|
||||
protected CollapsableView getCollapsableFavouritesView(final Context context, boolean collapsed, @NonNull final FavoriteGroup group, FavouritePoint selectedPoint) {
|
||||
|
@ -901,7 +914,7 @@ public class MenuBuilder {
|
|||
view.addView(button);
|
||||
}
|
||||
|
||||
return new CollapsableView(view, collapsed);
|
||||
return new CollapsableView(view, this, collapsed);
|
||||
}
|
||||
|
||||
protected CollapsableView getCollapsableWaypointsView(final Context context, boolean collapsed, @NonNull final GPXFile gpxFile, WptPt selectedPoint) {
|
||||
|
@ -944,7 +957,7 @@ public class MenuBuilder {
|
|||
view.addView(button);
|
||||
}
|
||||
|
||||
return new CollapsableView(view, collapsed);
|
||||
return new CollapsableView(view, this, collapsed);
|
||||
}
|
||||
|
||||
protected CollapsableView getCollapsableWikiView(Context context, boolean collapsed) {
|
||||
|
@ -966,7 +979,7 @@ public class MenuBuilder {
|
|||
view.addView(button);
|
||||
}
|
||||
|
||||
return new CollapsableView(view, collapsed);
|
||||
return new CollapsableView(view, this, collapsed);
|
||||
}
|
||||
|
||||
protected LinearLayout buildCollapsableContentView(Context context, boolean collapsed, boolean needMargin) {
|
||||
|
|
|
@ -42,6 +42,7 @@ import net.osmand.plus.download.DownloadIndexesThread;
|
|||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapseExpandListener;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController;
|
||||
|
@ -81,7 +82,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MenuController extends BaseMenuController {
|
||||
public abstract class MenuController extends BaseMenuController implements CollapseExpandListener {
|
||||
|
||||
public static class MenuState {
|
||||
public static final int HEADER_ONLY = 1;
|
||||
|
@ -124,10 +125,18 @@ public abstract class MenuController extends BaseMenuController {
|
|||
super(mapActivity);
|
||||
this.pointDescription = pointDescription;
|
||||
this.builder = builder;
|
||||
this.builder.setCollapseExpandListener(this);
|
||||
this.currentMenuState = getInitialMenuState();
|
||||
this.builder.setLight(isLight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCollapseExpand(boolean collapsed) {
|
||||
if (mapContextMenu != null) {
|
||||
mapContextMenu.updateMenuUI();
|
||||
}
|
||||
}
|
||||
|
||||
public String getPreferredMapLang() {
|
||||
return builder.getPreferredMapLang();
|
||||
}
|
||||
|
|
|
@ -200,13 +200,13 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (collapsableView.getContenView().getVisibility() == View.VISIBLE) {
|
||||
collapsableView.setCollapsed(true);
|
||||
collapsableView.getContenView().setVisibility(View.GONE);
|
||||
iconViewCollapse.setImageDrawable(getCollapseIcon(true));
|
||||
collapsableView.setCollapsed(true);
|
||||
} else {
|
||||
collapsableView.setCollapsed(false);
|
||||
collapsableView.getContenView().setVisibility(View.VISIBLE);
|
||||
iconViewCollapse.setImageDrawable(getCollapseIcon(false));
|
||||
collapsableView.setCollapsed(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue