1 /*
2  * Copyright 2019 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.pump.util;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 
24 import androidx.annotation.NonNull;
25 import androidx.annotation.Nullable;
26 import androidx.annotation.UiThread;
27 import androidx.fragment.app.Fragment;
28 
29 import com.android.pump.activity.ActivityStarterActivity;
30 
31 @UiThread
32 public final class IntentUtils {
IntentUtils()33     private IntentUtils() { }
34 
startExternalActivity(@onNull Context context, @NonNull Intent intent)35     public static void startExternalActivity(@NonNull Context context, @NonNull Intent intent) {
36         startExternalActivity(context, intent, null);
37     }
38 
startExternalActivity(@onNull Context context, @NonNull Intent intent, @Nullable Bundle options)39     public static void startExternalActivity(@NonNull Context context, @NonNull Intent intent,
40             @Nullable Bundle options) {
41         Intent startIntent = ActivityStarterActivity.createStartIntent(context, intent, options);
42         context.startActivity(startIntent);
43     }
44 
startExternalActivityForResult(@onNull Activity activity, @NonNull Intent intent, int requestCode)45     public static void startExternalActivityForResult(@NonNull Activity activity,
46             @NonNull Intent intent, int requestCode) {
47         startExternalActivityForResult(activity, intent, requestCode, null);
48     }
49 
startExternalActivityForResult(@onNull Activity activity, @NonNull Intent intent, int requestCode, @Nullable Bundle options)50     public static void startExternalActivityForResult(@NonNull Activity activity,
51             @NonNull Intent intent, int requestCode, @Nullable Bundle options) {
52         Intent startIntent = ActivityStarterActivity.createStartIntent(activity, intent, options);
53         activity.startActivityForResult(startIntent, requestCode);
54     }
55 
startExternalActivityForResult(@onNull Fragment fragment, @NonNull Intent intent, int requestCode)56     public static void startExternalActivityForResult(@NonNull Fragment fragment,
57             @NonNull Intent intent, int requestCode) {
58         startExternalActivityForResult(fragment, intent, requestCode, null);
59     }
60 
startExternalActivityForResult(@onNull Fragment fragment, @NonNull Intent intent, int requestCode, @Nullable Bundle options)61     public static void startExternalActivityForResult(@NonNull Fragment fragment,
62             @NonNull Intent intent, int requestCode, @Nullable Bundle options) {
63         Context context = fragment.requireContext();
64         Intent startIntent = ActivityStarterActivity.createStartIntent(context, intent, options);
65         fragment.startActivityForResult(startIntent, requestCode);
66     }
67 }
68