summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/drawable-v31/settingslib_switch_bar_bg.xml28
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml3
-rw-r--r--packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml3
-rw-r--r--packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java20
4 files changed, 36 insertions, 18 deletions
diff --git a/packages/SettingsLib/MainSwitchPreference/res/drawable-v31/settingslib_switch_bar_bg.xml b/packages/SettingsLib/MainSwitchPreference/res/drawable-v31/settingslib_switch_bar_bg.xml
new file mode 100644
index 000000000000..d3d324b272a1
--- /dev/null
+++ b/packages/SettingsLib/MainSwitchPreference/res/drawable-v31/settingslib_switch_bar_bg.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2023 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.
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:state_enabled="false"
+ android:drawable="@drawable/settingslib_switch_bar_bg_disabled"/>
+ <item
+ android:state_activated="true"
+ android:drawable="@drawable/settingslib_switch_bar_bg_on"/>
+ <item
+ android:state_activated="false"
+ android:drawable="@drawable/settingslib_switch_bar_bg_off"/>
+</selector>
diff --git a/packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml b/packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml
index b1c26e852cdc..e3f8fbb88a65 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml
@@ -32,7 +32,8 @@
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:paddingEnd="@dimen/settingslib_switchbar_padding_right"
+ android:background="@drawable/settingslib_switch_bar_bg">
<TextView
android:id="@+id/switch_text"
diff --git a/packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml b/packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml
index d2e9fbeef073..255b2c92e709 100644
--- a/packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml
+++ b/packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml
@@ -32,7 +32,8 @@
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:paddingEnd="@dimen/settingslib_switchbar_padding_right"
+ android:background="@drawable/settingslib_switch_bar_bg">
<TextView
android:id="@+id/switch_text"
diff --git a/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java b/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java
index c8df7602800f..097e8fcd0a38 100644
--- a/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java
+++ b/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java
@@ -18,7 +18,6 @@ package com.android.settingslib.widget;
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -52,9 +51,6 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
protected TextView mTextView;
protected Switch mSwitch;
- private Drawable mBackgroundOn;
- private Drawable mBackgroundOff;
- private Drawable mBackgroundDisabled;
private View mFrameView;
public MainSwitchBar(Context context) {
@@ -89,12 +85,6 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
mFrameView = findViewById(R.id.frame);
mTextView = (TextView) findViewById(R.id.switch_text);
mSwitch = (Switch) findViewById(android.R.id.switch_widget);
- if (BuildCompatUtils.isAtLeastS()) {
- mBackgroundOn = getContext().getDrawable(R.drawable.settingslib_switch_bar_bg_on);
- mBackgroundOff = getContext().getDrawable(R.drawable.settingslib_switch_bar_bg_off);
- mBackgroundDisabled = getContext().getDrawable(
- R.drawable.settingslib_switch_bar_bg_disabled);
- }
addOnSwitchChangeListener((switchView, isChecked) -> setChecked(isChecked));
if (mSwitch.getVisibility() == VISIBLE) {
@@ -216,17 +206,15 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
/**
* Enable or disable the text and switch.
*/
+ @Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
mTextView.setEnabled(enabled);
mSwitch.setEnabled(enabled);
if (BuildCompatUtils.isAtLeastS()) {
- if (enabled) {
- mFrameView.setBackground(isChecked() ? mBackgroundOn : mBackgroundOff);
- } else {
- mFrameView.setBackground(mBackgroundDisabled);
- }
+ mFrameView.setEnabled(enabled);
+ mFrameView.setActivated(isChecked());
}
}
@@ -243,7 +231,7 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
if (!BuildCompatUtils.isAtLeastS()) {
setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
} else {
- mFrameView.setBackground(isChecked ? mBackgroundOn : mBackgroundOff);
+ mFrameView.setActivated(isChecked);
}
}