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 private boolean mIsAnimationPlaying = true; 48 49 @Override onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)50 public View onCreateView( 51 LayoutInflater inflater, 52 @Nullable ViewGroup container, 53 @Nullable Bundle savedInstanceState) { 54 if (!android.os.Flags.allowPrivateProfile() 55 || !android.multiuser.Flags.enablePrivateSpaceFeatures()) { 56 return null; 57 } 58 GlifLayout rootView = 59 (GlifLayout) 60 inflater.inflate(R.layout.private_space_education_screen, container, false); 61 final FooterBarMixin mixin = rootView.getMixin(FooterBarMixin.class); 62 mixin.setPrimaryButton( 63 new FooterButton.Builder(getContext()) 64 .setText(R.string.private_space_setup_button_label) 65 .setListener(onSetup()) 66 .setButtonType(FooterButton.ButtonType.NEXT) 67 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Primary) 68 .build()); 69 mixin.setSecondaryButton( 70 new FooterButton.Builder(getContext()) 71 .setText(R.string.private_space_cancel_label) 72 .setListener(onCancel()) 73 .setButtonType(FooterButton.ButtonType.CANCEL) 74 .setTheme(com.google.android.setupdesign.R.style.SudGlifButton_Secondary) 75 .build()); 76 LottieAnimationView lottieAnimationView = rootView.findViewById(R.id.lottie_animation); 77 LottieColorUtils.applyDynamicColors(getContext(), lottieAnimationView); 78 lottieAnimationView.setOnClickListener(v -> handleAnimationClick(lottieAnimationView)); 79 PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(), 80 lottieAnimationView, mIsAnimationPlaying); 81 82 TextView infoTextView = rootView.findViewById(R.id.learn_more); 83 Pattern pattern = Pattern.compile(infoTextView.getText().toString()); 84 Linkify.addLinks( 85 infoTextView, 86 pattern, 87 getContext().getString(R.string.private_space_learn_more_url)); 88 89 return rootView; 90 } 91 92 @Override getMetricsCategory()93 public int getMetricsCategory() { 94 return SettingsEnums.PRIVATE_SPACE_SETUP_EDUCATION; 95 } 96 onSetup()97 private View.OnClickListener onSetup() { 98 return v -> { 99 mMetricsFeatureProvider.action( 100 getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_START); 101 Log.i(TAG, "Starting private space setup"); 102 NavHostFragment.findNavController(PrivateSpaceEducation.this) 103 .navigate(R.id.action_education_to_create); 104 }; 105 } 106 onCancel()107 private View.OnClickListener onCancel() { 108 return v -> { 109 Activity activity = getActivity(); 110 if (activity != null) { 111 mMetricsFeatureProvider.action( 112 getContext(), SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_CANCEL); 113 Log.i(TAG, "private space setup cancelled"); 114 activity.finish(); 115 } 116 }; 117 } 118 119 private void handleAnimationClick(LottieAnimationView lottieAnimationView) { 120 if (mIsAnimationPlaying) { 121 lottieAnimationView.pauseAnimation(); 122 } else { 123 lottieAnimationView.playAnimation(); 124 } 125 mIsAnimationPlaying = !mIsAnimationPlaying; 126 PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(), 127 lottieAnimationView, mIsAnimationPlaying); 128 } 129 } 130