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 949a0bc554..f1ed65d0e3 100644 --- a/OsmAnd/res/layout/preference_dialog_and_switch.xml +++ b/OsmAnd/res/layout/preference_dialog_and_switch.xml @@ -1,15 +1,17 @@ + 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 b8f4c87412..6dfa5a942b 100644 --- a/OsmAnd/res/layout/preference_radio_button.xml +++ b/OsmAnd/res/layout/preference_radio_button.xml @@ -1,24 +1,27 @@ + android:gravity="center_vertical" + android:orientation="vertical"> + android:minHeight="@dimen/bottom_sheet_list_item_height" + tools:background="?android:attr/selectableItemBackground"> @@ -27,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 c50dedeba4..cd6e06fd44 100644 --- a/OsmAnd/res/layout/preference_switch.xml +++ b/OsmAnd/res/layout/preference_switch.xml @@ -1,16 +1,18 @@ + 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 d786ca64d1..1cb71ed180 100644 --- a/OsmAnd/res/layout/preference_with_descr.xml +++ b/OsmAnd/res/layout/preference_with_descr.xml @@ -1,16 +1,18 @@ + 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,56 +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..5d614be1d8 100644 --- a/OsmAnd/res/xml/navigation_settings_new.xml +++ b/OsmAnd/res/xml/navigation_settings_new.xml @@ -13,7 +13,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 04f674aae7..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; @@ -196,13 +198,16 @@ 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)); + + 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 e294012ea3..d9a0489bc0 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -7,7 +7,6 @@ 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; @@ -71,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); } @@ -109,6 +106,42 @@ public class UiUtilities { return getDrawable(id, light ? R.color.icon_color_default_light : R.color.icon_color_default_dark); } + 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 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(); @@ -156,35 +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) { - 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 colorBackground, @ColorInt int colorForeground, boolean highlightOnNormal, boolean highlightOnPressed) { - 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; - } - public UpdateLocationViewCache getUpdateLocationViewCache(){ UpdateLocationViewCache uvc = new UpdateLocationViewCache(); uvc.screenOrientation = getScreenOrientation(); 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..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) { + 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) { @@ -213,64 +323,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(); @@ -289,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 @@ -305,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; } @@ -397,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) { @@ -410,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(); @@ -426,43 +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; - } - 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 b39d7e4f3e..7851433b50 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"; @@ -47,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)); @@ -80,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() { @@ -162,7 +153,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..6177f9c53f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -4,7 +4,6 @@ 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; @@ -42,8 +41,8 @@ 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 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() {