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.os.Bundle; 20 import android.view.Menu; 21 import android.view.accessibility.AccessibilityEvent; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceFragmentCompat; 25 26 import com.android.settings.R; 27 import com.android.settings.SettingsActivity; 28 import com.android.settings.SetupWizardUtils; 29 import com.android.settings.core.SubSettingLauncher; 30 import com.android.settings.search.actionbar.SearchMenuController; 31 import com.android.settings.support.actionbar.HelpResourceProvider; 32 import com.android.settingslib.core.instrumentation.Instrumentable; 33 34 import com.google.android.setupcompat.util.WizardManagerHelper; 35 import com.google.android.setupdesign.util.ThemeHelper; 36 37 public class AccessibilitySettingsForSetupWizardActivity extends SettingsActivity { 38 39 private static final String SAVE_KEY_TITLE = "activity_title"; 40 41 @Override onSaveInstanceState(Bundle savedState)42 protected void onSaveInstanceState(Bundle savedState) { 43 savedState.putCharSequence(SAVE_KEY_TITLE, getTitle()); 44 super.onSaveInstanceState(savedState); 45 } 46 47 @Override onRestoreInstanceState(Bundle savedState)48 protected void onRestoreInstanceState(Bundle savedState) { 49 super.onRestoreInstanceState(savedState); 50 setTitle(savedState.getCharSequence(SAVE_KEY_TITLE)); 51 } 52 53 @Override onCreateOptionsMenu(Menu menu)54 public boolean onCreateOptionsMenu(Menu menu) { 55 // Return true, so we get notified when items in the menu are clicked. 56 return true; 57 } 58 59 @Override onNavigateUp()60 public boolean onNavigateUp() { 61 onBackPressed(); 62 63 // Clear accessibility focus and let the screen reader announce the new title. 64 getWindow().getDecorView() 65 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); 66 67 return true; 68 } 69 70 @Override onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref)71 public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) { 72 Bundle args = pref.getExtras(); 73 if (args == null) { 74 args = new Bundle(); 75 } 76 args.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 0); 77 args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false); 78 new SubSettingLauncher(this) 79 .setDestination(pref.getFragment()) 80 .setArguments(args) 81 .setSourceMetricsCategory(caller instanceof Instrumentable 82 ? ((Instrumentable) caller).getMetricsCategory() 83 : Instrumentable.METRICS_CATEGORY_UNKNOWN) 84 .setExtras(SetupWizardUtils.copyLifecycleExtra(getIntent().getExtras(), 85 new Bundle())) 86 .launch(); 87 return true; 88 } 89 90 @Override onCreate(Bundle savedState)91 protected void onCreate(Bundle savedState) { 92 super.onCreate(savedState); 93 applyTheme(); 94 findViewById(R.id.content_parent).setFitsSystemWindows(false); 95 } 96 applyTheme()97 private void applyTheme() { 98 final boolean isAnySetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent()); 99 if (isAnySetupWizard) { 100 setTheme(SetupWizardUtils.getTheme(this, getIntent())); 101 setTheme(R.style.SettingsPreferenceTheme_SetupWizard); 102 ThemeHelper.trySetDynamicColor(this); 103 } 104 } 105 } 106