MainSwitchPreference minor fix

- Change the material switch because the oncheckchangelistener and
  onclicklistener is not register correctly
- Fix mis-used private resource in android P(28)

Bug: 198286931
Test: robotest & manual
Change-Id: If7e9c5edceb3523e84aa72ae319f8ff2b3c12812
This commit is contained in:
Edgar Wang
2021-12-23 21:36:20 +08:00
parent dd4769c8d4
commit caad2bc456
3 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
<!--
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.
-->
<!-- copy from frameworks/base/core/res/res/drawable/ic_info.xml-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/>
</vector>

View File

@@ -42,7 +42,7 @@
android:theme="@android:style/Theme.Material"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/settingslib_restricted_icon_margin_end"
android:src="@android:drawable/ic_info"
android:src="@drawable/settingslib_ic_info"
android:visibility="gone"/>
<Switch
@@ -51,6 +51,8 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/settingslib_switchbar_subsettings_margin_end"
android:focusable="false"
android:clickable="false"
android:theme="@style/SwitchBar.Switch.Settingslib"/>
</LinearLayout>

View File

@@ -30,6 +30,7 @@ import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import com.android.settingslib.utils.BuildCompatUtils;
@@ -97,6 +98,10 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
}
addOnSwitchChangeListener((switchView, isChecked) -> setChecked(isChecked));
if (mSwitch.getVisibility() == VISIBLE) {
mSwitch.setOnCheckedChangeListener(this);
}
setChecked(mSwitch.isChecked());
if (attrs != null) {
@@ -117,6 +122,12 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
propagateChecked(isChecked);
}
@Override
public void setOnClickListener(@Nullable OnClickListener l) {
super.setOnClickListener(l);
mSwitch.setOnClickListener(l);
}
@Override
public boolean performClick() {
return mSwitch.performClick();