Merge pull request #10319 from osmandapp/Send-GPX-Bottom-Sheet-Scroll

Bottomsheet: should scroll outside the screen, buttons behavior with keyboard
This commit is contained in:
Vitaliy 2020-12-03 10:13:43 +00:00 committed by GitHub
commit 40597e6f8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 51 deletions

View file

@ -8,7 +8,8 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="0dp"
android:layout_weight="1">
<ScrollView
android:id="@+id/scroll_view"

View file

@ -5,6 +5,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout

View file

@ -187,18 +187,27 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
// 8dp is the shadow height
boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(activity, 8);
if (AndroidUiHelper.isOrientationPortrait(activity)) {
AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity));
if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0);
}
} else {
AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity));
}
drawTopShadow(showTopShadow);
}
});
}
protected void drawTopShadow(boolean showTopShadow) {
final Activity activity = getActivity();
View mainView = getView();
if (activity == null || mainView == null) {
return;
}
if (AndroidUiHelper.isOrientationPortrait(activity)) {
AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity));
if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0);
}
} else {
AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity));
}
}
private int getContentHeight(int availableScreenHeight) {
int customHeight = getCustomHeight();
int buttonsHeight;

View file

@ -2,12 +2,10 @@ package net.osmand.plus.osmedit.dialogs;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.ScrollView;
@ -57,6 +55,9 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
private TextInputEditText tagsField;
private TextInputEditText messageField;
private int contentHeightPrevious = 0;
private int buttonsHeight;
private int shadowHeight;
private ScrollView scrollView;
public void setGpxInfos(GpxInfo[] gpxInfos) {
this.gpxInfos = gpxInfos;
@ -136,26 +137,18 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
int height = scrollView.getHeight();
int viewHeight = scrollView.getHeight();
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight || contentHeight < height) {
if (scrollView.getHeight() + shadowHeight > contentHeight) {
scrollView.getLayoutParams().height = contentHeight;
} else {
scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
}
if (contentHeightPrevious != contentHeight) {
boolean showTopShadow;
showTopShadow = viewHeight + shadowHeight < contentHeight;
scrollView.requestLayout();
int delay = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP ? 300 : 1000;
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, scrollView.getHeight());
}
}, delay);
contentHeightPrevious = contentHeight;
drawTopShadow(showTopShadow);
}
}
};

View file

@ -1,7 +1,6 @@
package net.osmand.plus.settings.bottomsheets;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
@ -23,13 +22,11 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
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.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.fragments.ApplyQueryType;
@ -52,6 +49,9 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
private float currentValue;
private int contentHeightPrevious = 0;
private EditText text;
private int buttonsHeight;
private int shadowHeight;
private ScrollView scrollView;
@Override
public void createMenuItems(Bundle savedInstanceState) {
@ -164,13 +164,13 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
boolean showTopShadow;
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
boolean showTopShadow;
if (scrollView.getHeight() + shadowHeight > contentHeight) {
scrollView.getLayoutParams().height = contentHeight;
showTopShadow = false;
@ -189,22 +189,6 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
drawTopShadow(showTopShadow);
}
}
private void drawTopShadow(boolean showTopShadow) {
final Activity activity = getActivity();
View mainView = getView();
if (activity == null || mainView == null) {
return;
}
if (AndroidUiHelper.isOrientationPortrait(activity)) {
AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity));
if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0);
}
} else {
AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity));
}
}
};
}
@ -225,7 +209,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
}
public static void showInstance(@NonNull FragmentManager fm, String key, Fragment target,
boolean usedOnMap, @Nullable ApplicationMode appMode) {
boolean usedOnMap, @Nullable ApplicationMode appMode) {
try {
if (!fm.isStateSaved()) {
Bundle args = new Bundle();