Fix bug with wrong height when few ContextMenuFragment fragments are displayed simultaneously

This commit is contained in:
Dima-1 2020-09-10 16:53:19 +03:00
parent f2d64a7464
commit 2248d47941
5 changed files with 331 additions and 106 deletions

View file

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:background="@color/color_transparent">
<LinearLayout
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<FrameLayout
android:id="@+id/map_controls_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="bottom">
<include
layout="@layout/map_ruler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:layout_marginStart="@dimen/fab_margin_right"
android:layout_marginLeft="@dimen/fab_margin_right"
android:layout_marginEnd="@dimen/fab_margin_right"
android:layout_marginRight="@dimen/fab_margin_right"
tools:visibility="invisible" />
<include
layout="@layout/map_hud_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginStart="@dimen/fab_margin_right"
android:layout_marginLeft="@dimen/fab_margin_right"
android:layout_marginEnd="@dimen/fab_margin_right"
android:layout_marginRight="@dimen/fab_margin_right"
tools:visibility="invisible" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<include layout="@layout/context_menu_top_shadow" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingTop="@dimen/measurement_tool_menu_title_padding_top"
android:orientation="vertical"
android:paddingEnd="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingBottom="@dimen/dialog_button_ex_height"
android:clickable="true"
android:focusable="true">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingBottom="@dimen/measurement_tool_menu_title_padding_bottom"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
android:text="@string/route_between_points"
tools:text="@string/route_between_points" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/content_padding_half"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
android:text="@string/rourte_between_points_warning_desc"
tools:text="@string/rourte_between_points_warning_desc" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/control_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:clickable="true"
android:focusable="true"
android:orientation="vertical">
<include
layout="@layout/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_height"
android:layout_gravity="bottom" />
</LinearLayout>
</FrameLayout>

View file

@ -122,7 +122,7 @@ import net.osmand.plus.measurementtool.GpxApproximationFragment;
import net.osmand.plus.measurementtool.GpxData;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.SnapTrackWarningBottomSheet;
import net.osmand.plus.measurementtool.SnapTrackWarningFragment;
import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager;
@ -692,9 +692,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return;
}
SnapTrackWarningBottomSheet snapTrackWarningBottomSheet = getSnapTrackWarningBottomSheet();
if (snapTrackWarningBottomSheet != null) {
snapTrackWarningBottomSheet.dismiss();
SnapTrackWarningFragment snapTrackWarningFragment = getSnapTrackWarningBottomSheet();
if (snapTrackWarningFragment != null) {
snapTrackWarningFragment.dismissImmediate();
return;
}
@ -2329,8 +2329,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return getFragment(GpxApproximationFragment.TAG);
}
private SnapTrackWarningBottomSheet getSnapTrackWarningBottomSheet() {
return getFragment(SnapTrackWarningBottomSheet.TAG);
public SnapTrackWarningFragment getSnapTrackWarningBottomSheet() {
return getFragment(SnapTrackWarningFragment.TAG);
}
public PointEditorFragmentNew getPointEditorFragmentNew() {

View file

@ -414,7 +414,18 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
toolBarController.setOnBackButtonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
quit(false);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
GpxApproximationFragment gpxApproximationFragment = mapActivity.getGpxApproximationFragment();
SnapTrackWarningFragment snapTrackWarningFragment = mapActivity.getSnapTrackWarningBottomSheet();
if (gpxApproximationFragment != null) {
gpxApproximationFragment.dismissImmediate();
} else if (snapTrackWarningFragment != null) {
snapTrackWarningFragment.dismissImmediate();
} else {
quit(false);
}
}
}
});
toolBarController.setOnSaveViewClickListener(new OnClickListener() {
@ -640,15 +651,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SnapTrackWarningBottomSheet.REQUEST_CODE:
case SnapTrackWarningFragment.REQUEST_CODE:
switch (resultCode) {
case SnapTrackWarningBottomSheet.CANCEL_RESULT_CODE:
case SnapTrackWarningFragment.CANCEL_RESULT_CODE:
toolBarController.setSaveViewVisible(true);
directionMode = false;
exitApproximationMode();
updateToolbar();
break;
case SnapTrackWarningBottomSheet.CONTINUE_RESULT_CODE:
case SnapTrackWarningFragment.CONTINUE_RESULT_CODE:
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(),
@ -2126,7 +2137,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
manager.beginTransaction()
.hide(this).commit();
layer.setTapsDisabled(true);
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
SnapTrackWarningFragment.showInstance(mapActivity.getSupportFragmentManager(), this);
AndroidUiHelper.setVisibility(mapActivity, View.GONE, R.id.map_ruler_container);
}
}

View file

@ -1,95 +0,0 @@
package net.osmand.plus.measurementtool;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.helpers.GpxTrackAdapter;
import org.apache.commons.logging.Log;
public class SnapTrackWarningBottomSheet extends MenuBottomSheetDialogFragment {
public static final int REQUEST_CODE = 1000;
public static final int CANCEL_RESULT_CODE = 2;
public static final int CONTINUE_RESULT_CODE = 3;
public static final String TAG = SnapTrackWarningBottomSheet.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SnapTrackWarningBottomSheet.class);
protected View mainView;
protected GpxTrackAdapter adapter;
private boolean continued = false;
@Override
public void createMenuItems(Bundle savedInstanceState) {
Activity activity = getActivity();
if (activity instanceof MapActivity) {
activity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.GONE);
}
BaseBottomSheetItem description = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.rourte_between_points_warning_desc))
.setTitle(getString(R.string.route_between_points))
.setLayoutId(R.layout.bottom_sheet_item_list_title_with_descr)
.create();
items.add(description);
items.add(new DividerSpaceItem(getContext(), getResources().getDimensionPixelSize(R.dimen.content_padding_half)));
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_continue;
}
@Override
protected void onRightBottomButtonClick() {
Fragment fragment = getTargetFragment();
if (fragment != null) {
continued = true;
fragment.onActivityResult(REQUEST_CODE, CONTINUE_RESULT_CODE, null);
}
dismiss();
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_cancel;
}
@Override
public void onDestroyView() {
super.onDestroyView();
Activity activity = getActivity();
if (activity instanceof MapActivity) {
activity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.VISIBLE);
}
Fragment fragment = getTargetFragment();
if (fragment != null && !continued) {
fragment.onActivityResult(REQUEST_CODE, CANCEL_RESULT_CODE, null);
}
}
public static void showInstance(FragmentManager fm, Fragment targetFragment) {
try {
if (!fm.isStateSaved()) {
SnapTrackWarningBottomSheet fragment = new SnapTrackWarningBottomSheet();
fragment.setTargetFragment(targetFragment, REQUEST_CODE);
fm.beginTransaction()
.add(R.id.bottomFragmentContainer, fragment, TAG)
.commitAllowingStateLoss();
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
}

View file

@ -0,0 +1,190 @@
package net.osmand.plus.measurementtool;
import android.app.Activity;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.MapControlsLayer;
import net.osmand.plus.views.layers.MapInfoLayer;
import org.apache.commons.logging.Log;
import static android.view.Gravity.TOP;
import static android.view.ViewGroup.LayoutParams.*;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.BACK_TO_LOC_HUD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_IN_HUD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.ZOOM_OUT_HUD_ID;
import static net.osmand.plus.UiUtilities.DialogButtonType.*;
public class SnapTrackWarningFragment extends BaseOsmAndFragment {
public static final int REQUEST_CODE = 1000;
public static final int CANCEL_RESULT_CODE = 2;
public static final int CONTINUE_RESULT_CODE = 3;
public static final String TAG = SnapTrackWarningFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SnapTrackWarningFragment.class);
private static final String ZOOM_IN_BUTTON_ID = ZOOM_IN_HUD_ID + TAG;
private static final String ZOOM_OUT_BUTTON_ID = ZOOM_OUT_HUD_ID + TAG;
private static final String BACK_TO_LOC_BUTTON_ID = BACK_TO_LOC_HUD_ID + TAG;
protected View mainView;
private boolean continued = false;
private View cancelButton;
private View applyButton;
private boolean nightMode;
private boolean portrait;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
OsmandApplication app = getMyApplication();
if (app != null) {
nightMode = app.getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(getMapActivity());
}
View rootView = UiUtilities.getInflater(getContext(), nightMode)
.inflate(R.layout.fragment_plan_route_warning, container, false);
if (rootView == null) {
return null;
}
applyButton = rootView.findViewById(R.id.right_bottom_button);
cancelButton = rootView.findViewById(R.id.dismiss_button);
View mapControlsContainer = rootView.findViewById(R.id.map_controls_container);
updateButtons(rootView);
if (portrait) {
setupControlButtons(rootView);
mapControlsContainer.setVisibility(View.VISIBLE);
} else {
mapControlsContainer.setVisibility(View.GONE);
final TypedValue typedValueAttr = new TypedValue();
int bgAttrId = AndroidUtils.isLayoutRtl(app) ? R.attr.right_menu_view_bg : R.attr.left_menu_view_bg;
getMapActivity().getTheme().resolveAttribute(bgAttrId, typedValueAttr, true);
rootView.setBackgroundResource(typedValueAttr.resourceId);
LinearLayout mainView = rootView.findViewById(R.id.main_view);
FrameLayout.LayoutParams params;
params = (FrameLayout.LayoutParams) mainView.getLayoutParams();
params.gravity = TOP;
int landscapeWidth = getResources().getDimensionPixelSize(R.dimen.dashboard_land_width);
rootView.setLayoutParams(new FrameLayout.LayoutParams(landscapeWidth, MATCH_PARENT));
}
return rootView;
}
private void setupControlButtons(@NonNull View view) {
MapActivity mapActivity = getMapActivity();
View zoomInButtonView = view.findViewById(R.id.map_zoom_in_button);
View zoomOutButtonView = view.findViewById(R.id.map_zoom_out_button);
View myLocButtonView = view.findViewById(R.id.map_my_location_button);
View mapRulerView = view.findViewById(R.id.map_ruler_layout);
MapActivityLayers mapLayers = mapActivity.getMapLayers();
OsmandMapTileView mapTileView = mapActivity.getMapView();
View.OnLongClickListener longClickListener = MapControlsLayer.getOnClickMagnifierListener(mapTileView);
MapControlsLayer mapControlsLayer = mapLayers.getMapControlsLayer();
mapControlsLayer.setupZoomInButton(zoomInButtonView, longClickListener, ZOOM_IN_BUTTON_ID);
mapControlsLayer.setupZoomOutButton(zoomOutButtonView, longClickListener, ZOOM_OUT_BUTTON_ID);
mapControlsLayer.setupBackToLocationButton(myLocButtonView, false, BACK_TO_LOC_BUTTON_ID);
MapInfoLayer mapInfoLayer = mapLayers.getMapInfoLayer();
mapInfoLayer.setupRulerWidget(mapRulerView);
}
private void updateButtons(View view) {
View buttonsContainer = view.findViewById(R.id.buttons_container);
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.list_background_color));
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment fragment = getTargetFragment();
if (fragment != null) {
continued = true;
dismissImmediate();
fragment.onActivityResult(REQUEST_CODE, CONTINUE_RESULT_CODE, null);
}
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity activity = getActivity();
if (activity != null) {
activity.onBackPressed();
}
}
});
UiUtilities.setupDialogButton(nightMode, cancelButton, SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(nightMode, applyButton, PRIMARY, R.string.shared_string_apply);
AndroidUiHelper.updateVisibility(applyButton, true);
AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true);
}
@Override
public void onDestroyView() {
super.onDestroyView();
Activity activity = getActivity();
if (activity instanceof MapActivity) {
activity.findViewById(R.id.snap_to_road_image_button).setVisibility(View.VISIBLE);
}
Fragment fragment = getTargetFragment();
if (fragment != null && !continued) {
fragment.onActivityResult(REQUEST_CODE, CANCEL_RESULT_CODE, null);
}
}
public MapActivity getMapActivity() {
FragmentActivity activity = getActivity();
if (activity instanceof MapActivity) {
return (MapActivity) activity;
} else {
return null;
}
}
public static void showInstance(FragmentManager fm, Fragment targetFragment) {
try {
if (!fm.isStateSaved()) {
SnapTrackWarningFragment fragment = new SnapTrackWarningFragment();
fragment.setTargetFragment(targetFragment, REQUEST_CODE);
fm.beginTransaction()
.replace(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(TAG)
.commitAllowingStateLoss();
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
public void dismissImmediate() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
try {
mapActivity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (Exception e) {
LOG.error(e);
}
}
}
}