setShadowOnScrollableView

This commit is contained in:
androiddevkkotlin 2020-12-06 13:22:23 +02:00
parent a7f2dd44d8
commit 5782c0100d
5 changed files with 51 additions and 46 deletions

View file

@ -16,6 +16,7 @@ import android.view.ViewTreeObserver.OnScrollChangedListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
@ -478,4 +479,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}
});
}
protected void setShadowOnScrollableView() {
ScrollView scrollView = getView().findViewById(R.id.scroll_view);
if (scrollView.canScrollVertically(1) || scrollView.canScrollVertically(-1)) {
drawTopShadow(false);
scrollView.getChildAt(0).setPadding(0, 8, 0, 0);
} else {
drawTopShadow(true);
}
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.osmedit.dialogs;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
@ -47,10 +46,6 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
private OsmNotesPoint point;
private HandleOsmNoteAsyncTask.HandleBugListener handleBugListener;
private TextInputEditText noteText;
private int contentHeightPrevious = 0;
private int buttonsHeight;
private int shadowHeight;
private ScrollView scrollView;
@Override
public void createMenuItems(Bundle savedInstanceState) {
@ -63,7 +58,7 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
R.layout.open_osm_note_text, null);
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
osmNoteView.getViewTreeObserver().addOnScrollChangedListener(getOnGlobalLayoutListener());
TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box);
textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
@ -80,24 +75,11 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding_small)));
}
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
private ViewTreeObserver.OnScrollChangedListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
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 viewHeight = scrollView.getHeight();
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
boolean showTopShadow;
showTopShadow = viewHeight + shadowHeight < contentHeight;
scrollView.requestLayout();
contentHeightPrevious = contentHeight;
drawTopShadow(showTopShadow);
}
public void onScrollChanged() {
setShadowOnScrollableView();
}
};
}
@ -115,9 +97,9 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
}
public static void showInstance(@NonNull FragmentManager fm, OsmBugsUtil osmBugsUtil, OsmBugsUtil local,
String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action,
final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point,
HandleOsmNoteAsyncTask.HandleBugListener handleBugListener) {
String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action,
final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point,
HandleOsmNoteAsyncTask.HandleBugListener handleBugListener) {
try {
if (!fm.isStateSaved()) {
BugBottomSheetDialog fragment = new BugBottomSheetDialog();

View file

@ -1,6 +1,5 @@
package net.osmand.plus.osmedit.dialogs;
import android.graphics.Rect;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
@ -54,9 +53,6 @@ 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) {
@ -70,7 +66,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener());
sendGpxView.getViewTreeObserver().addOnScrollChangedListener(getOnGlobalLayoutListener());
tagsField = sendGpxView.findViewById(R.id.tags_field);
messageField = sendGpxView.findViewById(R.id.message_field);
@ -132,23 +128,16 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
items.add(titleItem);
}
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
private ViewTreeObserver.OnScrollChangedListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_max_width);
shadowHeight = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_top_shadow_height);
public void onScrollChanged() {
scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
int viewHeight = scrollView.getHeight();
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
boolean showTopShadow;
showTopShadow = viewHeight + shadowHeight < contentHeight;
scrollView.requestLayout();
contentHeightPrevious = contentHeight;
drawTopShadow(showTopShadow);
if (scrollView.canScrollVertically(1) || scrollView.canScrollVertically(-1)) {
drawTopShadow(false);
scrollView.getChildAt(0).setPadding(0, 8, 0, 0);
} else {
drawTopShadow(true);
}
}
};

View file

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
@ -77,6 +78,7 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.send_osm_note_fragment, null);
sendOsmNoteView.getViewTreeObserver().addOnScrollChangedListener(getOnGlobalLayoutListener());
noteText = sendOsmNoteView.findViewById(R.id.note_text);
noteText.setText(((OsmNotesPoint) poi[0]).getText());
@ -148,6 +150,15 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen
items.add(bottomSheetItem);
}
private ViewTreeObserver.OnScrollChangedListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
setShadowOnScrollableView();
}
};
}
private void updateAccountName() {
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
@ -60,6 +61,7 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.send_poi_fragment, null);
sendOsmPoiView.getViewTreeObserver().addOnScrollChangedListener(getOnGlobalLayoutListener());
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
String defaultChangeSet = createDefaultChangeSet(app);
@ -104,6 +106,15 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
items.add(titleItem);
}
private ViewTreeObserver.OnScrollChangedListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
setShadowOnScrollableView();
}
};
}
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
try {
if (!fm.isStateSaved()) {