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