Fix context menu UI issues

This commit is contained in:
Alexey Kulish 2018-02-02 12:04:46 +03:00
parent 09e4e6bba8
commit 19e2e90276
3 changed files with 53 additions and 8 deletions

View file

@ -602,11 +602,11 @@
<FrameLayout <FrameLayout
android:id="@+id/context_menu_top_button_container" android:id="@+id/context_menu_top_button_container"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="@dimen/dashboard_map_toolbar" android:layout_height="@dimen/dashboard_map_toolbar"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:alpha="0"> android:alpha="1">
<LinearLayout <LinearLayout
android:layout_width="@dimen/list_item_height" android:layout_width="@dimen/list_item_height"
@ -669,6 +669,10 @@
android:scaleType="center" android:scaleType="center"
android:textColor="@color/abc_primary_text_material_dark" android:textColor="@color/abc_primary_text_material_dark"
android:textSize="@dimen/abc_text_size_large_material" android:textSize="@dimen/abc_text_size_large_material"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
tools:text="Toolbar" tools:text="Toolbar"
tools:visibility="visible"/> tools:visibility="visible"/>

View file

@ -665,6 +665,11 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} }
} }
public boolean hasActiveToolbar() {
TopToolbarController toolbarController = mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU);
return toolbarController != null && toolbarController instanceof ContextMenuToolbarController;
}
public void closeActiveToolbar() { public void closeActiveToolbar() {
TopToolbarController toolbarController = mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU); TopToolbarController toolbarController = mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU);
if (toolbarController != null && toolbarController instanceof ContextMenuToolbarController) { if (toolbarController != null && toolbarController instanceof ContextMenuToolbarController) {

View file

@ -159,14 +159,13 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
toolbarView = view.findViewById(R.id.context_menu_toolbar); toolbarView = view.findViewById(R.id.context_menu_toolbar);
toolbarBackButton = view.findViewById(R.id.context_menu_toolbar_back); toolbarBackButton = view.findViewById(R.id.context_menu_toolbar_back);
toolbarTextView = (TextView) view.findViewById(R.id.context_menu_toolbar_text); toolbarTextView = (TextView) view.findViewById(R.id.context_menu_toolbar_text);
toolbarContainer.setAlpha(0); updateVisibility(toolbarContainer, 0);
toolbarBackButton.setOnClickListener(new View.OnClickListener() { toolbarBackButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
openMenuHeaderOnly(); openMenuHeaderOnly();
} }
}); });
toolbarTextView.setText(menu.getTitleStr());
topButtonContainer = view.findViewById(R.id.context_menu_top_button_container); topButtonContainer = view.findViewById(R.id.context_menu_top_button_container);
view.findViewById(R.id.context_menu_top_back).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.context_menu_top_back).setOnClickListener(new View.OnClickListener() {
@ -175,7 +174,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
openMenuHeaderOnly(); openMenuHeaderOnly();
} }
}); });
topButtonContainer.setAlpha(0); updateVisibility(topButtonContainer, 0);
map = getMapActivity().getMapView(); map = getMapActivity().getMapView();
RotatedTileBox box = map.getCurrentRotatedTileBox().copy(); RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
@ -621,12 +620,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private void updateToolbar() { private void updateToolbar() {
float a = getToolbarAlpha(getViewY()); float a = getToolbarAlpha(getViewY());
toolbarContainer.setAlpha(a); updateVisibility(toolbarContainer, a);
} }
private float getTopButtonAlpha(int y) { private float getTopButtonAlpha(int y) {
float a = 0; float a = 0;
if (menu != null && !menu.isLandscapeLayout()) { if (menu != null && !menu.isLandscapeLayout() && !menu.hasActiveToolbar()) {
int headerTopY = getHeaderOnlyTopY(); int headerTopY = getHeaderOnlyTopY();
if (y < headerTopY) { if (y < headerTopY) {
a = 1f - (y - minHalfY) * (1f / (headerTopY - minHalfY)); a = 1f - (y - minHalfY) * (1f / (headerTopY - minHalfY));
@ -642,7 +641,25 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private void updateTopButton() { private void updateTopButton() {
float a = getTopButtonAlpha(getViewY()); float a = getTopButtonAlpha(getViewY());
topButtonContainer.setAlpha(a); updateVisibility(topButtonContainer, 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);
}
} }
private void toggleDetailsHideButton() { private void toggleDetailsHideButton() {
@ -788,15 +805,33 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
} }
final float topButtonAlpha = getTopButtonAlpha(posY); final float topButtonAlpha = getTopButtonAlpha(posY);
if (topButtonAlpha > 0) {
updateVisibility(topButtonContainer, true);
}
topButtonContainer.animate().alpha(topButtonAlpha) topButtonContainer.animate().alpha(topButtonAlpha)
.setDuration(200) .setDuration(200)
.setInterpolator(new DecelerateInterpolator()) .setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
updateVisibility(topButtonContainer, topButtonAlpha);
}
})
.start(); .start();
final float toolbarAlpha = getToolbarAlpha(posY); final float toolbarAlpha = getToolbarAlpha(posY);
if (toolbarAlpha > 0) {
updateVisibility(toolbarContainer, true);
}
toolbarContainer.animate().alpha(toolbarAlpha) toolbarContainer.animate().alpha(toolbarAlpha)
.setDuration(200) .setDuration(200)
.setInterpolator(new DecelerateInterpolator()) .setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
updateVisibility(toolbarContainer, toolbarAlpha);
}
})
.start(); .start();
mainView.animate().y(posY) mainView.animate().y(posY)
@ -1281,6 +1316,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Text line 1 // Text line 1
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1); TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
line1.setText(menu.getTitleStr()); line1.setText(menu.getTitleStr());
toolbarTextView.setText(menu.getTitleStr());
// Text line 2 // Text line 2
LinearLayout line2layout = (LinearLayout) view.findViewById(R.id.context_menu_line2_layout); LinearLayout line2layout = (LinearLayout) view.findViewById(R.id.context_menu_line2_layout);