diff --git a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingErrorDialog.kt b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingErrorDialog.kt index 6fa22d7f633..8fb1118d6f2 100644 --- a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingErrorDialog.kt +++ b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingErrorDialog.kt @@ -37,22 +37,19 @@ class FingerprintEnrollEnrollingErrorDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val value = mViewModel!!.errorDialogLiveData.value!! - return AlertDialog.Builder(requireActivity()) - .setTitle(value.errTitle) - .setMessage(value.errMsg) - .setCancelable(false) - .setPositiveButton( - R.string.security_settings_fingerprint_enroll_dialog_ok - ) { dialog: DialogInterface, _: Int -> - dialog.dismiss() - mViewModel?.onErrorDialogAction( - if (value.errMsgId == BiometricConstants.BIOMETRIC_ERROR_TIMEOUT) - FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_TIMEOUT - else - FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH) - } - .create() - .apply { setCanceledOnTouchOutside(false) } + return requireActivity().bindFingerprintEnrollEnrollingErrorDialog( + title = value.errTitle, + message = value.errMsg, + positiveButtonClickListener = { dialog: DialogInterface?, _: Int -> + dialog?.dismiss() + mViewModel?.onErrorDialogAction( + if (value.errMsgId == BiometricConstants.BIOMETRIC_ERROR_TIMEOUT) + FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_TIMEOUT + else + FINGERPRINT_ERROR_DIALOG_ACTION_SET_RESULT_FINISH + ) + } + ) } override fun onAttach(context: Context) { @@ -61,3 +58,18 @@ class FingerprintEnrollEnrollingErrorDialog : DialogFragment() { super.onAttach(context) } } + +fun Context.bindFingerprintEnrollEnrollingErrorDialog( + title: CharSequence?, + message: CharSequence?, + positiveButtonClickListener: DialogInterface.OnClickListener +): AlertDialog = AlertDialog.Builder(this) + .setTitle(title) + .setMessage(message) + .setCancelable(false) + .setPositiveButton( + R.string.security_settings_fingerprint_enroll_dialog_ok, + positiveButtonClickListener + ) + .create() + .apply { setCanceledOnTouchOutside(false) } \ No newline at end of file diff --git a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingIconTouchDialog.java b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingIconTouchDialog.java deleted file mode 100644 index f4fe7ff9b87..00000000000 --- a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingIconTouchDialog.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.biometrics2.ui.view; - -import android.app.Dialog; -import android.app.settings.SettingsEnums; -import android.os.Bundle; - -import androidx.appcompat.app.AlertDialog; - -import com.android.settings.R; -import com.android.settings.core.instrumentation.InstrumentedDialogFragment; - -/** - * Icon Touch dialog - */ -public class FingerprintEnrollEnrollingIconTouchDialog extends InstrumentedDialogFragment { - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), - R.style.Theme_AlertDialog); - builder.setTitle(R.string.security_settings_fingerprint_enroll_touch_dialog_title) - .setMessage(R.string.security_settings_fingerprint_enroll_touch_dialog_message) - .setPositiveButton( - R.string.security_settings_fingerprint_enroll_dialog_ok, - (dialog, which) -> dialog.dismiss()); - return builder.create(); - } - - @Override - public int getMetricsCategory() { - return SettingsEnums.DIALOG_FINGERPRINT_ICON_TOUCH; - } -} diff --git a/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingIconTouchDialog.kt b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingIconTouchDialog.kt new file mode 100644 index 00000000000..9f99d173fb2 --- /dev/null +++ b/src/com/android/settings/biometrics2/ui/view/FingerprintEnrollEnrollingIconTouchDialog.kt @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.biometrics2.ui.view + +import android.app.Dialog +import android.content.Context +import android.content.DialogInterface +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import com.android.settings.R + +/** + * Icon Touch dialog + */ +class FingerprintEnrollEnrollingIconTouchDialog : DialogFragment() { + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = + requireActivity().bindFingerprintEnrollEnrollingIconTouchDialog() +} + +fun Context.bindFingerprintEnrollEnrollingIconTouchDialog(): AlertDialog = + AlertDialog.Builder(this, R.style.Theme_AlertDialog) + .setTitle(R.string.security_settings_fingerprint_enroll_touch_dialog_title) + .setMessage(R.string.security_settings_fingerprint_enroll_touch_dialog_message) + .setPositiveButton(R.string.security_settings_fingerprint_enroll_dialog_ok) { + dialog: DialogInterface?, _: Int -> dialog?.dismiss() + } + .create() \ No newline at end of file diff --git a/src/com/android/settings/biometrics2/ui/view/GlifLayoutHelper.java b/src/com/android/settings/biometrics2/ui/view/GlifLayoutHelper.java deleted file mode 100644 index 6af4928fc2a..00000000000 --- a/src/com/android/settings/biometrics2/ui/view/GlifLayoutHelper.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.biometrics2.ui.view; - -import android.app.Activity; -import android.text.TextUtils; -import android.view.View; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.annotation.StringRes; - -import com.google.android.setupdesign.GlifLayout; - -/** - * Utils class for GlifLayout - */ -public class GlifLayoutHelper { - - @NonNull private final Activity mActivity; - @NonNull private final GlifLayout mGlifLayout; - - public GlifLayoutHelper(@NonNull Activity activity, @NonNull GlifLayout glifLayout) { - mActivity = activity; - mGlifLayout = glifLayout; - } - - /** - * Sets header text to GlifLayout - */ - public void setHeaderText(@StringRes int textResId) { - TextView layoutTitle = mGlifLayout.getHeaderTextView(); - CharSequence previousTitle = layoutTitle.getText(); - CharSequence title = mActivity.getText(textResId); - if (previousTitle != title) { - if (!TextUtils.isEmpty(previousTitle)) { - layoutTitle.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE); - } - mGlifLayout.setHeaderText(title); - mGlifLayout.getHeaderTextView().setContentDescription(title); - mActivity.setTitle(title); - } - mGlifLayout.getHeaderTextView().setContentDescription(title); - } - - /** - * Sets description text to GlifLayout - */ - public void setDescriptionText(CharSequence description) { - CharSequence previousDescription = mGlifLayout.getDescriptionText(); - // Prevent a11y for re-reading the same string - if (!TextUtils.equals(previousDescription, description)) { - mGlifLayout.setDescriptionText(description); - } - } - - @NonNull - public Activity getActivity() { - return mActivity; - } - - @NonNull - public GlifLayout getGlifLayout() { - return mGlifLayout; - } -} diff --git a/src/com/android/settings/biometrics2/ui/view/GlifLayoutHelper.kt b/src/com/android/settings/biometrics2/ui/view/GlifLayoutHelper.kt new file mode 100644 index 00000000000..756f309cf56 --- /dev/null +++ b/src/com/android/settings/biometrics2/ui/view/GlifLayoutHelper.kt @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.biometrics2.ui.view + +import android.app.Activity +import android.text.TextUtils +import android.view.View +import androidx.annotation.StringRes +import com.google.android.setupdesign.GlifLayout + +/** + * Utils class for GlifLayout + */ +class GlifLayoutHelper(val activity: Activity, val glifLayout: GlifLayout) { + + /** + * Sets header text to GlifLayout + */ + fun setHeaderText(@StringRes textResId: Int) { + val layoutTitle = glifLayout.headerTextView + val previousTitle = layoutTitle.text + val title = activity.getText(textResId) + if (previousTitle !== title) { + if (!TextUtils.isEmpty(previousTitle)) { + layoutTitle.accessibilityLiveRegion = View.ACCESSIBILITY_LIVE_REGION_POLITE + } + glifLayout.headerText = title + glifLayout.headerTextView.contentDescription = title + activity.title = title + } + } + + /** + * Sets description text to GlifLayout + */ + fun setDescriptionText(description: CharSequence?) { + val previousDescription = glifLayout.descriptionText + // Prevent a11y for re-reading the same string + if (!TextUtils.equals(previousDescription, description)) { + glifLayout.descriptionText = description + } + } +} diff --git a/src/com/android/settings/biometrics2/ui/view/SkipSetupFindFpsDialog.java b/src/com/android/settings/biometrics2/ui/view/SkipSetupFindFpsDialog.java deleted file mode 100644 index b011267c1b2..00000000000 --- a/src/com/android/settings/biometrics2/ui/view/SkipSetupFindFpsDialog.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.biometrics2.ui.view; - -import static android.content.DialogInterface.OnClickListener; - -import android.app.Dialog; -import android.app.settings.SettingsEnums; -import android.content.Context; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.lifecycle.ViewModelProvider; - -import com.android.settings.R; -import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel; -import com.android.settings.core.instrumentation.InstrumentedDialogFragment; - -/** - * Skip dialog which shows when user clicks "Do it later" button in FingerprintFindSensor page. - */ -public class SkipSetupFindFpsDialog extends InstrumentedDialogFragment { - - private FingerprintEnrollFindSensorViewModel mViewModel; - private final OnClickListener mOnSkipClickListener = - (d, w) -> mViewModel.onSkipDialogButtonClick(); - - @Override - public int getMetricsCategory() { - return SettingsEnums.DIALOG_FINGERPRINT_SKIP_SETUP; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - return onCreateDialogBuilder().create(); - } - - /** - * Returns builder for this dialog - */ - @NonNull - private AlertDialog.Builder onCreateDialogBuilder() { - return new AlertDialog.Builder(getActivity(), R.style.Theme_AlertDialog) - .setTitle(R.string.setup_fingerprint_enroll_skip_title) - .setPositiveButton(R.string.skip_anyway_button_label, mOnSkipClickListener) - .setNegativeButton(R.string.go_back_button_label, null) - .setMessage(R.string.setup_fingerprint_enroll_skip_after_adding_lock_text); - } - - @Override - public void onAttach(Context context) { - mViewModel = new ViewModelProvider(getActivity()).get( - FingerprintEnrollFindSensorViewModel.class); - super.onAttach(context); - } -} diff --git a/src/com/android/settings/biometrics2/ui/view/SkipSetupFindFpsDialog.kt b/src/com/android/settings/biometrics2/ui/view/SkipSetupFindFpsDialog.kt new file mode 100644 index 00000000000..bb74e360778 --- /dev/null +++ b/src/com/android/settings/biometrics2/ui/view/SkipSetupFindFpsDialog.kt @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.biometrics2.ui.view + +import android.app.Dialog +import android.content.Context +import android.content.DialogInterface +import android.os.Bundle +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment +import androidx.lifecycle.ViewModelProvider +import com.android.settings.R +import com.android.settings.biometrics2.ui.viewmodel.FingerprintEnrollFindSensorViewModel + +/** + * Skip dialog which shows when user clicks "Do it later" button in FingerprintFindSensor page. + */ +class SkipSetupFindFpsDialog : DialogFragment() { + + private var mViewModel: FingerprintEnrollFindSensorViewModel? = null + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = + requireActivity().bindSkipSetupFindFpsDialog { + _: DialogInterface?, _: Int -> mViewModel?.onSkipDialogButtonClick() + } + + override fun onAttach(context: Context) { + mViewModel = ViewModelProvider(requireActivity())[ + FingerprintEnrollFindSensorViewModel::class.java + ] + super.onAttach(context) + } +} + +fun Context.bindSkipSetupFindFpsDialog( + positiveButtonClickListener: DialogInterface.OnClickListener +): AlertDialog = + AlertDialog.Builder(this, R.style.Theme_AlertDialog) + .setTitle(R.string.setup_fingerprint_enroll_skip_title) + .setPositiveButton(R.string.skip_anyway_button_label, positiveButtonClickListener) + .setNegativeButton(R.string.go_back_button_label, null) + .setMessage(R.string.setup_fingerprint_enroll_skip_after_adding_lock_text) + .create()