From a4c2a79ac686c7f65131da011280684f418f09f8 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 11 Sep 2019 18:58:31 +0300 Subject: [PATCH 1/3] Preferences ui improvements initial commit --- .../layout/preference_dialog_and_switch.xml | 1 + OsmAnd/res/layout/preference_radio_button.xml | 1 + OsmAnd/res/layout/preference_switch.xml | 1 + OsmAnd/res/layout/preference_with_descr.xml | 1 + ...reference_with_descr_dialog_and_switch.xml | 1 + .../res/layout/profile_preference_toolbar.xml | 5 +- .../net/osmand/plus/ContextMenuAdapter.java | 5 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 67 +++++--- .../plus/activities/MapActivityActions.java | 2 +- ...gureAppModesBottomSheetDialogFragment.java | 2 + ...lectAppModesBottomSheetDialogFragment.java | 35 +++- .../profiles/SelectProfileMenuAdapter.java | 2 +- .../MapRouteInfoMenu.java | 2 +- .../plus/settings/BaseSettingsFragment.java | 150 ++++++++++-------- .../settings/CoordinatesFormatFragment.java | 11 +- .../GeneralProfileSettingsFragment.java | 28 ++-- 16 files changed, 200 insertions(+), 114 deletions(-) diff --git a/OsmAnd/res/layout/preference_dialog_and_switch.xml b/OsmAnd/res/layout/preference_dialog_and_switch.xml index 949a0bc554..549b84cdf1 100644 --- a/OsmAnd/res/layout/preference_dialog_and_switch.xml +++ b/OsmAnd/res/layout/preference_dialog_and_switch.xml @@ -7,6 +7,7 @@ android:gravity="center_vertical"> diff --git a/OsmAnd/res/layout/preference_radio_button.xml b/OsmAnd/res/layout/preference_radio_button.xml index b8f4c87412..e400f4b14c 100644 --- a/OsmAnd/res/layout/preference_radio_button.xml +++ b/OsmAnd/res/layout/preference_radio_button.xml @@ -7,6 +7,7 @@ android:gravity="center_vertical"> diff --git a/OsmAnd/res/layout/profile_preference_toolbar.xml b/OsmAnd/res/layout/profile_preference_toolbar.xml index 3c812534ca..428690c200 100644 --- a/OsmAnd/res/layout/profile_preference_toolbar.xml +++ b/OsmAnd/res/layout/profile_preference_toolbar.xml @@ -50,15 +50,14 @@ android:layout_width="40dp" android:layout_height="40dp" android:layout_marginLeft="@dimen/content_padding_half" - android:layout_marginRight="@dimen/content_padding_half" - android:background="@drawable/bg_transparent_rounded_profile"> + android:layout_marginRight="@dimen/content_padding_half"> diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 04f674aae7..e77758da73 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -196,13 +196,12 @@ public class ContextMenuAdapter { desc.setText(item.getDescription()); } if (layoutId == R.layout.main_menu_drawer_btn_configure_profile) { - int colorAlpha50 = UiUtilities.getColorWithAlpha(colorNoAlpha, 0.5f); View fatDivider = convertView.findViewById(R.id.fatDivider); - fatDivider.setBackgroundColor(colorAlpha50); + fatDivider.setBackgroundColor(colorNoAlpha); } int colorListBackground = ContextCompat.getColor(app, lightTheme ? R.color.list_background_color_light : R.color.list_background_color_dark); - convertView.setBackgroundDrawable(UiUtilities.getAlphaStateDrawable(colorListBackground, colorNoAlpha, true, true)); +// convertView.setBackgroundDrawable(UiUtilities.getAlphaStateDrawable(colorListBackground, colorNoAlpha)); return convertView; } if (layoutId == R.layout.help_to_improve_item) { diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index e294012ea3..9d1bbb6fa6 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -3,11 +3,11 @@ package net.osmand.plus; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; +import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.RippleDrawable; -import android.graphics.drawable.StateListDrawable; import android.hardware.Sensor; import android.hardware.SensorManager; import android.os.Build; @@ -17,6 +17,7 @@ import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; +import android.support.v4.graphics.drawable.TintAwareDrawable; import android.support.v7.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -109,6 +110,41 @@ public class UiUtilities { return getDrawable(id, light ? R.color.icon_color_default_light : R.color.icon_color_default_dark); } + public Drawable colorDrawable(Drawable drawable, int color) { + Drawable wrappedDrawable = DrawableCompat.wrap(drawable); + DrawableCompat.setTint(wrappedDrawable.mutate(), color); + return wrappedDrawable; + } + + public static void setBackgroundDrawable(View view, Drawable drawable) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + view.setBackgroundDrawable(drawable); + } else { + view.setBackground(drawable); + } + } + + public Drawable setRippleColor(@DrawableRes int id, int rippleColor) { + return setRippleColor(getIcon(id), rippleColor); + } + + public Drawable setRippleColor(Drawable drawable, int rippleColor) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && drawable instanceof RippleDrawable) { + ((RippleDrawable) drawable).setColor(ColorStateList.valueOf(rippleColor)); + } else { + if (drawable != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + drawable.setTintList(ColorStateList.valueOf(rippleColor)); + } else if (drawable instanceof TintAwareDrawable) { + ((TintAwareDrawable) drawable).setTintList(ColorStateList.valueOf(rippleColor)); + } else { + drawable.setColorFilter(rippleColor, PorterDuff.Mode.DST_ATOP); + } + } + } + return drawable; + } + @ColorRes public static int getDefaultColorRes(Context context) { final OsmandApplication app = (OsmandApplication) context.getApplicationContext(); @@ -156,33 +192,16 @@ public class UiUtilities { return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL; } - public static Drawable getAlphaStateDrawable(@ColorInt int colorNoAlpha) { - return getAlphaStateDrawable(colorNoAlpha, false, true); - } - - public static Drawable getAlphaStateDrawable(@ColorInt int colorNoAlpha, boolean highlightOnNormal, boolean highlightOnPressed) { - int colorAlpha25 = getColorWithAlpha(colorNoAlpha, 0.25f); - int colorAlpha30 = getColorWithAlpha(colorNoAlpha, 0.3f); - return getAlphaStateDrawableImpl(colorAlpha25, colorAlpha30, highlightOnNormal, highlightOnPressed); + public static Drawable getAlphaStateDrawable(@ColorInt int colorNoAlpha, float normalAlphaRatio, float pressedAlphaRatio) { + int colorAlpha25 = getColorWithAlpha(colorNoAlpha, normalAlphaRatio); + int colorAlpha30 = getColorWithAlpha(colorNoAlpha, pressedAlphaRatio); + return AndroidUtils.createPressedStateListDrawable(new ColorDrawable(colorAlpha25), new ColorDrawable(colorAlpha30)); } - public static Drawable getAlphaStateDrawable(@ColorInt int colorBackground, @ColorInt int colorForeground, boolean highlightOnNormal, boolean highlightOnPressed) { + public static Drawable getAlphaStateDrawable(@ColorInt int colorBackground, @ColorInt int colorForeground) { int colorAlpha25 = UiUtilities.mixTwoColors(colorForeground, colorBackground, 0.125f); int colorAlpha30 = UiUtilities.mixTwoColors(colorForeground, colorBackground, 0.15f); - return getAlphaStateDrawableImpl(colorAlpha25, colorAlpha30, highlightOnNormal, highlightOnPressed); - } - - private static Drawable getAlphaStateDrawableImpl(@ColorInt int colorMode1, @ColorInt int colorMode2, boolean highlightOnNormal, boolean highlightOnPressed) { - StateListDrawable sld = new StateListDrawable(); - if (highlightOnNormal && highlightOnPressed) { - sld.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(colorMode2)); - sld.addState(new int[]{}, new ColorDrawable(colorMode1)); - } else if (highlightOnPressed) { - sld.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(colorMode1)); - } else if (highlightOnNormal) { - sld.addState(new int[]{}, new ColorDrawable(colorMode1)); - } - return sld; + return AndroidUtils.createPressedStateListDrawable(new ColorDrawable(colorAlpha25), new ColorDrawable(colorAlpha30)); } public UpdateLocationViewCache getUpdateLocationViewCache(){ diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 0fd400308b..09ae214cbc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -657,7 +657,7 @@ public class MapActivityActions implements DialogProvider { final AppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment(); fragment.setUsedOnMap(true); mapActivity.getSupportFragmentManager().beginTransaction() - .add(fragment, "app_profile_settings").commitAllowingStateLoss(); + .add(fragment, SelectAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss(); return true; } }) diff --git a/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java index f532e38e3e..4520fafe69 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java @@ -12,6 +12,8 @@ import java.util.Set; public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment implements ConfigureProfileMenuAdapter.ProfileSelectedListener { + public static final String TAG = "ConfigureAppModesBottomSheetDialogFragment"; + private List allModes = new ArrayList<>(); private Set selectedModes = new HashSet<>(); diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectAppModesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/SelectAppModesBottomSheetDialogFragment.java index 9bd74bbfc4..6dad949aab 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/SelectAppModesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/SelectAppModesBottomSheetDialogFragment.java @@ -1,14 +1,24 @@ package net.osmand.plus.profiles; -import android.widget.Toast; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import net.osmand.PlatformUtil; import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; +import org.apache.commons.logging.Log; + import java.util.ArrayList; import java.util.List; public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment { + + public static final String TAG = "SelectAppModesBottomSheetDialogFragment"; + + private static final Log LOG = PlatformUtil.getLog(SelectAppModesBottomSheetDialogFragment.class); + private List activeModes = new ArrayList<>(); @Override @@ -38,8 +48,29 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet public void onProfilePressed(ApplicationMode item) { if (!(item == getMyApplication().getSettings().APPLICATION_MODE.get())) { getMyApplication().getSettings().APPLICATION_MODE.set(item); - Toast.makeText(getMyApplication(), String.format(getString(R.string.application_profile_changed), item.toHumanString(getMyApplication())), Toast.LENGTH_SHORT).show(); + + Fragment targetFragment = getTargetFragment(); + if (targetFragment instanceof AppModeChangedListener) { + AppModeChangedListener listener = (AppModeChangedListener) targetFragment; + listener.onAppModeChanged(); + } } dismiss(); } + + public static void showInstance(@NonNull FragmentManager fm, Fragment target) { + try { + if (fm.findFragmentByTag(SelectAppModesBottomSheetDialogFragment.TAG) == null) { + SelectAppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment(); + fragment.setTargetFragment(target, 0); + fragment.show(fm, SelectAppModesBottomSheetDialogFragment.TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } + + public interface AppModeChangedListener { + void onAppModeChanged(); + } } diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java index 91fece071e..17659046d9 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java @@ -106,7 +106,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter Build.VERSION_CODES.LOLLIPOP && selectableBg instanceof RippleDrawable) { + colorWithAlpha = UiUtilities.getColorWithAlpha(color, 0.4f); + }else { + colorWithAlpha = UiUtilities.getColorWithAlpha(color, 0.2f); + + } + if (selectableBg != null) { + Drawable drawable = app.getUIUtilities().setRippleColor(selectableBg, colorWithAlpha); + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + selectableView.setBackground(drawable); + } else { + selectableView.setBackgroundDrawable(drawable); + } + selectableView.invalidate(); + } + } + } + } + }; + } + @Override public void onResume() { super.onResume(); @@ -146,10 +188,40 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl }); View switchProfile = view.findViewById(R.id.switch_profile_button); if (switchProfile != null) { + + if (this.getClass().equals(ConfigureProfileFragment.class)) { + int drawableId; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + drawableId = nightMode ? R.drawable.ripple_dark : R.drawable.ripple_light; + } else { + drawableId = nightMode ? R.drawable.btn_border_trans_dark : R.drawable.btn_border_trans_light; + } + + int color = ContextCompat.getColor(app, getActiveProfileColor()); + int colorWithAlpha = UiUtilities.getColorWithAlpha(color, 0.40f); + + Drawable drawable = app.getUIUtilities().setRippleColor(drawableId, colorWithAlpha); + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + switchProfile.setBackground(drawable); + } else { + switchProfile.setBackgroundDrawable(drawable); + } + } else { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setBackground(app, switchProfile, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + } else { + AndroidUtils.setBackground(app, switchProfile, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); + } + } + switchProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - selectAppModeDialog().show(); + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager, BaseSettingsFragment.this); + } } }); } @@ -213,64 +285,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } - protected AlertDialog.Builder selectAppModeDialog() { - AlertDialog.Builder singleSelectDialogBuilder = new AlertDialog.Builder(getContext()); - singleSelectDialogBuilder.setTitle(R.string.profile_settings); - - final List activeModes = new ArrayList<>(); - for (ApplicationMode am : ApplicationMode.values(getMyApplication())) { - boolean isSelected = false; - if (am == getSelectedAppMode()) { - isSelected = true; - } - activeModes.add(new ProfileDataObject( - am.toHumanString(getMyApplication()), - getAppModeDescription(am), - am.getStringKey(), - am.getIconRes(), - isSelected, - am.getIconColorInfo() - )); - } - - final AppProfileArrayAdapter modeNames = new AppProfileArrayAdapter( - getActivity(), R.layout.bottom_sheet_item_with_descr_and_radio_btn, activeModes, true); - - singleSelectDialogBuilder.setNegativeButton(R.string.shared_string_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - singleSelectDialogBuilder.setAdapter(modeNames, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - ApplicationMode selectedAppMode = ApplicationMode.values(app).get(which); - requireSettings().APPLICATION_MODE.set(selectedAppMode); - updateAllSettings(); - } - }); - return singleSelectDialogBuilder; - } - - private String getAppModeDescription(ApplicationMode mode) { - String descr; - if (!mode.isCustomProfile()) { - descr = getString(R.string.profile_type_base_string); - } else { - descr = String.format(getString(R.string.profile_type_descr_string), - mode.getParent().toHumanString(getMyApplication())); - if (mode.getRoutingProfile() != null && mode.getRoutingProfile().contains("/")) { - descr = descr.concat(", " + mode.getRoutingProfile() - .substring(0, mode.getRoutingProfile().indexOf("/"))); - } - } - return descr; - } - public void updateAllSettings() { - getListView().getRecycledViewPool().clear(); PreferenceScreen screen = getPreferenceScreen(); if (screen != null) { getPreferenceScreen().removeAll(); @@ -463,6 +478,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl return false; } + @Override + public void onAppModeChanged() { + updateAllSettings(); + } + public SwitchPreference createSwitchPreference(OsmandSettings.OsmandPreference b, int title, int summary, int layoutId) { return createSwitchPreference(b, getString(title), getString(summary), layoutId); } diff --git a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java index b39d7e4f3e..958595988d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java @@ -1,5 +1,7 @@ package net.osmand.plus.settings; +import android.content.Context; +import android.net.Uri; import android.support.annotation.NonNull; import android.support.v4.app.FragmentManager; import android.support.v7.preference.CheckBoxPreference; @@ -17,19 +19,21 @@ import android.text.style.ClickableSpan; import android.view.MotionEvent; import android.view.View; import android.widget.TextView; -import android.widget.Toast; import net.osmand.Location; import net.osmand.data.PointDescription; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet; +import net.osmand.plus.wikipedia.WikipediaDialogFragment; public class CoordinatesFormatFragment extends BaseSettingsFragment { public static final String TAG = "CoordinatesFormatFragment"; + private static final String UTM_FORMAT_WIKI_LINK = "https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system"; + private static final String FORMAT_DEGREES = "format_degrees"; private static final String FORMAT_MINUTES = "format_minutes"; private static final String FORMAT_SECONDS = "format_seconds"; @@ -162,7 +166,10 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment { ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(@NonNull View widget) { - Toast.makeText(widget.getContext(), getString(R.string.shared_string_read_more), Toast.LENGTH_LONG).show(); + Context ctx = getContext(); + if (ctx != null) { + WikipediaDialogFragment.showFullArticle(ctx, Uri.parse(UTM_FORMAT_WIKI_LINK), isNightMode()); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java index 25977088d9..72fc752911 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -1,10 +1,10 @@ package net.osmand.plus.settings; +import android.content.Context; import android.content.DialogInterface; import android.content.pm.ActivityInfo; import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; -import android.support.v14.preference.SwitchPreference; import android.support.v4.app.FragmentManager; import android.support.v7.app.AlertDialog; import android.support.v7.preference.Preference; @@ -48,6 +48,10 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { @Override protected void setupPreferences() { + Context ctx = getContext(); + if (ctx == null) { + return; + } Preference appearanceCategory = findPreference("appearance_category"); Preference unitsAndFormats = findPreference("units_and_formats"); Preference other = findPreference("other"); @@ -68,9 +72,9 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupAppThemePref() { - final ListPreferenceEx appTheme = (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId()); - appTheme.setEntries(new String[]{getString(R.string.dark_theme), getString(R.string.light_theme)}); - appTheme.setEntryValues(new Integer[]{OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME}); + ListPreferenceEx appTheme = (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId()); + appTheme.setEntries(new String[] {getString(R.string.dark_theme), getString(R.string.light_theme)}); + appTheme.setEntryValues(new Integer[] {OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME}); appTheme.setIcon(getOsmandThemeIcon()); } @@ -79,9 +83,9 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupRotateMapPref() { - final ListPreferenceEx rotateMap = (ListPreferenceEx) findPreference(settings.ROTATE_MAP.getId()); - rotateMap.setEntries(new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}); - rotateMap.setEntryValues(new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); + ListPreferenceEx rotateMap = (ListPreferenceEx) findPreference(settings.ROTATE_MAP.getId()); + rotateMap.setEntries(new String[] {getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}); + rotateMap.setEntryValues(new Integer[] {OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); rotateMap.setIcon(getRotateMapIcon()); } @@ -97,9 +101,9 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupMapScreenOrientationPref() { - final ListPreferenceEx mapScreenOrientation = (ListPreferenceEx) findPreference(settings.MAP_SCREEN_ORIENTATION.getId()); - mapScreenOrientation.setEntries(new String[]{getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)}); - mapScreenOrientation.setEntryValues(new Integer[]{ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED}); + ListPreferenceEx mapScreenOrientation = (ListPreferenceEx) findPreference(settings.MAP_SCREEN_ORIENTATION.getId()); + mapScreenOrientation.setEntries(new String[] {getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)}); + mapScreenOrientation.setEntryValues(new Integer[] {ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED}); mapScreenOrientation.setIcon(getMapScreenOrientationIcon()); } @@ -186,14 +190,14 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { private void setupExternalInputDevicePref() { ListPreferenceEx externalInputDevice = (ListPreferenceEx) findPreference(settings.EXTERNAL_INPUT_DEVICE.getId()); - externalInputDevice.setEntries(new String[]{ + externalInputDevice.setEntries(new String[] { getString(R.string.sett_no_ext_input), getString(R.string.sett_generic_ext_input), getString(R.string.sett_wunderlinq_ext_input), getString(R.string.sett_parrot_ext_input) }); - externalInputDevice.setEntryValues(new Integer[]{ + externalInputDevice.setEntryValues(new Integer[] { OsmandSettings.NO_EXTERNAL_DEVICE, OsmandSettings.GENERIC_EXTERNAL_DEVICE, OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE, From 1a797d29fad35df4932e9c6382d02ce40d46488f Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 17 Sep 2019 16:57:54 +0300 Subject: [PATCH 2/3] Profile preferences Ui improvements --- OsmAnd/res/drawable/rectangle_rounded.xml | 12 + OsmAnd/res/drawable/ripple_circle.xml | 13 + .../res/drawable/ripple_rectangle_rounded.xml | 14 + .../layout/preference_dialog_and_switch.xml | 7 +- OsmAnd/res/layout/preference_info.xml | 8 +- OsmAnd/res/layout/preference_radio_button.xml | 27 +- OsmAnd/res/layout/preference_switch.xml | 11 +- OsmAnd/res/layout/preference_top_switch.xml | 25 +- OsmAnd/res/layout/preference_with_descr.xml | 11 +- ...reference_with_descr_dialog_and_switch.xml | 9 +- .../res/layout/profile_preference_toolbar.xml | 85 +++--- .../layout/profile_preference_toolbar_big.xml | 157 +++++------ OsmAnd/res/values/colors.xml | 1 + OsmAnd/res/values/strings.xml | 2 +- OsmAnd/res/xml/configure_profile.xml | 6 +- OsmAnd/res/xml/coordinates_format.xml | 16 +- OsmAnd/res/xml/navigation_settings_new.xml | 2 +- OsmAnd/res/xml/turn_screen_on.xml | 3 +- OsmAnd/src/net/osmand/AndroidUtils.java | 17 +- .../net/osmand/plus/ContextMenuAdapter.java | 12 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 73 ++--- .../profiles/SelectProfileMenuAdapter.java | 27 +- .../plus/settings/BaseSettingsFragment.java | 257 +++++++++--------- .../settings/ConfigureProfileFragment.java | 94 ++++++- .../settings/CoordinatesFormatFragment.java | 35 +-- .../GeneralProfileSettingsFragment.java | 31 +-- .../plus/settings/GlobalSettingsFragment.java | 4 +- .../plus/settings/MainSettingsFragment.java | 14 +- .../settings/MapDuringNavigationFragment.java | 4 +- .../plus/settings/NavigationFragment.java | 4 +- .../plus/settings/ProxySettingsFragment.java | 5 +- .../settings/RouteParametersFragment.java | 4 +- .../plus/settings/ScreenAlertsFragment.java | 22 +- .../plus/settings/TurnScreenOnFragment.java | 22 +- .../settings/VehicleParametersFragment.java | 4 +- .../plus/settings/VoiceAnnouncesFragment.java | 22 +- 36 files changed, 586 insertions(+), 474 deletions(-) create mode 100644 OsmAnd/res/drawable/rectangle_rounded.xml create mode 100644 OsmAnd/res/drawable/ripple_circle.xml create mode 100644 OsmAnd/res/drawable/ripple_rectangle_rounded.xml diff --git a/OsmAnd/res/drawable/rectangle_rounded.xml b/OsmAnd/res/drawable/rectangle_rounded.xml new file mode 100644 index 0000000000..7edb35d6d9 --- /dev/null +++ b/OsmAnd/res/drawable/rectangle_rounded.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/ripple_circle.xml b/OsmAnd/res/drawable/ripple_circle.xml new file mode 100644 index 0000000000..47ef3daf42 --- /dev/null +++ b/OsmAnd/res/drawable/ripple_circle.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/ripple_rectangle_rounded.xml b/OsmAnd/res/drawable/ripple_rectangle_rounded.xml new file mode 100644 index 0000000000..b5d5df88ab --- /dev/null +++ b/OsmAnd/res/drawable/ripple_rectangle_rounded.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_dialog_and_switch.xml b/OsmAnd/res/layout/preference_dialog_and_switch.xml index 549b84cdf1..f1ed65d0e3 100644 --- a/OsmAnd/res/layout/preference_dialog_and_switch.xml +++ b/OsmAnd/res/layout/preference_dialog_and_switch.xml @@ -1,6 +1,7 @@ + tools:background="?android:attr/selectableItemBackground"> diff --git a/OsmAnd/res/layout/preference_info.xml b/OsmAnd/res/layout/preference_info.xml index 34c0a90c03..075e94d733 100644 --- a/OsmAnd/res/layout/preference_info.xml +++ b/OsmAnd/res/layout/preference_info.xml @@ -22,10 +22,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginLeft="@dimen/content_padding" - android:layout_marginTop="@dimen/content_padding_small" - android:layout_marginRight="@dimen/content_padding" - android:layout_marginBottom="@dimen/list_header_settings_top_margin" + android:paddingLeft="@dimen/content_padding" + android:paddingTop="@dimen/content_padding_small" + android:paddingRight="@dimen/content_padding" + android:paddingBottom="@dimen/list_header_settings_top_margin" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_regular" /> diff --git a/OsmAnd/res/layout/preference_radio_button.xml b/OsmAnd/res/layout/preference_radio_button.xml index e400f4b14c..6dfa5a942b 100644 --- a/OsmAnd/res/layout/preference_radio_button.xml +++ b/OsmAnd/res/layout/preference_radio_button.xml @@ -1,25 +1,27 @@ + android:gravity="center_vertical" + android:orientation="vertical"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + tools:background="?android:attr/selectableItemBackground"> @@ -28,10 +30,11 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginLeft="@dimen/content_padding" - android:layout_marginRight="@dimen/content_padding" android:layout_weight="1" - android:orientation="vertical"> + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingTop="@dimen/gpx_small_text_margin" + android:paddingRight="@dimen/content_padding"> + + diff --git a/OsmAnd/res/layout/preference_switch.xml b/OsmAnd/res/layout/preference_switch.xml index 9df4a56fca..cd6e06fd44 100644 --- a/OsmAnd/res/layout/preference_switch.xml +++ b/OsmAnd/res/layout/preference_switch.xml @@ -1,6 +1,7 @@ + android:minHeight="@dimen/bottom_sheet_list_item_height" + tools:background="?android:attr/selectableItemBackground"> + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding"> - - - - - + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" + android:textColor="?attr/text_color_tab_active" + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_medium" /> diff --git a/OsmAnd/res/layout/preference_with_descr.xml b/OsmAnd/res/layout/preference_with_descr.xml index 8cbf72025e..1cb71ed180 100644 --- a/OsmAnd/res/layout/preference_with_descr.xml +++ b/OsmAnd/res/layout/preference_with_descr.xml @@ -1,6 +1,7 @@ + android:minHeight="@dimen/bottom_sheet_list_item_height" + tools:background="?android:attr/selectableItemBackground"> + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding"> + tools:background="?android:attr/selectableItemBackground"> + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding"> @@ -14,55 +13,49 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/card_and_list_background_basic" - android:orientation="vertical"> + android:gravity="center_vertical" + android:orientation="horizontal"> - + + + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" + android:textColor="?android:textColorPrimary" + android:textSize="@dimen/dialog_header_text_size" + osmand:typeface="@string/font_roboto_medium" + tools:text="@string/routing_settings_2" /> - + - + - - - - - - - + diff --git a/OsmAnd/res/layout/profile_preference_toolbar_big.xml b/OsmAnd/res/layout/profile_preference_toolbar_big.xml index 17dd95658b..d878c085a8 100644 --- a/OsmAnd/res/layout/profile_preference_toolbar_big.xml +++ b/OsmAnd/res/layout/profile_preference_toolbar_big.xml @@ -4,8 +4,6 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/colorPrimary" - android:minHeight="56dp" osmand:contentInsetLeft="0dp" osmand:contentInsetStart="0dp" osmand:theme="@style/ThemeOverlay.AppCompat.ActionBar"> @@ -20,14 +18,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" - android:minHeight="@dimen/dashboard_map_toolbar" + android:minHeight="@dimen/toolbar_height" android:orientation="horizontal"> @@ -35,110 +33,93 @@ - - + android:layout_marginLeft="@dimen/context_menu_padding_margin_tiny" + android:layout_marginRight="@dimen/context_menu_padding_margin_tiny" + android:layout_marginBottom="@dimen/context_menu_padding_margin_tiny" + android:clickable="true" + android:focusable="true" + android:minHeight="@dimen/bottom_sheet_list_item_height" + android:orientation="horizontal"> + + + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:orientation="vertical" + android:paddingLeft="@dimen/content_padding" + android:paddingRight="@dimen/content_padding"> - + android:ellipsize="end" + android:maxLines="1" + android:textColor="?android:textColorPrimary" + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_medium" + tools:text="@string/profile_type_base_string" /> - - - - - - - - - + android:ellipsize="end" + android:maxLines="1" + android:textColor="?android:textColorSecondary" + android:textSize="@dimen/default_desc_text_size" + osmand:typeface="@string/font_roboto_regular" + tools:text="Item additional description" /> - + + + \ No newline at end of file diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 5837c292ae..7166b2fcc6 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -424,6 +424,7 @@ #eeeeee #7E33FF + #808080 #101112 diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 49bccfb23a..52235fb3a1 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,7 +11,7 @@ Thx - Hardy --> - + Plugin settings Logcat buffer Application profile changed to \"%s\" Switch profile diff --git a/OsmAnd/res/xml/configure_profile.xml b/OsmAnd/res/xml/configure_profile.xml index 51b203d7fd..7abb3a1e87 100644 --- a/OsmAnd/res/xml/configure_profile.xml +++ b/OsmAnd/res/xml/configure_profile.xml @@ -44,6 +44,10 @@ android:key="plugin_settings" android:layout="@layout/preference_category_with_descr" android:summary="@string/list_of_installed_plugins" - android:title="@string/plugin_settings" /> + android:title="@string/plugins_settings" /> + + \ No newline at end of file diff --git a/OsmAnd/res/xml/coordinates_format.xml b/OsmAnd/res/xml/coordinates_format.xml index 825ce178c6..0f1a787cbc 100644 --- a/OsmAnd/res/xml/coordinates_format.xml +++ b/OsmAnd/res/xml/coordinates_format.xml @@ -5,7 +5,6 @@ - - - - - - + diff --git a/OsmAnd/res/xml/navigation_settings_new.xml b/OsmAnd/res/xml/navigation_settings_new.xml index 60146acefb..03734736b4 100644 --- a/OsmAnd/res/xml/navigation_settings_new.xml +++ b/OsmAnd/res/xml/navigation_settings_new.xml @@ -49,7 +49,7 @@ diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 68c6c88ce0..847f81f994 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -318,14 +318,21 @@ public class AndroidUtils { tv.setMaxLines(maxLines); } - @SuppressLint("NewApi") - @SuppressWarnings("deprecation") public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) { + Drawable drawable; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - view.setBackground(ctx.getResources().getDrawable(night ? darkResId : lightResId, - ctx.getTheme())); + drawable = ctx.getResources().getDrawable(night ? darkResId : lightResId, ctx.getTheme()); } else { - view.setBackgroundDrawable(ctx.getResources().getDrawable(night ? darkResId : lightResId)); + drawable = ctx.getResources().getDrawable(night ? darkResId : lightResId); + } + setBackground(view, drawable); + } + + public static void setBackground(View view, Drawable drawable) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + view.setBackground(drawable); + } else { + view.setBackgroundDrawable(drawable); } } diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index e77758da73..72d9d5c2fc 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -2,7 +2,9 @@ package net.osmand.plus; import android.app.Activity; import android.content.Intent; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; @@ -199,9 +201,13 @@ public class ContextMenuAdapter { View fatDivider = convertView.findViewById(R.id.fatDivider); fatDivider.setBackgroundColor(colorNoAlpha); } - - int colorListBackground = ContextCompat.getColor(app, lightTheme ? R.color.list_background_color_light : R.color.list_background_color_dark); -// convertView.setBackgroundDrawable(UiUtilities.getAlphaStateDrawable(colorListBackground, colorNoAlpha)); + + Drawable selectableBg = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f); + Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.15f)), selectableBg}; + LayerDrawable layerDrawable = new LayerDrawable(layers); + + AndroidUtils.setBackground(convertView, layerDrawable); + return convertView; } if (layoutId == R.layout.help_to_improve_item) { diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 9d1bbb6fa6..d9a0489bc0 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -3,7 +3,6 @@ package net.osmand.plus; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; -import android.graphics.PorterDuff; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; @@ -17,7 +16,6 @@ import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; -import android.support.v4.graphics.drawable.TintAwareDrawable; import android.support.v7.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; @@ -72,9 +70,7 @@ public class UiUtilities { Drawable d = drawableCache.get(hash); if (d == null) { d = ContextCompat.getDrawable(app, resId); - d = DrawableCompat.wrap(d); - d.mutate(); - DrawableCompat.setTint(d, color); + d = tintDrawable(d, color); drawableCache.put(hash, d); } @@ -110,41 +106,42 @@ public class UiUtilities { return getDrawable(id, light ? R.color.icon_color_default_light : R.color.icon_color_default_dark); } - public Drawable colorDrawable(Drawable drawable, int color) { - Drawable wrappedDrawable = DrawableCompat.wrap(drawable); - DrawableCompat.setTint(wrappedDrawable.mutate(), color); - return wrappedDrawable; - } - - public static void setBackgroundDrawable(View view, Drawable drawable) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { - view.setBackgroundDrawable(drawable); - } else { - view.setBackground(drawable); + public static Drawable getSelectableDrawable(Context ctx) { + int bgResId = AndroidUtils.resolveAttribute(ctx, R.attr.selectableItemBackground); + if (bgResId != 0) { + return ContextCompat.getDrawable(ctx, bgResId); } + return null; } - public Drawable setRippleColor(@DrawableRes int id, int rippleColor) { - return setRippleColor(getIcon(id), rippleColor); - } - - public Drawable setRippleColor(Drawable drawable, int rippleColor) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && drawable instanceof RippleDrawable) { - ((RippleDrawable) drawable).setColor(ColorStateList.valueOf(rippleColor)); - } else { - if (drawable != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - drawable.setTintList(ColorStateList.valueOf(rippleColor)); - } else if (drawable instanceof TintAwareDrawable) { - ((TintAwareDrawable) drawable).setTintList(ColorStateList.valueOf(rippleColor)); - } else { - drawable.setColorFilter(rippleColor, PorterDuff.Mode.DST_ATOP); - } + public static Drawable getColoredSelectableDrawable(Context ctx, int color, float alpha) { + Drawable drawable = null; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + Drawable bg = getSelectableDrawable(ctx); + if (bg != null) { + drawable = tintDrawable(bg, getColorWithAlpha(color, alpha)); } + } else { + drawable = AndroidUtils.createPressedStateListDrawable(new ColorDrawable(Color.TRANSPARENT), new ColorDrawable(getColorWithAlpha(color, alpha))); } return drawable; } + public static Drawable tintDrawable(Drawable drawable, int color) { + Drawable coloredDrawable = null; + if (drawable != null) { + coloredDrawable = DrawableCompat.wrap(drawable); + coloredDrawable.mutate(); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && coloredDrawable instanceof RippleDrawable) { + ((RippleDrawable) coloredDrawable).setColor(ColorStateList.valueOf(color)); + } else { + DrawableCompat.setTint(coloredDrawable, color); + } + } + + return coloredDrawable; + } + @ColorRes public static int getDefaultColorRes(Context context) { final OsmandApplication app = (OsmandApplication) context.getApplicationContext(); @@ -192,18 +189,6 @@ public class UiUtilities { return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL; } - public static Drawable getAlphaStateDrawable(@ColorInt int colorNoAlpha, float normalAlphaRatio, float pressedAlphaRatio) { - int colorAlpha25 = getColorWithAlpha(colorNoAlpha, normalAlphaRatio); - int colorAlpha30 = getColorWithAlpha(colorNoAlpha, pressedAlphaRatio); - return AndroidUtils.createPressedStateListDrawable(new ColorDrawable(colorAlpha25), new ColorDrawable(colorAlpha30)); - } - - public static Drawable getAlphaStateDrawable(@ColorInt int colorBackground, @ColorInt int colorForeground) { - int colorAlpha25 = UiUtilities.mixTwoColors(colorForeground, colorBackground, 0.125f); - int colorAlpha30 = UiUtilities.mixTwoColors(colorForeground, colorBackground, 0.15f); - return AndroidUtils.createPressedStateListDrawable(new ColorDrawable(colorAlpha25), new ColorDrawable(colorAlpha30)); - } - public UpdateLocationViewCache getUpdateLocationViewCache(){ UpdateLocationViewCache uvc = new UpdateLocationViewCache(); uvc.screenOrientation = getScreenOrientation(); diff --git a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java index 17659046d9..ed0241a016 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/profiles/SelectProfileMenuAdapter.java @@ -1,7 +1,8 @@ package net.osmand.plus.profiles; import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.StateListDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.support.annotation.ColorRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -11,6 +12,7 @@ import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; +import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; @@ -106,8 +108,14 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter Build.VERSION_CODES.LOLLIPOP && selectableBg instanceof RippleDrawable) { - colorWithAlpha = UiUtilities.getColorWithAlpha(color, 0.4f); - }else { - colorWithAlpha = UiUtilities.getColorWithAlpha(color, 0.2f); - - } - if (selectableBg != null) { - Drawable drawable = app.getUIUtilities().setRippleColor(selectableBg, colorWithAlpha); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - selectableView.setBackground(drawable); - } else { - selectableView.setBackgroundDrawable(drawable); - } - selectableView.invalidate(); - } - } + Preference preference = getItem(position); + if (preference != null) { + onBindPreferenceViewHolder(preference, holder); } } }; @@ -157,27 +145,76 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl @Override public void onPause() { super.onPause(); + MapActivity mapActivity = getMapActivity(); if (!wasDrawerDisabled && mapActivity != null) { mapActivity.enableDrawer(); } } + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + return true; + } + + @Override + public boolean onPreferenceClick(Preference preference) { + return false; + } + + @Override + public void onDisplayPreferenceDialog(Preference preference) { + if (preference instanceof ListPreferenceEx) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this); + } + } else if (preference instanceof SwitchPreferenceEx) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this); + } + } else if (preference instanceof EditTextPreference) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this); + } + } else if (preference instanceof MultiSelectBooleanPreference) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + MultiSelectPreferencesBottomSheet.showInstance(getFragmentManager(), preference.getKey(), this); + } + } else { + super.onDisplayPreferenceDialog(preference); + } + } + + @Override + public void onAppModeChanged() { + updateAllSettings(); + } + + protected abstract void setupPreferences(); + + protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { + if (preference.isSelectable()) { + View selectableView = holder.itemView.findViewById(R.id.selectable_list_item); + if (selectableView != null) { + Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, getActiveProfileColor(), 0.3f); + AndroidUtils.setBackground(selectableView, drawable); + } + } + } + private void createToolbar(LayoutInflater inflater, View view) { AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.appbar); int toolbarRes = getToolbarResId(); if (toolbarRes != -1) { - Context activityContext = getActivity(); + Context themedContext = new ContextThemeWrapper(getActivity(), themeRes); + View toolbarContainer = inflater.cloneInContext(themedContext).inflate(toolbarRes, appBarLayout); - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - final Context themedContext = new ContextThemeWrapper(activityContext, themeRes); - LayoutInflater themedInflater = LayoutInflater.from(themedContext); - - View toolbarContainer = themedInflater.inflate(toolbarRes, null); - appBarLayout.addView(toolbarContainer); - - view.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { + toolbarContainer.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MapActivity mapActivity = getMapActivity(); @@ -186,35 +223,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } }); - View switchProfile = view.findViewById(R.id.switch_profile_button); + View switchProfile = toolbarContainer.findViewById(R.id.switch_profile_button); if (switchProfile != null) { - - if (this.getClass().equals(ConfigureProfileFragment.class)) { - int drawableId; - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - drawableId = nightMode ? R.drawable.ripple_dark : R.drawable.ripple_light; - } else { - drawableId = nightMode ? R.drawable.btn_border_trans_dark : R.drawable.btn_border_trans_light; - } - - int color = ContextCompat.getColor(app, getActiveProfileColor()); - int colorWithAlpha = UiUtilities.getColorWithAlpha(color, 0.40f); - - Drawable drawable = app.getUIUtilities().setRippleColor(drawableId, colorWithAlpha); - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - switchProfile.setBackground(drawable); - } else { - switchProfile.setBackgroundDrawable(drawable); - } - } else { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - AndroidUtils.setBackground(app, switchProfile, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } else { - AndroidUtils.setBackground(app, switchProfile, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); - } - } - switchProfile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -225,7 +235,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } }); } - updateToolbar(view); + updateToolbar(toolbarContainer); } } @@ -235,9 +245,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } ApplicationMode selectedAppMode = getSelectedAppMode(); - int iconRes = selectedAppMode.getIconRes(); - int iconColor = selectedAppMode.getIconColorInfo().getColor(nightMode); - String title = selectedAppMode.isCustomProfile() ? selectedAppMode.getCustomProfileName() : getResources().getString(selectedAppMode.getNameKeyResource()); + int iconColor = getActiveProfileColor(); TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title); if (toolbarTitle != null) { @@ -245,11 +253,13 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } ImageView profileIcon = (ImageView) view.findViewById(R.id.profile_icon); if (profileIcon != null) { - profileIcon.setImageDrawable(getIcon(iconRes, iconColor)); + int iconRes = selectedAppMode.getIconRes(); + profileIcon.setImageDrawable(getPaintedIcon(iconRes, iconColor)); } TextView profileTitle = (TextView) view.findViewById(R.id.profile_title); if (profileTitle != null) { - profileTitle.setText(title); + String appName = selectedAppMode.toHumanString(app); + profileTitle.setText(appName); } TextView profileType = (TextView) view.findViewById(R.id.profile_type); if (profileType != null) { @@ -257,12 +267,40 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } View toolbarDivider = view.findViewById(R.id.toolbar_divider); if (toolbarDivider != null) { - toolbarDivider.setBackgroundColor(ContextCompat.getColor(app, iconColor)); + toolbarDivider.setBackgroundColor(iconColor); } - view.setBackgroundColor(ContextCompat.getColor(app, getBackgroundColor())); - } + View profileButton = view.findViewById(R.id.switch_profile_button); + if (profileButton != null) { + int toolbarRes = getToolbarResId(); + int bgColor = UiUtilities.getColorWithAlpha(iconColor, 0.1f); + int selectedColor = UiUtilities.getColorWithAlpha(iconColor, 0.3f); - protected abstract void setupPreferences(); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + int bgResId = 0; + int selectableResId = 0; + if (toolbarRes == R.layout.profile_preference_toolbar) { + bgResId = R.drawable.circle_background_light; + selectableResId = R.drawable.ripple_circle; + } else if (toolbarRes == R.layout.profile_preference_toolbar_big) { + bgResId = R.drawable.rectangle_rounded; + selectableResId = R.drawable.ripple_rectangle_rounded; + } + Drawable bgDrawable = getPaintedIcon(bgResId, bgColor); + Drawable selectable = getPaintedIcon(selectableResId, selectedColor); + Drawable[] layers = {bgDrawable, selectable}; + AndroidUtils.setBackground(profileButton, new LayerDrawable(layers)); + } else { + int bgResId = 0; + if (toolbarRes == R.layout.profile_preference_toolbar) { + bgResId = R.drawable.circle_background_light; + } else if (toolbarRes == R.layout.profile_preference_toolbar_big) { + bgResId = R.drawable.rectangle_rounded; + } + Drawable bgDrawable = getPaintedIcon(bgResId, bgColor); + AndroidUtils.setBackground(profileButton, bgDrawable); + } + } + } private void updatePreferencesScreen() { if (getSelectedAppMode() != null) { @@ -304,8 +342,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl return -1; } - protected String getToolbarTitle() { - return getString(R.string.shared_string_settings); + @StringRes + protected int getToolbarTitle() { + return R.string.shared_string_settings; } @ColorRes @@ -320,13 +359,18 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl return -1; } - @ColorRes + @ColorInt protected int getActiveProfileColor() { + return ContextCompat.getColor(app, getActiveProfileColorRes()); + } + + @ColorRes + protected int getActiveProfileColorRes() { return getSelectedAppMode().getIconColorInfo().getColor(isNightMode()); } @ColorRes - protected int getBackgroundColor() { + protected int getBackgroundColorRes() { return isNightMode() ? R.color.list_background_color_dark : R.color.list_background_color_light; } @@ -412,7 +456,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl protected Drawable getActiveIcon(@DrawableRes int id) { UiUtilities cache = getIconsCache(); - return cache != null ? cache.getIcon(id, getActiveProfileColor()) : null; + return cache != null ? cache.getIcon(id, getActiveProfileColorRes()) : null; } protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { @@ -425,6 +469,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl return cache != null ? cache.getThemedIcon(id) : null; } + protected Drawable getPaintedIcon(@DrawableRes int id, @ColorInt int color) { + UiUtilities cache = getIconsCache(); + return cache != null ? cache.getPaintedIcon(id, color) : null; + } + @Nullable protected OsmandSettings getSettings() { OsmandApplication app = getMyApplication(); @@ -441,48 +490,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl return app.getSettings(); } - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - return true; - } - - @Override - public void onDisplayPreferenceDialog(Preference preference) { - if (preference instanceof ListPreferenceEx) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this); - } - } else if (preference instanceof SwitchPreferenceEx) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this); - } - } else if (preference instanceof EditTextPreference) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this); - } - } else if (preference instanceof MultiSelectBooleanPreference) { - FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - MultiSelectPreferencesBottomSheet.showInstance(getFragmentManager(), preference.getKey(), this); - } - } else { - super.onDisplayPreferenceDialog(preference); - } - } - - @Override - public boolean onPreferenceClick(Preference preference) { - return false; - } - - @Override - public void onAppModeChanged() { - updateAllSettings(); - } - public SwitchPreference createSwitchPreference(OsmandSettings.OsmandPreference b, int title, int summary, int layoutId) { return createSwitchPreference(b, getString(title), getString(summary), layoutId); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index f3d8cd6d19..e2d046f465 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -3,12 +3,25 @@ package net.osmand.plus.settings; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.os.Bundle; import android.support.annotation.ColorRes; import android.support.v14.preference.SwitchPreference; import android.support.v4.app.FragmentManager; +import android.support.v4.content.ContextCompat; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceCategory; +import android.support.v7.preference.PreferenceGroup; +import android.support.v7.preference.PreferenceGroupAdapter; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import net.osmand.AndroidUtils; import net.osmand.aidl.OsmandAidlApi; import net.osmand.aidl.OsmandAidlApi.ConnectedApp; import net.osmand.plus.ApplicationMode; @@ -40,27 +53,84 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.configure_profile); + protected int getToolbarTitle() { + return R.string.configure_profile; } @ColorRes - protected int getBackgroundColor() { + protected int getBackgroundColorRes() { return isNightMode() ? R.color.activity_background_color_dark : R.color.activity_background_color_light; } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = super.onCreateView(inflater, container, savedInstanceState); + + getListView().addItemDecoration(createDividerItemDecoration()); + + return view; + } + + private RecyclerView.ItemDecoration createDividerItemDecoration() { + final Drawable dividerLight = new ColorDrawable(ContextCompat.getColor(app, R.color.list_background_color_light)); + final Drawable dividerDark = new ColorDrawable(ContextCompat.getColor(app, R.color.list_background_color_dark)); + final int pluginDividerHeight = AndroidUtils.dpToPx(app, 3); + + return new RecyclerView.ItemDecoration() { + @Override + public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { + int dividerLeft = parent.getPaddingLeft(); + int dividerRight = parent.getWidth() - parent.getPaddingRight(); + + int childCount = parent.getChildCount(); + for (int i = 0; i < childCount - 1; i++) { + View child = parent.getChildAt(i); + + if (shouldDrawDivider(child)) { + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); + + int dividerTop = child.getBottom() + params.bottomMargin; + int dividerBottom = dividerTop + pluginDividerHeight; + + Drawable divider = isNightMode() ? dividerDark : dividerLight; + divider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom); + divider.draw(canvas); + } + } + } + + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + if (shouldDrawDivider(view)) { + outRect.set(0, 0, 0, pluginDividerHeight); + } + } + + private boolean shouldDrawDivider(View view) { + int position = getListView().getChildAdapterPosition(view); + Preference pref = ((PreferenceGroupAdapter) getListView().getAdapter()).getItem(position); + if (pref != null && pref.getParent() != null) { + PreferenceGroup preferenceGroup = pref.getParent(); + return preferenceGroup.hasKey() && preferenceGroup.getKey().equals("plugin_settings"); + } + return false; + } + }; + } + @Override protected void setupPreferences() { Preference generalSettings = findPreference("general_settings"); - Preference pluginSettings = findPreference("plugin_settings"); - pluginSettings.setIconSpaceReserved(false); - generalSettings.setIcon(getContentIcon(R.drawable.ic_action_settings)); setupNavigationSettingsPref(); setupConfigureMapPref(); - setupConnectedAppsPref(); - setupOsmandPluginsPref(); + + PreferenceCategory pluginSettings = (PreferenceCategory) findPreference("plugin_settings"); + pluginSettings.setIconSpaceReserved(false); + + setupConnectedAppsPref(pluginSettings); + setupOsmandPluginsPref(pluginSettings); } private void setupNavigationSettingsPref() { @@ -86,7 +156,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { configureMap.setVisible(false); } - private void setupConnectedAppsPref() { + private void setupConnectedAppsPref(PreferenceCategory preferenceCategory) { OsmandApplication app = getMyApplication(); if (app == null) { return; @@ -101,11 +171,11 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { preference.setChecked(connectedApp.isEnabled()); preference.setLayoutResource(R.layout.preference_switch); - getPreferenceScreen().addPreference(preference); + preferenceCategory.addPreference(preference); } } - private void setupOsmandPluginsPref() { + private void setupOsmandPluginsPref(PreferenceCategory preferenceCategory) { Context ctx = getContext(); if (ctx == null) { return; @@ -121,7 +191,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { preference.setLayoutResource(R.layout.preference_dialog_and_switch); preference.setIntent(getPluginIntent(plugin)); - getPreferenceScreen().addPreference(preference); + preferenceCategory.addPreference(preference); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java index 958595988d..7851433b50 100644 --- a/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/CoordinatesFormatFragment.java @@ -51,26 +51,21 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.coordinates_format); + protected int getToolbarTitle() { + return R.string.coordinates_format; } @Override protected void setupPreferences() { - PreferenceScreen screen = getPreferenceScreen(); - screen.setOrderingAsAdded(false); - Preference generalSettings = findPreference("coordinates_format_info"); generalSettings.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); CheckBoxPreference degreesPref = (CheckBoxPreference) findPreference(FORMAT_DEGREES); CheckBoxPreference minutesPref = (CheckBoxPreference) findPreference(FORMAT_MINUTES); CheckBoxPreference secondsPref = (CheckBoxPreference) findPreference(FORMAT_SECONDS); + CheckBoxPreference utmPref = (CheckBoxPreference) findPreference(UTM_FORMAT); CheckBoxPreference olcPref = (CheckBoxPreference) findPreference(OLC_FORMAT); - CheckBoxPreference utmPref = createUtmFormatPref(); - screen.addPreference(utmPref); - Location loc = app.getLocationProvider().getLastKnownLocation(); degreesPref.setSummary(getCoordinatesFormatSummary(loc, PointDescription.FORMAT_DEGREES)); @@ -84,24 +79,16 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment { updateSelectedFormatPrefs(currentPrefKey); } - private CheckBoxPreference createUtmFormatPref() { - CheckBoxPreference utmPref = new CheckBoxPreference(app) { + @Override + protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { + super.onBindPreferenceViewHolder(preference, holder); - @Override - public void onBindViewHolder(PreferenceViewHolder holder) { - super.onBindViewHolder(holder); - TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); - if (summaryView != null) { - summaryView.setOnTouchListener(getSummaryTouchListener()); - } + if (UTM_FORMAT.equals(preference.getKey())) { + TextView summaryView = (TextView) holder.findViewById(android.R.id.summary); + if (summaryView != null) { + summaryView.setOnTouchListener(getSummaryTouchListener()); } - }; - utmPref.setKey(UTM_FORMAT); - utmPref.setTitle(R.string.navigate_point_format_utm); - utmPref.setPersistent(false); - utmPref.setOrder(4); - utmPref.setLayoutResource(R.layout.preference_radio_button); - return utmPref; + } } private View.OnTouchListener getSummaryTouchListener() { diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java index 72fc752911..6177f9c53f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.settings; -import android.content.Context; import android.content.DialogInterface; import android.content.pm.ActivityInfo; import android.graphics.drawable.Drawable; @@ -42,16 +41,12 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.general_settings_2); + protected int getToolbarTitle() { + return R.string.general_settings_2; } @Override protected void setupPreferences() { - Context ctx = getContext(); - if (ctx == null) { - return; - } Preference appearanceCategory = findPreference("appearance_category"); Preference unitsAndFormats = findPreference("units_and_formats"); Preference other = findPreference("other"); @@ -72,9 +67,9 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupAppThemePref() { - ListPreferenceEx appTheme = (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId()); - appTheme.setEntries(new String[] {getString(R.string.dark_theme), getString(R.string.light_theme)}); - appTheme.setEntryValues(new Integer[] {OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME}); + final ListPreferenceEx appTheme = (ListPreferenceEx) findPreference(settings.OSMAND_THEME.getId()); + appTheme.setEntries(new String[]{getString(R.string.dark_theme), getString(R.string.light_theme)}); + appTheme.setEntryValues(new Integer[]{OsmandSettings.OSMAND_DARK_THEME, OsmandSettings.OSMAND_LIGHT_THEME}); appTheme.setIcon(getOsmandThemeIcon()); } @@ -83,9 +78,9 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupRotateMapPref() { - ListPreferenceEx rotateMap = (ListPreferenceEx) findPreference(settings.ROTATE_MAP.getId()); - rotateMap.setEntries(new String[] {getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}); - rotateMap.setEntryValues(new Integer[] {OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); + final ListPreferenceEx rotateMap = (ListPreferenceEx) findPreference(settings.ROTATE_MAP.getId()); + rotateMap.setEntries(new String[]{getString(R.string.rotate_map_none_opt), getString(R.string.rotate_map_bearing_opt), getString(R.string.rotate_map_compass_opt)}); + rotateMap.setEntryValues(new Integer[]{OsmandSettings.ROTATE_MAP_NONE, OsmandSettings.ROTATE_MAP_BEARING, OsmandSettings.ROTATE_MAP_COMPASS}); rotateMap.setIcon(getRotateMapIcon()); } @@ -101,9 +96,9 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { } private void setupMapScreenOrientationPref() { - ListPreferenceEx mapScreenOrientation = (ListPreferenceEx) findPreference(settings.MAP_SCREEN_ORIENTATION.getId()); - mapScreenOrientation.setEntries(new String[] {getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)}); - mapScreenOrientation.setEntryValues(new Integer[] {ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED}); + final ListPreferenceEx mapScreenOrientation = (ListPreferenceEx) findPreference(settings.MAP_SCREEN_ORIENTATION.getId()); + mapScreenOrientation.setEntries(new String[]{getString(R.string.map_orientation_portrait), getString(R.string.map_orientation_landscape), getString(R.string.map_orientation_default)}); + mapScreenOrientation.setEntryValues(new Integer[]{ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED}); mapScreenOrientation.setIcon(getMapScreenOrientationIcon()); } @@ -190,14 +185,14 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment { private void setupExternalInputDevicePref() { ListPreferenceEx externalInputDevice = (ListPreferenceEx) findPreference(settings.EXTERNAL_INPUT_DEVICE.getId()); - externalInputDevice.setEntries(new String[] { + externalInputDevice.setEntries(new String[]{ getString(R.string.sett_no_ext_input), getString(R.string.sett_generic_ext_input), getString(R.string.sett_wunderlinq_ext_input), getString(R.string.sett_parrot_ext_input) }); - externalInputDevice.setEntryValues(new Integer[] { + externalInputDevice.setEntryValues(new Integer[]{ OsmandSettings.NO_EXTERNAL_DEVICE, OsmandSettings.GENERIC_EXTERNAL_DEVICE, OsmandSettings.WUNDERLINQ_EXTERNAL_DEVICE, diff --git a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java index 04629a829c..5d534f64e2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java @@ -34,8 +34,8 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send } @Override - protected String getToolbarTitle() { - return getString(R.string.osmand_settings); + protected int getToolbarTitle() { + return R.string.osmand_settings; } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java index de9846541c..c00a72c16d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.support.annotation.ColorRes; import android.support.v4.app.FragmentManager; import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceCategory; import net.osmand.plus.ApplicationMode; import net.osmand.plus.R; @@ -26,8 +25,8 @@ public class MainSettingsFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.shared_string_settings); + protected int getToolbarTitle() { + return R.string.shared_string_settings; } @Override @@ -36,7 +35,7 @@ public class MainSettingsFragment extends BaseSettingsFragment { } @ColorRes - protected int getBackgroundColor() { + protected int getBackgroundColorRes() { return isNightMode() ? R.color.activity_background_color_dark : R.color.activity_background_color_light; } @@ -58,10 +57,7 @@ public class MainSettingsFragment extends BaseSettingsFragment { private void setupConfigureProfilePref() { ApplicationMode selectedMode = getSelectedAppMode(); - int iconRes = selectedMode.getIconRes(); - int iconColor = getActiveProfileColor(); String title = selectedMode.toHumanString(getContext()); - String profileType; if (selectedMode.isCustomProfile()) { profileType = String.format(getString(R.string.profile_type_descr_string), Algorithms.capitalizeFirstLetterAndLowercase(selectedMode.getParent().toHumanString(getContext()))); @@ -69,8 +65,10 @@ public class MainSettingsFragment extends BaseSettingsFragment { profileType = getString(R.string.profile_type_base_string); } + int iconRes = selectedMode.getIconRes(); + Preference configureProfile = findPreference("configure_profile"); - configureProfile.setIcon(getIcon(iconRes, iconColor)); + configureProfile.setIcon(getPaintedIcon(iconRes, getActiveProfileColor())); configureProfile.setTitle(title); configureProfile.setSummary(profileType); } diff --git a/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java index 367716e8d8..c81a52f334 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MapDuringNavigationFragment.java @@ -23,8 +23,8 @@ public class MapDuringNavigationFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.map_during_navigation); + protected int getToolbarTitle() { + return R.string.map_during_navigation; } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java index 7731fc05cb..af6976869c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java @@ -20,8 +20,8 @@ public class NavigationFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.routing_settings_2); + protected int getToolbarTitle() { + return R.string.routing_settings_2; } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java index 2bc895dd73..b7bc316ec8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.settings; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.widget.Toast; @@ -25,8 +24,8 @@ public class ProxySettingsFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.proxy_pref_title); + protected int getToolbarTitle() { + return R.string.proxy_pref_title; } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java index 551c40e924..6805b91ed3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java @@ -52,8 +52,8 @@ public class RouteParametersFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.route_parameters); + protected int getToolbarTitle() { + return R.string.route_parameters; } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java index 3f00079d46..cdc6db2cc3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java @@ -1,8 +1,12 @@ package net.osmand.plus.settings; +import android.graphics.drawable.ColorDrawable; import android.support.v14.preference.SwitchPreference; +import android.support.v4.content.ContextCompat; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; +import net.osmand.AndroidUtils; import net.osmand.plus.R; public class ScreenAlertsFragment extends BaseSettingsFragment { @@ -19,14 +23,13 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { return R.layout.profile_preference_toolbar; } - protected String getToolbarTitle() { - return getString(R.string.screen_alerts); + @Override + protected int getToolbarTitle() { + return R.string.screen_alerts; } @Override protected void setupPreferences() { - setupShowRoutingAlarmsPref(); - Preference showRoutingAlarmsInfo = findPreference("show_routing_alarms_info"); SwitchPreference showTrafficWarnings = (SwitchPreference) findPreference(settings.SHOW_TRAFFIC_WARNINGS.getId()); SwitchPreference showPedestrian = (SwitchPreference) findPreference(settings.SHOW_PEDESTRIAN.getId()); @@ -40,8 +43,15 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel)); } - private void setupShowRoutingAlarmsPref() { - SwitchPreference showRoutingAlarms = (SwitchPreference) findPreference(settings.SHOW_ROUTING_ALARMS.getId()); + @Override + protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { + super.onBindPreferenceViewHolder(preference, holder); + if (settings.SHOW_ROUTING_ALARMS.getId().equals(preference.getKey())) { + boolean checked = ((SwitchPreference) preference).isChecked(); + int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off); + + AndroidUtils.setBackground(holder.itemView, new ColorDrawable(color)); + } } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java index 71f0fa4ecf..580468d006 100644 --- a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java @@ -1,8 +1,12 @@ package net.osmand.plus.settings; +import android.graphics.drawable.ColorDrawable; import android.support.v14.preference.SwitchPreference; +import android.support.v4.content.ContextCompat; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; +import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; @@ -22,14 +26,12 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.turn_screen_on); + protected int getToolbarTitle() { + return R.string.turn_screen_on; } @Override protected void setupPreferences() { - setupTurnScreenOnPref(); - Preference turnScreenOnInfo = findPreference("turn_screen_on_info"); turnScreenOnInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); @@ -37,8 +39,16 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { setupTurnScreenOnSensorPref(); } - private void setupTurnScreenOnPref() { - SwitchPreference turnScreenOn = (SwitchPreference) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId()); + @Override + protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { + super.onBindPreferenceViewHolder(preference, holder); + + if (settings.TURN_SCREEN_ON_ENABLED.getId().equals(preference.getKey())) { + boolean checked = ((SwitchPreference) preference).isChecked(); + int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off); + + AndroidUtils.setBackground(holder.itemView, new ColorDrawable(color)); + } } private void setupTurnScreenOnTimePref() { diff --git a/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java index cd52f5947c..92c39885f9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VehicleParametersFragment.java @@ -32,8 +32,8 @@ public class VehicleParametersFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.vehicle_parameters); + protected int getToolbarTitle() { + return R.string.vehicle_parameters; } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java index 91e88eb214..cdb8b7cb4b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java @@ -4,11 +4,15 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.drawable.ColorDrawable; import android.media.AudioManager; import android.support.v14.preference.SwitchPreference; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; +import net.osmand.AndroidUtils; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -37,13 +41,12 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { } @Override - protected String getToolbarTitle() { - return getString(R.string.voice_announces); + protected int getToolbarTitle() { + return R.string.voice_announces; } + @Override protected void setupPreferences() { - setupSpeakRoutingAlarmsPref(); - Preference voiceAnnouncesInfo = findPreference("voice_announces_info"); voiceAnnouncesInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); @@ -59,9 +62,16 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { } } - private void setupSpeakRoutingAlarmsPref() { - SwitchPreference speakRoutingAlarms = (SwitchPreference) findPreference(settings.SPEAK_ROUTING_ALARMS.getId()); + @Override + protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { + super.onBindPreferenceViewHolder(preference, holder); + if (settings.SPEAK_ROUTING_ALARMS.getId().equals(preference.getKey())) { + boolean checked = ((SwitchPreference) preference).isChecked(); + int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off); + + AndroidUtils.setBackground(holder.itemView, new ColorDrawable(color)); + } } private void setupSpeedLimitExceedPref() { From d561b40b6e3801c76caf6dd599cff7c822a2d9dd Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 17 Sep 2019 17:04:12 +0300 Subject: [PATCH 3/3] Add missing summary --- OsmAnd/res/xml/navigation_settings_new.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/xml/navigation_settings_new.xml b/OsmAnd/res/xml/navigation_settings_new.xml index 03734736b4..5d614be1d8 100644 --- a/OsmAnd/res/xml/navigation_settings_new.xml +++ b/OsmAnd/res/xml/navigation_settings_new.xml @@ -13,7 +13,7 @@