Merge pull request #8410 from osmandapp/prefs_fixes
Fix icons colors for old android versions
This commit is contained in:
commit
50a676b712
8 changed files with 37 additions and 15 deletions
|
@ -56,7 +56,6 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -264,6 +263,17 @@ public class AndroidUtils {
|
|||
lightNormal, lightChecked, darkNormal, darkChecked);
|
||||
}
|
||||
|
||||
public static ColorStateList createEnabledColorStateList(Context ctx, @ColorRes int normal, @ColorRes int pressed) {
|
||||
return createEnabledColorStateList(ctx, false, normal, pressed, 0, 0);
|
||||
}
|
||||
|
||||
public static ColorStateList createEnabledColorStateList(Context ctx, boolean night,
|
||||
@ColorRes int lightNormal, @ColorRes int lightPressed,
|
||||
@ColorRes int darkNormal, @ColorRes int darkPressed) {
|
||||
return createColorStateList(ctx, night, android.R.attr.state_enabled,
|
||||
lightNormal, lightPressed, darkNormal, darkPressed);
|
||||
}
|
||||
|
||||
public static ColorStateList createPressedColorStateList(Context ctx, @ColorRes int normal, @ColorRes int pressed) {
|
||||
return createPressedColorStateList(ctx, false, normal, pressed, 0, 0);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.support.v7.preference.Preference;
|
|||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -222,7 +221,7 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
|
|||
private void setupLiveMonitoringPref() {
|
||||
Drawable disabled = getContentIcon(R.drawable.ic_action_offline);
|
||||
Drawable enabled = getActiveIcon(R.drawable.ic_world_globe_dark);
|
||||
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
Drawable icon = getPersistentPrefIcon(enabled, disabled);
|
||||
|
||||
SwitchPreferenceEx liveMonitoring = (SwitchPreferenceEx) findPreference(settings.LIVE_MONITORING.getId());
|
||||
liveMonitoring.setDescription(getString(R.string.live_monitoring_m_descr));
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -71,7 +70,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
|
|||
private void setupOfflineEditingPref() {
|
||||
Drawable disabled = getContentIcon(R.drawable.ic_action_offline);
|
||||
Drawable enabled = getActiveIcon(R.drawable.ic_world_globe_dark);
|
||||
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
Drawable icon = getPersistentPrefIcon(enabled, disabled);
|
||||
|
||||
SwitchPreferenceEx offlineEditingPref = (SwitchPreferenceEx) findPreference(settings.OFFLINE_EDITION.getId());
|
||||
offlineEditingPref.setDescription(getString(R.string.offline_edition_descr));
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.settings;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
|
@ -18,6 +19,7 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.preference.EditTextPreference;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
|
@ -730,7 +732,19 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
protected Drawable getPersistentPrefIcon(@DrawableRes int iconId) {
|
||||
Drawable disabled = UiUtilities.createTintedDrawable(app, iconId, ContextCompat.getColor(app, R.color.icon_color_default_light));
|
||||
Drawable enabled = UiUtilities.createTintedDrawable(app, iconId, getActiveProfileColor());
|
||||
return AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
return getPersistentPrefIcon(enabled, disabled);
|
||||
}
|
||||
|
||||
protected Drawable getPersistentPrefIcon(Drawable enabled, Drawable disabled) {
|
||||
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
|
||||
if (Build.VERSION.SDK_INT < 21) {
|
||||
ColorStateList colorStateList = AndroidUtils.createEnabledColorStateList(app, R.color.icon_color_default_light, getActiveProfileColorRes());
|
||||
icon = DrawableCompat.wrap(icon);
|
||||
DrawableCompat.setTintList(icon, colorStateList);
|
||||
return icon;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
public SwitchPreferenceCompat createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b, int title, int summary, int layoutId) {
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -127,7 +126,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
|||
private void setupCenterPositionOnMapPref() {
|
||||
Drawable disabled = getContentIcon(R.drawable.ic_action_display_position_bottom);
|
||||
Drawable enabled = getActiveIcon(R.drawable.ic_action_display_position_center);
|
||||
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
Drawable icon = getPersistentPrefIcon(enabled, disabled);
|
||||
|
||||
SwitchPreferenceCompat centerPositionOnMap = (SwitchPreferenceCompat) findPreference(settings.CENTER_POSITION_ON_MAP.getId());
|
||||
centerPositionOnMap.setIcon(icon);
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.support.v7.preference.SwitchPreferenceCompat;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -88,7 +87,7 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
private void setupSpeakRoutingAlarmsPref() {
|
||||
Drawable disabled = getContentIcon(R.drawable.ic_action_volume_mute);
|
||||
Drawable enabled = getActiveIcon(R.drawable.ic_action_volume_up);
|
||||
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
Drawable icon = getPersistentPrefIcon(enabled, disabled);
|
||||
|
||||
SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.VOICE_MUTE.getId());
|
||||
speakRoutingAlarms.setIcon(icon);
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.support.v7.preference.PreferenceScreen;
|
|||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -391,7 +390,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
case GeneralRouter.ALLOW_MOTORWAYS:
|
||||
Drawable disabled = getContentIcon(R.drawable.ic_action_avoid_motorways);
|
||||
Drawable enabled = getActiveIcon(R.drawable.ic_action_motorways);
|
||||
return AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
return getPersistentPrefIcon(enabled, disabled);
|
||||
case GeneralRouter.USE_HEIGHT_OBSTACLES:
|
||||
case RELIEF_SMOOTHNESS_FACTOR:
|
||||
return getPersistentPrefIcon(R.drawable.ic_action_elevation);
|
||||
|
|
|
@ -175,7 +175,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
|||
|
||||
Drawable disabled = getContentIcon(R.drawable.ic_action_volume_mute);
|
||||
Drawable enabled = getActiveIcon(R.drawable.ic_action_volume_up);
|
||||
Drawable icon = AndroidUtils.createEnabledStateListDrawable(disabled, enabled);
|
||||
Drawable icon = getPersistentPrefIcon(enabled, disabled);
|
||||
|
||||
ListPreferenceEx voiceProvider = (ListPreferenceEx) findPreference(settings.VOICE_PROVIDER.getId());
|
||||
voiceProvider.setEntries(entries);
|
||||
|
@ -240,11 +240,14 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
|||
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
|
||||
super.onBindPreferenceViewHolder(preference, holder);
|
||||
if (settings.VOICE_PROVIDER.getId().equals(preference.getKey()) && preference instanceof ListPreferenceEx) {
|
||||
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
|
||||
if (titleView != null) {
|
||||
titleView.setTextColor(preference.isEnabled() ? getActiveTextColor() : getDisabledTextColor());
|
||||
}
|
||||
ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon);
|
||||
if (imageView != null) {
|
||||
Object currentValue = ((ListPreferenceEx) preference).getValue();
|
||||
boolean enabled = preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue);
|
||||
imageView.setEnabled(enabled);
|
||||
imageView.setEnabled(preference.isEnabled() && !OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue