Cleanup to screensaver settings for O
Reworked the way screensaver settings are laid out for O. Instead of using the options menu and dialogs to navigate screensaver options, there are now two rows: one row for the screensaver choice and optionally its own settings, and one row for the "when to show" setting. And now there's a nice obvious button you can press to preview your choices. Test: 'export ROBOTEST_FILTER="RadioButtonListFragmentTest";\ mmm -j20 packages/apps/Settings/tests/robotests' Bug: 35031991 Change-Id: Ie7d2055fb45f6dfe72e34cb9598d9a25f7bee75a
This commit is contained in:
117
src/com/android/settings/dream/CurrentDreamPicker.java
Normal file
117
src/com/android/settings/dream/CurrentDreamPicker.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.dream.DreamBackend.DreamInfo;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class CurrentDreamPicker extends RadioButtonPickerFragment {
|
||||
|
||||
private DreamBackend mBackend;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DREAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
Map<String, ComponentName> componentNameMap = getDreamComponentsMap();
|
||||
if (componentNameMap.get(key) != null) {
|
||||
mBackend.setActiveDream(componentNameMap.get(key));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
return mBackend.getActiveDream().flattenToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<? extends CandidateInfo> getCandidates() {
|
||||
final List<DreamCandidateInfo> candidates;
|
||||
candidates = mBackend.getDreamInfos().stream()
|
||||
.map(DreamCandidateInfo::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSelectionPerformed(boolean success) {
|
||||
super.onSelectionPerformed(success);
|
||||
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
private Map<String, ComponentName> getDreamComponentsMap() {
|
||||
Map<String, ComponentName> comps = new HashMap<>();
|
||||
mBackend.getDreamInfos()
|
||||
.forEach((info) ->
|
||||
comps.put(info.componentName.flattenToString(), info.componentName));
|
||||
|
||||
return comps;
|
||||
}
|
||||
|
||||
private static final class DreamCandidateInfo extends CandidateInfo {
|
||||
private final CharSequence name;
|
||||
private final Drawable icon;
|
||||
private final String key;
|
||||
|
||||
DreamCandidateInfo(DreamInfo info) {
|
||||
super(true);
|
||||
|
||||
name = info.caption;
|
||||
icon = info.icon;
|
||||
key = info.componentName.flattenToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence loadLabel() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable loadIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.dream.DreamBackend.DreamInfo;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CurrentDreamPreferenceController extends PreferenceController {
|
||||
private final DreamBackend mBackend;
|
||||
private final static String TAG = "CurrentDreamPreferenceController";
|
||||
private final static String CURRENT_SCREENSAVER = "current_screensaver";
|
||||
|
||||
public CurrentDreamPreferenceController(Context context) {
|
||||
super(context);
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mBackend.getDreamInfos().size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return CURRENT_SCREENSAVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
preference.setSummary(mBackend.getActiveDreamName());
|
||||
setGearClickListenerForPreference(preference);
|
||||
}
|
||||
|
||||
private void setGearClickListenerForPreference(Preference preference) {
|
||||
if (!(preference instanceof GearPreference)) return;
|
||||
|
||||
GearPreference gearPreference = (GearPreference)preference;
|
||||
Optional<DreamInfo> info = getActiveDreamInfo();
|
||||
if (!info.isPresent() || info.get().settingsComponentName == null) {
|
||||
gearPreference.setOnGearClickListener(null);
|
||||
return;
|
||||
}
|
||||
gearPreference.setOnGearClickListener(gearPref -> launchScreenSaverSettings());
|
||||
}
|
||||
|
||||
private void launchScreenSaverSettings() {
|
||||
Optional<DreamInfo> info = getActiveDreamInfo();
|
||||
if (!info.isPresent()) return;
|
||||
mBackend.launchSettings(info.get());
|
||||
}
|
||||
|
||||
private Optional<DreamInfo> getActiveDreamInfo() {
|
||||
return mBackend.getDreamInfos()
|
||||
.stream()
|
||||
.filter((info) -> info.isActive)
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
147
src/com/android/settings/dream/DreamSettings.java
Normal file
147
src/com/android/settings/dream/DreamSettings.java
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.dream.DreamBackend.WhenToDream;
|
||||
import java.util.ArrayList;
|
||||
import android.content.Context;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.settingslib.dream.DreamBackend.EITHER;
|
||||
import static com.android.settingslib.dream.DreamBackend.NEVER;
|
||||
import static com.android.settingslib.dream.DreamBackend.WHILE_CHARGING;
|
||||
import static com.android.settingslib.dream.DreamBackend.WHILE_DOCKED;
|
||||
|
||||
public class DreamSettings extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "DreamSettings";
|
||||
static final String WHILE_CHARGING_ONLY = "while_charging_only";
|
||||
static final String WHILE_DOCKED_ONLY = "while_docked_only";
|
||||
static final String EITHER_CHARGING_OR_DOCKED = "either_charging_or_docked";
|
||||
static final String NEVER_DREAM = "never";
|
||||
|
||||
@WhenToDream
|
||||
static int getSettingFromPrefKey(String key) {
|
||||
switch (key) {
|
||||
case WHILE_CHARGING_ONLY:
|
||||
return WHILE_CHARGING;
|
||||
case WHILE_DOCKED_ONLY:
|
||||
return WHILE_DOCKED;
|
||||
case EITHER_CHARGING_OR_DOCKED:
|
||||
return EITHER;
|
||||
case NEVER_DREAM:
|
||||
default:
|
||||
return NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
static String getKeyFromSetting(@WhenToDream int dreamSetting) {
|
||||
switch (dreamSetting) {
|
||||
case WHILE_CHARGING:
|
||||
return WHILE_CHARGING_ONLY;
|
||||
case WHILE_DOCKED:
|
||||
return WHILE_DOCKED_ONLY;
|
||||
case EITHER:
|
||||
return EITHER_CHARGING_OR_DOCKED;
|
||||
case NEVER:
|
||||
default:
|
||||
return NEVER_DREAM;
|
||||
}
|
||||
}
|
||||
|
||||
static int getDreamSettingDescriptionResId(@WhenToDream int dreamSetting) {
|
||||
switch (dreamSetting) {
|
||||
case WHILE_CHARGING:
|
||||
return R.string.screensaver_settings_summary_sleep;
|
||||
case WHILE_DOCKED:
|
||||
return R.string.screensaver_settings_summary_dock;
|
||||
case EITHER:
|
||||
return R.string.screensaver_settings_summary_either_long;
|
||||
case NEVER:
|
||||
default:
|
||||
return R.string.screensaver_settings_summary_never;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DREAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.dream_fragment_overview;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
|
||||
public static CharSequence getSummaryTextWithDreamName(Context context) {
|
||||
DreamBackend backend = DreamBackend.getInstance(context);
|
||||
return getSummaryTextFromBackend(backend, context);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static CharSequence getSummaryTextFromBackend(DreamBackend backend, Context context) {
|
||||
if (!backend.isEnabled()) {
|
||||
return context.getString(R.string.screensaver_settings_summary_off);
|
||||
} else {
|
||||
return backend.getActiveDreamName();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PreferenceController> buildPreferenceControllers(Context context) {
|
||||
List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new CurrentDreamPreferenceController(context));
|
||||
controllers.add(new WhenToDreamPreferenceController(context));
|
||||
controllers.add(new StartNowPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER
|
||||
= new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.dream_fragment_overview;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.Button;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
public class StartNowPreferenceController extends PreferenceController {
|
||||
private static final String TAG = "StartNowPreferenceController";
|
||||
private static final String PREF_KEY = "dream_start_now_button_container";
|
||||
private final DreamBackend mBackend;
|
||||
|
||||
public StartNowPreferenceController(Context context) {
|
||||
super(context);
|
||||
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return PREF_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
LayoutPreference pref = (LayoutPreference) screen.findPreference(getPreferenceKey());
|
||||
Button startButton = (Button)pref.findViewById(R.id.dream_start_now_button);
|
||||
startButton.setOnClickListener(v -> mBackend.startDreaming());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
Button startButton = (Button)((LayoutPreference)preference)
|
||||
.findViewById(R.id.dream_start_now_button);
|
||||
startButton.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
|
||||
}
|
||||
}
|
||||
115
src/com/android/settings/dream/WhenToDreamPicker.java
Normal file
115
src/com/android/settings/dream/WhenToDreamPicker.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WhenToDreamPicker extends RadioButtonPickerFragment {
|
||||
|
||||
private static final String TAG = "WhenToDreamPicker";
|
||||
private DreamBackend mBackend;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DREAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<? extends CandidateInfo> getCandidates() {
|
||||
final String[] entries = entries();
|
||||
final String[] values = keys();
|
||||
final List<WhenToDreamCandidateInfo> candidates = new ArrayList<>();
|
||||
|
||||
if (entries == null || entries.length <= 0) return null;
|
||||
if (values == null || values.length != entries.length) {
|
||||
throw new IllegalArgumentException("Entries and values must be of the same length.");
|
||||
}
|
||||
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
candidates.add(new WhenToDreamCandidateInfo(entries[i], values[i]));
|
||||
}
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
private String[] entries() {
|
||||
return getResources().getStringArray(R.array.when_to_start_screensaver_entries);
|
||||
}
|
||||
|
||||
private String[] keys() {
|
||||
return getResources().getStringArray(R.array.when_to_start_screensaver_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultKey() {
|
||||
return DreamSettings.getKeyFromSetting(mBackend.getWhenToDreamSetting());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
mBackend.setWhenToDream(DreamSettings.getSettingFromPrefKey(key));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSelectionPerformed(boolean success) {
|
||||
super.onSelectionPerformed(success);
|
||||
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
private final class WhenToDreamCandidateInfo extends CandidateInfo {
|
||||
private final String name;
|
||||
private final String key;
|
||||
|
||||
WhenToDreamCandidateInfo(String title, String value) {
|
||||
super(true);
|
||||
|
||||
name = title;
|
||||
key = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence loadLabel() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable loadIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
public class WhenToDreamPreferenceController extends PreferenceController {
|
||||
|
||||
private static final String WHEN_TO_START = "when_to_start";
|
||||
private final DreamBackend mBackend;
|
||||
|
||||
WhenToDreamPreferenceController(Context context) {
|
||||
super(context);
|
||||
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
int resId = DreamSettings.getDreamSettingDescriptionResId(mBackend.getWhenToDreamSetting());
|
||||
preference.setSummary(preference.getContext().getString(resId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return WHEN_TO_START;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user