Implement dream complication settings.
This component allows the user to select dream complications to enable/disable. Bug: 215703483 Test: locally on device Change-Id: I03dd9d67b4aeb3f41885b42391d97c18bd7465f6
This commit is contained in:
@@ -13831,6 +13831,13 @@
|
||||
<string name="tare_dialog_confirm_button_title">Confirm</string>
|
||||
<!-- Button to preview the selected screensaver in settings [CHAR LIMIT=40] -->
|
||||
<string name="dream_preview_button_title">Preview screensaver</string>
|
||||
<!-- The title of the category to show for the screensaver selector in settings [CHAR LIMIT=none] -->
|
||||
<string name="dream_picker_category">Choose an image</string>
|
||||
<!-- The title of the category to show for the screensaver overlay selector in settings [CHAR LIMIT=none] -->
|
||||
<string name="dream_complications_picker_category">Choose more options</string>
|
||||
<!-- The title of the category to show for the screensaver miscellaneous settings [CHAR LIMIT=none] -->
|
||||
<string name="dream_more_settings_category">More settings</string>
|
||||
|
||||
<!-- Button to customize the screensaver [CHAR LIMIT=20] -->
|
||||
<string name="customize_button_title">Customize</string>
|
||||
|
||||
|
@@ -19,15 +19,32 @@
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/screensaver_settings_title">
|
||||
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
android:key="dream_picker"
|
||||
android:selectable="false"
|
||||
android:layout="@layout/dream_picker_layout"
|
||||
settings:controller="com.android.settings.dream.DreamPickerController"/>
|
||||
<PreferenceCategory
|
||||
android:title="@string/dream_picker_category">
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
android:key="dream_picker"
|
||||
android:selectable="false"
|
||||
android:layout="@layout/dream_picker_layout"
|
||||
settings:controller="com.android.settings.dream.DreamPickerController"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<Preference
|
||||
android:key="when_to_start"
|
||||
android:title="@string/screensaver_settings_when_to_dream"
|
||||
android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
|
||||
<PreferenceCategory
|
||||
android:key="dream_complication_category"
|
||||
android:title="@string/dream_complications_picker_category"
|
||||
settings:controller="com.android.settings.dream.DreamComplicationCategoryController">
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
android:key="dream_complication_picker"
|
||||
android:selectable="false"
|
||||
android:layout="@layout/dream_picker_layout"
|
||||
settings:controller="com.android.settings.dream.DreamComplicationPickerController"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/dream_more_settings_category">
|
||||
<Preference
|
||||
android:key="when_to_start"
|
||||
android:title="@string/screensaver_settings_when_to_dream"
|
||||
android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -64,7 +64,14 @@ class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
*/
|
||||
public void bindView(IDreamItem item) {
|
||||
mTitleView.setText(item.getTitle());
|
||||
mPreviewView.setImageDrawable(item.getPreviewImage());
|
||||
|
||||
final Drawable previewImage = item.getPreviewImage();
|
||||
if (previewImage != null) {
|
||||
mPreviewView.setVisibility(View.VISIBLE);
|
||||
mPreviewView.setImageDrawable(previewImage);
|
||||
} else {
|
||||
mPreviewView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
final Drawable icon = item.getIcon();
|
||||
if (icon instanceof VectorDrawable) {
|
||||
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 androidx.preference.PreferenceScreen;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Controller for the component allowing a user to select overlays to show on top of dreams.
|
||||
*/
|
||||
public class DreamComplicationPickerController extends BasePreferenceController {
|
||||
private static final String KEY = "dream_complication_picker";
|
||||
|
||||
private final DreamBackend mBackend;
|
||||
private final Drawable mEnabledDrawable;
|
||||
private final Set<Integer> mSupportedComplications;
|
||||
private DreamAdapter mAdapter;
|
||||
|
||||
private class ComplicationItem implements IDreamItem {
|
||||
private final int mComplicationType;
|
||||
private boolean mEnabled;
|
||||
|
||||
ComplicationItem(@DreamBackend.ComplicationType int complicationType) {
|
||||
mComplicationType = complicationType;
|
||||
mEnabled = mBackend.isComplicationEnabled(mComplicationType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mBackend.getComplicationTitle(mComplicationType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
// TODO(b/215703483): add icon for each complication
|
||||
return mEnabled ? mEnabledDrawable : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked() {
|
||||
mEnabled = !mEnabled;
|
||||
mBackend.setComplicationEnabled(mComplicationType, mEnabled);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getPreviewImage() {
|
||||
// TODO(b/215703483): add preview image for each complication
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return mEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public DreamComplicationPickerController(Context context) {
|
||||
super(context, KEY);
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
mSupportedComplications = mBackend.getSupportedComplications();
|
||||
mEnabledDrawable = context.getDrawable(R.drawable.ic_dream_check_circle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mSupportedComplications.size() > 0 ? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mAdapter = new DreamAdapter(mSupportedComplications.stream()
|
||||
.map(ComplicationItem::new)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
LayoutPreference pref = screen.findPreference(getPreferenceKey());
|
||||
if (pref != null) {
|
||||
final RecyclerView recyclerView = pref.findViewById(R.id.dream_list);
|
||||
recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
}
|
||||
}
|
||||
}
|
@@ -40,7 +40,7 @@ import java.util.stream.Collectors;
|
||||
* Controller for the dream picker where the user can select a screensaver.
|
||||
*/
|
||||
public class DreamPickerController extends BasePreferenceController {
|
||||
public static final String KEY = "dream_picker";
|
||||
private static final String KEY = "dream_picker";
|
||||
|
||||
private final DreamBackend mBackend;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -51,12 +51,12 @@ public class DreamPickerController extends BasePreferenceController {
|
||||
private DreamBackend.DreamInfo mActiveDream;
|
||||
private DreamAdapter mAdapter;
|
||||
|
||||
public DreamPickerController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, DreamBackend.getInstance(context));
|
||||
public DreamPickerController(Context context) {
|
||||
this(context, DreamBackend.getInstance(context));
|
||||
}
|
||||
|
||||
public DreamPickerController(Context context, String preferenceKey, DreamBackend backend) {
|
||||
super(context, preferenceKey);
|
||||
public DreamPickerController(Context context, DreamBackend backend) {
|
||||
super(context, KEY);
|
||||
mBackend = backend;
|
||||
mDreamInfos = mBackend.getDreamInfos();
|
||||
mActiveDrawable = context.getDrawable(R.drawable.ic_dream_check_circle);
|
||||
|
@@ -29,12 +29,14 @@ import androidx.annotation.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.dream.DreamBackend.WhenToDream;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
@@ -45,6 +47,7 @@ public class DreamSettings extends DashboardFragment {
|
||||
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";
|
||||
private static final String COMPLICATIONS_CATEGORY_KEY = "dream_complication_category";
|
||||
|
||||
@WhenToDream
|
||||
static int getSettingFromPrefKey(String key) {
|
||||
@@ -130,7 +133,14 @@ public class DreamSettings extends DashboardFragment {
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final DreamComplicationPickerController complicationPickerController =
|
||||
new DreamComplicationPickerController(context);
|
||||
|
||||
controllers.add(complicationPickerController);
|
||||
controllers.add(new WhenToDreamPreferenceController(context));
|
||||
controllers.add(new DreamPickerController(context));
|
||||
controllers.add(new PreferenceCategoryController(context, COMPLICATIONS_CATEGORY_KEY)
|
||||
.setChildren(Collections.singletonList(complicationPickerController)));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -25,11 +25,14 @@ interface IDreamItem {
|
||||
|
||||
void onItemClicked();
|
||||
|
||||
void onCustomizeClicked();
|
||||
default void onCustomizeClicked() {
|
||||
}
|
||||
|
||||
Drawable getPreviewImage();
|
||||
|
||||
boolean isActive();
|
||||
|
||||
boolean allowCustomization();
|
||||
default boolean allowCustomization() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -65,10 +65,7 @@ public class DreamPickerControllerTest {
|
||||
}
|
||||
|
||||
private DreamPickerController buildController() {
|
||||
final DreamPickerController controller = new DreamPickerController(
|
||||
mContext,
|
||||
/* preferenceKey= */ "test",
|
||||
mBackend);
|
||||
final DreamPickerController controller = new DreamPickerController(mContext, mBackend);
|
||||
controller.displayPreference(mScreen);
|
||||
return controller;
|
||||
}
|
||||
|
Reference in New Issue
Block a user