1 /* 2 * Copyright (C) 2022 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 static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums.DIALOG_RESET_SETTINGS; 22 23 import android.app.settings.SettingsEnums; 24 import android.graphics.drawable.Drawable; 25 import android.os.Bundle; 26 import android.view.LayoutInflater; 27 import android.view.View; 28 import android.view.ViewGroup; 29 30 import androidx.recyclerview.widget.RecyclerView; 31 32 import com.android.internal.annotations.VisibleForTesting; 33 import com.android.settings.R; 34 import com.android.settingslib.Utils; 35 36 import com.google.android.setupcompat.template.FooterBarMixin; 37 import com.google.android.setupdesign.GlifPreferenceLayout; 38 39 /** 40 * A {@link androidx.preference.PreferenceFragmentCompat} that displays the settings page related 41 * to the text and reading option in the SetupWizard. 42 */ 43 public class TextReadingPreferenceFragmentForSetupWizard extends TextReadingPreferenceFragment { 44 45 @Override addPreferencesFromResource(int preferencesResId)46 public void addPreferencesFromResource(int preferencesResId) { 47 super.addPreferencesFromResource(preferencesResId); 48 49 adjustPreviewPaddingsForSetupWizard(); 50 } 51 52 @VisibleForTesting adjustPreviewPaddingsForSetupWizard()53 void adjustPreviewPaddingsForSetupWizard() { 54 TextReadingPreviewPreference textReadingPreviewPreference = findPreference(PREVIEW_KEY); 55 textReadingPreviewPreference.setLayoutMinHorizontalPadding( 56 getContext().getResources().getDimensionPixelSize( 57 R.dimen.text_reading_preview_layout_padding_horizontal_min_suw)); 58 textReadingPreviewPreference.setBackgroundMinHorizontalPadding( 59 getContext().getResources().getDimensionPixelSize( 60 R.dimen.text_reading_preview_background_padding_horizontal_min_suw)); 61 } 62 63 @Override onViewCreated(View view, Bundle savedInstanceState)64 public void onViewCreated(View view, Bundle savedInstanceState) { 65 super.onViewCreated(view, savedInstanceState); 66 67 if (view instanceof GlifPreferenceLayout) { 68 final GlifPreferenceLayout layout = (GlifPreferenceLayout) view; 69 final String title = getContext().getString( 70 R.string.accessibility_text_reading_options_title); 71 final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility); 72 icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary)); 73 AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title, 74 /* description= */ null, icon); 75 76 final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class); 77 AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done, 78 () -> { 79 setResult(RESULT_CANCELED); 80 finish(); 81 }); 82 AccessibilitySetupWizardUtils.setSecondaryButton(getContext(), mixin, 83 R.string.accessibility_text_reading_reset_button_title, 84 () -> showDialog(DIALOG_RESET_SETTINGS) 85 ); 86 } 87 } 88 89 @Override onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)90 public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, 91 Bundle savedInstanceState) { 92 if (parent instanceof GlifPreferenceLayout) { 93 final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent; 94 return layout.onCreateRecyclerView(inflater, parent, savedInstanceState); 95 } 96 return super.onCreateRecyclerView(inflater, parent, savedInstanceState); 97 } 98 99 @Override getMetricsCategory()100 public int getMetricsCategory() { 101 return SettingsEnums.SUW_ACCESSIBILITY_TEXT_READING_OPTIONS; 102 } 103 104 @Override getHelpResource()105 public int getHelpResource() { 106 // Hides help center in action bar and footer bar in SuW 107 return 0; 108 } 109 } 110