• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.internal.app;
19 
20 import android.content.DialogInterface;
21 import android.content.pm.PackageManager;
22 import android.graphics.drawable.Drawable;
23 import android.os.Bundle;
24 import android.os.UserHandle;
25 
26 import com.android.internal.app.chooser.DisplayResolveInfo;
27 import com.android.internal.app.chooser.MultiDisplayResolveInfo;
28 
29 /**
30  * Shows individual actions for a "stacked" app target - such as an app with multiple posting
31  * streams represented in the Sharesheet.
32  */
33 public class ChooserStackedAppDialogFragment extends ChooserTargetActionsDialogFragment
34         implements DialogInterface.OnClickListener {
35 
36     static final String WHICH_KEY = "which_key";
37     static final String MULTI_DRI_KEY = "multi_dri_key";
38 
39     private MultiDisplayResolveInfo mMultiDisplayResolveInfo;
40     private int mParentWhich;
41 
ChooserStackedAppDialogFragment()42     public ChooserStackedAppDialogFragment() {}
43 
setStateFromBundle(Bundle b)44     void setStateFromBundle(Bundle b) {
45         mMultiDisplayResolveInfo = (MultiDisplayResolveInfo) b.get(MULTI_DRI_KEY);
46         mTargetInfos = mMultiDisplayResolveInfo.getTargets();
47         mUserHandle = (UserHandle) b.get(USER_HANDLE_KEY);
48         mParentWhich = b.getInt(WHICH_KEY);
49     }
50 
51     @Override
onSaveInstanceState(Bundle outState)52     public void onSaveInstanceState(Bundle outState) {
53         super.onSaveInstanceState(outState);
54         outState.putInt(WHICH_KEY, mParentWhich);
55         outState.putParcelable(MULTI_DRI_KEY, mMultiDisplayResolveInfo);
56     }
57 
58     @Override
getItemLabel(DisplayResolveInfo dri)59     protected CharSequence getItemLabel(DisplayResolveInfo dri) {
60         final PackageManager pm = getContext().getPackageManager();
61         return dri.getResolveInfo().loadLabel(pm);
62     }
63 
64     @Override
getItemIcon(DisplayResolveInfo dri)65     protected Drawable getItemIcon(DisplayResolveInfo dri) {
66 
67         // Show no icon for the group disambig dialog, null hides the imageview
68         return null;
69     }
70 
71     @Override
onClick(DialogInterface dialog, int which)72     public void onClick(DialogInterface dialog, int which) {
73         mMultiDisplayResolveInfo.setSelected(which);
74         ((ChooserActivity) getActivity()).startSelected(mParentWhich, false, true);
75         dismiss();
76     }
77 }
78