Added toolbar to context menu
This commit is contained in:
parent
e4298a796c
commit
cb2ede54bc
5 changed files with 226 additions and 25 deletions
4
OsmAnd/res/drawable/btn_circle_trans_flat.xml
Normal file
4
OsmAnd/res/drawable/btn_circle_trans_flat.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/btn_circle_trans_flat_n"/>
|
||||
</selector>
|
8
OsmAnd/res/drawable/btn_circle_trans_flat_n.xml
Normal file
8
OsmAnd/res/drawable/btn_circle_trans_flat_n.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<solid android:color="@color/map_widget_stroke"/>
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
|
@ -600,6 +600,82 @@
|
|||
|
||||
</net.osmand.plus.mapcontextmenu.InterceptorLinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/context_menu_top_button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginStart="4dp"
|
||||
android:alpha="0">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/list_item_height"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:background="@drawable/btn_circle_trans_flat"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/context_menu_top_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"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<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="fill_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:scaleType="center"
|
||||
android:textColor="@color/abc_primary_text_material_dark"
|
||||
android:textSize="@dimen/abc_text_size_large_material"
|
||||
tools:text="Toolbar"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/context_menu_fab_container"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -1069,7 +1069,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if (menuController != null) {
|
||||
return menuController.getHalfScreenMaxHeightKoef();
|
||||
} else {
|
||||
return 0f;
|
||||
return .75f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
|
|||
public class MapContextMenuFragment extends BaseOsmAndFragment implements DownloadEvents {
|
||||
public static final String TAG = "MapContextMenuFragment";
|
||||
|
||||
public static final float FAB_PADDING_TOP_DP = 4f;
|
||||
public static final float ZOOM_PADDING_TOP_DP = 4f;
|
||||
public static final float MARKER_PADDING_DP = 20f;
|
||||
public static final float MARKER_PADDING_X_DP = 50f;
|
||||
public static final float SKIP_HALF_SCREEN_STATE_KOEF = .21f;
|
||||
|
@ -76,6 +76,13 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
private View view;
|
||||
private InterceptorLinearLayout mainView;
|
||||
|
||||
private View toolbarContainer;
|
||||
private View toolbarView;
|
||||
private View toolbarBackButton;
|
||||
private TextView toolbarTextView;
|
||||
private View topButtonContainer;
|
||||
|
||||
private View zoomButtonsView;
|
||||
private ImageButton zoomInButtonView;
|
||||
private ImageButton zoomOutButtonView;
|
||||
|
@ -99,6 +106,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
private int markerPaddingPx;
|
||||
private int markerPaddingXPx;
|
||||
private int topScreenPosY;
|
||||
private int bottomToolbarPosY;
|
||||
private int minHalfY;
|
||||
private int shadowHeight;
|
||||
private int zoomPaddingTop;
|
||||
|
||||
private OsmandMapTileView map;
|
||||
private LatLon mapCenter;
|
||||
|
@ -124,18 +135,47 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
processScreenHeight(container);
|
||||
|
||||
menu = getMapActivity().getContextMenu();
|
||||
|
||||
markerPaddingPx = dpToPx(MARKER_PADDING_DP);
|
||||
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
|
||||
topScreenPosY = addStatusBarHeightIfNeeded(-dpToPx(SHADOW_HEIGHT_TOP_DP));
|
||||
shadowHeight = dpToPx(SHADOW_HEIGHT_TOP_DP);
|
||||
topScreenPosY = addStatusBarHeightIfNeeded(-shadowHeight);
|
||||
bottomToolbarPosY = addStatusBarHeightIfNeeded(getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar));
|
||||
minHalfY = viewHeight - (int) (viewHeight * menu.getHalfScreenMaxHeightKoef());
|
||||
zoomPaddingTop = dpToPx(ZOOM_PADDING_TOP_DP);
|
||||
|
||||
menu = getMapActivity().getContextMenu();
|
||||
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
|
||||
if (!menu.isActive()) {
|
||||
return view;
|
||||
}
|
||||
AndroidUtils.addStatusBarPadding21v(getMapActivity(), view);
|
||||
|
||||
nightMode = menu.isNightMode();
|
||||
mainView = view.findViewById(R.id.context_menu_main);
|
||||
|
||||
toolbarContainer = view.findViewById(R.id.context_menu_toolbar_container);
|
||||
toolbarView = view.findViewById(R.id.context_menu_toolbar);
|
||||
toolbarBackButton = view.findViewById(R.id.context_menu_toolbar_back);
|
||||
toolbarTextView = (TextView) view.findViewById(R.id.context_menu_toolbar_text);
|
||||
toolbarContainer.setAlpha(0);
|
||||
toolbarBackButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openMenuHeaderOnly();
|
||||
}
|
||||
});
|
||||
toolbarTextView.setText(menu.getTitleStr());
|
||||
|
||||
topButtonContainer = view.findViewById(R.id.context_menu_top_button_container);
|
||||
view.findViewById(R.id.context_menu_top_back).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openMenuHeaderOnly();
|
||||
}
|
||||
});
|
||||
topButtonContainer.setAlpha(0);
|
||||
|
||||
map = getMapActivity().getMapView();
|
||||
RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
|
||||
customMapCenter = menu.getMapCenter() != null;
|
||||
|
@ -252,11 +292,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
private float dy;
|
||||
private float dyMain;
|
||||
private float mDownY;
|
||||
private VelocityTracker velocity;
|
||||
private VelocityTracker velocityTracker;
|
||||
private boolean slidingUp;
|
||||
private boolean slidingDown;
|
||||
|
||||
private float velocityY;
|
||||
private float maxVelocityY;
|
||||
private boolean hasMoved;
|
||||
|
||||
|
@ -270,12 +309,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
applyPosY(getViewY(), false, false, 0, 0, 0);
|
||||
}
|
||||
openMenuHalfScreen();
|
||||
|
||||
recycleVelocityTracker();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (menu.isLandscapeLayout()) {
|
||||
if (swipeDetector.onTouchEvent(event)) {
|
||||
menu.close();
|
||||
|
||||
recycleVelocityTracker();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -286,10 +329,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
mDownY = event.getRawY();
|
||||
dy = event.getY();
|
||||
dyMain = getViewY();
|
||||
velocity = VelocityTracker.obtain();
|
||||
velocityY = 0;
|
||||
|
||||
maxVelocityY = 0;
|
||||
velocity.addMovement(event);
|
||||
initOrResetVelocityTracker();
|
||||
velocityTracker.addMovement(event);
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
|
@ -311,20 +354,22 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
mainView.setLayoutParams(lp);
|
||||
mainView.requestLayout();
|
||||
|
||||
if (velocity != null) {
|
||||
velocity.addMovement(event);
|
||||
velocity.computeCurrentVelocity(1000);
|
||||
velocityY = Math.abs(velocity.getYVelocity());
|
||||
if (velocityTracker != null) {
|
||||
velocityTracker.addMovement(event);
|
||||
velocityTracker.computeCurrentVelocity(1000);
|
||||
float velocityY = Math.abs(velocityTracker.getYVelocity());
|
||||
if (velocityY > maxVelocityY) {
|
||||
maxVelocityY = velocityY;
|
||||
}
|
||||
}
|
||||
|
||||
updateToolbar();
|
||||
updateTopButton();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
if (moving) {
|
||||
moving = false;
|
||||
int currentY = getViewY();
|
||||
|
@ -332,18 +377,35 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50;
|
||||
slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50;
|
||||
|
||||
if (velocity != null) {
|
||||
velocity.recycle();
|
||||
}
|
||||
|
||||
boolean skipScreenState = Math.abs(currentY - dyMain) > skipScreenStateLimit;
|
||||
changeMenuState(currentY, skipScreenState, slidingUp, slidingDown);
|
||||
}
|
||||
recycleVelocityTracker();
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
moving = false;
|
||||
recycleVelocityTracker();
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void initOrResetVelocityTracker() {
|
||||
if (velocityTracker == null) {
|
||||
velocityTracker = VelocityTracker.obtain();
|
||||
} else {
|
||||
velocityTracker.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void recycleVelocityTracker() {
|
||||
if (velocityTracker != null) {
|
||||
velocityTracker.recycle();
|
||||
velocityTracker = null;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
View topShadowAllView = view.findViewById(R.id.context_menu_top_shadow_all);
|
||||
|
@ -541,6 +603,43 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
return view;
|
||||
}
|
||||
|
||||
private float getToolbarAlpha(int y) {
|
||||
float a = 0;
|
||||
if (y < minHalfY) {
|
||||
a = 1f - (y - bottomToolbarPosY) * (1f / (minHalfY - bottomToolbarPosY));
|
||||
}
|
||||
if (a < 0) {
|
||||
a = 0;
|
||||
} else if (a > 1) {
|
||||
a = 1;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private void updateToolbar() {
|
||||
float a = getToolbarAlpha(getViewY());
|
||||
toolbarContainer.setAlpha(a);
|
||||
}
|
||||
|
||||
private float getTopButtonAlpha(int y) {
|
||||
float a = 0;
|
||||
int headerTopY = getHeaderOnlyTopY();
|
||||
if (y < headerTopY) {
|
||||
a = 1f - (y - minHalfY) * (1f / (headerTopY - minHalfY));
|
||||
}
|
||||
if (a < 0) {
|
||||
a = 0;
|
||||
} else if (a > 1) {
|
||||
a = 1;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private void updateTopButton() {
|
||||
float a = getTopButtonAlpha(getViewY());
|
||||
topButtonContainer.setAlpha(a);
|
||||
}
|
||||
|
||||
private void toggleDetailsHideButton() {
|
||||
int menuState = menu.getCurrentMenuState();
|
||||
final boolean showShowHideButton = menuState == MenuState.HALF_SCREEN || (!menu.isLandscapeLayout() && menuState == MenuState.FULL_SCREEN);
|
||||
|
@ -582,7 +681,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
private void processScreenHeight(ViewParent parent) {
|
||||
View container = (View)parent;
|
||||
View container = (View) parent;
|
||||
screenHeight = container.getHeight() + AndroidUtils.getStatusBarHeight(getActivity());
|
||||
skipScreenStateLimit = screenHeight * SKIP_HALF_SCREEN_STATE_KOEF;
|
||||
viewHeight = screenHeight - AndroidUtils.getStatusBarHeight(getMapActivity());
|
||||
|
@ -682,6 +781,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
updateMainViewLayout(posY);
|
||||
}
|
||||
|
||||
final float topButtonAlpha = getTopButtonAlpha(posY);
|
||||
topButtonContainer.animate().alpha(topButtonAlpha)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.start();
|
||||
|
||||
final float toolbarAlpha = getToolbarAlpha(posY);
|
||||
toolbarContainer.animate().alpha(toolbarAlpha)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
.start();
|
||||
|
||||
mainView.animate().y(posY)
|
||||
.setDuration(200)
|
||||
.setInterpolator(new DecelerateInterpolator())
|
||||
|
@ -739,7 +850,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
|
||||
button.setTextColor(buttonColorStateList);
|
||||
} else {
|
||||
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_disabled_bg_dark: R.drawable.context_menu_controller_disabled_bg_light);
|
||||
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_disabled_bg_dark : R.drawable.context_menu_controller_disabled_bg_light);
|
||||
button.setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_controller_disabled_text_color_dark : R.color.ctx_menu_controller_disabled_text_color_light));
|
||||
}
|
||||
button.setEnabled(enabled);
|
||||
|
@ -1267,6 +1378,11 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
|
||||
private int getHeaderOnlyTopY() {
|
||||
return viewHeight - menuTitleHeight;
|
||||
}
|
||||
|
||||
|
||||
private int getPosY() {
|
||||
return getPosY(CURRENT_Y_UNDEFINED, false);
|
||||
}
|
||||
|
@ -1277,13 +1393,10 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
int destinationState;
|
||||
int minHalfY;
|
||||
if (menu.isExtended()) {
|
||||
destinationState = menu.getCurrentMenuState();
|
||||
minHalfY = viewHeight - (int) (viewHeight * menu.getHalfScreenMaxHeightKoef());
|
||||
} else {
|
||||
destinationState = MenuState.HEADER_ONLY;
|
||||
minHalfY = viewHeight - (int) (viewHeight * .75f);
|
||||
}
|
||||
|
||||
updateZoomButtonsVisibility(destinationState);
|
||||
|
@ -1291,7 +1404,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
int posY = 0;
|
||||
switch (destinationState) {
|
||||
case MenuState.HEADER_ONLY:
|
||||
posY = viewHeight - menuTitleHeight;
|
||||
posY = getHeaderOnlyTopY();
|
||||
break;
|
||||
case MenuState.HALF_SCREEN:
|
||||
posY = minHalfY;
|
||||
|
@ -1440,7 +1553,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
private int getZoomButtonsY(int y) {
|
||||
return y - zoomButtonsHeight;
|
||||
return y - zoomButtonsHeight - shadowHeight - zoomPaddingTop;
|
||||
}
|
||||
|
||||
private void doLayoutMenu() {
|
||||
|
|
Loading…
Reference in a new issue