1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.accessibility; 18 19 import android.content.ComponentName; 20 import android.os.Bundle; 21 import android.util.Log; 22 import android.view.Menu; 23 import android.view.accessibility.AccessibilityEvent; 24 25 import androidx.annotation.VisibleForTesting; 26 import androidx.preference.Preference; 27 import androidx.preference.PreferenceFragmentCompat; 28 29 import com.android.settings.SettingsActivity; 30 import com.android.settings.SetupWizardUtils; 31 import com.android.settings.core.SubSettingLauncher; 32 import com.android.settings.display.FontSizePreferenceFragmentForSetupWizard; 33 import com.android.settings.search.actionbar.SearchMenuController; 34 import com.android.settings.support.actionbar.HelpResourceProvider; 35 import com.android.settingslib.core.instrumentation.Instrumentable; 36 37 import com.google.android.setupcompat.util.WizardManagerHelper; 38 39 public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivity { 40 41 private static final String LOG_TAG = "A11ySettingsForSUW"; 42 private static final String SAVE_KEY_TITLE = "activity_title"; 43 44 @VisibleForTesting 45 static final String CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW = 46 "com.android.settings.FontSizeSettingsForSetupWizardActivity"; 47 48 @Override onSaveInstanceState(Bundle savedState)49 protected void onSaveInstanceState(Bundle savedState) { 50 savedState.putCharSequence(SAVE_KEY_TITLE, getTitle()); 51 super.onSaveInstanceState(savedState); 52 } 53 54 @Override onRestoreInstanceState(Bundle savedState)55 protected void onRestoreInstanceState(Bundle savedState) { 56 super.onRestoreInstanceState(savedState); 57 setTitle(savedState.getCharSequence(SAVE_KEY_TITLE)); 58 } 59 60 @Override onCreateOptionsMenu(Menu menu)61 public boolean onCreateOptionsMenu(Menu menu) { 62 // Return true, so we get notified when items in the menu are clicked. 63 return true; 64 } 65 66 @Override onNavigateUp()67 public boolean onNavigateUp() { 68 onBackPressed(); 69 70 // Clear accessibility focus and let the screen reader announce the new title. 71 getWindow().getDecorView() 72 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); 73 74 return true; 75 } 76 77 @Override onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref)78 public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) { 79 Bundle args = pref.getExtras(); 80 if (args == null) { 81 args = new Bundle(); 82 } 83 args.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 0); 84 args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false); 85 new SubSettingLauncher(this) 86 .setDestination(pref.getFragment()) 87 .setArguments(args) 88 .setSourceMetricsCategory(caller instanceof Instrumentable 89 ? ((Instrumentable) caller).getMetricsCategory() 90 : Instrumentable.METRICS_CATEGORY_UNKNOWN) 91 .launch(); 92 return true; 93 } 94 95 @Override onCreate(Bundle savedState)96 protected void onCreate(Bundle savedState) { 97 super.onCreate(savedState); 98 99 tryLaunchFontSizeSettings(); 100 } 101 102 @VisibleForTesting tryLaunchFontSizeSettings()103 void tryLaunchFontSizeSettings() { 104 if (WizardManagerHelper.isAnySetupWizard(getIntent()) 105 && new ComponentName(getPackageName(), 106 CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW).equals( 107 getIntent().getComponent())) { 108 final Bundle args = new Bundle(); 109 args.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 0); 110 args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false); 111 final SubSettingLauncher subSettingLauncher = new SubSettingLauncher(this) 112 .setDestination(FontSizePreferenceFragmentForSetupWizard.class.getName()) 113 .setArguments(args) 114 .setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN) 115 .setExtras(SetupWizardUtils.copyLifecycleExtra(getIntent().getExtras(), 116 new Bundle())); 117 118 Log.d(LOG_TAG, "Launch font size settings"); 119 subSettingLauncher.launch(); 120 finish(); 121 } 122 } 123 } 124