1 /* 2 * 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.privatespace; 18 19 import android.app.Activity; 20 import android.app.settings.SettingsEnums; 21 import android.os.Bundle; 22 import android.util.Log; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.view.ViewGroup; 26 27 import androidx.activity.OnBackPressedCallback; 28 import androidx.annotation.Nullable; 29 import androidx.navigation.fragment.NavHostFragment; 30 31 import com.android.settings.R; 32 import com.android.settings.core.InstrumentedFragment; 33 34 import com.google.android.setupcompat.template.FooterBarMixin; 35 import com.google.android.setupcompat.template.FooterButton; 36 import com.google.android.setupdesign.GlifLayout; 37 38 /** Fragment to display error screen if creation of private profile failed for any reason. */ 39 public class PrivateProfileCreationError extends InstrumentedFragment { 40 private static final String TAG = "PrivateSpaceCreationErr"; 41 42 @Override onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)43 public View onCreateView( 44 LayoutInflater inflater, 45 @Nullable ViewGroup container, 46 @Nullable Bundle savedInstanceState) { 47 GlifLayout rootView = 48 (GlifLayout) 49 inflater.inflate(R.layout.privatespace_creation_error, container, false); 50 final FooterBarMixin mixin = rootView.getMixin(FooterBarMixin.class); 51 mixin.setPrimaryButton( 52 new FooterButton.Builder(getContext()) 53 .setText(R.string.private_space_tryagain_label) 54 .setListener(onTryAgain()) 55 .setButtonType(FooterButton.ButtonType.NEXT) 56 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary) 57 .build()); 58 mixin.setSecondaryButton( 59 new FooterButton.Builder(getContext()) 60 .setText(R.string.private_space_cancel_label) 61 .setListener(onCancel()) 62 .setButtonType(FooterButton.ButtonType.CANCEL) 63 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary) 64 .build()); 65 OnBackPressedCallback callback = 66 new OnBackPressedCallback(true /* enabled by default */) { 67 @Override 68 public void handleOnBackPressed() { 69 // Handle the back button event. We intentionally don't want to allow back 70 // button to work in this screen during the setup flow. 71 } 72 }; 73 requireActivity().getOnBackPressedDispatcher().addCallback(this, callback); 74 75 return rootView; 76 } 77 78 @Override getMetricsCategory()79 public int getMetricsCategory() { 80 return SettingsEnums.PRIVATE_SPACE_SETUP_SPACE_CREATION_ERROR; 81 } 82 onTryAgain()83 private View.OnClickListener onTryAgain() { 84 return v -> { 85 mMetricsFeatureProvider.action( 86 getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_TRY_CREATE_SPACE_AGAIN); 87 Log.i(TAG, "Retry private space creation"); 88 NavHostFragment.findNavController(PrivateProfileCreationError.this) 89 .navigate(R.id.action_retry_profile_creation); 90 }; 91 } 92 onCancel()93 private View.OnClickListener onCancel() { 94 return v -> { 95 Activity activity = getActivity(); 96 if (activity != null) { 97 mMetricsFeatureProvider.action( 98 getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_CANCEL_CREATE_SPACE); 99 Log.i(TAG, "private space setup cancelled"); 100 activity.finish(); 101 } 102 }; 103 } 104 } 105