diff options
Diffstat (limited to 'packages/SettingsLib/ActionButtonsPreference')
13 files changed, 385 insertions, 41 deletions
diff --git a/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml b/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml index 22b25a31ae07..95b7e3b8033d 100644 --- a/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml +++ b/packages/SettingsLib/ActionButtonsPreference/lint-baseline.xml @@ -26,10 +26,54 @@ <issue id="NewApi" message="`?android:attr/dialogCornerRadius` requires API level 28 (current min is 21)" - errorLine1=" android:radius="?android:attr/dialogCornerRadius"" + errorLine1=" android:topLeftRadius="?android:attr/dialogCornerRadius"" errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~"> <location - file="frameworks/base/packages/SettingsLib/ActionButtonsPreference/res/drawable/settingslib_rounded_background.xml" + file="frameworks/base/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_left_bk.xml" + line="23" + column="9"/> + </issue> + + <issue + id="NewApi" + message="`?android:attr/dialogCornerRadius` requires API level 28 (current min is 21)" + errorLine1=" android:bottomLeftRadius="?android:attr/dialogCornerRadius"" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + <location + file="frameworks/base/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_left_bk.xml" + line="25" + column="9"/> + </issue> + + <issue + id="NewApi" + message="`?android:attr/dialogCornerRadius` requires API level 28 (current min is 21)" + errorLine1=" android:topRightRadius="?android:attr/dialogCornerRadius"" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + <location + file="frameworks/base/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_right_bk.xml" + line="24" + column="9"/> + </issue> + + <issue + id="NewApi" + message="`?android:attr/dialogCornerRadius` requires API level 28 (current min is 21)" + errorLine1=" android:bottomRightRadius="?android:attr/dialogCornerRadius"" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + <location + file="frameworks/base/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_right_bk.xml" + line="26" + column="9"/> + </issue> + + <issue + id="NewApi" + message="`?android:attr/dialogCornerRadius` requires API level 28 (current min is 21)" + errorLine1=" android:bottomRightRadius="?android:attr/dialogCornerRadius"" + errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~"> + <location + file="frameworks/base/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_bk.xml" line="23" column="9"/> </issue> 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 000000000000..16a85d694bf8 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_left_bk.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + android:shape="rectangle"> + <solid android:color="?androidprv:attr/colorSurface" /> + <corners + android:topLeftRadius="?android:attr/dialogCornerRadius" + android:topRightRadius="0dp" + android:bottomLeftRadius="?android:attr/dialogCornerRadius" + android:bottomRightRadius="0dp" + /> +</shape>
\ 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 000000000000..1b9f68fac850 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/half_rounded_right_bk.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + android:shape="rectangle"> + <solid android:color="?androidprv:attr/colorSurface" /> + <corners + android:topLeftRadius="0dp" + android:topRightRadius="?android:attr/dialogCornerRadius" + android:bottomLeftRadius="0dp" + android:bottomRightRadius="?android:attr/dialogCornerRadius" + /> +</shape>
\ 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 000000000000..1584b45aabf9 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/left_rounded_ripple.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:drawable="@drawable/half_rounded_left_bk"/> +</ripple>
\ 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 000000000000..15f2b5cd79d0 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/right_rounded_ripple.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:drawable="@drawable/half_rounded_right_bk"/> +</ripple>
\ 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 000000000000..a884ef11e835 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_bk.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + android:shape="rectangle"> + <solid android:color="?androidprv:attr/colorSurface" /> + <corners + android:radius="?android:attr/dialogCornerRadius" + /> +</shape>
\ 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 000000000000..90eefbe9a86e --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/rounded_ripple.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:drawable="@drawable/rounded_bk"/> +</ripple>
\ 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 ae3834dc0d9d..000000000000 --- a/packages/SettingsLib/ActionButtonsPreference/res/drawable/settingslib_rounded_background.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - Copyright (C) 2021 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. - --> - -<shape xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" - android:shape="rectangle"> - <solid android:color="?androidprv:attr/colorSurface" /> - <corners - android:radius="?android:attr/dialogCornerRadius" - /> -</shape>
\ 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 000000000000..67b5107576a7 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_bk.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<shape xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + android:shape="rectangle"> + <solid android:color="?androidprv:attr/colorSurface" /> + <corners + android:radius="0dp" + /> +</shape>
\ 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 000000000000..06be00dc2279 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/drawable/square_ripple.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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. + --> + +<ripple xmlns:android="http://schemas.android.com/apk/res/android" + android:color="?android:attr/colorControlHighlight"> + <item android:drawable="@drawable/square_bk"/> +</ripple>
\ 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 ba612d76fa57..7c3f5a566bdb 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"> <Button android:id="@+id/button1" style="@style/SettingsLibActionButton" android:layout_width="0dp" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_weight="1"/> <View @@ -43,7 +42,7 @@ android:id="@+id/button2" style="@style/SettingsLibActionButton" android:layout_width="0dp" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_weight="1"/> <View @@ -58,7 +57,7 @@ android:id="@+id/button3" style="@style/SettingsLibActionButton" android:layout_width="0dp" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_weight="1"/> <View @@ -73,6 +72,6 @@ android:id="@+id/button4" style="@style/SettingsLibActionButton" android:layout_width="0dp" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_weight="1"/> </LinearLayout> diff --git a/packages/SettingsLib/ActionButtonsPreference/res/values/arrays.xml b/packages/SettingsLib/ActionButtonsPreference/res/values/arrays.xml new file mode 100644 index 000000000000..fe88845daa64 --- /dev/null +++ b/packages/SettingsLib/ActionButtonsPreference/res/values/arrays.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2021 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 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <!-- Do not translate. --> + <integer-array name="background_style1"> + <item>@drawable/rounded_ripple</item> + </integer-array> + + <!-- Do not translate. --> + <integer-array name="background_style2"> + <item>@drawable/left_rounded_ripple</item> + <item>@drawable/right_rounded_ripple</item> + </integer-array> + + <!-- Do not translate. --> + <integer-array name="background_style3"> + <item>@drawable/left_rounded_ripple</item> + <item>@drawable/square_ripple</item> + <item>@drawable/right_rounded_ripple</item> + </integer-array> + + <!-- Do not translate. --> + <integer-array name="background_style4"> + <item>@drawable/left_rounded_ripple</item> + <item>@drawable/square_ripple</item> + <item>@drawable/square_ripple</item> + <item>@drawable/right_rounded_ripple</item> + </integer-array> +</resources>
\ 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 029c9196fa5e..4d3ca945f7e1 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<ButtonInfo> mVisibleButtonInfos = new ArrayList<>(4); + private final List<Drawable> mBtnBackgroundStyle1 = new ArrayList<>(1); + private final List<Drawable> mBtnBackgroundStyle2 = new ArrayList<>(2); + private final List<Drawable> mBtnBackgroundStyle3 = new ArrayList<>(3); + private final List<Drawable> 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<Drawable> 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<ButtonInfo> buttonInfoList, List<Drawable> buttonBackgroundStyles) { + for (int i = 0; i < buttonBackgroundStyles.size(); i++) { + buttonInfoList.get(i).mButton.setBackground(buttonBackgroundStyles.get(i)); + } + } + + private void setupRtlBackgrounds( + List<ButtonInfo> buttonInfoList, List<Drawable> 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. */ |