Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 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 | |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 27 | import com.android.documentsui.ActionHandler; |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 28 | import com.android.documentsui.R; |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 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 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 39 | private final ActionHandler mActionHandler; |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 40 | |
Steve McKay | 739f94b | 2016-09-22 14:54:23 -0700 | [diff] [blame] | 41 | public AppItem(ResolveInfo info, ActionHandler actionHandler) { |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 42 | 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 Tan | b285b40 | 2016-09-21 17:12:18 -0700 | [diff] [blame] | 57 | boolean showAppDetails() { |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 58 | 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 McKay | 6d20d19 | 2016-09-21 17:57:10 -0700 | [diff] [blame] | 84 | mActionHandler.openRoot(info); |
Garfield Tan | 7d75f7b | 2016-09-20 16:33:24 -0700 | [diff] [blame] | 85 | } |
| 86 | } |