Update dream settings UX to match latest mocks.

Updates:
- removed individual complication toggle
- added single toggle which enables/disables all supported complications
- updated colors to match mocks
- updated grid padding in order to line up with existing content. Note:
  this required more complex padding logic, using an item decorator to
  apply the padding only to inner grid elements.
- updated preview image, removing view nesting to make better use of
  ConstraintLayout
- Updated some strings to match mocks

Test: locally on device
Bug: 217555053
Change-Id: I573e5f4ed807cbe2ae9e00f183d402e6e3339590
This commit is contained in:
Lucas Silva
2022-02-11 22:31:12 +00:00
parent cce99074e9
commit 75c44cd02b
15 changed files with 220 additions and 201 deletions

View File

@@ -70,6 +70,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (previewImage != null) {
mPreviewView.setVisibility(View.VISIBLE);
mPreviewView.setImageDrawable(previewImage);
mPreviewView.setClipToOutline(true);
} else {
mPreviewView.setVisibility(View.GONE);
}

View File

@@ -1,113 +0,0 @@
/*
* 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 Set<Integer> mSupportedComplications;
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 null;
}
@Override
public void onItemClicked() {
mEnabled = !mEnabled;
mBackend.setComplicationEnabled(mComplicationType, mEnabled);
}
@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();
}
@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);
DreamAdapter adapter = 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.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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 com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.dream.DreamBackend;
/**
* Controller for the {@link androidx.preference.SwitchPreference} which controls if dream
* overlays should be enabled.
*/
public class DreamComplicationPreferenceController extends TogglePreferenceController {
private final DreamBackend mBackend;
public DreamComplicationPreferenceController(Context context, String key) {
super(context, key);
mBackend = DreamBackend.getInstance(context);
}
@Override
public int getAvailabilityStatus() {
return mBackend.getSupportedComplications().isEmpty() ? CONDITIONALLY_UNAVAILABLE
: AVAILABLE;
}
@Override
public boolean isChecked() {
return mBackend.getEnabledComplications().containsAll(mBackend.getSupportedComplications());
}
@Override
public boolean setChecked(boolean isChecked) {
for (int complication : mBackend.getSupportedComplications()) {
mBackend.setComplicationEnabled(complication, isChecked);
}
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;
}
}

View File

@@ -21,7 +21,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
@@ -71,16 +71,21 @@ public class DreamPickerController extends BasePreferenceController {
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mAdapter = new DreamAdapter(mDreamInfos.stream()
.map(DreamItem::new)
.collect(Collectors.toList()));
final RecyclerView recyclerView =
((LayoutPreference) preference).findViewById(R.id.dream_list);
final LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref == null) {
return;
}
final RecyclerView recyclerView = pref.findViewById(R.id.dream_list);
recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
recyclerView.addItemDecoration(
new GridSpacingItemDecoration(mContext, R.dimen.dream_preference_card_padding));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(mAdapter);
}

View File

@@ -34,14 +34,12 @@ import androidx.recyclerview.widget.RecyclerView;
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
@@ -52,7 +50,6 @@ 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) {
@@ -138,14 +135,8 @@ 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)));
controllers.add(new WhenToDreamPreferenceController(context));
return controllers;
}

View File

@@ -0,0 +1,63 @@
/*
* 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.Rect;
import android.view.View;
import androidx.annotation.DimenRes;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/**
* RecyclerView item decorator to be used with {@link GridLayoutManager} for applying padding to
* only the inner elements of the grid.
*/
public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private final int mSpacing;
private final boolean mRtl;
public GridSpacingItemDecoration(Context context, @DimenRes int spacingId) {
mSpacing = context.getResources().getDimensionPixelSize(spacingId);
mRtl = context.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
final RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (!(layoutManager instanceof GridLayoutManager)) {
return;
}
final int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
final int position = parent.getChildAdapterPosition(view);
final int column = position % spanCount;
final int startPadding = column * mSpacing / spanCount;
final int endPadding = mSpacing - (column + 1) * mSpacing / spanCount;
outRect.left = mRtl ? endPadding : startPadding;
outRect.right = mRtl ? startPadding : endPadding;
if (position >= spanCount) {
outRect.top = mSpacing;
}
}
}