Files
packages_apps_Settings/src/com/android/settings/accessibility/MagnificationGesturesPreferenceController.java
Arc Wang 1596a2838d Allow Magnification Settings launch from outside of AccessibilitySettings
Before this CL, Magnification Settings can only be
launched from MagnificationPreferenceController.

This CL initializes FooterPreferenceController if the
parent class does not initialize it from Intent extras.

Bug: 268411305
Test: manual
      make RunSettingsRoboTests ROBOTEST_FILTER=MagnificationGesturesPreferenceControllerTest
      make RunSettingsRoboTests ROBOTEST_FILTER=ToggleScreenMagnificationPreferenceFragmentTest
Change-Id: I954739c39c823ce7fe0daa711743f729d182571b
2023-02-24 15:56:43 +08:00

105 lines
3.5 KiB
Java

/*
* Copyright (C) 2018 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.
*/
package com.android.settings.accessibility;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class MagnificationGesturesPreferenceController extends TogglePreferenceController {
private boolean mIsFromSUW = false;
public MagnificationGesturesPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return MagnificationPreferenceFragment.isChecked(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
}
@Override
public boolean setChecked(boolean isChecked) {
return MagnificationPreferenceFragment.setChecked(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, isChecked);
}
public void setIsFromSUW(boolean fromSUW) {
mIsFromSUW = fromSUW;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
Bundle extras = preference.getExtras();
populateMagnificationGesturesPreferenceExtras(extras, mContext);
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked());
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
return true;
}
return false;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(),
"screen_magnification_gestures_preference_screen");
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
@Override
public CharSequence getSummary() {
int resId = 0;
if (mIsFromSUW) {
resId = R.string.accessibility_screen_magnification_short_summary;
} else {
final boolean enabled = isChecked();
resId = (enabled ? R.string.on : R.string.off);
}
return mContext.getString(resId);
}
static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) {
// TODO(b/270481978): It seems not necessary to put EXTRA_TITLE_RES.
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
R.string.accessibility_screen_magnification_gestures_title);
// TODO(b/270481978): It seems not necessary to put EXTRA_VIDEO_RAW_RESOURCE_ID.
extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
R.raw.accessibility_screen_magnification);
}
}