Merge "[5/n] Add graphics to app aspect ratio options" into udc-qpr-dev am: 16f8639404

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24224466

Change-Id: I2608156bcda676d325136beda37c2d04863a31ff
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Graciela Putri
2023-08-10 08:13:31 +00:00
committed by Automerger Merge Worker
19 changed files with 1038 additions and 23 deletions

View File

@@ -0,0 +1,134 @@
/*
* Copyright (C) 2023 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.applications.appcompat;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import androidx.preference.CheckBoxPreference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
/**
* Radio button preference with image at the bottom.
*
* <p>Layout should stay the same as
* {@link com.android.settingslib.widget.SelectorWithWidgetPreference} for consistency.
*/
public class RadioWithImagePreference extends CheckBoxPreference {
/**
* Interface definition for a callback to be invoked when the preference is clicked.
*/
public interface OnClickListener {
/**
* Called when a preference has been clicked.
*
* @param emiter The clicked preference
*/
void onRadioButtonClicked(RadioWithImagePreference emiter);
}
private OnClickListener mListener = null;
/**
* Performs inflation from XML and apply a class-specific base style.
*
* @param context The {@link Context} this is associated with, through which it can
* access the current theme, resources, {@link SharedPreferences}, etc.
* @param attrs The attributes of the XML tag that is inflating the preference
* @param defStyle An attribute in the current theme that contains a reference to a style
* resource that supplies default values for the view. Can be 0 to not
* look for defaults.
*/
public RadioWithImagePreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
/**
* Performs inflation from XML and apply a class-specific base style.
*
* @param context The {@link Context} this is associated with, through which it can
* access the current theme, resources, {@link SharedPreferences}, etc.
* @param attrs The attributes of the XML tag that is inflating the preference
*/
public RadioWithImagePreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
/**
* Constructor to create a preference.
*
* @param context The Context this is associated with.
*/
public RadioWithImagePreference(Context context) {
this(context, null);
}
/**
* Sets the callback to be invoked when this preference is clicked by the user.
*
* @param listener The callback to be invoked
*/
public void setOnClickListener(OnClickListener listener) {
mListener = listener;
}
/**
* Processes a click on the preference.
*/
@Override
public void onClick() {
if (mListener != null) {
mListener.onRadioButtonClicked(this);
}
}
/**
* Binds the created View to the data for this preference.
*
* <p>This is a good place to grab references to custom Views in the layout and set
* properties on them.
*
* <p>Make sure to call through to the superclass's implementation.
*
* @param holder The ViewHolder that provides references to the views to fill in. These views
* will be recycled, so you should not hold a reference to them after this method
* returns.
*/
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View summaryContainer = holder.findViewById(R.id.summary_container);
if (summaryContainer != null) {
summaryContainer.setVisibility(
TextUtils.isEmpty(getSummary()) ? View.GONE : View.VISIBLE);
}
}
private void init() {
setWidgetLayoutResource(com.android.settingslib.R.layout.preference_widget_radiobutton);
setLayoutResource(R.layout.radio_with_image_preference);
setIconSpaceReserved(false);
}
}

View File

@@ -42,7 +42,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.applications.AppInfoWithHeader;
import com.android.settingslib.widget.ActionButtonsPreference;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import java.util.ArrayList;
import java.util.List;
@@ -51,7 +50,7 @@ import java.util.List;
* App specific activity to show aspect ratio overrides
*/
public class UserAspectRatioDetails extends AppInfoWithHeader implements
SelectorWithWidgetPreference.OnClickListener {
RadioWithImagePreference.OnClickListener {
private static final String TAG = UserAspectRatioDetails.class.getSimpleName();
private static final String KEY_HEADER_BUTTONS = "header_view";
@@ -65,7 +64,7 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
@VisibleForTesting
static final String KEY_PREF_3_2 = "3_2_pref";
private final List<SelectorWithWidgetPreference> mAspectRatioPreferences = new ArrayList<>();
private final List<RadioWithImagePreference> mAspectRatioPreferences = new ArrayList<>();
@NonNull private UserAspectRatioManager mUserAspectRatioManager;
@NonNull private String mSelectedKey = KEY_PREF_DEFAULT;
@@ -87,7 +86,7 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
}
@Override
public void onRadioButtonClicked(@NonNull SelectorWithWidgetPreference selected) {
public void onRadioButtonClicked(@NonNull RadioWithImagePreference selected) {
final String selectedKey = selected.getKey();
if (mSelectedKey.equals(selectedKey)) {
return;
@@ -198,7 +197,7 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
private void addPreference(@NonNull String key,
@PackageManager.UserMinAspectRatio int aspectRatio) {
final SelectorWithWidgetPreference pref = findPreference(key);
final RadioWithImagePreference pref = findPreference(key);
if (pref == null) {
return;
}
@@ -212,7 +211,7 @@ public class UserAspectRatioDetails extends AppInfoWithHeader implements
}
private void updateAllPreferences(@NonNull String selectedKey) {
for (SelectorWithWidgetPreference pref : mAspectRatioPreferences) {
for (RadioWithImagePreference pref : mAspectRatioPreferences) {
pref.setChecked(selectedKey.equals(pref.getKey()));
}
}

View File

@@ -48,6 +48,9 @@ import com.android.settingslib.spa.framework.util.asyncMap
import com.android.settingslib.spa.framework.util.filterItem
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.illustration.Illustration
import com.android.settingslib.spa.widget.illustration.IllustrationModel
import com.android.settingslib.spa.widget.illustration.ResourceType
import com.android.settingslib.spa.widget.ui.SettingsBody
import com.android.settingslib.spa.widget.ui.SpinnerOption
import com.android.settingslib.spaprivileged.model.app.AppListModel
@@ -109,6 +112,10 @@ fun UserAspectRatioAppList(
Box(Modifier.padding(SettingsDimension.itemPadding)) {
SettingsBody(UserAspectRatioAppsPageProvider.getSummary())
}
Illustration(object : IllustrationModel {
override val resId = R.raw.user_aspect_ratio_education
override val resourceType = ResourceType.LOTTIE
})
}
)
}