Make Preferences more visible with colored rounded rectangle background and an arrow icon

Bug: 320709814
Test: atest ArrowPreferenceTest
Change-Id: Id1ed44554010ae0df901cceba2624a1b56661df6
This commit is contained in:
jasonwshsu
2024-01-29 16:51:17 +08:00
committed by Jason Hsu
parent 6dc0e30b56
commit d23c2867c6
5 changed files with 95 additions and 23 deletions

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2024 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.
-->
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:contentDescription="@null"
android:scaleType="center"
android:src="@drawable/ic_arrow_forward" />

View File

@@ -152,10 +152,10 @@
<string name="bluetooth_pair_other_ear_dialog_left_ear_positive_button">Pair left ear</string>
<!-- Title for all hearing devices related controls section. [CHAR LIMIT=60] -->
<string name="bluetooth_device_controls_general">For all available hearing devices</string>
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device controls related page. [CHAR LIMIT=65] -->
<string name="bluetooth_device_controls_title">Hearing device settings</string>
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device controls related page. [CHAR LIMIT=65] -->
<string name="bluetooth_device_controls_summary">Shortcut, hearing aid compatibility</string>
<!-- Connected devices settings. Title of the preference to show the entrance of the hearing device settings related page. [CHAR LIMIT=65] -->
<string name="bluetooth_device_controls_title">More hearing device settings</string>
<!-- Connected devices settings. Summary of the preference to show the item in the hearing device settings related page. [CHAR LIMIT=120] -->
<string name="bluetooth_device_controls_summary">Change cross-device settings like shortcut, and telecoil controls</string>
<!-- Title for this device specific controls section. [CHAR LIMIT=30] -->
<string name="bluetooth_device_controls_specific">For this device</string>
<!-- Connected devices settings. Title of the preference to show the entrance of the audio output page. It can change different types of audio are played on phone or other bluetooth devices. [CHAR LIMIT=35] -->

View File

@@ -22,17 +22,25 @@ import android.util.AttributeSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.Preference;
import com.android.settings.R;
/**
* A settings preference with colored rounded rectangle background and an arrow icon on the right
* A settings preference with colored rounded rectangle background and an arrow icon on the right.
*/
public class ArrowPreference extends Preference {
public class ArrowPreference extends BackgroundPreference {
public ArrowPreference(@NonNull Context context) {
this(context, null);
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
setBackground(
com.android.settingslib.widget.mainswitch.R.drawable.settingslib_switch_bar_bg_on);
setWidgetLayoutResource(R.layout.preference_widget_arrow);
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
@@ -41,18 +49,7 @@ public class ArrowPreference extends Preference {
android.R.attr.preferenceStyle));
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setLayoutResource(R.layout.arrow_preference);
public ArrowPreference(@NonNull Context context) {
this(context, null);
}
}

View File

@@ -26,6 +26,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityHearingAidsFragment;
import com.android.settings.accessibility.ArrowPreference;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -83,7 +84,7 @@ public class BluetoothDetailsHearingDeviceControlsController extends BluetoothDe
}
private Preference createHearingDeviceControlsPreference(Context context) {
final Preference preference = new Preference(context);
final ArrowPreference preference = new ArrowPreference(context);
preference.setKey(KEY_HEARING_DEVICE_CONTROLS);
preference.setTitle(context.getString(R.string.bluetooth_device_controls_title));
preference.setSummary(context.getString(R.string.bluetooth_device_controls_summary));

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2024 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.accessibility;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/** Tests for {@link ArrowPreference} */
@RunWith(RobolectricTestRunner.class)
public class ArrowPreferenceTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
private ArrowPreference mPreference;
@Before
public void setUp() {
mPreference = new ArrowPreference(mContext);
}
@Test
public void construct_withArrow() {
assertThat(mPreference.getWidgetLayoutResource()).isEqualTo(
R.layout.preference_widget_arrow);
}
}