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