1 /* 2 * Copyright (C) 2021 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 package com.android.settings.accessibility; 17 18 import android.content.Context; 19 import android.graphics.drawable.Drawable; 20 import android.widget.LinearLayout; 21 22 import androidx.annotation.StringRes; 23 24 import com.android.settings.R; 25 26 import com.google.android.setupcompat.template.FooterBarMixin; 27 import com.google.android.setupcompat.template.FooterButton; 28 import com.google.android.setupcompat.template.Mixin; 29 import com.google.android.setupdesign.GlifPreferenceLayout; 30 import com.google.android.setupdesign.util.ThemeHelper; 31 32 /** Provides utility methods to accessibility settings for Setup Wizard only. */ 33 class AccessibilitySetupWizardUtils { 34 AccessibilitySetupWizardUtils()35 private AccessibilitySetupWizardUtils(){} 36 37 /** 38 * Updates the {@link GlifPreferenceLayout} attributes if they have previously been initialized. 39 * When the SetupWizard supports the extended partner configs, it means the material layout 40 * would be applied. It should set a different padding/margin in views to align Settings style 41 * for accessibility feature pages. 42 * 43 * @param layout The layout instance 44 * @param title The text to be set as title 45 * @param description The text to be set as description 46 * @param icon The icon to be set 47 */ updateGlifPreferenceLayout(Context context, GlifPreferenceLayout layout, CharSequence title, CharSequence description, Drawable icon)48 public static void updateGlifPreferenceLayout(Context context, GlifPreferenceLayout layout, 49 CharSequence title, CharSequence description, Drawable icon) { 50 layout.setHeaderText(title); 51 layout.setDescriptionText(description); 52 layout.setIcon(icon); 53 layout.setDividerInsets(Integer.MAX_VALUE, 0); 54 55 if (ThemeHelper.shouldApplyMaterialYouStyle(context)) { 56 final LinearLayout headerLayout = layout.findManagedViewById(R.id.sud_layout_header); 57 if (headerLayout != null) { 58 headerLayout.setPadding(0, layout.getPaddingTop(), 0, 59 layout.getPaddingBottom()); 60 } 61 } 62 } 63 64 /** 65 * Sets primary button for footer of the {@link GlifPreferenceLayout}. 66 * 67 * <p> This will be the initial by given material theme style. 68 * 69 * @param context A {@link Context} 70 * @param mixin A {@link Mixin} for managing buttons. 71 * @param text The {@code text} by resource. 72 * @param runnable The {@link Runnable} to run. 73 */ setPrimaryButton(Context context, FooterBarMixin mixin, @StringRes int text, Runnable runnable)74 public static void setPrimaryButton(Context context, FooterBarMixin mixin, @StringRes int text, 75 Runnable runnable) { 76 mixin.setPrimaryButton( 77 new FooterButton.Builder(context) 78 .setText(text) 79 .setListener(l -> runnable.run()) 80 .setButtonType(FooterButton.ButtonType.DONE) 81 .setTheme(R.style.SudGlifButton_Primary) 82 .build()); 83 } 84 85 /** 86 * Sets secondary button for the footer of the {@link GlifPreferenceLayout}. 87 * 88 * <p> This will be the initial by given material theme style. 89 * 90 * @param context A {@link Context} 91 * @param mixin A {@link Mixin} for managing buttons. 92 * @param text The {@code text} by resource. 93 * @param runnable The {@link Runnable} to run. 94 */ setSecondaryButton(Context context, FooterBarMixin mixin, @StringRes int text, Runnable runnable)95 public static void setSecondaryButton(Context context, FooterBarMixin mixin, 96 @StringRes int text, Runnable runnable) { 97 mixin.setSecondaryButton( 98 new FooterButton.Builder(context) 99 .setText(text) 100 .setListener(l -> runnable.run()) 101 .setButtonType(FooterButton.ButtonType.CLEAR) 102 .setTheme(R.style.SudGlifButton_Secondary) 103 .build()); 104 } 105 } 106