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 static android.app.Activity.RESULT_CANCELED; 20 21 import android.app.settings.SettingsEnums; 22 import android.graphics.drawable.Drawable; 23 import android.os.Bundle; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 28 import androidx.recyclerview.widget.RecyclerView; 29 30 import com.android.settings.R; 31 32 import com.google.android.setupcompat.template.FooterBarMixin; 33 import com.google.android.setupdesign.GlifPreferenceLayout; 34 35 public class ToggleScreenReaderPreferenceFragmentForSetupWizard 36 extends ToggleAccessibilityServicePreferenceFragment { 37 38 private boolean mToggleSwitchWasInitiallyChecked; 39 40 @Override onViewCreated(View view, Bundle savedInstanceState)41 public void onViewCreated(View view, Bundle savedInstanceState) { 42 super.onViewCreated(view, savedInstanceState); 43 44 if (view instanceof GlifPreferenceLayout) { 45 final GlifPreferenceLayout layout = (GlifPreferenceLayout) view; 46 final String title = getArguments().getString(AccessibilitySettings.EXTRA_TITLE); 47 final String description = getContext().getString(R.string.talkback_summary); 48 final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility); 49 AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title, 50 description, icon); 51 52 final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class); 53 AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done, 54 () -> { 55 setResult(RESULT_CANCELED); 56 finish(); 57 }); 58 } 59 60 mToggleSwitchWasInitiallyChecked = mToggleServiceSwitchPreference.isChecked(); 61 if (mTopIntroPreference != null) { 62 mTopIntroPreference.setVisible(false); 63 } 64 } 65 66 @Override onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)67 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, 68 Bundle savedInstanceState) { 69 if (parent instanceof GlifPreferenceLayout) { 70 final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent; 71 return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); 72 } 73 return super.onCreateRecyclerView(inflater, parent, savedInstanceState); 74 } 75 76 @Override getMetricsCategory()77 public int getMetricsCategory() { 78 return SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER; 79 } 80 81 @Override onStop()82 public void onStop() { 83 // Log the final choice in value if it's different from the previous value. 84 if (mToggleServiceSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) { 85 mMetricsFeatureProvider.action(getContext(), 86 SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER, 87 mToggleServiceSwitchPreference.isChecked()); 88 } 89 super.onStop(); 90 } 91 } 92