Loading packages/SettingsLib/MainSwitchPreference/res/drawable-v31/settingslib_switch_bar_bg.xml 0 → 100644 +28 −0 Original line number Diff line number Diff line <?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> packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml +2 −1 Original line number Diff line number Diff line Loading @@ -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" Loading packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml +2 −1 Original line number Diff line number Diff line Loading @@ -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" Loading packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java +4 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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) { Loading Loading @@ -217,17 +207,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()); } } Loading @@ -244,7 +232,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); } } Loading Loading
packages/SettingsLib/MainSwitchPreference/res/drawable-v31/settingslib_switch_bar_bg.xml 0 → 100644 +28 −0 Original line number Diff line number Diff line <?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>
packages/SettingsLib/MainSwitchPreference/res/layout-v31/settingslib_main_switch_bar.xml +2 −1 Original line number Diff line number Diff line Loading @@ -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" Loading
packages/SettingsLib/MainSwitchPreference/res/layout-v33/settingslib_main_switch_bar.xml +2 −1 Original line number Diff line number Diff line Loading @@ -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" Loading
packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchBar.java +4 −16 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading Loading @@ -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) { Loading Loading @@ -217,17 +207,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()); } } Loading @@ -244,7 +232,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); } } Loading