From bc0ef56fba54ec1e5614f2b24a2c7281ce0a26c1 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 26 Dec 2019 12:01:07 +0200 Subject: [PATCH] Cancel and Save buttons appear above keyboard --- .../osmand/plus/activities/MapActivity.java | 2 +- .../plus/settings/BaseSettingsFragment.java | 44 +++++++++++++++---- .../settings/ProfileAppearanceFragment.java | 9 +++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 8e1e426a2f..4d36ea9073 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1060,7 +1060,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven private BaseSettingsFragment getVisibleBaseSettingsFragment(int... ids) { for (int id : ids) { Fragment fragment = getSupportFragmentManager().findFragmentById(id); - if (fragment != null && !fragment.isRemoving() && fragment.isVisible() && fragment instanceof BaseSettingsFragment + if (fragment != null && !fragment.isRemoving() && fragment instanceof BaseSettingsFragment && ((BaseSettingsFragment) fragment).getStatusBarColorId() != -1) { return (BaseSettingsFragment) fragment; } diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index 32a80458ae..5717a5d169 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.settings; import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.graphics.drawable.Drawable; @@ -34,6 +35,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.TextView; @@ -142,7 +144,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl updateTheme(); View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { - AndroidUtils.addStatusBarPadding21v(getContext(), view); if (getPreferenceScreen() != null) { PreferenceManager prefManager = getPreferenceManager(); PreferenceScreen preferenceScreen = prefManager.inflateFromResource(prefManager.getContext(), currentScreenType.preferencesResId, null); @@ -228,6 +229,27 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, colorId)); } } + if (activity instanceof MapActivity) { + View view = getView(); + if (view != null) { + ViewTreeObserver vto = view.getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @Override + public void onGlobalLayout() { + + View view = getView(); + if (view != null) { + ViewTreeObserver obs = view.getViewTreeObserver(); + obs.removeOnGlobalLayoutListener(this); + view.requestLayout(); + } + } + }); + } + ((MapActivity) activity).exitFromFullScreen(); + } } } } @@ -236,17 +258,19 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl public void onPause() { super.onPause(); - MapActivity mapActivity = getMapActivity(); - if (!wasDrawerDisabled && mapActivity != null) { - mapActivity.enableDrawer(); - } + Activity activity = getActivity(); + if (activity != null) { + if (!wasDrawerDisabled && activity instanceof MapActivity) { + ((MapActivity) activity).enableDrawer(); + } - if (Build.VERSION.SDK_INT >= 21) { - Activity activity = getActivity(); - if (activity != null) { + if (Build.VERSION.SDK_INT >= 21) { if (!(activity instanceof MapActivity) && statusBarColor != -1) { activity.getWindow().setStatusBarColor(statusBarColor); } + if (!isFullScreenAllowed() && activity instanceof MapActivity) { + ((MapActivity) activity).enterToFullScreen(); + } } } } @@ -343,6 +367,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } + protected boolean isFullScreenAllowed() { + return true; + } + protected abstract void setupPreferences(); protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index d4be179b5e..dd0e7d1020 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -149,8 +149,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { AndroidUtils.setBackground(getContext(), buttonsContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); - UiUtilities.setupDialogButton(false, cancelButton, DialogButtonType.SECONDARY, R.string.shared_string_cancel); - UiUtilities.setupDialogButton(false, saveButton, DialogButtonType.PRIMARY, R.string.shared_string_save); + UiUtilities.setupDialogButton(isNightMode(), cancelButton, DialogButtonType.SECONDARY, R.string.shared_string_cancel); + UiUtilities.setupDialogButton(isNightMode(), saveButton, DialogButtonType.PRIMARY, R.string.shared_string_save); cancelButton.setOnClickListener(new View.OnClickListener() { @Override @@ -177,6 +177,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { return view; } + @Override + protected boolean isFullScreenAllowed() { + return false; + } + private boolean isChanged() { return !profile.equals(changedProfile); }