Settings: Hide downtime settings if not supported.
Depends on frameworks/base: I4f801018ddb0beb6eb9fa03a81c79f7949888a3f Bug: 16373455 Change-Id: I88b526d947fb697a7abd4d4cf4225f926434915a
This commit is contained in:
@@ -23,6 +23,7 @@ import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.INotificationManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -131,6 +132,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
private SwitchPreference mMessages;
|
||||
private DropDownPreference mStarred;
|
||||
private SwitchPreference mEvents;
|
||||
private boolean mDowntimeSupported;
|
||||
private Preference mDays;
|
||||
private TimePickerPreference mStart;
|
||||
private TimePickerPreference mEnd;
|
||||
@@ -227,7 +229,10 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
});
|
||||
|
||||
final PreferenceCategory downtime = (PreferenceCategory) root.findPreference(KEY_DOWNTIME);
|
||||
|
||||
mDowntimeSupported = isDowntimeSupported(mContext);
|
||||
if (!mDowntimeSupported) {
|
||||
removePreference(KEY_DOWNTIME);
|
||||
} else {
|
||||
mDays = downtime.findPreference(KEY_DAYS);
|
||||
mDays.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
@@ -320,6 +325,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
});
|
||||
mDowntimeMode.setOrder(10); // sort at the bottom of the category
|
||||
mDowntimeMode.setDependency(mDays.getKey());
|
||||
}
|
||||
|
||||
mAutomationCategory = (PreferenceCategory) findPreference(KEY_AUTOMATION);
|
||||
mEntry = findPreference(KEY_ENTRY);
|
||||
@@ -376,6 +382,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
}
|
||||
|
||||
private void updateEndSummary() {
|
||||
if (!mDowntimeSupported) return;
|
||||
final int startMin = 60 * mConfig.sleepStartHour + mConfig.sleepStartMinute;
|
||||
final int endMin = 60 * mConfig.sleepEndHour + mConfig.sleepEndMinute;
|
||||
final boolean nextDay = startMin >= endMin;
|
||||
@@ -399,10 +406,12 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
mStarred.setSelectedValue(mConfig.allowFrom);
|
||||
mEvents.setChecked(mConfig.allowEvents);
|
||||
updateStarredEnabled();
|
||||
if (mDowntimeSupported) {
|
||||
updateDays();
|
||||
mStart.setTime(mConfig.sleepStartHour, mConfig.sleepStartMinute);
|
||||
mEnd.setTime(mConfig.sleepEndHour, mConfig.sleepEndMinute);
|
||||
mDowntimeMode.setSelectedValue(mConfig.sleepNone);
|
||||
}
|
||||
mDisableListeners = false;
|
||||
refreshAutomationSection();
|
||||
updateEndSummary();
|
||||
@@ -552,9 +561,15 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
mDialog = null;
|
||||
}
|
||||
|
||||
private static boolean isDowntimeSupported(Context context) {
|
||||
return NotificationManager.from(context)
|
||||
.isSystemConditionProviderEnabled(ZenModeConfig.DOWNTIME_PATH);
|
||||
}
|
||||
|
||||
// Enable indexing of searchable data
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
||||
final SparseArray<String> keyTitles = allKeyTitles(context);
|
||||
@@ -570,6 +585,19 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final ArrayList<String> rt = new ArrayList<String>();
|
||||
if (!isDowntimeSupported(context)) {
|
||||
rt.add(KEY_DOWNTIME);
|
||||
rt.add(KEY_DAYS);
|
||||
rt.add(KEY_START_TIME);
|
||||
rt.add(KEY_END_TIME);
|
||||
rt.add(KEY_DOWNTIME_MODE);
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
};
|
||||
|
||||
private static class SettingPrefWithCallback extends SettingPref {
|
||||
|
Reference in New Issue
Block a user