Convert Magnify controller to TogglePrefController

Convert below to TogglePreferenceController:
MagnificationNavbarPreferenceController
(Magnify with Button)
MagnificationGesturesPreferenceController
(Magnify with triple-tap)

The two controllers share the same fragment,
Add static method for set/get state in fragment,
And use them in controllers and fragment.

Change-Id: I2bdbdb36be71e1a3ffb557abc5a6115d48de53cf
Fixes: 67997698
Fixes: 67997726
Test: make RunSettingsRoboTests
This commit is contained in:
hjchangliao
2018-05-02 16:57:20 +08:00
parent 5de68ea81a
commit 2f73a6646f
8 changed files with 135 additions and 29 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.accessibility;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
@@ -38,10 +39,15 @@ import com.android.settingslib.search.SearchIndexable;
import java.util.Arrays;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@SearchIndexable
public final class MagnificationPreferenceFragment extends DashboardFragment {
@VisibleForTesting
static final int ON = 1;
@VisibleForTesting
static final int OFF = 0;
private static final String TAG = "MagnificationPreferenceFragment";
@@ -135,6 +141,15 @@ public final class MagnificationPreferenceFragment extends DashboardFragment {
return null;
}
static boolean isChecked(ContentResolver contentResolver, String settingsKey) {
return Settings.Secure.getInt(contentResolver, settingsKey, OFF) == ON;
}
static boolean setChecked(ContentResolver contentResolver, String settingsKey,
boolean isChecked) {
return Settings.Secure.putInt(contentResolver, settingsKey, isChecked ? ON : OFF);
}
/**
* @return {@code true} if this fragment should be shown, {@code false} otherwise. This
* fragment is shown in the case that more than one magnification mode is available.