Migrate to CompoundButton.OnCheckedChangeListener

Switch and SwitchCompat are both CompoundButton.

Using CompoundButton in Java will helps migration in the future.

Bug: 306658427
Test: manual - check Settings pages
Change-Id: If2e08a9a9557ec66a3b31ef18cd2e15943098a59
This commit is contained in:
Chaohui Wang
2023-10-24 23:48:10 +08:00
parent 86bf501829
commit 71d1f021af
49 changed files with 174 additions and 188 deletions

View File

@@ -25,7 +25,7 @@ import android.provider.Settings;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import androidx.preference.TwoStatePreference;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
@@ -79,7 +79,7 @@ public class AutoRestorePreferenceController extends TogglePreferenceController
backupManager.setAutoRestore(nextValue);
result = true;
} catch (RemoteException e) {
((SwitchPreference) mPreference).setChecked(!nextValue);
((TwoStatePreference) mPreference).setChecked(!nextValue);
Log.e(TAG, "Error can't set setAutoRestore", e);
}

View File

@@ -11,7 +11,6 @@ import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
@@ -116,8 +115,7 @@ public class ToggleBackupSettingFragment extends SettingsPreferenceFragment
mSwitchBar.setOnBeforeCheckedChangeListener(
new SettingsMainSwitchBar.OnBeforeCheckedChangeListener() {
@Override
public boolean onBeforeCheckedChanged(
Switch toggleSwitch, boolean checked) {
public boolean onBeforeCheckedChanged(boolean checked) {
if (!checked) {
// Don't change Switch status until user makes choice in dialog
// so return true here.