Gray out Wallpapers menu item when setting of wallpapers is not allowed.

BUG: 24890474

Change-Id: Ia6bfcd1c8fefeff46f30c4e9a60aa2a52c39fa27
This commit is contained in:
Oleksandr Peletskyi
2016-01-27 18:07:18 +01:00
parent befdce36fd
commit 8b53b1e9bf

View File

@@ -19,6 +19,7 @@ package com.android.settings;
import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.UiModeManager;
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -78,6 +79,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private static final String KEY_CAMERA_GESTURE = "camera_gesture";
private static final String KEY_CAMERA_DOUBLE_TAP_POWER_GESTURE
= "camera_double_tap_power_gesture";
private static final String KEY_WALLPAPER = "wallpaper";
private DropDownPreference mFontSizePref;
@@ -131,6 +133,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
removePreference(KEY_AUTO_BRIGHTNESS);
}
if (!isWallpaperSettingAllowed(activity)) {
grayPreferenceOut(KEY_WALLPAPER);
}
if (isLiftToWakeAvailable(activity)) {
mLiftToWakePreference = (SwitchPreference) findPreference(KEY_LIFT_TO_WAKE);
mLiftToWakePreference.setOnPreferenceChangeListener(this);
@@ -222,6 +228,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
com.android.internal.R.bool.config_allowAllRotations);
}
private static boolean isWallpaperSettingAllowed(Context context) {
return WallpaperManager.getInstance(context).isWallpaperSettingAllowed();
}
private static boolean isLiftToWakeAvailable(Context context) {
SensorManager sensors = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
return sensors != null && sensors.getDefaultSensor(Sensor.TYPE_WAKE_GESTURE) != null;
@@ -479,6 +489,13 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
return R.string.help_uri_display;
}
private void grayPreferenceOut(String key) {
Preference pref = findPreference(key);
if (pref != null) {
pref.setEnabled(false);
}
}
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
private final Context mContext;
private final SummaryLoader mLoader;