1 /* 2 * Copyright (C) 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 18 package com.android.intentresolver; 19 20 import android.content.DialogInterface; 21 import android.content.pm.PackageManager; 22 import android.graphics.drawable.Drawable; 23 import android.os.UserHandle; 24 25 import androidx.fragment.app.FragmentManager; 26 27 import com.android.intentresolver.chooser.DisplayResolveInfo; 28 import com.android.intentresolver.chooser.MultiDisplayResolveInfo; 29 30 /** 31 * Shows individual actions for a "stacked" app target - such as an app with multiple posting 32 * streams represented in the Sharesheet. 33 */ 34 public class ChooserStackedAppDialogFragment extends ChooserTargetActionsDialogFragment { 35 36 /** 37 * Display a fragment for the user to select one of the members of a target "stack." 38 * @param stackedTarget The display info for the full stack to select within. 39 * @param stackedTargetParentWhich The "which" value that the {@link ChooserActivity} uses to 40 * identify the {@code stackedTarget} as presented in the chooser menu UI. If the user selects 41 * a target in this fragment, the selection will be saved in the {@link MultiDisplayResolveInfo} 42 * and then the {@link ChooserActivity} will receive a {@code #startSelected()} callback using 43 * this "which" value to identify the stack that's now unambiguously resolved. 44 * @param userHandle 45 * 46 * TODO: consider taking a client-provided callback instead of {@code stackedTargetParentWhich} 47 * to avoid coupling with {@link ChooserActivity}'s mechanism for handling the selection. 48 */ show( FragmentManager fragmentManager, MultiDisplayResolveInfo stackedTarget, int stackedTargetParentWhich, UserHandle userHandle)49 public static void show( 50 FragmentManager fragmentManager, 51 MultiDisplayResolveInfo stackedTarget, 52 int stackedTargetParentWhich, 53 UserHandle userHandle) { 54 ChooserStackedAppDialogFragment fragment = new ChooserStackedAppDialogFragment( 55 stackedTarget, stackedTargetParentWhich, userHandle); 56 fragment.show(fragmentManager, TARGET_DETAILS_FRAGMENT_TAG); 57 } 58 59 private final MultiDisplayResolveInfo mMultiDisplayResolveInfo; 60 private final int mParentWhich; 61 62 @Override onClick(DialogInterface dialog, int which)63 public void onClick(DialogInterface dialog, int which) { 64 mMultiDisplayResolveInfo.setSelected(which); 65 ((ChooserActivity) getActivity()).startSelected(mParentWhich, false, true); 66 dismiss(); 67 } 68 69 @Override getItemLabel(DisplayResolveInfo dri)70 protected CharSequence getItemLabel(DisplayResolveInfo dri) { 71 final PackageManager pm = getContext().getPackageManager(); 72 return dri.getResolveInfo().loadLabel(pm); 73 } 74 75 @Override getItemIcon(DisplayResolveInfo dri)76 protected Drawable getItemIcon(DisplayResolveInfo dri) { 77 // Show no icon for the group disambig dialog, null hides the imageview 78 return null; 79 } 80 ChooserStackedAppDialogFragment( MultiDisplayResolveInfo stackedTarget, int stackedTargetParentWhich, UserHandle userHandle)81 private ChooserStackedAppDialogFragment( 82 MultiDisplayResolveInfo stackedTarget, 83 int stackedTargetParentWhich, 84 UserHandle userHandle) { 85 super(stackedTarget.getAllDisplayTargets(), userHandle); 86 mMultiDisplayResolveInfo = stackedTarget; 87 mParentWhich = stackedTargetParentWhich; 88 } 89 } 90