blob: d13b47580b6539887991ae1c7e5ecf03140f25c9 [file] [log] [blame]
Garfield Tan7d75f7b2016-09-20 16:33:24 -07001/*
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
17package com.android.documentsui.sidebar;
18
19import android.content.Intent;
20import android.content.pm.ActivityInfo;
21import android.content.pm.PackageManager;
22import android.content.pm.ResolveInfo;
23import android.view.View;
24import android.widget.ImageView;
25import android.widget.TextView;
26
Garfield Tan7d75f7b2016-09-20 16:33:24 -070027import com.android.documentsui.ActionHandler;
Steve McKay739f94b2016-09-22 14:54:23 -070028import com.android.documentsui.R;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070029
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 */
34class AppItem extends Item {
35 private static final String STRING_ID_FORMAT = "AppItem{%s/%s}";
36
37 public final ResolveInfo info;
38
Steve McKay739f94b2016-09-22 14:54:23 -070039 private final ActionHandler mActionHandler;
Garfield Tan7d75f7b2016-09-20 16:33:24 -070040
Steve McKay739f94b2016-09-22 14:54:23 -070041 public AppItem(ResolveInfo info, ActionHandler actionHandler) {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070042 super(R.layout.item_root, getStringId(info));
43 this.info = info;
44
45 mActionHandler = actionHandler;
46 }
47
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
Garfield Tanb285b402016-09-21 17:12:18 -070057 boolean showAppDetails() {
Garfield Tan7d75f7b2016-09-20 16:33:24 -070058 mActionHandler.showAppDetails(info);
59 return true;
60 }
61
62 @Override
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
77 boolean isDropTarget() {
78 // We won't support drag n' drop in pickers, and apps only show up there.
79 return false;
80 }
81
82 @Override
83 void open() {
Steve McKay6d20d192016-09-21 17:57:10 -070084 mActionHandler.openRoot(info);
Garfield Tan7d75f7b2016-09-20 16:33:24 -070085 }
86}