From bb0ccd33f5ced8a10eb3cef7efbc1c8ba096c12b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 24 Dec 2019 12:19:42 +0200 Subject: [PATCH 01/17] Fix UI in edit profiles screen --- .../MeasurementToolFragment.java | 2 +- .../adapter/MeasurementToolAdapter.java | 2 +- .../plus/profiles/EditProfilesFragment.java | 41 +++++++++++++++++++ .../quickaction/QuickActionListFragment.java | 6 +-- .../plus/quickaction/SwitchableAction.java | 2 +- .../ReorderItemTouchHelperCallback.java | 2 +- 6 files changed, 48 insertions(+), 7 deletions(-) rename OsmAnd/src/net/osmand/plus/{profiles => views/controls}/ReorderItemTouchHelperCallback.java (97%) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 907779eb4b..13fdaa5270 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -68,7 +68,7 @@ import net.osmand.plus.measurementtool.command.ClearPointsCommand; import net.osmand.plus.measurementtool.command.MovePointCommand; import net.osmand.plus.measurementtool.command.RemovePointCommand; import net.osmand.plus.measurementtool.command.ReorderPointCommand; -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java index cd5fb5c3de..9e0b157c9e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/MeasurementToolAdapter.java @@ -20,7 +20,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.measurementtool.NewGpxData.ActionType; -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import java.util.Collections; import java.util.List; diff --git a/OsmAnd/src/net/osmand/plus/profiles/EditProfilesFragment.java b/OsmAnd/src/net/osmand/plus/profiles/EditProfilesFragment.java index 325c135f74..c3ceb7dc3a 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/EditProfilesFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/EditProfilesFragment.java @@ -29,6 +29,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.settings.BaseSettingsFragment; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import java.util.ArrayList; import java.util.Collections; @@ -47,6 +48,9 @@ public class EditProfilesFragment extends BaseOsmAndFragment { private EditProfilesAdapter adapter; + private boolean nightMode; + private boolean wasDrawerDisabled; + @Nullable @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -59,6 +63,8 @@ public class EditProfilesFragment extends BaseOsmAndFragment { appModesOrders.put(mode.getStringKey(), mode.getOrder()); } } + nightMode = !app.getSettings().isLightContent(); + View mainView = inflater.inflate(R.layout.edit_profiles_list_fragment, container, false); AndroidUtils.addStatusBarPadding21v(getContext(), mainView); @@ -186,6 +192,41 @@ public class EditProfilesFragment extends BaseOsmAndFragment { outState.putStringArrayList(DELETED_APP_MODES_KEY, deletedModesKeys); } + @Override + public void onResume() { + super.onResume(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + wasDrawerDisabled = mapActivity.isDrawerDisabled(); + if (!wasDrawerDisabled) { + mapActivity.disableDrawer(); + } + } + } + + public void onPause() { + super.onPause(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && !wasDrawerDisabled) { + mapActivity.enableDrawer(); + } + } + + @Override + public int getStatusBarColorId() { + return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; + } + + @Nullable + public MapActivity getMapActivity() { + FragmentActivity activity = getActivity(); + if (activity instanceof MapActivity) { + return (MapActivity) activity; + } else { + return null; + } + } + public List getProfiles(boolean deleted) { List profiles = new ArrayList<>(); for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 66bce540dd..998a1464a1 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -28,9 +28,9 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback.UnmovableItem; -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback.OnItemMoveCallback; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback.UnmovableItem; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback.OnItemMoveCallback; import java.util.ArrayList; import java.util.Collections; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java index abad8a7432..3c8dcd9464 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java @@ -20,7 +20,7 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; +import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import java.util.ArrayList; import java.util.Collections; diff --git a/OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/views/controls/ReorderItemTouchHelperCallback.java similarity index 97% rename from OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java rename to OsmAnd/src/net/osmand/plus/views/controls/ReorderItemTouchHelperCallback.java index c6b72e413a..832f7a10fa 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/ReorderItemTouchHelperCallback.java @@ -1,4 +1,4 @@ -package net.osmand.plus.profiles; +package net.osmand.plus.views.controls; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; From d0714fce0734f20ff9cfb63c64811f867eadca44 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 24 Dec 2019 12:20:26 +0200 Subject: [PATCH 02/17] Fox for airplane --- .../net/osmand/plus/settings/NavigationFragment.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java index 7b8be26915..e66b307e2f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java @@ -52,10 +52,12 @@ public class NavigationFragment extends BaseSettingsFragment { SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId()); SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId()); if (getSelectedAppMode().getRoutingProfile() != null) { - GeneralRouter gr = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile()); - RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(gr.getProfileName().toUpperCase()); - navigationType.setSummary(routingProfilesResources.getStringRes()); - navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes())); + GeneralRouter routingProfile = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile()); + if (routingProfile != null) { + RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(routingProfile.getProfileName().toUpperCase()); + navigationType.setSummary(routingProfilesResources.getStringRes()); + navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes())); + } } routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance)); showRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_alert)); From 39a02f2eb246830e4f85a6bb9ecc050757a74c32 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 24 Dec 2019 13:54:23 +0200 Subject: [PATCH 03/17] Fix profile name multiline, active color, hide keyboard when back pressed --- OsmAnd/res/layout/preference_text_field.xml | 17 ++++++++--------- .../settings/ProfileAppearanceFragment.java | 9 +++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/OsmAnd/res/layout/preference_text_field.xml b/OsmAnd/res/layout/preference_text_field.xml index c8fd71c944..53bfd30d10 100644 --- a/OsmAnd/res/layout/preference_text_field.xml +++ b/OsmAnd/res/layout/preference_text_field.xml @@ -1,7 +1,7 @@ + app:secondaryColor="?android:textColorSecondary" + app:labelText="@string/profile_name_hint"> - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 089cdd8b97..d4be179b5e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -4,6 +4,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.graphics.PorterDuff; import android.graphics.drawable.GradientDrawable; import android.os.Bundle; import android.support.annotation.Nullable; @@ -74,6 +75,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private EditText profileName; private FlowLayout colorItems; private FlowLayout iconItems; + private OsmandTextFieldBoxes profileNameOtfb; @Override public void onCreate(Bundle savedInstanceState) { @@ -256,8 +258,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { changedProfile.name = s.toString(); } }); + profileNameOtfb = (OsmandTextFieldBoxes) holder.findViewById(R.id.profile_name_otfb); } else if (MASTER_PROFILE.equals(preference.getKey())) { baseProfileName = (EditText) holder.findViewById(R.id.master_profile_et); + baseProfileName.setFocusable(false); baseProfileName.setText(changedProfile.parent != null ? changedProfile.parent.toHumanString(getContext()) : getSelectedAppMode().toHumanString(getContext())); @@ -344,6 +348,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (iconItems != null) { setIconNewColor(changedProfile.iconRes); } + int selectedColor = ContextCompat.getColor(app, + changedProfile.color.getColor(isNightMode())); + profileNameOtfb.setPrimaryColor(selectedColor); + profileName.getBackground().mutate().setColorFilter(selectedColor, PorterDuff.Mode.SRC_ATOP); updateProfileButton(); } @@ -487,6 +495,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } public boolean isProfileAppearanceChanged(final MapActivity mapActivity) { + hideKeyboard(); if (isChanged()) { AlertDialog.Builder dismissDialog = createWarningDialog(getActivity(), R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel); From bc0ef56fba54ec1e5614f2b24a2c7281ce0a26c1 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 26 Dec 2019 12:01:07 +0200 Subject: [PATCH 04/17] 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); } From 1531ee3becb8037c7969c1aa6a8b9d87e9abce43 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 26 Dec 2019 13:09:22 +0200 Subject: [PATCH 05/17] Fix color issue in the color selector on API 16 --- OsmAnd/res/drawable/circle_contour_bg_dark.xml | 1 + .../res/drawable/circle_contour_bg_light.xml | 1 + OsmAnd/res/layout/preference_circle_item.xml | 5 ++--- .../settings/ProfileAppearanceFragment.java | 18 ++++++++++-------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/drawable/circle_contour_bg_dark.xml b/OsmAnd/res/drawable/circle_contour_bg_dark.xml index 8fa7a92507..22b13c602e 100644 --- a/OsmAnd/res/drawable/circle_contour_bg_dark.xml +++ b/OsmAnd/res/drawable/circle_contour_bg_dark.xml @@ -1,5 +1,6 @@ + diff --git a/OsmAnd/res/drawable/circle_contour_bg_light.xml b/OsmAnd/res/drawable/circle_contour_bg_light.xml index 0b226e9f3a..a32bd3af90 100644 --- a/OsmAnd/res/drawable/circle_contour_bg_light.xml +++ b/OsmAnd/res/drawable/circle_contour_bg_light.xml @@ -1,5 +1,6 @@ + diff --git a/OsmAnd/res/layout/preference_circle_item.xml b/OsmAnd/res/layout/preference_circle_item.xml index 29a4e93a7f..5f314b0041 100644 --- a/OsmAnd/res/layout/preference_circle_item.xml +++ b/OsmAnd/res/layout/preference_circle_item.xml @@ -12,11 +12,11 @@ app:srcCompat="@drawable/circle_contour_bg_light" /> + app:srcCompat="@drawable/circle_background_light" /> - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index dd0e7d1020..5ac0e8a869 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -327,8 +327,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private View createColorItemView(final ApplicationMode.ProfileIconColors colorRes, ViewGroup rootView) { FrameLayout colorItemView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode()) .inflate(R.layout.preference_circle_item, rootView, false); - ImageView coloredCircle = colorItemView.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + ImageView coloredCircle = colorItemView.findViewById(R.id.backgroundCircle); + AndroidUtils.setBackground(coloredCircle, + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), ContextCompat.getColor(app, colorRes.getColor(isNightMode())))); coloredCircle.setOnClickListener(new View.OnClickListener() { @Override @@ -365,8 +366,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { .inflate(R.layout.preference_circle_item, rootView, false); ImageView checkMark = iconItemView.findViewById(R.id.checkMark); checkMark.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color_default_light)); - ImageView coloredCircle = iconItemView.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + ImageView coloredCircle = iconItemView.findViewById(R.id.backgroundCircle); + AndroidUtils.setBackground(coloredCircle, + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); coloredCircle.setOnClickListener(new View.OnClickListener() { @Override @@ -386,8 +388,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { iconItem.findViewById(R.id.outlineCircle).setVisibility(View.GONE); ImageView checkMark = iconItem.findViewById(R.id.checkMark); checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light)); - ImageView coloredCircle = iconItem.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle), + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); changedProfile.iconRes = iconRes; updateProfileButton(); @@ -398,8 +400,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { app.getDaynightHelper().isNightModeForMapControls())); View iconItem = iconItems.findViewWithTag(iconRes); if (iconItem != null) { - ImageView coloredCircle = iconItem.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle), + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f))); ImageView outlineCircle = iconItem.findViewById(R.id.outlineCircle); GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light); From 5f0de26a3067f75f1a0adf77cc67047650d10318 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 26 Dec 2019 13:09:22 +0200 Subject: [PATCH 06/17] Fix color issue in the color selector on API 16 --- OsmAnd/res/drawable/circle_contour_bg_dark.xml | 1 + .../res/drawable/circle_contour_bg_light.xml | 1 + OsmAnd/res/layout/preference_circle_item.xml | 5 ++--- .../settings/ProfileAppearanceFragment.java | 18 ++++++++++-------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/drawable/circle_contour_bg_dark.xml b/OsmAnd/res/drawable/circle_contour_bg_dark.xml index 8fa7a92507..22b13c602e 100644 --- a/OsmAnd/res/drawable/circle_contour_bg_dark.xml +++ b/OsmAnd/res/drawable/circle_contour_bg_dark.xml @@ -1,5 +1,6 @@ + diff --git a/OsmAnd/res/drawable/circle_contour_bg_light.xml b/OsmAnd/res/drawable/circle_contour_bg_light.xml index 0b226e9f3a..a32bd3af90 100644 --- a/OsmAnd/res/drawable/circle_contour_bg_light.xml +++ b/OsmAnd/res/drawable/circle_contour_bg_light.xml @@ -1,5 +1,6 @@ + diff --git a/OsmAnd/res/layout/preference_circle_item.xml b/OsmAnd/res/layout/preference_circle_item.xml index 29a4e93a7f..d6a3c6492b 100644 --- a/OsmAnd/res/layout/preference_circle_item.xml +++ b/OsmAnd/res/layout/preference_circle_item.xml @@ -12,11 +12,11 @@ app:srcCompat="@drawable/circle_contour_bg_light" /> + android:background="@drawable/circle_background_light" /> - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index dd0e7d1020..5ac0e8a869 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -327,8 +327,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private View createColorItemView(final ApplicationMode.ProfileIconColors colorRes, ViewGroup rootView) { FrameLayout colorItemView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode()) .inflate(R.layout.preference_circle_item, rootView, false); - ImageView coloredCircle = colorItemView.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + ImageView coloredCircle = colorItemView.findViewById(R.id.backgroundCircle); + AndroidUtils.setBackground(coloredCircle, + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), ContextCompat.getColor(app, colorRes.getColor(isNightMode())))); coloredCircle.setOnClickListener(new View.OnClickListener() { @Override @@ -365,8 +366,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { .inflate(R.layout.preference_circle_item, rootView, false); ImageView checkMark = iconItemView.findViewById(R.id.checkMark); checkMark.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color_default_light)); - ImageView coloredCircle = iconItemView.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + ImageView coloredCircle = iconItemView.findViewById(R.id.backgroundCircle); + AndroidUtils.setBackground(coloredCircle, + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); coloredCircle.setOnClickListener(new View.OnClickListener() { @Override @@ -386,8 +388,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { iconItem.findViewById(R.id.outlineCircle).setVisibility(View.GONE); ImageView checkMark = iconItem.findViewById(R.id.checkMark); checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light)); - ImageView coloredCircle = iconItem.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle), + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f))); changedProfile.iconRes = iconRes; updateProfileButton(); @@ -398,8 +400,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { app.getDaynightHelper().isNightModeForMapControls())); View iconItem = iconItems.findViewWithTag(iconRes); if (iconItem != null) { - ImageView coloredCircle = iconItem.findViewById(R.id.bckgroundCircle); - coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light, + AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle), + UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f))); ImageView outlineCircle = iconItem.findViewById(R.id.outlineCircle); GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light); From be9d72b6203f13b1e69280a4ccfee774477d5e56 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 26 Dec 2019 17:44:54 +0200 Subject: [PATCH 07/17] Fix padding and theme for EditProfilesFragment --- OsmAnd/res/layout/edit_profiles_list_fragment.xml | 3 ++- .../osmand/plus/profiles/EditProfilesFragment.java | 13 ++++++++----- .../osmand/plus/settings/BaseSettingsFragment.java | 6 +----- .../plus/settings/ProfileAppearanceFragment.java | 5 ----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/OsmAnd/res/layout/edit_profiles_list_fragment.xml b/OsmAnd/res/layout/edit_profiles_list_fragment.xml index 36eaaaf6cc..9b89814d16 100644 --- a/OsmAnd/res/layout/edit_profiles_list_fragment.xml +++ b/OsmAnd/res/layout/edit_profiles_list_fragment.xml @@ -24,7 +24,8 @@ android:layout_height="match_parent" android:background="?attr/list_background_color" android:clipToPadding="false" - android:paddingBottom="72dp" /> + android:paddingBottom="72dp" + android:paddingTop="16dp"/> Date: Fri, 27 Dec 2019 12:36:10 +0200 Subject: [PATCH 08/17] Redirect all profile settings menu to new MainSettingsFragment --- .../net/osmand/plus/activities/MapActivity.java | 9 +++++++++ .../plus/activities/MapActivityActions.java | 5 +---- .../routepreparationmenu/MapRouteInfoMenu.java | 16 ++-------------- .../plus/settings/MainSettingsFragment.java | 12 ++++++++++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 4d36ea9073..590e04fb19 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -133,6 +133,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.DataStorageFragment; +import net.osmand.plus.settings.MainSettingsFragment; import net.osmand.plus.settings.ProfileAppearanceFragment; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AnimateDraggingMapThread; @@ -683,6 +684,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; } } + MainSettingsFragment mainSettingsFragment = getMainSettingsFragment(); + if (mainSettingsFragment != null) { + mainSettingsFragment.close(); + } if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) { mapContextMenu.openMenuHeaderOnly(); @@ -2415,6 +2420,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(QuickActionListFragment.TAG); } + public MainSettingsFragment getMainSettingsFragment() { + return getFragment(MainSettingsFragment.TAG); + } + T getFragment(String fragmentTag){ Fragment fragment = getSupportFragmentManager().findFragmentByTag(fragmentTag); return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (T) fragment : null; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 6430a68197..c9d8445948 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -59,7 +59,6 @@ import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; -import net.osmand.plus.profiles.SettingsProfileActivity; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.WaypointsFragment; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; @@ -706,9 +705,7 @@ public class MapActivityActions implements DialogProvider { .setListener(new ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) { - Intent intent = new Intent(app, SettingsProfileActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - app.startActivity(intent); + BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS); return true; } }) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index c263554288..3e4569d956 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -19,7 +19,6 @@ import android.support.transition.Transition; import android.support.transition.TransitionListenerAdapter; import android.support.transition.TransitionManager; import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatImageView; import android.view.View; @@ -70,9 +69,6 @@ import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; -import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener; -import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; @@ -98,6 +94,7 @@ import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.search.QuickSearchHelper; +import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.widgets.TextViewExProgress; import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.RoutingParameter; @@ -796,16 +793,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } private void showProfileBottomSheetDialog() { - final AppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); - fragment.setUpdateMapRouteMenuListener(new UpdateMapRouteMenuListener() { - @Override - public void updateAppModeMenu() { - updateApplicationModes(); - } - }); - getMapActivity().getSupportFragmentManager().beginTransaction() - .add(fragment, ConfigureAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss(); + BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS); } private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) { diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java index fc21889ed7..00aecf503d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java @@ -16,6 +16,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; @@ -38,7 +39,7 @@ public class MainSettingsFragment extends BaseSettingsFragment { private static final String APP_PROFILES = "app_profiles"; private static final String SELECTED_PROFILE = "selected_profile"; private static final String CREATE_PROFILE = "create_profile"; - private static final String IMPORT_PROFILE = "import_profile"; + // private static final String IMPORT_PROFILE = "import_profile"; private static final String REORDER_PROFILES = "reorder_profiles"; private List allAppModes; @@ -136,7 +137,7 @@ public class MainSettingsFragment extends BaseSettingsFragment { Preference createProfile = findPreference(CREATE_PROFILE); createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); - Preference importProfile = findPreference(IMPORT_PROFILE); +// Preference importProfile = findPreference(IMPORT_PROFILE); // importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import, // isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); Preference reorderProfiles = findPreference(REORDER_PROFILES); @@ -198,4 +199,11 @@ public class MainSettingsFragment extends BaseSettingsFragment { } return selectProfileListener; } + + public void close() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } } \ No newline at end of file From 366a61ba52cac53bb4f0b7066634bf5640057c54 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 27 Dec 2019 15:07:16 +0200 Subject: [PATCH 09/17] Increment digit on the end of profile name when create new profile. --- .../settings/ProfileAppearanceFragment.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 4ed0950f2c..369e79d92e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -95,7 +95,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (baseModeForNewProfile != null) { profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis(); profile.parent = baseModeForNewProfile; - profile.name = baseModeForNewProfile.toHumanString(getContext()); + profile.name = baseModeForNewProfile.toHumanString(app); profile.color = baseModeForNewProfile.getIconColorInfo(); profile.iconRes = baseModeForNewProfile.getIconRes(); profile.routingProfile = baseModeForNewProfile.getRoutingProfile(); @@ -115,7 +115,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } else { changedProfile.stringKey = profile.stringKey; changedProfile.parent = profile.parent; - changedProfile.name = profile.name; + if (baseModeForNewProfile != null) { + changedProfile.name = createNonDuplicateName(baseModeForNewProfile.toHumanString(app)); + } else { + changedProfile.name = profile.name; + } changedProfile.color = profile.color; changedProfile.iconRes = profile.iconRes; changedProfile.routingProfile = profile.routingProfile; @@ -123,6 +127,21 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } } + private String createNonDuplicateName(String oldName) { + int suffix = 0; + int i = oldName.length() - 1; + do { + try { + suffix = Integer.parseInt(oldName.substring(i)); + } catch (NumberFormatException e) { + break; + } + i--; + } while (i >= 0); + suffix++; + return oldName.substring(0, i + 1) + suffix; + } + @Override protected void setupPreferences() { findPreference(SELECT_COLOR).setIconSpaceReserved(false); From 7b1921e5983bbeddd486942a1e17e02fa239b172 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 27 Dec 2019 16:56:44 +0200 Subject: [PATCH 10/17] Add space in between name and digit, check all names --- .../settings/ProfileAppearanceFragment.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 369e79d92e..72b5e8d2f3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -132,14 +132,32 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { int i = oldName.length() - 1; do { try { + if (oldName.charAt(i) == ' ' || oldName.charAt(i) == '-') { + throw new NumberFormatException(); + } suffix = Integer.parseInt(oldName.substring(i)); } catch (NumberFormatException e) { break; } i--; } while (i >= 0); - suffix++; - return oldName.substring(0, i + 1) + suffix; + String newName; + String divider = suffix == 0 ? " " : ""; + do { + suffix++; + newName = oldName.substring(0, i + 1) + divider + suffix; + } + while (hasThatName(newName)); + return newName; + } + + boolean hasThatName(String newName) { + for (ApplicationMode m : ApplicationMode.allPossibleValues()) { + if (m.toHumanString(app).equals(newName)) { + return true; + } + } + return false; } @Override From 187390eed57d12fdcba7d6c61a6f4d51c5894456 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 27 Dec 2019 18:06:24 +0200 Subject: [PATCH 11/17] Add return onto ConfigureProfile after save new profile --- .../net/osmand/plus/settings/ProfileAppearanceFragment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 72b5e8d2f3..611fd01797 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -204,7 +204,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (isChanged()) { if (saveNewProfile()) { profile = changedProfile; - getActivity().onBackPressed(); + ProfileAppearanceFragment.this.dismiss(); + BaseSettingsFragment.showInstance(getMapActivity(), SettingsScreenType.CONFIGURE_PROFILE, + ApplicationMode.valueOfStringKey(changedProfile.stringKey, null)); } } } From 706f47891cdb2365491c5e524fbc217265b7aee2 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 27 Dec 2019 19:25:13 +0200 Subject: [PATCH 12/17] Fix manage profile on road preparation --- .../AppModesBottomSheetDialogFragment.java | 18 +++++------------- .../routepreparationmenu/MapRouteInfoMenu.java | 14 ++++++++++++-- .../settings/ConfigureProfileFragment.java | 4 ++++ .../settings/ProfileAppearanceFragment.java | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/profiles/AppModesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/AppModesBottomSheetDialogFragment.java index 3952016a87..6084e0f185 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/AppModesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/AppModesBottomSheetDialogFragment.java @@ -1,7 +1,6 @@ package net.osmand.plus.profiles; import android.content.DialogInterface; -import android.content.Intent; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -9,14 +8,11 @@ import android.view.ContextThemeWrapper; import android.view.View; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; - -import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE; -import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY; +import net.osmand.plus.settings.BaseSettingsFragment; public abstract class AppModesBottomSheetDialogFragment extends MenuBottomSheetDialogFragment implements AbstractProfileMenuAdapter.ButtonPressedListener, AbstractProfileMenuAdapter.ProfilePressedListener { @@ -79,17 +75,13 @@ public abstract class AppModesBottomSheetDialogFragment Date: Mon, 30 Dec 2019 10:57:04 +0200 Subject: [PATCH 13/17] Fix Name field, change keyboard "New line" button to "Apply". --- OsmAnd/res/layout/preference_text_field.xml | 2 +- .../net/osmand/plus/settings/ProfileAppearanceFragment.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/layout/preference_text_field.xml b/OsmAnd/res/layout/preference_text_field.xml index 53bfd30d10..be7c364a28 100644 --- a/OsmAnd/res/layout/preference_text_field.xml +++ b/OsmAnd/res/layout/preference_text_field.xml @@ -21,7 +21,7 @@ android:id="@+id/profile_name_et" android:layout_width="match_parent" android:layout_height="wrap_content" - android:inputType="text|textMultiLine|textCapSentences" + android:inputType="textMultiLine" android:scrollHorizontally="false" android:maxLines="4" tools:text="@string/lorem_ipsum" /> diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 4a8c36ba70..172f4fc14e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -15,6 +15,7 @@ import android.support.v7.app.AlertDialog; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; import android.text.Editable; +import android.text.InputType; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; @@ -201,6 +202,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { @Override public void onClick(View v) { if (getActivity() != null) { + hideKeyboard(); if (isChanged()) { if (saveNewProfile()) { profile = changedProfile; @@ -281,6 +283,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (PROFILE_NAME.equals(preference.getKey())) { profileName = (EditText) holder.findViewById(R.id.profile_name_et); profileName.setImeOptions(EditorInfo.IME_ACTION_DONE); + profileName.setRawInputType(InputType.TYPE_CLASS_TEXT); profileName.setText(changedProfile.name); profileName.requestFocus(); profileName.addTextChangedListener(new TextWatcher() { From b7a4c7947a5a7bb29a1fbd0193136aee0be5c8a9 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 31 Dec 2019 11:34:25 +0200 Subject: [PATCH 14/17] Small code refactoring --- OsmAnd/res/values-ar/strings.xml | 2 +- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 9 --------- .../net/osmand/plus/settings/BaseSettingsFragment.java | 7 +++++++ .../osmand/plus/settings/ConfigureProfileFragment.java | 5 +---- .../net/osmand/plus/settings/MainSettingsFragment.java | 10 ++++------ .../plus/settings/ProfileAppearanceFragment.java | 4 ++-- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 649d2941da..d7802ba7ce 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -3248,7 +3248,7 @@ حفظ التغييرات احفظ التغييرات في ملف التعريف أولاً حذف الملف الشخصي - هل تريد بالتأكيد حذف ملف التعريف \"٪ s\" + هل تريد بالتأكيد حذف ملف التعريف \"%s\" حدد ملف تعريف أساسي إسناد ملف التعريف المخصص الخاص بك إلى أحد ملفات تعريف التطبيق الافتراضية ، يحدد الإعداد الأساسي مثل الرؤية الافتراضية لعناصر واجهة المستخدم ووحدات السرعة والمسافة. وهذه هي ملفات تعريف التطبيق الافتراضية ، إلى جانب أمثلة لملفات تعريف مخصصة يمكن تمديدها إلى: حدد نوع الملاحة diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 590e04fb19..4d36ea9073 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -133,7 +133,6 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.DataStorageFragment; -import net.osmand.plus.settings.MainSettingsFragment; import net.osmand.plus.settings.ProfileAppearanceFragment; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AnimateDraggingMapThread; @@ -684,10 +683,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; } } - MainSettingsFragment mainSettingsFragment = getMainSettingsFragment(); - if (mainSettingsFragment != null) { - mainSettingsFragment.close(); - } if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) { mapContextMenu.openMenuHeaderOnly(); @@ -2420,10 +2415,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(QuickActionListFragment.TAG); } - public MainSettingsFragment getMainSettingsFragment() { - return getFragment(MainSettingsFragment.TAG); - } - T getFragment(String fragmentTag){ Fragment fragment = getSupportFragmentManager().findFragmentByTag(fragmentTag); return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (T) fragment : null; diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index 596369d493..b911d14615 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -772,4 +772,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } return false; } + + void updateRouteInfoMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 013d59a80e..d4163e2c65 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -135,10 +135,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(isChecked ? R.string.shared_string_on : R.string.shared_string_off); - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMapRouteInfoMenu().updateMenu(); - } + updateRouteInfoMenu(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java index 00aecf503d..3f1e028cab 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java @@ -16,7 +16,6 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; @@ -200,10 +199,9 @@ public class MainSettingsFragment extends BaseSettingsFragment { return selectProfileListener; } - public void close() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMapRouteInfoMenu().updateMenu(); - } + @Override + public void onPause() { + updateRouteInfoMenu(); + super.onPause(); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 172f4fc14e..f81ed304b6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -148,11 +148,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { suffix++; newName = oldName.substring(0, i + 1) + divider + suffix; } - while (hasThatName(newName)); + while (hasProfileWithName(newName)); return newName; } - boolean hasThatName(String newName) { + private boolean hasProfileWithName(String newName) { for (ApplicationMode m : ApplicationMode.allPossibleValues()) { if (m.toHumanString(app).equals(newName)) { return true; From 58f134d96425d3d9f22ffa2c4b8183c2ba811e9f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 31 Dec 2019 11:34:25 +0200 Subject: [PATCH 15/17] Small code refactoring --- OsmAnd/res/values-ar/strings.xml | 2 +- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 9 --------- .../net/osmand/plus/settings/BaseSettingsFragment.java | 7 +++++++ .../osmand/plus/settings/ConfigureProfileFragment.java | 10 ++++++---- .../net/osmand/plus/settings/MainSettingsFragment.java | 10 ++++------ .../plus/settings/ProfileAppearanceFragment.java | 4 ++-- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 649d2941da..d7802ba7ce 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -3248,7 +3248,7 @@ حفظ التغييرات احفظ التغييرات في ملف التعريف أولاً حذف الملف الشخصي - هل تريد بالتأكيد حذف ملف التعريف \"٪ s\" + هل تريد بالتأكيد حذف ملف التعريف \"%s\" حدد ملف تعريف أساسي إسناد ملف التعريف المخصص الخاص بك إلى أحد ملفات تعريف التطبيق الافتراضية ، يحدد الإعداد الأساسي مثل الرؤية الافتراضية لعناصر واجهة المستخدم ووحدات السرعة والمسافة. وهذه هي ملفات تعريف التطبيق الافتراضية ، إلى جانب أمثلة لملفات تعريف مخصصة يمكن تمديدها إلى: حدد نوع الملاحة diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 590e04fb19..4d36ea9073 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -133,7 +133,6 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.DataStorageFragment; -import net.osmand.plus.settings.MainSettingsFragment; import net.osmand.plus.settings.ProfileAppearanceFragment; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AnimateDraggingMapThread; @@ -684,10 +683,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; } } - MainSettingsFragment mainSettingsFragment = getMainSettingsFragment(); - if (mainSettingsFragment != null) { - mainSettingsFragment.close(); - } if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) { mapContextMenu.openMenuHeaderOnly(); @@ -2420,10 +2415,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(QuickActionListFragment.TAG); } - public MainSettingsFragment getMainSettingsFragment() { - return getFragment(MainSettingsFragment.TAG); - } - T getFragment(String fragmentTag){ Fragment fragment = getSupportFragmentManager().findFragmentByTag(fragmentTag); return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (T) fragment : null; diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index 596369d493..b911d14615 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -772,4 +772,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } return false; } + + void updateRouteInfoMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 013d59a80e..fd04b69c4f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -119,6 +119,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { } } + @Override + public void onPause() { + updateRouteInfoMenu(); + super.onPause(); + } + private void updateToolbarSwitch() { View view = getView(); if (view == null) { @@ -135,10 +141,6 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(isChecked ? R.string.shared_string_on : R.string.shared_string_off); - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMapRouteInfoMenu().updateMenu(); - } } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java index 00aecf503d..3f1e028cab 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java @@ -16,7 +16,6 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; @@ -200,10 +199,9 @@ public class MainSettingsFragment extends BaseSettingsFragment { return selectProfileListener; } - public void close() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMapRouteInfoMenu().updateMenu(); - } + @Override + public void onPause() { + updateRouteInfoMenu(); + super.onPause(); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 172f4fc14e..f81ed304b6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -148,11 +148,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { suffix++; newName = oldName.substring(0, i + 1) + divider + suffix; } - while (hasThatName(newName)); + while (hasProfileWithName(newName)); return newName; } - boolean hasThatName(String newName) { + private boolean hasProfileWithName(String newName) { for (ApplicationMode m : ApplicationMode.allPossibleValues()) { if (m.toHumanString(app).equals(newName)) { return true; From 594ed86b60358c738cf9372f00eeedd03d5a3ee0 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 2 Jan 2020 11:58:05 +0200 Subject: [PATCH 16/17] Fix empty space on bottom map screen --- .../osmand/plus/activities/MapActivity.java | 22 ++++++++++++++++- .../osmand/plus/base/BaseOsmAndFragment.java | 24 ++----------------- .../plus/settings/BaseSettingsFragment.java | 22 +---------------- 3 files changed, 24 insertions(+), 44 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 4d36ea9073..8d61dec6ff 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1,6 +1,7 @@ package net.osmand.plus.activities; import android.Manifest; +import android.annotation.TargetApi; import android.app.Activity; import android.app.AlarmManager; import android.app.Dialog; @@ -37,6 +38,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewStub; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.widget.ProgressBar; @@ -373,14 +375,32 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven mIsDestroyed = false; } - public void exitFromFullScreen() { + public void exitFromFullScreen(View view) { + runLayoutListener(view); AndroidUtils.exitFromFullScreen(this); } public void enterToFullScreen() { + runLayoutListener(getLayout()); AndroidUtils.enterToFullScreen(this); } + private void runLayoutListener(final View view) { + if (view != null) { + ViewTreeObserver vto = view.getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + @Override + public void onGlobalLayout() { + ViewTreeObserver obs = view.getViewTreeObserver(); + obs.removeOnGlobalLayoutListener(this); + view.requestLayout(); + } + }); + } + } + @Override protected void onSaveInstanceState(Bundle outState) { if (removeFragment(PlanRouteFragment.TAG)) { diff --git a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java index 79a1e79b78..35915f558c 100644 --- a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.base; -import android.annotation.TargetApi; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Build; @@ -14,13 +13,12 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.content.ContextCompat; import android.view.View; -import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.widget.ImageView; -import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandInAppPurchaseActivity; @@ -47,25 +45,7 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator { } } if (!isFullScreenAllowed() && 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(); + ((MapActivity) activity).exitFromFullScreen(getView()); } } } diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index b911d14615..7c740513ed 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -1,7 +1,6 @@ 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; @@ -36,7 +35,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; -import android.view.ViewTreeObserver; import android.widget.ImageView; import android.widget.TextView; @@ -231,25 +229,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } 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(); + ((MapActivity) activity).exitFromFullScreen(getView()); } } } From 2e09dd873161b177f6d800779e34b6ae3cc88a93 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 2 Jan 2020 12:14:34 +0200 Subject: [PATCH 17/17] Move requestLayout to AndroidUtils --- OsmAnd/src/net/osmand/AndroidUtils.java | 26 +++++++++++++++++-- .../osmand/plus/activities/MapActivity.java | 24 ++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index ef52c769df..e960678869 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -48,6 +48,7 @@ import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.view.ViewParent; +import android.view.ViewTreeObserver; import android.view.inputmethod.InputMethodManager; import android.widget.FrameLayout; import android.widget.ImageButton; @@ -551,19 +552,40 @@ public class AndroidUtils { return coordinates; } - public static void enterToFullScreen(Activity activity) { + public static void enterToFullScreen(Activity activity, View view) { if (Build.VERSION.SDK_INT >= 21) { + requestLayout(view); activity.getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } } - public static void exitFromFullScreen(Activity activity) { + public static void exitFromFullScreen(Activity activity, View view) { if (Build.VERSION.SDK_INT >= 21) { + requestLayout(view); activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } } + private static void requestLayout(final View view) { + if (view != null) { + ViewTreeObserver vto = view.getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + + @Override + public void onGlobalLayout() { + ViewTreeObserver obs = view.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + view.requestLayout(); + } + }); + } + } + public static > Map sortByValue(Map map) { List> list = new LinkedList<>(map.entrySet()); Collections.sort(list, new Comparator>() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 8d61dec6ff..e933ca9232 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1,7 +1,6 @@ package net.osmand.plus.activities; import android.Manifest; -import android.annotation.TargetApi; import android.app.Activity; import android.app.AlarmManager; import android.app.Dialog; @@ -38,7 +37,6 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewStub; -import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.widget.ProgressBar; @@ -376,29 +374,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void exitFromFullScreen(View view) { - runLayoutListener(view); - AndroidUtils.exitFromFullScreen(this); + AndroidUtils.exitFromFullScreen(this, view); } public void enterToFullScreen() { - runLayoutListener(getLayout()); - AndroidUtils.enterToFullScreen(this); - } - - private void runLayoutListener(final View view) { - if (view != null) { - ViewTreeObserver vto = view.getViewTreeObserver(); - vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - @Override - public void onGlobalLayout() { - ViewTreeObserver obs = view.getViewTreeObserver(); - obs.removeOnGlobalLayoutListener(this); - view.requestLayout(); - } - }); - } + AndroidUtils.enterToFullScreen(this, getLayout()); } @Override