Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f8cb2a9 authored by Stanley Wang's avatar Stanley Wang Committed by Automerger Merge Worker
Browse files

Merge "Synchronize the states of MainSwitchBar and MainSwitchPreference." into...

Merge "Synchronize the states of MainSwitchBar and MainSwitchPreference." into sc-dev am: 4f097e34

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14580808

Change-Id: I99e7f602b2091abe1f9f8f0da6132918dbe56d16
parents c634282f 4f097e34
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.settingslib.widget">

    <uses-sdk android:minSdkVersion="21" />
    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="31"/>

</manifest>
+9 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settingslib.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.Switch;

import androidx.preference.PreferenceViewHolder;
import androidx.preference.TwoStatePreference;
@@ -31,7 +32,7 @@ import java.util.List;
 * This component is used as the main switch of the page
 * to enable or disable the prefereces on the page.
 */
public class MainSwitchPreference extends TwoStatePreference {
public class MainSwitchPreference extends TwoStatePreference implements OnMainSwitchChangeListener {

    private final List<OnMainSwitchChangeListener> mSwitchChangeListeners = new ArrayList<>();

@@ -73,7 +74,7 @@ public class MainSwitchPreference extends TwoStatePreference {

    private void init(Context context, AttributeSet attrs) {
        setLayoutResource(R.layout.settingslib_main_switch_layout);

        mSwitchChangeListeners.add(this);
        if (attrs != null) {
            final TypedArray a = context.obtainStyledAttributes(attrs,
                    androidx.preference.R.styleable.Preference, 0 /*defStyleAttr*/,
@@ -88,7 +89,7 @@ public class MainSwitchPreference extends TwoStatePreference {
    @Override
    public void setChecked(boolean checked) {
        super.setChecked(checked);
        if (mMainSwitchBar != null) {
        if (mMainSwitchBar != null && mMainSwitchBar.isChecked() != checked) {
            mMainSwitchBar.setChecked(checked);
        }
    }
@@ -101,13 +102,17 @@ public class MainSwitchPreference extends TwoStatePreference {
        }
    }

    @Override
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        super.setChecked(isChecked);
    }

    /**
     * Update the switch status of preference
     */
    public void updateStatus(boolean checked) {
        setChecked(checked);
        if (mMainSwitchBar != null) {
            mMainSwitchBar.setChecked(checked);
            mMainSwitchBar.setTitle(mTitle);
            mMainSwitchBar.show();
        }