This commit is contained in:
androiddevkkotlin 2020-12-07 09:56:20 +02:00
parent 908d4d1127
commit 7dfa873e39
7 changed files with 225 additions and 280 deletions

View file

@ -193,6 +193,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}); });
} }
protected ViewTreeObserver.OnGlobalLayoutListener getShadowLayoutListener(){
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
setShadowOnScrollableView();
}
};
}
protected void drawTopShadow(boolean showTopShadow) { protected void drawTopShadow(boolean showTopShadow) {
final Activity activity = getActivity(); final Activity activity = getActivity();
View mainView = getView(); View mainView = getView();

View file

@ -152,6 +152,11 @@ public class SaveGPXBottomSheetFragment extends MenuBottomSheetDialogFragment {
doRename(true); doRename(true);
} }
@Override
protected void onDismissButtonClickAction() {
doRename(false);
}
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog); super.onDismiss(dialog);

View file

@ -4,8 +4,6 @@ import android.content.res.ColorStateList;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ScrollView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -58,7 +56,7 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode), View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
R.layout.open_osm_note_text, null); R.layout.open_osm_note_text, null);
osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener()); osmNoteView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box); TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box);
textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name)); textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
@ -75,14 +73,6 @@ public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding_small))); items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding_small)));
} }
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override public void onGlobalLayout() {
setShadowOnScrollableView();
}
};
}
@Override @Override
protected int getRightBottomButtonTextId() { protected int getRightBottomButtonTextId() {
return posButtonTextId; return posButtonTextId;

View file

@ -5,9 +5,7 @@ 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.ViewTreeObserver;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -53,7 +51,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
private TextInputEditText tagsField; private TextInputEditText tagsField;
private TextInputEditText messageField; private TextInputEditText messageField;
private ScrollView scrollView;
public void setGpxInfos(GpxInfo[] gpxInfos) { public void setGpxInfos(GpxInfo[] gpxInfos) {
this.gpxInfos = gpxInfos; this.gpxInfos = gpxInfos;
@ -66,7 +63,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode); LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null); View sendGpxView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getOnGlobalLayoutListener()); sendGpxView.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
tagsField = sendGpxView.findViewById(R.id.tags_field); tagsField = sendGpxView.findViewById(R.id.tags_field);
messageField = sendGpxView.findViewById(R.id.message_field); messageField = sendGpxView.findViewById(R.id.message_field);
@ -128,21 +125,6 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
items.add(titleItem); items.add(titleItem);
} }
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
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);
}
}
};
}
protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) { protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) {
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING); BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING);

View file

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

View file

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

View file

@ -1,18 +1,15 @@
package net.osmand.plus.settings.bottomsheets; package net.osmand.plus.settings.bottomsheets;
import android.content.Context; import android.content.Context;
import android.graphics.Rect;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ScrollView; import android.widget.ScrollView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -52,6 +49,7 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode); LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
View view = themedInflater.inflate(R.layout.osm_login_data, null); View view = themedInflater.inflate(R.layout.osm_login_data, null);
view.getViewTreeObserver().addOnGlobalLayoutListener(getShadowLayoutListener());
userNameEditText = view.findViewById(R.id.name_edit_text); userNameEditText = view.findViewById(R.id.name_edit_text);
passwordEditText = view.findViewById(R.id.password_edit_text); passwordEditText = view.findViewById(R.id.password_edit_text);
@ -81,27 +79,6 @@ public class OsmLoginDataBottomSheet extends BasePreferenceBottomSheet {
items.add(titleItem); items.add(titleItem);
} }
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
return new ViewTreeObserver.OnGlobalLayoutListener() {
@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);
}
}
};
}
@Override @Override
public void onSaveInstanceState(@NonNull Bundle outState) { public void onSaveInstanceState(@NonNull Bundle outState) {