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:
commit
40597e6f8f
5 changed files with 40 additions and 51 deletions
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -187,18 +187,27 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
|
|
||||||
// 8dp is the shadow height
|
// 8dp is the shadow height
|
||||||
boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(activity, 8);
|
boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(activity, 8);
|
||||||
if (AndroidUiHelper.isOrientationPortrait(activity)) {
|
drawTopShadow(showTopShadow);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
private int getContentHeight(int availableScreenHeight) {
|
||||||
int customHeight = getCustomHeight();
|
int customHeight = getCustomHeight();
|
||||||
int buttonsHeight;
|
int buttonsHeight;
|
||||||
|
|
|
@ -2,12 +2,10 @@ package net.osmand.plus.osmedit.dialogs;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -57,6 +55,9 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
private TextInputEditText tagsField;
|
private TextInputEditText tagsField;
|
||||||
private TextInputEditText messageField;
|
private TextInputEditText messageField;
|
||||||
private int contentHeightPrevious = 0;
|
private int contentHeightPrevious = 0;
|
||||||
|
private int buttonsHeight;
|
||||||
|
private int shadowHeight;
|
||||||
|
private ScrollView scrollView;
|
||||||
|
|
||||||
public void setGpxInfos(GpxInfo[] gpxInfos) {
|
public void setGpxInfos(GpxInfo[] gpxInfos) {
|
||||||
this.gpxInfos = gpxInfos;
|
this.gpxInfos = gpxInfos;
|
||||||
|
@ -136,26 +137,18 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
Rect visibleDisplayFrame = new Rect();
|
Rect visibleDisplayFrame = new Rect();
|
||||||
int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
|
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
|
||||||
int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
|
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
|
||||||
final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
|
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) {
|
||||||
if (scrollView.getHeight() + shadowHeight > contentHeight) {
|
boolean showTopShadow;
|
||||||
scrollView.getLayoutParams().height = contentHeight;
|
showTopShadow = viewHeight + shadowHeight < contentHeight;
|
||||||
} else {
|
|
||||||
scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
||||||
}
|
|
||||||
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;
|
contentHeightPrevious = contentHeight;
|
||||||
|
drawTopShadow(showTopShadow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.osmand.plus.settings.bottomsheets;
|
package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -23,13 +22,11 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
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;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
|
||||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
import net.osmand.plus.settings.fragments.ApplyQueryType;
|
||||||
|
@ -52,6 +49,9 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
|
||||||
private float currentValue;
|
private float currentValue;
|
||||||
private int contentHeightPrevious = 0;
|
private int contentHeightPrevious = 0;
|
||||||
private EditText text;
|
private EditText text;
|
||||||
|
private int buttonsHeight;
|
||||||
|
private int shadowHeight;
|
||||||
|
private ScrollView scrollView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
@ -164,13 +164,13 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
Rect visibleDisplayFrame = new Rect();
|
Rect visibleDisplayFrame = new Rect();
|
||||||
int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
|
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
|
||||||
int shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
|
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
|
||||||
final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
|
scrollView = getView().findViewById(R.id.scroll_view);
|
||||||
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
|
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
|
||||||
boolean showTopShadow;
|
|
||||||
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
|
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
|
||||||
if (contentHeightPrevious != contentHeight) {
|
if (contentHeightPrevious != contentHeight) {
|
||||||
|
boolean showTopShadow;
|
||||||
if (scrollView.getHeight() + shadowHeight > contentHeight) {
|
if (scrollView.getHeight() + shadowHeight > contentHeight) {
|
||||||
scrollView.getLayoutParams().height = contentHeight;
|
scrollView.getLayoutParams().height = contentHeight;
|
||||||
showTopShadow = false;
|
showTopShadow = false;
|
||||||
|
@ -189,22 +189,6 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
|
||||||
drawTopShadow(showTopShadow);
|
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,
|
public static void showInstance(@NonNull FragmentManager fm, String key, Fragment target,
|
||||||
boolean usedOnMap, @Nullable ApplicationMode appMode) {
|
boolean usedOnMap, @Nullable ApplicationMode appMode) {
|
||||||
try {
|
try {
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
Loading…
Reference in a new issue