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 ToggleScreenMagnificationPreferenceFragmentForSetupWizard
36         extends ToggleScreenMagnificationPreferenceFragment {
37 
38     @Override
onViewCreated(View view, Bundle savedInstanceState)39     public void onViewCreated(View view, Bundle savedInstanceState) {
40         super.onViewCreated(view, savedInstanceState);
41 
42         if (view instanceof GlifPreferenceLayout) {
43             final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
44             final String title = getContext().getString(
45                     R.string.accessibility_screen_magnification_title);
46             final String description = getContext().getString(
47                     R.string.accessibility_screen_magnification_intro_text);
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         hidePreferenceSettingComponents();
61     }
62 
63     /**
64      * Hide the magnification preference settings in the SuW's vision settings.
65      */
hidePreferenceSettingComponents()66     private void hidePreferenceSettingComponents() {
67         // Intro
68         if (mTopIntroPreference != null) {
69             mTopIntroPreference.setVisible(false);
70         }
71         // Setting of magnification type
72         if (mSettingsPreference != null) {
73             mSettingsPreference.setVisible(false);
74         }
75     }
76 
77     @Override
onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)78     public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
79             Bundle savedInstanceState) {
80         if (parent instanceof GlifPreferenceLayout) {
81             final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
82             return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
83         }
84         return super.onCreateRecyclerView(inflater, parent, savedInstanceState);
85     }
86 
87     @Override
getMetricsCategory()88     public int getMetricsCategory() {
89         return SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION;
90     }
91 
92     @Override
onStop()93     public void onStop() {
94         // Log the final choice in value if it's different from the previous value.
95         Bundle args = getArguments();
96         if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
97             if (mToggleServiceSwitchPreference.isChecked() != args.getBoolean(
98                     AccessibilitySettings.EXTRA_CHECKED)) {
99                 // TODO: Distinguish between magnification modes
100                 mMetricsFeatureProvider.action(getContext(),
101                         SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION,
102                         mToggleServiceSwitchPreference.isChecked());
103             }
104         }
105         super.onStop();
106     }
107 
108     @Override
getHelpResource()109     public int getHelpResource() {
110         // Hides help center in action bar and footer bar in SuW
111         return 0;
112     }
113 }
114