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.text.util.Linkify; 23 import android.util.Log; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import android.widget.TextView; 28 29 import androidx.annotation.Nullable; 30 import androidx.navigation.fragment.NavHostFragment; 31 32 import com.android.settings.R; 33 import com.android.settings.core.InstrumentedFragment; 34 import com.android.settingslib.widget.LottieColorUtils; 35 36 import com.airbnb.lottie.LottieAnimationView; 37 import com.google.android.setupcompat.template.FooterBarMixin; 38 import com.google.android.setupcompat.template.FooterButton; 39 import com.google.android.setupdesign.GlifLayout; 40 41 import java.util.regex.Pattern; 42 43 /** Fragment educating about the usage of Private Space. */ 44 public class PrivateSpaceEducation extends InstrumentedFragment { 45 private static final String TAG = "PrivateSpaceEducation"; 46 47 @Override onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)48 public View onCreateView( 49 LayoutInflater inflater, 50 @Nullable ViewGroup container, 51 @Nullable Bundle savedInstanceState) { 52 if (!android.os.Flags.allowPrivateProfile() 53 || !android.multiuser.Flags.enablePrivateSpaceFeatures()) { 54 return null; 55 } 56 GlifLayout rootView = 57 (GlifLayout) 58 inflater.inflate(R.layout.private_space_education_screen, container, false); 59 final FooterBarMixin mixin = rootView.getMixin(FooterBarMixin.class); 60 mixin.setPrimaryButton( 61 new FooterButton.Builder(getContext()) 62 .setText(R.string.private_space_setup_button_label) 63 .setListener(onSetup()) 64 .setButtonType(FooterButton.ButtonType.NEXT) 65 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary) 66 .build()); 67 mixin.setSecondaryButton( 68 new FooterButton.Builder(getContext()) 69 .setText(R.string.private_space_cancel_label) 70 .setListener(onCancel()) 71 .setButtonType(FooterButton.ButtonType.CANCEL) 72 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary) 73 .build()); 74 LottieAnimationView lottieAnimationView = rootView.findViewById(R.id.lottie_animation); 75 LottieColorUtils.applyDynamicColors(getContext(), lottieAnimationView); 76 77 TextView infoTextView = rootView.findViewById(R.id.learn_more); 78 Pattern pattern = Pattern.compile(infoTextView.getText().toString()); 79 Linkify.addLinks( 80 infoTextView, 81 pattern, 82 getContext().getString(R.string.private_space_learn_more_url)); 83 84 return rootView; 85 } 86 87 @Override getMetricsCategory()88 public int getMetricsCategory() { 89 return SettingsEnums.PRIVATE_SPACE_SETUP_EDUCATION; 90 } 91 onSetup()92 private View.OnClickListener onSetup() { 93 return v -> { 94 mMetricsFeatureProvider.action( 95 getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_START); 96 Log.i(TAG, "Starting private space setup"); 97 NavHostFragment.findNavController(PrivateSpaceEducation.this) 98 .navigate(R.id.action_education_to_create); 99 }; 100 } 101 onCancel()102 private View.OnClickListener onCancel() { 103 return v -> { 104 Activity activity = getActivity(); 105 if (activity != null) { 106 mMetricsFeatureProvider.action( 107 getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_CANCEL); 108 Log.i(TAG, "private space setup cancelled"); 109 activity.finish(); 110 } 111 }; 112 } 113 } 114