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.text.TextUtils; 21 import android.widget.LinearLayout; 22 23 import androidx.annotation.Nullable; 24 import androidx.annotation.StringRes; 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.setupcompat.util.ForceTwoPaneHelper; 30 import com.google.android.setupdesign.GlifPreferenceLayout; 31 import com.google.android.setupdesign.R; 32 import com.google.android.setupdesign.util.ThemeHelper; 33 34 /** Provides utility methods to accessibility settings for Setup Wizard only. */ 35 public class AccessibilitySetupWizardUtils { 36 AccessibilitySetupWizardUtils()37 private AccessibilitySetupWizardUtils(){} 38 39 /** 40 * Updates the {@link GlifPreferenceLayout} attributes if they have previously been initialized. 41 * When the SetupWizard supports the extended partner configs, it means the material layout 42 * would be applied. It should set a different padding/margin in views to align Settings style 43 * for accessibility feature pages. 44 * 45 * @param layout The layout instance 46 * @param title The text to be set as title 47 * @param description The text to be set as description 48 * @param icon The icon to be set 49 */ updateGlifPreferenceLayout(Context context, GlifPreferenceLayout layout, @Nullable CharSequence title, @Nullable CharSequence description, @Nullable Drawable icon)50 public static void updateGlifPreferenceLayout(Context context, GlifPreferenceLayout layout, 51 @Nullable CharSequence title, @Nullable CharSequence description, 52 @Nullable Drawable icon) { 53 if (!TextUtils.isEmpty(title)) { 54 layout.setHeaderText(title); 55 } 56 57 if (!TextUtils.isEmpty(description)) { 58 layout.setDescriptionText(description); 59 } 60 61 if (icon != null) { 62 layout.setIcon(icon); 63 } 64 layout.setDividerInsets(Integer.MAX_VALUE, 0); 65 66 if (ThemeHelper.shouldApplyMaterialYouStyle(context)) { 67 // For b/323771329#comment26, if the layout is forced-two-pan, we should not adjust the 68 // headerLayout horizontal padding to 0, which will make an unexpected large padding on 69 // two-pane layout. 70 // TODO: This is just a short-term quick workaround for force-two-pane devices padding 71 // issue. The long-term goal here is to remove the header padding adjustment since it 72 // should be handled in setup design lib. (b/331878747) 73 if (ForceTwoPaneHelper.shouldForceTwoPane(context)) { 74 return; 75 } 76 77 final LinearLayout headerLayout = layout.findManagedViewById(R.id.sud_layout_header); 78 if (headerLayout != null) { 79 headerLayout.setPadding(0, layout.getPaddingTop(), 0, 80 layout.getPaddingBottom()); 81 } 82 } 83 } 84 85 /** 86 * Sets primary button for 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 */ setPrimaryButton(Context context, FooterBarMixin mixin, @StringRes int text, Runnable runnable)95 public static void setPrimaryButton(Context context, FooterBarMixin mixin, @StringRes int text, 96 Runnable runnable) { 97 mixin.setPrimaryButton( 98 new FooterButton.Builder(context) 99 .setText(text) 100 .setListener(l -> runnable.run()) 101 .setButtonType(FooterButton.ButtonType.DONE) 102 .setTheme(R.style.SudGlifButton_Primary) 103 .build()); 104 } 105 106 /** 107 * Sets secondary button for the footer of the {@link GlifPreferenceLayout}. 108 * 109 * <p> This will be the initial by given material theme style. 110 * 111 * @param context A {@link Context} 112 * @param mixin A {@link Mixin} for managing buttons. 113 * @param text The {@code text} by resource. 114 * @param runnable The {@link Runnable} to run. 115 */ setSecondaryButton(Context context, FooterBarMixin mixin, @StringRes int text, Runnable runnable)116 public static void setSecondaryButton(Context context, FooterBarMixin mixin, 117 @StringRes int text, Runnable runnable) { 118 mixin.setSecondaryButton( 119 new FooterButton.Builder(context) 120 .setText(text) 121 .setListener(l -> runnable.run()) 122 .setButtonType(FooterButton.ButtonType.CLEAR) 123 .setTheme(R.style.SudGlifButton_Secondary) 124 .build()); 125 } 126 } 127