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

Commit 1b729656 authored by David Liu's avatar David Liu
Browse files

[Expressive design] update ActionButtonPreference

- update to material button
- update layout

Bug: 367534605
Test: manual
Flag: EXEMPT resource only update
Change-Id: I93e16cb7872e9e18d51e3db5999cbfadb6aff5a2
parent 21b6c759
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ android_library {

    static_libs: [
        "androidx.preference_preference",
        "SettingsLibSettingsTheme",
    ],

    sdk_version: "system_current",
+104 −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.
  -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/settingslib_expressive_space_extrasmall4"
    android:paddingHorizontal="@dimen/settingslib_expressive_space_extrasmall4"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/action1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/button1"
            style="@style/SettingsLibActionButton.Expressive"
            android:layout_width="@dimen/settingslib_expressive_space_large3"
            android:layout_height="@dimen/settingslib_expressive_space_medium5"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:id="@+id/text1"
            style="@style/SettingsLibActionButton.Expressive.Label"
            android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/action2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/button2"
            style="@style/SettingsLibActionButton.Expressive"
            android:layout_width="@dimen/settingslib_expressive_space_large3"
            android:layout_height="@dimen/settingslib_expressive_space_medium5"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:id="@+id/text2"
            style="@style/SettingsLibActionButton.Expressive.Label"
            android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/action3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/button3"
            style="@style/SettingsLibActionButton.Expressive"
            android:layout_width="@dimen/settingslib_expressive_space_large3"
            android:layout_height="@dimen/settingslib_expressive_space_medium5"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:id="@+id/text3"
            style="@style/SettingsLibActionButton.Expressive.Label"
            android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/action4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <com.google.android.material.button.MaterialButton
            android:id="@+id/button4"
            style="@style/SettingsLibActionButton.Expressive"
            android:layout_width="@dimen/settingslib_expressive_space_large3"
            android:layout_height="@dimen/settingslib_expressive_space_medium5"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:id="@+id/text4"
            style="@style/SettingsLibActionButton.Expressive.Label"
            android:layout_marginTop="@dimen/settingslib_expressive_space_extrasmall3"/>
    </LinearLayout>
</LinearLayout>
+34 −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.
  -->

<resources>
    <style name="SettingsLibActionButton.Expressive" parent="SettingsLibButtonStyle.Expressive.Tonal">
        <item name="android:backgroundTint">@color/settingslib_materialColorPrimaryContainer</item>
        <item name="iconTint">@color/settingslib_materialColorOnPrimaryContainer</item>
        <item name="iconGravity">textTop</item>
    </style>

    <style name="SettingsLibActionButton.Expressive.Label" parent="SettingsLibTextAppearance.Emphasized.Title.Small">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:minWidth">@dimen/settingslib_expressive_space_small3</item>
        <item name="android:minHeight">@dimen/settingslib_expressive_space_small3</item>
        <item name="android:textColor">@color/settingslib_materialColorOnSurface</item>
        <item name="android:layout_gravity">center</item>
    </style>

</resources>
+86 −42
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
@@ -34,6 +36,8 @@ import androidx.preference.PreferenceViewHolder;

import com.android.settingslib.widget.preference.actionbuttons.R;

import com.google.android.material.button.MaterialButton;

import java.util.ArrayList;
import java.util.List;

@@ -98,7 +102,10 @@ public class ActionButtonsPreference extends Preference {
    }

    private void init() {
        setLayoutResource(R.layout.settingslib_action_buttons);
        int resId = SettingsThemeHelper.isExpressiveTheme(getContext())
                ? R.layout.settingslib_expressive_action_buttons
                : R.layout.settingslib_action_buttons;
        setLayoutResource(resId);
        setSelectable(false);

        final Resources res = getContext().getResources();
@@ -127,6 +134,21 @@ public class ActionButtonsPreference extends Preference {
        mButton3Info.mButton = (Button) holder.findViewById(R.id.button3);
        mButton4Info.mButton = (Button) holder.findViewById(R.id.button4);

        if (SettingsThemeHelper.isExpressiveTheme(getContext())) {
            mButton1Info.mIsExpressive = true;
            mButton1Info.mTextView = (TextView) holder.findViewById(R.id.text1);
            mButton1Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action1);
            mButton2Info.mIsExpressive = true;
            mButton2Info.mTextView = (TextView) holder.findViewById(R.id.text2);
            mButton2Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action2);
            mButton3Info.mIsExpressive = true;
            mButton3Info.mTextView = (TextView) holder.findViewById(R.id.text3);
            mButton3Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action3);
            mButton4Info.mIsExpressive = true;
            mButton4Info.mTextView = (TextView) holder.findViewById(R.id.text4);
            mButton4Info.mActionLayout = (LinearLayout) holder.findViewById(R.id.action4);
        }

        mDivider1 = holder.findViewById(R.id.divider1);
        mDivider2 = holder.findViewById(R.id.divider2);
        mDivider3 = holder.findViewById(R.id.divider3);
@@ -169,6 +191,7 @@ public class ActionButtonsPreference extends Preference {
            mVisibleButtonInfos.add(mButton4Info);
        }

        if (!SettingsThemeHelper.isExpressiveTheme(getContext())) {
            final boolean isRtl = getContext().getResources().getConfiguration()
                    .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
            switch (mVisibleButtonInfos.size()) {
@@ -209,6 +232,7 @@ public class ActionButtonsPreference extends Preference {
            setupDivider2();
            setupDivider3();
        }
    }

    private void setupBackgrounds(
            List<ButtonInfo> buttonInfoList, List<Drawable> buttonBackgroundStyles) {
@@ -509,23 +533,43 @@ public class ActionButtonsPreference extends Preference {

    static class ButtonInfo {
        private Button mButton;
        private TextView mTextView;
        private LinearLayout mActionLayout;
        private CharSequence mText;
        private Drawable mIcon;
        private View.OnClickListener mListener;
        private boolean mIsEnabled = true;
        private boolean mIsVisible = true;
        private boolean mIsExpressive = false;

        void setUpButton() {
            if (mIsExpressive) {
                mTextView.setText(mText);
                if (mButton instanceof MaterialButton) {
                    ((MaterialButton) mButton).setIcon(mIcon);
                }
            } else {
                mButton.setText(mText);
            mButton.setOnClickListener(mListener);
            mButton.setEnabled(mIsEnabled);
                mButton.setCompoundDrawablesWithIntrinsicBounds(
                        null /* left */, mIcon /* top */, null /* right */, null /* bottom */);
            }

            mButton.setOnClickListener(mListener);
            mButton.setEnabled(mIsEnabled);


            if (shouldBeVisible()) {
                mButton.setVisibility(View.VISIBLE);
                if (mIsExpressive) {
                    mTextView.setVisibility(View.VISIBLE);
                    mActionLayout.setVisibility(View.VISIBLE);
                }
            } else {
                mButton.setVisibility(View.GONE);
                if (mIsExpressive) {
                    mTextView.setVisibility(View.GONE);
                    mActionLayout.setVisibility(View.GONE);
                }
            }
        }

+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
    <dimen name="settingslib_expressive_space_medium2">36dp</dimen>
    <dimen name="settingslib_expressive_space_medium3">40dp</dimen>
    <dimen name="settingslib_expressive_space_medium4">48dp</dimen>
    <dimen name="settingslib_expressive_space_medium5">56dp</dimen>
    <dimen name="settingslib_expressive_space_large1">60dp</dimen>
    <dimen name="settingslib_expressive_space_large2">64dp</dimen>
    <dimen name="settingslib_expressive_space_large3">72dp</dimen>
Loading