1 /* 2 * Copyright (C) 2018 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.car.settings.common; 18 19 import android.content.Intent; 20 import android.content.IntentSender; 21 import android.os.Bundle; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 import androidx.fragment.app.DialogFragment; 26 import androidx.fragment.app.Fragment; 27 import androidx.lifecycle.Lifecycle; 28 29 /** 30 * Encapsulates a subset of the operations possible from a {@link Fragment}. 31 */ 32 public interface FragmentController { 33 34 /** 35 * Launches a Fragment in the main container of the current Activity. This cannot be used to 36 * show dialog fragments and will throw an IllegalArgumentException if attempted. The method 37 * {@link #showDialog} should be used instead. 38 */ launchFragment(Fragment fragment)39 void launchFragment(Fragment fragment); 40 41 /** 42 * Pops the top off the Fragment stack. 43 */ goBack()44 void goBack(); 45 46 /** 47 * Shows dialog with given tag. 48 */ showDialog(DialogFragment dialogFragment, @Nullable String tag)49 void showDialog(DialogFragment dialogFragment, @Nullable String tag); 50 51 /** 52 * Shows/hides the Fragment's progress bar. 53 */ showProgressBar(boolean visible)54 void showProgressBar(boolean visible); 55 56 /** 57 * Finds dialog by tag. This is primarily used to reattach listeners to dialogs after 58 * configuration change. This method will return null if the tag references a fragment that 59 * isn't a dialog fragment or no dialog with the given tag exists. 60 */ 61 @Nullable findDialogByTag(String tag)62 DialogFragment findDialogByTag(String tag); 63 64 /** 65 * Returns the current Lifecycle instance for the fragment. 66 */ 67 @NonNull getSettingsLifecycle()68 Lifecycle getSettingsLifecycle(); 69 70 /** 71 * Starts an activity for a result. When the result is received, the {@link 72 * ActivityResultCallback} is passed the result. Note that the implementer of this interface 73 * must ensure that the callback is valid throughout the lifecycle of the new activity that is 74 * created. 75 * 76 * @param intent The intent used to start an activity. 77 * @param requestCode User defined code which is passed to the callback when the activity exits. 78 * Values must use the first 8 bits of the int (i.e. 0-255). 79 * @param callback Defines how the result from the started activity should be handled. 80 */ startActivityForResult(Intent intent, int requestCode, ActivityResultCallback callback)81 void startActivityForResult(Intent intent, int requestCode, ActivityResultCallback callback); 82 83 /** 84 * Starts an intent sender for a result. When the result is received, the {@link 85 * ActivityResultCallback} is passed the result. Note that the implementer of this interface 86 * must ensure that the callback is valid throughout the lifecycle of the new activity that is 87 * created. 88 * 89 * @param intent The IntentSender to launch. 90 * @param requestCode User defined code which is passed to the callback when the activity 91 * exits. Values must use the first 8 bits of the int (i.e. 0-255). 92 * @param fillInIntent If non-null, this will be provided as the intent parameter to {@link 93 * IntentSender#sendIntent}. 94 * @param flagsMask Intent flags in the original IntentSender that you would like to change. 95 * @param flagsValues Desired values for any bits set in <var>flagsMask</var> 96 * @param options Additional options for how the Activity should be started. 97 * @param callback Defines how the result from the started IntentSender should be handled. 98 */ startIntentSenderForResult(IntentSender intent, int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, Bundle options, ActivityResultCallback callback)99 void startIntentSenderForResult(IntentSender intent, int requestCode, 100 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, Bundle options, 101 ActivityResultCallback callback) 102 throws IntentSender.SendIntentException; 103 } 104