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 package com.android.settings.biometrics2.ui.view
17 
18 import android.content.Context
19 import android.os.Bundle
20 import android.view.LayoutInflater
21 import android.view.View
22 import android.view.ViewGroup
23 import androidx.fragment.app.Fragment
24 import androidx.fragment.app.FragmentActivity
25 import androidx.lifecycle.ViewModelProvider
26 import com.airbnb.lottie.LottieAnimationView
27 import com.android.settings.R
28 import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel
29 import com.google.android.setupcompat.template.FooterBarMixin
30 import com.google.android.setupcompat.template.FooterButton
31 import com.google.android.setupdesign.GlifLayout
32 
33 /**
34  * Fragment explaining the under-display fingerprint sensor location for fingerprint enrollment.
35  * It interacts with Primary button, and LottieAnimationView.
36  * <pre>
37  * | Has                 | UDFPS | SFPS | Other (Rear FPS) |
38  * |---------------------|-------|------|------------------|
39  * | Primary button      | Yes   | No   | No               |
40  * | Illustration Lottie | Yes   | Yes  | No               |
41  * | Animation           | No    | No   | Depend on layout |
42  * | Progress ViewModel  | No    | Yes  | Yes              |
43  * | Orientation detect  | No    | Yes  | No               |
44  * | Foldable detect     | No    | Yes  | No               |
45  * </pre>
46  */
47 class FingerprintEnrollFindUdfpsFragment : Fragment() {
48 
49     private var _viewModel: FingerprintEnrollFindSensorViewModel? = null
50     private val mViewModel: FingerprintEnrollFindSensorViewModel
51         get() = _viewModel!!
52 
53     private var findUdfpsView: GlifLayout? = null
54 
55     private val mOnSkipClickListener =
56         View.OnClickListener { _: View? -> mViewModel.onSkipButtonClick() }
57 
58     private val mOnStartClickListener =
59         View.OnClickListener { _: View? -> mViewModel.onStartButtonClick() }
60 
61     override fun onCreateView(
62         inflater: LayoutInflater, container: ViewGroup?,
63         savedInstanceState: Bundle?
64     ): View = (inflater.inflate(
65         R.layout.udfps_enroll_find_sensor_layout,
66         container,
67         false
68     ) as GlifLayout).also {
69         findUdfpsView = it
70     }
71 
72     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
73         super.onViewCreated(view, savedInstanceState)
74         requireActivity().bindFingerprintEnrollFindUdfpsView(
75             view = findUdfpsView!!,
76             isAccessibilityEnabled = mViewModel.isAccessibilityEnabled,
77             onSkipClickListener = mOnSkipClickListener,
78             onStartClickListener = mOnStartClickListener
79         )
80     }
81 
82     override fun onAttach(context: Context) {
83         _viewModel = ViewModelProvider(requireActivity())[
84             FingerprintEnrollFindSensorViewModel::class.java
85         ]
86         super.onAttach(context)
87     }
88 }
89 
FragmentActivitynull90 fun FragmentActivity.bindFingerprintEnrollFindUdfpsView(
91     view: GlifLayout,
92     isAccessibilityEnabled: Boolean,
93     onSkipClickListener: View.OnClickListener,
94     onStartClickListener: View.OnClickListener,
95 ) {
96     GlifLayoutHelper(this, view).let { helper ->
97         helper.setHeaderText(R.string.security_settings_udfps_enroll_find_sensor_title)
98         helper.setDescriptionText(
99             getText(R.string.security_settings_udfps_enroll_find_sensor_message)
100         )
101     }
102 
103     view.getMixin(FooterBarMixin::class.java)!!.let {
104         it.secondaryButton = FooterButton.Builder(this)
105             .setText(R.string.security_settings_fingerprint_enroll_enrolling_skip)
106             .setButtonType(FooterButton.ButtonType.SKIP)
107             .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary)
108             .build()
109         it.secondaryButton.setOnClickListener(onSkipClickListener)
110 
111         it.primaryButton = FooterButton.Builder(this)
112             .setText(R.string.security_settings_udfps_enroll_find_sensor_start_button)
113             .setButtonType(FooterButton.ButtonType.NEXT)
114             .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary)
115             .build()
116         it.primaryButton.setOnClickListener(onStartClickListener)
117     }
118 
119     view.findViewById<LottieAnimationView>(R.id.illustration_lottie)!!.let {
120         it.setOnClickListener(onStartClickListener)
121         if (isAccessibilityEnabled) {
122             it.setAnimation(R.raw.udfps_edu_a11y_lottie)
123         }
124     }
125 }