diff --git a/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml b/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml
index 22b25a31ae075..95b7e3b8033d7 100644
--- a/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml
+++ b/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml
@@ -26,10 +26,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_left_bk.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_left_bk.xml
new file mode 100644
index 0000000000000..16a85d694bf81
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_left_bk.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_right_bk.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_right_bk.xml
new file mode 100644
index 0000000000000..1b9f68fac8505
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_right_bk.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/left_rounded_ripple.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/left_rounded_ripple.xml
new file mode 100644
index 0000000000000..1584b45aabf9d
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/left_rounded_ripple.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/right_rounded_ripple.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/right_rounded_ripple.xml
new file mode 100644
index 0000000000000..15f2b5cd79d0d
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/right_rounded_ripple.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_bk.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_bk.xml
new file mode 100644
index 0000000000000..a884ef11e8354
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_bk.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_ripple.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_ripple.xml
new file mode 100644
index 0000000000000..90eefbe9a86e0
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_ripple.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/settingslib_rounded_background.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/settingslib_rounded_background.xml
deleted file mode 100644
index ae3834dc0d9da..0000000000000
--- a/packages/SettingsLib/ActionButtonsPreference/res/drawable/settingslib_rounded_background.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_bk.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_bk.xml
new file mode 100644
index 0000000000000..67b5107576a79
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_bk.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_ripple.xml b/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_ripple.xml
new file mode 100644
index 0000000000000..06be00dc2279a
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_ripple.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/layout-v31/settingslib_action_buttons.xml b/packages/SettingsLib/ActionButtonsPreference/res/layout-v31/settingslib_action_buttons.xml
index ba612d76fa57d..7c3f5a566bdbd 100644
--- a/packages/SettingsLib/ActionButtonsPreference/res/layout-v31/settingslib_action_buttons.xml
+++ b/packages/SettingsLib/ActionButtonsPreference/res/layout-v31/settingslib_action_buttons.xml
@@ -21,14 +21,13 @@
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:paddingHorizontal="8dp"
- android:orientation="horizontal"
- android:background="@drawable/settingslib_rounded_background">
+ android:orientation="horizontal">
diff --git a/packages/SettingsLib/ActionButtonsPreference/res/values/arrays.xml b/packages/SettingsLib/ActionButtonsPreference/res/values/arrays.xml
new file mode 100644
index 0000000000000..fe88845daa645
--- /dev/null
+++ b/packages/SettingsLib/ActionButtonsPreference/res/values/arrays.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+ - @drawable/rounded_ripple
+
+
+
+
+ - @drawable/left_rounded_ripple
+ - @drawable/right_rounded_ripple
+
+
+
+
+ - @drawable/left_rounded_ripple
+ - @drawable/square_ripple
+ - @drawable/right_rounded_ripple
+
+
+
+
+ - @drawable/left_rounded_ripple
+ - @drawable/square_ripple
+ - @drawable/square_ripple
+ - @drawable/right_rounded_ripple
+
+
\ No newline at end of file
diff --git a/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java b/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java
index 029c9196fa5e2..4d3ca945f7e15 100644
--- a/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java
+++ b/packages/SettingsLib/ActionButtonsPreference/src/com/android/settingslib/widget/ActionButtonsPreference.java
@@ -18,6 +18,7 @@ package com.android.settingslib.widget;
import android.content.Context;
import android.content.res.Resources;
+import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -54,12 +55,21 @@ import java.util.List;
public class ActionButtonsPreference extends Preference {
private static final String TAG = "ActionButtonPreference";
+ private static final boolean mIsAtLeastS = BuildCompatUtils.isAtLeastS();
+ private static final int SINGLE_BUTTON_STYLE = 1;
+ private static final int TWO_BUTTONS_STYLE = 2;
+ private static final int THREE_BUTTONS_STYLE = 3;
+ private static final int FOUR_BUTTONS_STYLE = 4;
private final ButtonInfo mButton1Info = new ButtonInfo();
private final ButtonInfo mButton2Info = new ButtonInfo();
private final ButtonInfo mButton3Info = new ButtonInfo();
private final ButtonInfo mButton4Info = new ButtonInfo();
private final List mVisibleButtonInfos = new ArrayList<>(4);
+ private final List mBtnBackgroundStyle1 = new ArrayList<>(1);
+ private final List mBtnBackgroundStyle2 = new ArrayList<>(2);
+ private final List mBtnBackgroundStyle3 = new ArrayList<>(3);
+ private final List mBtnBackgroundStyle4 = new ArrayList<>(4);
private View mDivider1;
private View mDivider2;
@@ -89,15 +99,27 @@ public class ActionButtonsPreference extends Preference {
private void init() {
setLayoutResource(R.layout.settingslib_action_buttons);
setSelectable(false);
+
+ final Resources res = getContext().getResources();
+ fetchDrawableArray(mBtnBackgroundStyle1, res.obtainTypedArray(R.array.background_style1));
+ fetchDrawableArray(mBtnBackgroundStyle2, res.obtainTypedArray(R.array.background_style2));
+ fetchDrawableArray(mBtnBackgroundStyle3, res.obtainTypedArray(R.array.background_style3));
+ fetchDrawableArray(mBtnBackgroundStyle4, res.obtainTypedArray(R.array.background_style4));
+ }
+
+ private void fetchDrawableArray(List drawableList, TypedArray typedArray) {
+ for (int i = 0; i < typedArray.length(); i++) {
+ drawableList.add(
+ getContext().getDrawable(typedArray.getResourceId(i, 0 /* defValue */)));
+ }
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
- final boolean allowedDivider = !BuildCompatUtils.isAtLeastS();
- holder.setDividerAllowedAbove(allowedDivider);
- holder.setDividerAllowedBelow(allowedDivider);
+ holder.setDividerAllowedAbove(!mIsAtLeastS);
+ holder.setDividerAllowedBelow(!mIsAtLeastS);
mButton1Info.mButton = (Button) holder.findViewById(R.id.button1);
mButton2Info.mButton = (Button) holder.findViewById(R.id.button2);
@@ -113,25 +135,95 @@ public class ActionButtonsPreference extends Preference {
mButton3Info.setUpButton();
mButton4Info.setUpButton();
- // Add visible button into list only
- if (mButton1Info.isVisible()) {
+ // Clear info list to avoid duplicate setup.
+ if (!mVisibleButtonInfos.isEmpty()) {
+ mVisibleButtonInfos.clear();
+ }
+ updateLayout();
+ }
+
+ @Override
+ protected void notifyChanged() {
+ super.notifyChanged();
+
+ // Update buttons background and layout when notified and visible button list exist.
+ if (!mVisibleButtonInfos.isEmpty()) {
+ mVisibleButtonInfos.clear();
+ updateLayout();
+ }
+ }
+
+ private void updateLayout() {
+ // Add visible button into list only when platform version is newer than S.
+ if (mButton1Info.isVisible() && mIsAtLeastS) {
mVisibleButtonInfos.add(mButton1Info);
}
- if (mButton2Info.isVisible()) {
+ if (mButton2Info.isVisible() && mIsAtLeastS) {
mVisibleButtonInfos.add(mButton2Info);
}
- if (mButton3Info.isVisible()) {
+ if (mButton3Info.isVisible() && mIsAtLeastS) {
mVisibleButtonInfos.add(mButton3Info);
}
- if (mButton4Info.isVisible()) {
+ if (mButton4Info.isVisible() && mIsAtLeastS) {
mVisibleButtonInfos.add(mButton4Info);
}
+ final boolean isRtl = getContext().getResources().getConfiguration()
+ .getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+ switch (mVisibleButtonInfos.size()) {
+ case SINGLE_BUTTON_STYLE :
+ if (isRtl) {
+ setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle1);
+ } else {
+ setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle1);
+ }
+ break;
+ case TWO_BUTTONS_STYLE :
+ if (isRtl) {
+ setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle2);
+ } else {
+ setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle2);
+ }
+ break;
+ case THREE_BUTTONS_STYLE :
+ if (isRtl) {
+ setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle3);
+ } else {
+ setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle3);
+ }
+ break;
+ case FOUR_BUTTONS_STYLE :
+ if (isRtl) {
+ setupRtlBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle4);
+ } else {
+ setupBackgrounds(mVisibleButtonInfos, mBtnBackgroundStyle4);
+ }
+ break;
+ default:
+ Log.e(TAG, "No visible buttons info, skip background settings.");
+ break;
+ }
+
setupDivider1();
setupDivider2();
setupDivider3();
}
+ private void setupBackgrounds(
+ List buttonInfoList, List buttonBackgroundStyles) {
+ for (int i = 0; i < buttonBackgroundStyles.size(); i++) {
+ buttonInfoList.get(i).mButton.setBackground(buttonBackgroundStyles.get(i));
+ }
+ }
+
+ private void setupRtlBackgrounds(
+ List buttonInfoList, List buttonBackgroundStyles) {
+ for (int i = buttonBackgroundStyles.size() - 1; i >= 0; i--) {
+ buttonInfoList.get(buttonBackgroundStyles.size() - 1 - i)
+ .mButton.setBackground(buttonBackgroundStyles.get(i));
+ }
+ }
+
/**
* Set the visibility state of button1.
*/