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:
@@ -17,6 +17,6 @@
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||
<item android:state_selected="true" android:color="?androidprv:attr/colorSurfaceVariant"/>
|
||||
<item android:color="?androidprv:attr/colorSurfaceHighlight"/>
|
||||
<item android:state_selected="true" android:color="?androidprv:attr/colorAccentPrimary"/>
|
||||
<item android:color="?androidprv:attr/colorSurface"/>
|
||||
</selector>
|
22
res/color/dream_card_text_color_state_list.xml
Normal file
22
res/color/dream_card_text_color_state_list.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||
<item android:state_selected="true" android:color="?androidprv:attr/textColorOnAccent"/>
|
||||
<item android:color="?android:attr/textColorPrimary"/>
|
||||
</selector>
|
20
res/drawable/dream_preview_rounded_bg.xml
Normal file
20
res/drawable/dream_preview_rounded_bg.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/dream_item_corner_radius"/>
|
||||
</shape>
|
@@ -15,32 +15,25 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/dream_picker_container"
|
||||
android:layout_width="match_parent"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/dream_list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/DreamPickerBackgroundStyle">
|
||||
android:clipToPadding="true"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingBottom="@dimen/dream_preference_card_padding"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/dream_list"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="true"
|
||||
android:nestedScrollingEnabled="false"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -17,7 +17,6 @@
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
@@ -30,21 +29,15 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/preview_container"
|
||||
android:layout_width="match_parent"
|
||||
<ImageView
|
||||
android:id="@+id/preview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:cardCornerRadius="@dimen/dream_item_corner_radius"
|
||||
app:cardElevation="0dp"
|
||||
android:background="@drawable/dream_preview_rounded_bg"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
<ImageView
|
||||
android:id="@+id/preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"/>
|
||||
</androidx.cardview.widget.CardView>
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/customize_button"
|
||||
@@ -53,10 +46,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:text="@string/customize_button_title"
|
||||
app:layout_constraintTop_toTopOf="@+id/preview_container"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/preview_container"
|
||||
app:layout_constraintStart_toStartOf="@+id/preview_container"
|
||||
app:layout_constraintEnd_toEndOf="@+id/preview_container"/>
|
||||
app:layout_constraintTop_toTopOf="@+id/preview"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/preview"
|
||||
app:layout_constraintStart_toStartOf="@+id/preview"
|
||||
app:layout_constraintEnd_toEndOf="@+id/preview"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
@@ -68,7 +61,7 @@
|
||||
android:gravity="center_vertical"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintHorizontal_chainStyle="packed"
|
||||
app:layout_constraintTop_toBottomOf="@+id/preview_container"
|
||||
app:layout_constraintTop_toBottomOf="@+id/preview"
|
||||
app_layout_constraintEnd_toStartOf="@+id/title_text"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
@@ -82,8 +75,9 @@
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSmall"
|
||||
app:layout_constraintTop_toBottomOf="@+id/preview_container"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/dream_card_text_color_state_list"
|
||||
app:layout_constraintTop_toBottomOf="@+id/preview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/icon"/>
|
||||
|
||||
|
@@ -449,7 +449,7 @@
|
||||
<dimen name="dream_item_title_margin_bottom">8dp</dimen>
|
||||
<dimen name="dream_item_title_margin_start">18dp</dimen>
|
||||
<dimen name="dream_item_icon_margin_start">10dp</dimen>
|
||||
<dimen name="dream_preference_margin_horizontal">10dp</dimen>
|
||||
<dimen name="dream_preference_card_padding">20dp</dimen>
|
||||
<dimen name="dream_preference_margin_bottom">20dp</dimen>
|
||||
<dimen name="dream_picker_margin_horizontal">48dp</dimen>
|
||||
|
||||
|
@@ -13905,11 +13905,13 @@
|
||||
<!-- TARE dialog button to proceed with a value change [CHAR LIMIT=none] -->
|
||||
<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>
|
||||
<string name="dream_preview_button_title">Preview screen saver</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>
|
||||
<string name="dream_picker_category">Choose a background</string>
|
||||
<!-- The title of the toggle which enables/disables overlays on top of the screen saver [CHAR LIMIT=none] -->
|
||||
<string name="dream_complications_toggle_title">Show additional information</string>
|
||||
<!-- The summary of what overlays this toggle controls [CHAR LIMIT=none] -->
|
||||
<string name="dream_complications_toggle_summary">Display data time, date and weather on the screen saver</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>
|
||||
<!-- The title of the screen saver setup page [CHAR LIMIT=none] -->
|
||||
|
@@ -944,23 +944,10 @@
|
||||
</style>
|
||||
|
||||
<style name="DreamCardStyle">
|
||||
<item name="android:layout_marginBottom">@dimen/dream_preference_margin_bottom</item>
|
||||
<item name="android:layout_marginStart">@dimen/dream_preference_margin_horizontal</item>
|
||||
<item name="android:layout_marginEnd">@dimen/dream_preference_margin_horizontal</item>
|
||||
<item name="cardBackgroundColor">@color/dream_card_color_state_list</item>
|
||||
<item name="cardCornerRadius">@dimen/dream_item_corner_radius</item>
|
||||
<item name="cardElevation">0dp</item>
|
||||
<item name="rippleColor">?android:attr/colorControlHighlight</item>
|
||||
<item name="contentPadding">@dimen/dream_item_content_padding</item>
|
||||
</style>
|
||||
|
||||
<style name="DreamPickerBackgroundStyle">
|
||||
<item name="android:layout_marginBottom">48dp</item>
|
||||
<item name="android:layout_marginStart">@dimen/dream_picker_margin_horizontal</item>
|
||||
<item name="android:layout_marginEnd">@dimen/dream_picker_margin_horizontal</item>
|
||||
<item name="cardBackgroundColor">?androidprv:attr/colorSurface</item>
|
||||
<item name="cardCornerRadius">24dp</item>
|
||||
<item name="cardElevation">0dp</item>
|
||||
<item name="contentPadding">32dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@@ -28,19 +28,13 @@
|
||||
settings:controller="com.android.settings.dream.DreamPickerController"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<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">
|
||||
<SwitchPreference
|
||||
android:key="dream_complications_toggle"
|
||||
android:title="@string/dream_complications_toggle_title"
|
||||
android:summary="@string/dream_complications_toggle_summary"
|
||||
settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
|
||||
<Preference
|
||||
android:key="when_to_start"
|
||||
android:title="@string/screensaver_settings_when_to_dream"
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user