1 /* <lambda>null2 * Copyright (C) 2023 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.remoteauth 18 19 import android.R 20 import android.graphics.Color 21 import android.os.Bundle 22 import android.view.LayoutInflater 23 import android.view.View 24 import android.view.ViewGroup 25 import androidx.annotation.ColorInt 26 import androidx.annotation.IdRes 27 import androidx.annotation.LayoutRes 28 import androidx.fragment.app.Fragment 29 30 import com.android.settings.Utils 31 import com.google.android.setupcompat.template.FooterBarMixin 32 import com.google.android.setupcompat.template.FooterButton 33 import com.google.android.setupdesign.GlifLayout 34 35 /** 36 * Displays a content view with a sticky footer in the SetupDesign style. Implementations 37 * must define a primary button, and an optional secondary button. 38 * 39 * A layout with a [GlifLayout] must be provided, along with the id of the [GlifLayout]. 40 */ 41 abstract class RemoteAuthEnrollBase( 42 @LayoutRes val layoutResId: Int, 43 @IdRes private val glifLayoutId: Int 44 ) : Fragment(layoutResId) { 45 protected val primaryFooterButton by lazy { initializePrimaryFooterButton() } 46 protected val secondaryFooterButton by lazy { initializeSecondaryFooterButton() } 47 48 override fun onCreateView( 49 inflater: LayoutInflater, 50 viewGroup: ViewGroup?, 51 savedInstanceArgs: Bundle? 52 ) = 53 super.onCreateView(inflater, viewGroup, savedInstanceArgs)!!.also { view -> 54 initializeFooterbarMixin(view) 55 } 56 57 protected fun getGlifLayout(view: View) = view.findViewById<GlifLayout>(glifLayoutId) 58 59 /** 60 * Return a button will be used as the primary footer button. 61 */ 62 abstract fun initializePrimaryFooterButton(): FooterButton 63 64 /** If non-null, returned button will be used as the secondary footer button. */ 65 abstract fun initializeSecondaryFooterButton(): FooterButton? 66 67 private fun initializeFooterbarMixin(view: View) { 68 val footerBarMixin = checkNotNull(getGlifLayout(view)).getMixin(FooterBarMixin::class.java) 69 primaryFooterButton.also { footerBarMixin.primaryButton = it } 70 secondaryFooterButton?.also { footerBarMixin.secondaryButton = it } 71 footerBarMixin.getButtonContainer().setBackgroundColor(getBackgroundColor()) 72 } 73 74 @ColorInt 75 private fun getBackgroundColor(): Int { 76 val stateList = Utils.getColorAttr(context, R.attr.windowBackground) 77 return stateList?.defaultColor ?: Color.TRANSPARENT 78 } 79 80 private companion object{ 81 const val TAG = "RemoteAuthEnrollBase" 82 } 83 } 84