From d3fd16c098bfa76b39a2c992b4fbb7fe9132d13a Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Tue, 6 Feb 2024 13:39:56 +0300 Subject: [PATCH] Fix panel positioning issues --- .../main/java/mobi/maptrek/MainActivity.java | 136 +++++++++++------- .../main/res/layout-land/activity_main.xml | 18 +-- app/src/main/res/layout/activity_main.xml | 17 ++- .../main/res/layout/list_with_empty_view.xml | 19 ++- app/src/main/res/values-land/dimens.xml | 1 + app/src/main/res/values/dimens.xml | 1 + 6 files changed, 118 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/mobi/maptrek/MainActivity.java b/app/src/main/java/mobi/maptrek/MainActivity.java index 39da5cd7..cc6fda09 100644 --- a/app/src/main/java/mobi/maptrek/MainActivity.java +++ b/app/src/main/java/mobi/maptrek/MainActivity.java @@ -484,6 +484,8 @@ protected void onCreate(Bundle savedInstanceState) { mPanelState = PANEL_STATE.NONE; if (savedInstanceState != null) { setPanelState((PANEL_STATE) savedInstanceState.getSerializable("panelState")); + if (mPanelState != PANEL_STATE.NONE) + mViews.extendPanel.post(this::adjustPanelViews); } // Prepare handlers @@ -544,50 +546,7 @@ protected void onCreate(Bundle savedInstanceState) { mViews.extendPanel.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() { @Override public void onChildViewAdded(View parent, View child) { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams(); - switch (mPanelState) { - case LOCATION: - if (mVerticalOrientation) { - adjustGuideline(false); - } - break; - case TRACKS: - if (mVerticalOrientation) { - adjustGuideline(true); - } else { - child.post(() -> child.setMinimumHeight((int) (mViews.constraintLayout.getHeight() - mViews.tracksButton.getY()))); - lp.gravity = Gravity.BOTTOM; - child.setLayoutParams(lp); - } - break; - case PLACES: - if (mVerticalOrientation) { - adjustGuideline(true); - } else { - child.post(() -> child.setMinimumHeight((int) (mViews.constraintLayout.getHeight() - mViews.placesButton.getY()))); - lp.gravity = Gravity.BOTTOM; - child.setLayoutParams(lp); - } - break; - case MAPS: - if (mVerticalOrientation) { - adjustGuideline(false); - lp.gravity = Gravity.END; - } else { - child.post(() -> child.setMinimumHeight((int) (mViews.constraintLayout.getHeight() - mViews.mapsButton.getY()))); - lp.gravity = Gravity.BOTTOM; - } - child.setLayoutParams(lp); - break; - case MORE: - if (mVerticalOrientation) { - adjustGuideline(false); - lp.gravity = Gravity.END; - } else { - lp.gravity = Gravity.BOTTOM; - } - child.setLayoutParams(lp); - } + adjustPanelViews(); } @Override @@ -674,12 +633,7 @@ public void onChildViewRemoved(View parent, View child) { int strokeColor = resources.getColor(R.color.colorBackground, theme); DefaultMapScaleBar mapScaleBar = new DefaultMapScaleBar(mMap, MapTrek.density * .75f, paintColor, strokeColor); mMapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar); - mCrosshairLayer = new CrosshairLayer(mMap, MapTrek.density, paintColor, new Runnable() { - @Override - public void run() { - Configuration.setPosition(mMap.getMapPosition()); - } - }); + mCrosshairLayer = new CrosshairLayer(mMap, MapTrek.density, paintColor, () -> Configuration.setPosition(mMap.getMapPosition())); mLocationOverlay = new LocationOverlay(mMap, MapTrek.density); layers.add(mMapScaleBarLayer, MAP_OVERLAYS); layers.add(mCrosshairLayer, MAP_OVERLAYS); @@ -3562,6 +3516,44 @@ private void brightenExtendPanel() { child.setForeground(null); } + private void adjustPanelViews() { + switch (mPanelState) { + case LOCATION: + if (mVerticalOrientation) + adjustGuideline(false); + adjustPanelConstraint(Gravity.START, null); + break; + case TRACKS: + if (mVerticalOrientation) { + adjustGuideline(true); + adjustPanelConstraint(Gravity.FILL, null); + } else { + adjustPanelConstraint(Gravity.END, mViews.tracksButton); + } + break; + case PLACES: + if (mVerticalOrientation) { + adjustGuideline(true); + adjustPanelConstraint(Gravity.FILL, null); + } else { + adjustPanelConstraint(Gravity.END, mViews.placesButton); + } + break; + case MAPS: + if (mVerticalOrientation) { + adjustGuideline(false); + adjustPanelConstraint(Gravity.END, null); + } else { + adjustPanelConstraint(Gravity.END, mViews.mapsButton); + } + break; + case MORE: + if (mVerticalOrientation) + adjustGuideline(false); + adjustPanelConstraint(Gravity.END, null); + } + } + private void adjustGuideline(boolean limited) { if (mVerticalOrientation) { ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mViews.guideline.getLayoutParams(); @@ -3570,6 +3562,50 @@ private void adjustGuideline(boolean limited) { } } + private void adjustPanelConstraint(int gravity, View ref) { + ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mViews.extendPanel.getLayoutParams(); + if (mVerticalOrientation) { + switch (gravity) { + case Gravity.START: + params.startToStart = ConstraintLayout.LayoutParams.PARENT_ID; + params.endToEnd = ConstraintLayout.LayoutParams.UNSET; + break; + case Gravity.FILL: + params.startToStart = ConstraintLayout.LayoutParams.PARENT_ID; + params.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID; + break; + case Gravity.END: + params.startToStart = ConstraintLayout.LayoutParams.UNSET; + params.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID; + break; + } + } else { + params.matchConstraintMinHeight = 0; + switch (gravity) { + case Gravity.START: + params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID; + params.bottomToBottom = ConstraintLayout.LayoutParams.UNSET; + if (ref != null) + params.matchConstraintMinHeight = (int) (ref.getHeight() + ref.getY()); + break; + case Gravity.FILL: + params.topToTop = ConstraintLayout.LayoutParams.PARENT_ID; + params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID; + break; + case Gravity.END: + params.topToTop = ConstraintLayout.LayoutParams.UNSET; + params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID; + if (ref != null) + logger.error("{} {}", mViews.constraintLayout.getHeight(), ref.getY()); + if (ref != null) + params.matchConstraintMinHeight = (int) (mViews.constraintLayout.getHeight() - ref.getY()); + break; + } + } + mViews.extendPanel.setLayoutParams(params); + mViews.extendPanel.requestLayout(); + } + @Override public FloatingActionButton enableActionButton() { if (mViews.listActionButton.getVisibility() == View.VISIBLE) diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index 72ab5383..0a4883f9 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -385,10 +385,11 @@ android:layout_width="wrap_content" android:layout_height="0dp" android:clickable="true" - android:focusable="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@id/actionPanel" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintHeight="match_constraint" + app:layout_constraintTop_toTopOf="parent" + tools:ignore="KeyboardInaccessibleWidget" /> + app:layout_constraintEnd_toEndOf="parent" + tools:ignore="KeyboardInaccessibleWidget" /> + app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" + tools:comment="Without clickable clicks are propagated to underlying map" + tools:ignore="KeyboardInaccessibleWidget" /> + app:layout_constraintWidth="match_constraint" + app:layout_constraintVertical_bias="1" + tools:ignore="KeyboardInaccessibleWidget" /> + app:layout_constraintVertical_bias="1" + tools:ignore="KeyboardInaccessibleWidget" /> + app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" + tools:comment="Without clickable clicks are propagated to underlying map" + tools:ignore="KeyboardInaccessibleWidget" /> - + tools:comment="Without it recyclerview doesn't work with wrap_content parent (FragmentContainerView)"> + + + 360dp + -1px 420dp 16dp 32dp diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 0f9d16bd..592e5dba 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -14,6 +14,7 @@ 52dp -1px + -2px 2dp 16dp -1px