Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 429291b7 authored by Jason Hsu's avatar Jason Hsu Committed by Android (Google) Code Review
Browse files

Merge changes Id1ed4455,I73e62733 into main

* changes:
  Make Preferences more visible with colored rounded rectangle background and an arrow icon
  Provides BackgroundPreference that can set background statically or dynamically
parents 08b25d04 d23c2867
Loading
Loading
Loading
Loading
+95 −0
Original line number Diff line number Diff line
<?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.
  -->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingVertical="@dimen/settingslib_switchbar_margin"
    android:background="@android:color/transparent">

    <LinearLayout
        android:id="@+id/background"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:paddingStart="@dimen/settingslib_switchbar_padding_left"
        android:paddingEnd="@dimen/settingslib_switchbar_padding_right"
        android:orientation="horizontal"
        android:gravity="start|center_vertical"
        android:baselineAligned="false">

        <FrameLayout
            android:id="@+id/icon_frame"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="15dip"
            android:layout_marginRight="15dip">
            <androidx.preference.internal.PreferenceImageView
                android:id="@android:id/icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:maxWidth="48dp"
                app:maxHeight="48dp" />
        </FrameLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="6dip"
            android:layout_marginRight="6dip"
            android:layout_marginTop="@dimen/settingslib_switch_title_margin"
            android:layout_marginBottom="@dimen/settingslib_switch_title_margin"
            android:layout_weight="1">

            <TextView android:id="@android:id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceListItem"
                android:textColor="?android:attr/textColorPrimary"
                android:ellipsize="marquee"
                android:fadingEdge="horizontal"
                android:hyphenationFrequency="normalFast"
                android:lineBreakWordStyle="phrase" />

            <TextView android:id="@android:id/summary"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@android:id/title"
                android:layout_alignStart="@android:id/title"
                android:layout_alignLeft="@android:id/title"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="?android:attr/textColorSecondary"
                android:hyphenationFrequency="normalFast"
                android:lineBreakWordStyle="phrase"
                android:maxLines="4"
                android:scrollbars="none"/>
        </RelativeLayout>

        <!-- Preference should place its actual preference widget here. -->
        <LinearLayout android:id="@android:id/widget_frame"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:orientation="vertical" />
    </LinearLayout>

</FrameLayout>
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
<?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" />
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -198,4 +198,9 @@
    <attr name="notification_importance_button_background_color_selected" format="color" />
    <attr name="notification_importance_button_border_color_selected" format="color" />
    <attr name="notification_importance_button_foreground_color_selected" format="color" />

    <!-- For BackgroundPreference -->
    <declare-styleable name="BackgroundPreference">
        <attr name="background" format="reference" />
    </declare-styleable>
</resources>
+4 −4
Original line number Diff line number Diff line
@@ -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] -->
+14 −17
Original line number Diff line number Diff line
@@ -22,23 +22,20 @@ 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) {
        this(context, attrs, TypedArrayUtils.getAttr(context,
                androidx.preference.R.attr.preferenceStyle,
                android.R.attr.preferenceStyle));
    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,
@@ -46,13 +43,13 @@ public class ArrowPreference extends Preference {
        this(context, attrs, defStyleAttr, 0);
    }

    public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    public ArrowPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, TypedArrayUtils.getAttr(context,
                androidx.preference.R.attr.preferenceStyle,
                android.R.attr.preferenceStyle));
    }

    private void init() {
        setLayoutResource(R.layout.arrow_preference);
    public ArrowPreference(@NonNull Context context) {
        this(context, null);
    }
}
Loading