Add adjustMapPosition and remove toolbar
This commit is contained in:
parent
3e00b90f81
commit
aa1e2f8738
3 changed files with 79 additions and 139 deletions
|
@ -523,52 +523,6 @@
|
|||
|
||||
</net.osmand.plus.mapcontextmenu.InterceptorLinearLayout>
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/context_menu_toolbar_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:alpha="0">
|
||||
|
||||
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/context_menu_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:background="@color/actionbar_light_color"
|
||||
app:contentInsetLeft="4dp"
|
||||
app:contentInsetStart="4dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/context_menu_toolbar_back"
|
||||
android:layout_width="@dimen/list_item_height"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="left"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/shared_string_collapse"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_arrow_back"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/context_menu_toolbar_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="left"
|
||||
android:ellipsize="end"
|
||||
android:lines="1"
|
||||
android:maxLines="1"
|
||||
android:scaleType="center"
|
||||
android:singleLine="true"
|
||||
android:text="Toolbar"
|
||||
android:textColor="@color/abc_primary_text_material_dark"
|
||||
android:textSize="@dimen/abc_text_size_large_material"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/control_buttons"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -313,6 +313,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
if (fragmentRef != null) {
|
||||
fragmentRef.get().hideRouteCalculationProgressBar();
|
||||
fragmentRef.get().updateControlButtons();
|
||||
if (currentMenuState == MenuState.HEADER_ONLY) {
|
||||
fragmentRef.get().openMenuHalfScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -932,8 +935,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
targetPointsHelper.navigateToPoint(startPoint.point, false, -1, startPoint.getPointDescription(mapActivity));
|
||||
targetPointsHelper.setStartPoint(endPoint.point, false, endPoint.getPointDescription(mapActivity));
|
||||
targetPointsHelper.updateRouteAndRefresh(true);
|
||||
|
||||
// updateInfo(mainView);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -29,18 +29,23 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.LockableScrollView;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
|
||||
import net.osmand.plus.widgets.ImageViewExProgress;
|
||||
import net.osmand.plus.widgets.TextViewExProgress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.mapcontextmenu.MapContextMenuFragment.CURRENT_Y_UNDEFINED;
|
||||
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
|
||||
|
||||
|
@ -49,7 +54,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
|
||||
private MapRouteInfoMenu menu;
|
||||
private InterceptorLinearLayout mainView;
|
||||
private View toolbarContainer;
|
||||
private View view;
|
||||
private View.OnLayoutChangeListener containerLayoutListener;
|
||||
|
||||
|
@ -64,7 +68,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
private int menuTopShadowAllHeight;
|
||||
private int topScreenPosY;
|
||||
private int menuBottomViewHeight;
|
||||
private int bottomToolbarPosY;
|
||||
private int menuFullHeightMax;
|
||||
private int menuTitleHeight;
|
||||
private int shadowHeight;
|
||||
|
@ -86,7 +89,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
menu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
|
||||
shadowHeight = AndroidUtils.dpToPx(mapActivity, SHADOW_HEIGHT_TOP_DP);
|
||||
topScreenPosY = addStatusBarHeightIfNeeded(0);
|
||||
bottomToolbarPosY = addStatusBarHeightIfNeeded(getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar));
|
||||
minHalfY = viewHeight - (int) (viewHeight * .75f);
|
||||
|
||||
view = inflater.inflate(R.layout.plan_route_info, container, false);
|
||||
|
@ -105,16 +107,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
});
|
||||
|
||||
toolbarContainer = view.findViewById(R.id.context_menu_toolbar_container);
|
||||
View toolbarBackButton = view.findViewById(R.id.context_menu_toolbar_back);
|
||||
updateVisibility(toolbarContainer, 0);
|
||||
toolbarBackButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openMenuHeaderOnly();
|
||||
}
|
||||
});
|
||||
|
||||
LockableScrollView bottomScrollView = (LockableScrollView) view.findViewById(R.id.route_menu_bottom_scroll);
|
||||
bottomScrollView.setScrollingEnabled(false);
|
||||
bottomScrollView.setBackgroundColor(getResources().getColor(nightMode ? R.color.activity_background_dark : R.color.activity_background_light));
|
||||
|
@ -216,8 +208,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
|
||||
initVelocityTrackerIfNotExists();
|
||||
velocityTracker.addMovement(ev);
|
||||
|
||||
updateToolbar();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -341,7 +331,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
|
||||
@Override
|
||||
public int getStatusBarColorId() {
|
||||
if (menu != null && (menu.getCurrentMenuState() == MenuController.MenuState.FULL_SCREEN || !portrait)) {
|
||||
if (menu != null && (menu.getCurrentMenuState() == MapRouteInfoMenu.MenuState.FULL_SCREEN || !portrait)) {
|
||||
return nightMode ? R.color.status_bar_dark : R.color.status_bar_route_light;
|
||||
}
|
||||
return -1;
|
||||
|
@ -370,7 +360,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
private int getFullScreenTopPosY() {
|
||||
return -menuTitleHeight + bottomToolbarPosY;
|
||||
return -menuTitleHeight + AndroidUtils.getStatusBarHeight(getMyApplication());
|
||||
}
|
||||
|
||||
private int addStatusBarHeightIfNeeded(int res) {
|
||||
|
@ -385,18 +375,18 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
public void openMenuFullScreen() {
|
||||
changeMenuState(getMenuStatePosY(MenuController.MenuState.FULL_SCREEN), false, false);
|
||||
changeMenuState(getMenuStatePosY(MapRouteInfoMenu.MenuState.FULL_SCREEN), false, false);
|
||||
}
|
||||
|
||||
public void openMenuHeaderOnly() {
|
||||
if (portrait) {
|
||||
changeMenuState(getMenuStatePosY(MenuController.MenuState.HEADER_ONLY), false, false);
|
||||
changeMenuState(getMenuStatePosY(MapRouteInfoMenu.MenuState.HEADER_ONLY), false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void openMenuHalfScreen() {
|
||||
if (portrait) {
|
||||
changeMenuState(getMenuStatePosY(MenuController.MenuState.HALF_SCREEN), false, false);
|
||||
changeMenuState(getMenuStatePosY(MapRouteInfoMenu.MenuState.HALF_SCREEN), false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -426,16 +416,16 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
int fullDist = Math.abs(currentY - getMenuStatePosY(MapRouteInfoMenu.MenuState.FULL_SCREEN));
|
||||
int newState;
|
||||
if (headerDist < halfDist && headerDist < fullDist) {
|
||||
newState = MenuController.MenuState.HEADER_ONLY;
|
||||
newState = MapRouteInfoMenu.MenuState.HEADER_ONLY;
|
||||
} else if (halfDist < headerDist && halfDist < fullDist) {
|
||||
newState = MenuController.MenuState.HALF_SCREEN;
|
||||
newState = MapRouteInfoMenu.MenuState.HALF_SCREEN;
|
||||
} else {
|
||||
newState = MenuController.MenuState.FULL_SCREEN;
|
||||
newState = MapRouteInfoMenu.MenuState.FULL_SCREEN;
|
||||
}
|
||||
|
||||
if (slidingDown && currentMenuState == MenuController.MenuState.FULL_SCREEN && getViewY() < getFullScreenTopPosY()) {
|
||||
if (slidingDown && currentMenuState == MapRouteInfoMenu.MenuState.FULL_SCREEN && getViewY() < getFullScreenTopPosY()) {
|
||||
slidingDown = false;
|
||||
newState = MenuController.MenuState.FULL_SCREEN;
|
||||
newState = MapRouteInfoMenu.MenuState.FULL_SCREEN;
|
||||
}
|
||||
if (menuBottomViewHeight > 0 && slidingUp) {
|
||||
while (menu.getCurrentMenuState() != newState) {
|
||||
|
@ -444,7 +434,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
} else if (slidingDown) {
|
||||
if (currentMenuState == MenuController.MenuState.HEADER_ONLY) {
|
||||
if (currentMenuState == MapRouteInfoMenu.MenuState.HEADER_ONLY) {
|
||||
needCloseMenu = true;
|
||||
} else {
|
||||
while (menu.getCurrentMenuState() != newState) {
|
||||
|
@ -471,7 +461,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
int newMenuState = menu.getCurrentMenuState();
|
||||
boolean needMapAdjust = currentMenuState != newMenuState && newMenuState != MenuController.MenuState.FULL_SCREEN;
|
||||
boolean needMapAdjust = currentMenuState != newMenuState && newMenuState != MapRouteInfoMenu.MenuState.FULL_SCREEN;
|
||||
|
||||
applyPosY(currentY, needCloseMenu, needMapAdjust, currentMenuState, newMenuState, 0);
|
||||
}
|
||||
|
@ -487,20 +477,20 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
|
||||
int posY = 0;
|
||||
switch (destinationState) {
|
||||
case MenuController.MenuState.HEADER_ONLY:
|
||||
posY = getMenuStatePosY(MenuController.MenuState.HEADER_ONLY);
|
||||
case MapRouteInfoMenu.MenuState.HEADER_ONLY:
|
||||
posY = getMenuStatePosY(MapRouteInfoMenu.MenuState.HEADER_ONLY);
|
||||
break;
|
||||
case MenuController.MenuState.HALF_SCREEN:
|
||||
posY = getMenuStatePosY(MenuController.MenuState.HALF_SCREEN);
|
||||
case MapRouteInfoMenu.MenuState.HALF_SCREEN:
|
||||
posY = getMenuStatePosY(MapRouteInfoMenu.MenuState.HALF_SCREEN);
|
||||
break;
|
||||
case MenuController.MenuState.FULL_SCREEN:
|
||||
case MapRouteInfoMenu.MenuState.FULL_SCREEN:
|
||||
if (currentY != CURRENT_Y_UNDEFINED) {
|
||||
int maxPosY = viewHeight - menuFullHeightMax;
|
||||
int minPosY = getMenuStatePosY(MenuController.MenuState.FULL_SCREEN);
|
||||
int minPosY = getMenuStatePosY(MapRouteInfoMenu.MenuState.FULL_SCREEN);
|
||||
if (maxPosY > minPosY) {
|
||||
maxPosY = minPosY;
|
||||
}
|
||||
if (currentY > minPosY || previousState != MenuController.MenuState.FULL_SCREEN) {
|
||||
if (currentY > minPosY || previousState != MapRouteInfoMenu.MenuState.FULL_SCREEN) {
|
||||
posY = minPosY;
|
||||
} else if (currentY < maxPosY) {
|
||||
posY = maxPosY;
|
||||
|
@ -508,7 +498,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
posY = currentY;
|
||||
}
|
||||
} else {
|
||||
posY = getMenuStatePosY(MenuController.MenuState.FULL_SCREEN);
|
||||
posY = getMenuStatePosY(MapRouteInfoMenu.MenuState.FULL_SCREEN);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -539,21 +529,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
updateMainViewLayout(posY);
|
||||
}
|
||||
|
||||
final float toolbarAlpha = getToolbarAlpha(posY);
|
||||
if (toolbarAlpha > 0) {
|
||||
updateVisibility(toolbarContainer, true);
|
||||
}
|
||||
toolbarContainer.animate().alpha(toolbarAlpha)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
updateVisibility(toolbarContainer, toolbarAlpha);
|
||||
}
|
||||
})
|
||||
.start();
|
||||
|
||||
mainView.animate().y(posY)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
|
@ -582,6 +557,9 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
})
|
||||
.start();
|
||||
|
||||
if (needMapAdjust) {
|
||||
adjustMapPosition(posY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -589,44 +567,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
runLayoutListener();
|
||||
}
|
||||
|
||||
private float getToolbarAlpha(int y) {
|
||||
float a = 0;
|
||||
if (menu != null && portrait) {
|
||||
if (y < bottomToolbarPosY) {
|
||||
a = 1f - (y - topScreenPosY) * (1f / (bottomToolbarPosY - topScreenPosY));
|
||||
}
|
||||
if (a < 0) {
|
||||
a = 0;
|
||||
} else if (a > 1) {
|
||||
a = 1;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private void updateToolbar() {
|
||||
float a = getToolbarAlpha(getViewY());
|
||||
updateVisibility(toolbarContainer, a);
|
||||
}
|
||||
|
||||
private void updateVisibility(View v, float alpha) {
|
||||
boolean visible = alpha > 0;
|
||||
v.setAlpha(alpha);
|
||||
if (visible && v.getVisibility() != View.VISIBLE) {
|
||||
v.setVisibility(View.VISIBLE);
|
||||
} else if (!visible && v.getVisibility() == View.VISIBLE) {
|
||||
v.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVisibility(View v, boolean visible) {
|
||||
if (visible && v.getVisibility() != View.VISIBLE) {
|
||||
v.setVisibility(View.VISIBLE);
|
||||
} else if (!visible && v.getVisibility() == View.VISIBLE) {
|
||||
v.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
private void runLayoutListener() {
|
||||
if (view != null) {
|
||||
|
@ -677,13 +617,58 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
public int getHeight() {
|
||||
if (mainView != null) {
|
||||
return mainView.getHeight();
|
||||
if (menu != null) {
|
||||
int height = getMenuStatePosY(menu.getCurrentMenuState());
|
||||
return viewHeight - height - AndroidUtils.getStatusBarHeight(getMyApplication());
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustMapPosition(int y) {
|
||||
if (menu.isSelectFromMapTouch()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RoutingHelper rh = getMyApplication().getRoutingHelper();
|
||||
if (rh.isRoutePlanningMode() && getMapActivity().getMapView() != null) {
|
||||
Location lt = rh.getLastProjection();
|
||||
if (lt == null) {
|
||||
lt = getMyApplication().getTargetPointsHelper().getPointToStartLocation();
|
||||
}
|
||||
if (lt != null) {
|
||||
double left = lt.getLongitude(), right = lt.getLongitude();
|
||||
double top = lt.getLatitude(), bottom = lt.getLatitude();
|
||||
List<Location> list = rh.getCurrentCalculatedRoute();
|
||||
for (Location l : list) {
|
||||
left = Math.min(left, l.getLongitude());
|
||||
right = Math.max(right, l.getLongitude());
|
||||
top = Math.max(top, l.getLatitude());
|
||||
bottom = Math.min(bottom, l.getLatitude());
|
||||
}
|
||||
List<TargetPointsHelper.TargetPoint> targetPoints = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget();
|
||||
for (TargetPointsHelper.TargetPoint l : targetPoints) {
|
||||
left = Math.min(left, l.getLongitude());
|
||||
right = Math.max(right, l.getLongitude());
|
||||
top = Math.max(top, l.getLatitude());
|
||||
bottom = Math.min(bottom, l.getLatitude());
|
||||
}
|
||||
|
||||
RotatedTileBox tb = getMapActivity().getMapView().getCurrentRotatedTileBox().copy();
|
||||
int tileBoxWidthPx = 0;
|
||||
int tileBoxHeightPx = 0;
|
||||
|
||||
if (!portrait) {
|
||||
tileBoxWidthPx = tb.getPixWidth() - getWidth();
|
||||
} else {
|
||||
int fHeight = viewHeight - y - AndroidUtils.getStatusBarHeight(getMyApplication());
|
||||
tileBoxHeightPx = tb.getPixHeight() - fHeight;
|
||||
}
|
||||
getMapActivity().getMapView().fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
if (mainView != null) {
|
||||
return mainView.getWidth();
|
||||
|
|
Loading…
Reference in a new issue