Cancel and Save buttons appear above keyboard

This commit is contained in:
Dima-1 2019-12-26 12:01:07 +02:00
parent 39a02f2eb2
commit bc0ef56fba
3 changed files with 44 additions and 11 deletions

View file

@ -1060,7 +1060,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private BaseSettingsFragment getVisibleBaseSettingsFragment(int... ids) { private BaseSettingsFragment getVisibleBaseSettingsFragment(int... ids) {
for (int id : ids) { for (int id : ids) {
Fragment fragment = getSupportFragmentManager().findFragmentById(id); 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) { && ((BaseSettingsFragment) fragment).getStatusBarColorId() != -1) {
return (BaseSettingsFragment) fragment; return (BaseSettingsFragment) fragment;
} }

View file

@ -1,6 +1,7 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -34,6 +35,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -142,7 +144,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
updateTheme(); updateTheme();
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) { if (view != null) {
AndroidUtils.addStatusBarPadding21v(getContext(), view);
if (getPreferenceScreen() != null) { if (getPreferenceScreen() != null) {
PreferenceManager prefManager = getPreferenceManager(); PreferenceManager prefManager = getPreferenceManager();
PreferenceScreen preferenceScreen = prefManager.inflateFromResource(prefManager.getContext(), currentScreenType.preferencesResId, null); 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)); 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() { public void onPause() {
super.onPause(); super.onPause();
MapActivity mapActivity = getMapActivity(); Activity activity = getActivity();
if (!wasDrawerDisabled && mapActivity != null) { if (activity != null) {
mapActivity.enableDrawer(); if (!wasDrawerDisabled && activity instanceof MapActivity) {
} ((MapActivity) activity).enableDrawer();
}
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
Activity activity = getActivity();
if (activity != null) {
if (!(activity instanceof MapActivity) && statusBarColor != -1) { if (!(activity instanceof MapActivity) && statusBarColor != -1) {
activity.getWindow().setStatusBarColor(statusBarColor); 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 abstract void setupPreferences();
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {

View file

@ -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); 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(isNightMode(), cancelButton, DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(false, saveButton, DialogButtonType.PRIMARY, R.string.shared_string_save); UiUtilities.setupDialogButton(isNightMode(), saveButton, DialogButtonType.PRIMARY, R.string.shared_string_save);
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -177,6 +177,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return view; return view;
} }
@Override
protected boolean isFullScreenAllowed() {
return false;
}
private boolean isChanged() { private boolean isChanged() {
return !profile.equals(changedProfile); return !profile.equals(changedProfile);
} }