1 /* 2 * Copyright (C) 2018 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.wifi.dpp; 18 19 import android.content.res.Resources; 20 import android.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.util.Log; 23 import android.view.View; 24 import android.widget.TextView; 25 26 import androidx.annotation.DrawableRes; 27 28 import com.android.settings.core.InstrumentedFragment; 29 30 import com.google.android.setupcompat.template.FooterBarMixin; 31 import com.google.android.setupcompat.template.FooterButton; 32 import com.google.android.setupdesign.GlifLayout; 33 34 /** 35 * There are below 4 fragments for Wi-Fi DPP UI flow, to reduce redundant code of UI components, 36 * this parent fragment instantiates common UI components 37 * 38 * {@code WifiDppQrCodeScannerFragment} 39 * {@code WifiDppQrCodeGeneratorFragment} 40 * {@code WifiDppChooseSavedWifiNetworkFragment} 41 * {@code WifiDppAddDeviceFragment} 42 */ 43 public abstract class WifiDppQrCodeBaseFragment extends InstrumentedFragment { 44 private static final String TAG = "WifiDppQrCodeBaseFragment"; 45 46 private GlifLayout mGlifLayout; 47 protected TextView mSummary; 48 protected FooterButton mLeftButton; 49 protected FooterButton mRightButton; 50 51 @Override onViewCreated(View view, Bundle savedInstanceState)52 public void onViewCreated(View view, Bundle savedInstanceState) { 53 super.onViewCreated(view, savedInstanceState); 54 55 mGlifLayout = (GlifLayout) view; 56 mSummary = view.findViewById(android.R.id.summary); 57 58 if (isFooterAvailable()) { 59 mLeftButton = new FooterButton.Builder(getContext()) 60 .setButtonType(FooterButton.ButtonType.CANCEL) 61 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary) 62 .build(); 63 mGlifLayout.getMixin(FooterBarMixin.class).setSecondaryButton(mLeftButton); 64 65 mRightButton = new FooterButton.Builder(getContext()) 66 .setButtonType(FooterButton.ButtonType.NEXT) 67 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary) 68 .build(); 69 mGlifLayout.getMixin(FooterBarMixin.class).setPrimaryButton(mRightButton); 70 } 71 72 mGlifLayout.getHeaderTextView().setAccessibilityLiveRegion( 73 View.ACCESSIBILITY_LIVE_REGION_POLITE); 74 } 75 setHeaderIconImageResource(@rawableRes int iconResId)76 protected void setHeaderIconImageResource(@DrawableRes int iconResId) { 77 mGlifLayout.setIcon(getDrawable(iconResId)); 78 } 79 getDrawable(@rawableRes int iconResId)80 private Drawable getDrawable(@DrawableRes int iconResId) { 81 Drawable buttonIcon = null; 82 83 try { 84 buttonIcon = getContext().getDrawable(iconResId); 85 } catch (Resources.NotFoundException exception) { 86 Log.e(TAG, "Resource does not exist: " + iconResId); 87 } 88 return buttonIcon; 89 } 90 setHeaderTitle(String title)91 protected void setHeaderTitle(String title) { 92 mGlifLayout.setHeaderText(title); 93 } 94 setHeaderTitle(int resId, Object... formatArgs)95 protected void setHeaderTitle(int resId, Object... formatArgs) { 96 mGlifLayout.setHeaderText(getString(resId, formatArgs)); 97 } 98 setProgressBarShown(boolean shown)99 protected void setProgressBarShown(boolean shown) { 100 mGlifLayout.setProgressBarShown(shown); 101 } 102 isFooterAvailable()103 protected abstract boolean isFooterAvailable(); 104 } 105