• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 ToggleSelectToSpeakPreferenceFragmentForSetupWizard
36         extends InvisibleToggleAccessibilityServicePreferenceFragment {
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         final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
45         final String title = getArguments().getString(AccessibilitySettings.EXTRA_TITLE);
46         final String description = getContext().getString(R.string.select_to_speak_summary);
47         final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility);
48         AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
49                 description, icon);
50 
51         final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
52         AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done, () -> {
53             setResult(RESULT_CANCELED);
54             finish();
55         });
56 
57         mToggleSwitchWasInitiallyChecked = mToggleServiceSwitchPreference.isChecked();
58         if (mTopIntroPreference != null) {
59             mTopIntroPreference.setVisible(false);
60         }
61     }
62 
63     @Override
onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)64     public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
65             Bundle savedInstanceState) {
66         final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
67         return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
68     }
69 
70     @Override
getMetricsCategory()71     public int getMetricsCategory() {
72         return SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK;
73     }
74 
75     @Override
onStop()76     public void onStop() {
77         // Log the final choice in value if it's different from the previous value.
78         if (mToggleServiceSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
79             mMetricsFeatureProvider.action(getContext(),
80                     SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK,
81                     mToggleServiceSwitchPreference.isChecked());
82         }
83 
84         super.onStop();
85     }
86 }
87