Skip to content

Commit

Permalink
Fix panel positioning issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Feb 6, 2024
1 parent e12fb23 commit d3fd16c
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 74 deletions.
136 changes: 86 additions & 50 deletions app/src/main/java/mobi/maptrek/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<ProgressBar
android:id="@+id/progressBar"
Expand All @@ -399,9 +400,9 @@
android:minHeight="4dp"
android:progressTint="@color/colorAccent"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:visibility="visible" />

<androidx.fragment.app.FragmentContainerView
Expand All @@ -410,9 +411,9 @@
android:layout_height="wrap_content"
android:clickable="true"
android:elevation="@dimen/fragment_elevation"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="KeyboardInaccessibleWidget" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
Expand All @@ -430,17 +431,16 @@
android:layout_gravity="end"
android:clickable="true"
android:elevation="@dimen/bottom_sheet_elevation"
android:focusable="true"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
tools:comment="Without clickable clicks are propagated to underlying map"
tools:ignore="KeyboardInaccessibleWidget" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/actionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fragment_padding"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_done"
android:tint="@color/colorBackground"
android:visibility="gone"
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@+id/actionPanel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline"
app:layout_constraintVertical_bias="1" />
app:layout_constraintWidth="match_constraint"
app:layout_constraintVertical_bias="1"
tools:ignore="KeyboardInaccessibleWidget" />

<ProgressBar
android:id="@+id/progressBar"
Expand All @@ -418,13 +418,13 @@
android:layout_height="wrap_content"
android:clickable="true"
android:elevation="@dimen/fragment_elevation"
android:focusable="true"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline"
app:layout_constraintVertical_bias="1" />
app:layout_constraintVertical_bias="1"
tools:ignore="KeyboardInaccessibleWidget" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
Expand All @@ -441,17 +441,16 @@
android:layout_height="wrap_content"
android:clickable="true"
android:elevation="@dimen/bottom_sheet_elevation"
android:focusable="true"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
tools:comment="Without clickable clicks are propagated to underlying map"
tools:ignore="KeyboardInaccessibleWidget" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/actionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fragment_padding"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ic_done"
android:tint="@color/colorBackground"
android:visibility="gone"
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/res/layout/list_with_empty_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/panel_width"
android:layout_height="wrap_content"
android:layout_height="@dimen/panel_height"
android:background="@color/panelSolidBackground"
android:clickable="true"
android:focusable="true"
tools:comment="Clickable is required to prevent event bubbling because DataList is placed over DataSourceList"
tools:layout_height="wrap_content"
tools:layout_width="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
style="@style/Scrollbar"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
tools:comment="Without it recyclerview doesn't work with wrap_content parent (FragmentContainerView)">

<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
style="@style/Scrollbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</RelativeLayout>

<TextView
android:id="@android:id/empty"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-land/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="panel_width">360dp</dimen>
<dimen name="panel_height">-1px</dimen> <!-- match_parent -->
<dimen name="fragment_width">420dp</dimen>
<dimen name="fragment_with_fab_top_padding">16dp</dimen>
<dimen name="fragment_with_fab_start_padding">32dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<dimen name="image_button_size_margin">52dp</dimen>

<dimen name="panel_width">-1px</dimen> <!-- match_parent -->
<dimen name="panel_height">-2px</dimen> <!-- wrap_content -->
<dimen name="panel_elevation">2dp</dimen>
<dimen name="panel_padding">16dp</dimen>
<dimen name="fragment_width">-1px</dimen> <!-- match_parent -->
Expand Down

0 comments on commit d3fd16c

Please sign in to comment.