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
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

@ -1,13 +1,12 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.Activity;
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;
@ -23,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.textfield.TextInputEditText;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -56,7 +56,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
private TextInputEditText tagsField;
private TextInputEditText messageField;
private int contentHeightPrevious = 0;
private final int contentHeightPrevious = 0;
public void setGpxInfos(GpxInfo[] gpxInfos) {
this.gpxInfos = gpxInfos;
@ -136,26 +136,20 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
Activity activity = getActivity();
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);
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;
if (contentHeightPrevious != contentHeight && activity != null) {
if (viewHeight + shadowHeight < contentHeight) {
AndroidUtils.setBackground(getView(), getPortraitBg(activity));
} else {
scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
AndroidUtils.setBackground(getView(), getColoredBg(activity));
}
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;
}
}
};