• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.documentsui.sidebar;
18 
19 import android.content.Intent;
20 import android.content.pm.ActivityInfo;
21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
23 import android.view.View;
24 import android.widget.ImageView;
25 import android.widget.TextView;
26 
27 import com.android.documentsui.ActionHandler;
28 import com.android.documentsui.R;
29 
30 /**
31  * An {@link Item} for apps that supports some picking actions like
32  * {@link Intent#ACTION_GET_CONTENT} such as Photos. This is only used in pickers.
33  */
34 class AppItem extends Item {
35     private static final String STRING_ID_FORMAT = "AppItem{%s/%s}";
36 
37     public final ResolveInfo info;
38 
39     private final ActionHandler mActionHandler;
40 
AppItem(ResolveInfo info, ActionHandler actionHandler)41     public AppItem(ResolveInfo info, ActionHandler actionHandler) {
42         super(R.layout.item_root, getStringId(info));
43         this.info = info;
44 
45         mActionHandler = actionHandler;
46     }
47 
getStringId(ResolveInfo info)48     private static String getStringId(ResolveInfo info) {
49         ActivityInfo activityInfo = info.activityInfo;
50 
51         String component = String.format(
52                 STRING_ID_FORMAT, activityInfo.applicationInfo.packageName, activityInfo.name);
53         return component;
54     }
55 
56     @Override
showAppDetails()57     boolean showAppDetails() {
58         mActionHandler.showAppDetails(info);
59         return true;
60     }
61 
62     @Override
bindView(View convertView)63     void bindView(View convertView) {
64         final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon);
65         final TextView title = (TextView) convertView.findViewById(android.R.id.title);
66         final TextView summary = (TextView) convertView.findViewById(android.R.id.summary);
67 
68         final PackageManager pm = convertView.getContext().getPackageManager();
69         icon.setImageDrawable(info.loadIcon(pm));
70         title.setText(info.loadLabel(pm));
71 
72         // TODO: match existing summary behavior from disambig dialog
73         summary.setVisibility(View.GONE);
74     }
75 
76     @Override
isRoot()77     boolean isRoot() {
78         // We won't support drag n' drop in pickers, and apps only show up there.
79         return false;
80     }
81 
82     @Override
open()83     void open() {
84         mActionHandler.openRoot(info);
85     }
86 
87     @Override
toString()88     public String toString() {
89         return "AppItem{"
90                 + "id=" + stringId
91                 + ", resolveInfo=" + info
92                 + "}";
93     }
94 }
95