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