Bottom sheet should scroll outside the screen, bottom sheets behavior with keyboard

Bottom sheet should scroll outside the screen
Check keyboard doesn't show after open
If the bottom sheet contains "text field" taping on it will show the keyboard, bottom sheet main buttons should be above the keyboard.
This commit is contained in:
androiddevkkotlin 2020-12-02 14:28:31 +02:00
parent ba569bb809
commit 372e35c46b
3 changed files with 13 additions and 16 deletions

View file

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

View file

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

View file

@ -1,13 +1,12 @@
package net.osmand.plus.osmedit.dialogs; package net.osmand.plus.osmedit.dialogs;
import android.app.Activity;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
@ -23,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
@ -56,7 +56,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
private TextInputEditText tagsField; private TextInputEditText tagsField;
private TextInputEditText messageField; private TextInputEditText messageField;
private int contentHeightPrevious = 0; private final int contentHeightPrevious = 0;
public void setGpxInfos(GpxInfo[] gpxInfos) { public void setGpxInfos(GpxInfo[] gpxInfos) {
this.gpxInfos = gpxInfos; this.gpxInfos = gpxInfos;
@ -136,26 +136,20 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect(); Rect visibleDisplayFrame = new Rect();
Activity activity = getActivity();
int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width); int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height); int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
final ScrollView scrollView = getView().findViewById(R.id.scroll_view); final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame); scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
int height = scrollView.getHeight(); int viewHeight = scrollView.getHeight();
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight; int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight || contentHeight < height) { if (contentHeightPrevious != contentHeight && activity != null) {
if (scrollView.getHeight() + shadowHeight > contentHeight) { if (viewHeight + shadowHeight < contentHeight) {
scrollView.getLayoutParams().height = contentHeight; AndroidUtils.setBackground(getView(), getPortraitBg(activity));
} else { } else {
scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; AndroidUtils.setBackground(getView(), getColoredBg(activity));
} }
scrollView.requestLayout(); 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;
} }
} }
}; };