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 package com.android.internal.app.chooser; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.os.UserHandle; 22 23 import com.android.internal.app.ResolverActivity; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * Represents a "stack" of chooser targets for various activities within the same component. 30 */ 31 public class MultiDisplayResolveInfo extends DisplayResolveInfo { 32 33 List<DisplayResolveInfo> mTargetInfos = new ArrayList<>(); 34 // We'll use this DRI for basic presentation info - eg icon, name. 35 final DisplayResolveInfo mBaseInfo; 36 // Index of selected target 37 private int mSelected = -1; 38 39 /** 40 * @param firstInfo A representative DRI to use for the main icon, title, etc for this Info. 41 */ MultiDisplayResolveInfo(String packageName, DisplayResolveInfo firstInfo)42 public MultiDisplayResolveInfo(String packageName, DisplayResolveInfo firstInfo) { 43 super(firstInfo); 44 mBaseInfo = firstInfo; 45 mTargetInfos.add(firstInfo); 46 } 47 48 @Override getExtendedInfo()49 public CharSequence getExtendedInfo() { 50 // Never show subtitle for stacked apps 51 return null; 52 } 53 54 /** 55 * Add another DisplayResolveInfo to the list included for this target. 56 */ addTarget(DisplayResolveInfo target)57 public void addTarget(DisplayResolveInfo target) { 58 mTargetInfos.add(target); 59 } 60 61 /** 62 * List of all DisplayResolveInfos included in this target. 63 */ getTargets()64 public List<DisplayResolveInfo> getTargets() { 65 return mTargetInfos; 66 } 67 setSelected(int selected)68 public void setSelected(int selected) { 69 mSelected = selected; 70 } 71 72 /** 73 * Return selected target. 74 */ getSelectedTarget()75 public DisplayResolveInfo getSelectedTarget() { 76 return hasSelected() ? mTargetInfos.get(mSelected) : null; 77 } 78 79 /** 80 * Whether or not the user has selected a specific target for this MultiInfo. 81 */ hasSelected()82 public boolean hasSelected() { 83 return mSelected >= 0; 84 } 85 86 @Override start(Activity activity, Bundle options)87 public boolean start(Activity activity, Bundle options) { 88 return mTargetInfos.get(mSelected).start(activity, options); 89 } 90 91 @Override startAsCaller(ResolverActivity activity, Bundle options, int userId)92 public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) { 93 return mTargetInfos.get(mSelected).startAsCaller(activity, options, userId); 94 } 95 96 @Override startAsUser(Activity activity, Bundle options, UserHandle user)97 public boolean startAsUser(Activity activity, Bundle options, UserHandle user) { 98 return mTargetInfos.get(mSelected).startAsUser(activity, options, user); 99 } 100 101 } 102