• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.Context;
20 import android.content.pm.ResolveInfo;
21 import android.os.UserManager;
22 import android.provider.DocumentsProvider;
23 import android.text.TextUtils;
24 import android.view.View;
25 
26 import com.android.documentsui.ActionHandler;
27 import com.android.documentsui.R;
28 import com.android.documentsui.base.RootInfo;
29 
30 /**
31  * An {@link Item} for each root provided by {@link DocumentsProvider}s
32  * and apps that supports some picking actions like {@link Intent#ACTION_GET_CONTENT}.
33  * This is only used in pickers.
34  */
35 class RootAndAppItem extends RootItem {
36 
37     public final ResolveInfo resolveInfo;
38 
RootAndAppItem(RootInfo root, ResolveInfo info, ActionHandler actionHandler, boolean maybeShowBadge)39     public RootAndAppItem(RootInfo root, ResolveInfo info, ActionHandler actionHandler,
40             boolean maybeShowBadge) {
41         super(root, actionHandler, info.activityInfo.packageName, maybeShowBadge);
42         this.resolveInfo = info;
43     }
44 
45     @Override
showAppDetails()46     boolean showAppDetails() {
47         mActionHandler.showAppDetails(resolveInfo, userId);
48         return true;
49     }
50 
51     @Override
bindView(View convertView)52     public void bindView(View convertView) {
53         final Context context = convertView.getContext();
54 
55         String contentDescription =
56                 context.getResources().getString(
57                         R.string.open_external_app, userId.getUserBadgedLabel(context, root.title));
58 
59         bindAction(convertView, View.VISIBLE, R.drawable.ic_exit_to_app, contentDescription);
60         bindIconAndTitle(convertView);
61         bindSummary(convertView, root.summary);
62     }
63 
64     @Override
onActionClick(View view)65     protected void onActionClick(View view) {
66         mActionHandler.openRoot(resolveInfo, userId);
67     }
68 
69     @Override
toString()70     public String toString() {
71         return "RootAndAppItem{"
72                 + "id=" + stringId
73                 + ", userId=" + userId
74                 + ", root=" + root
75                 + ", resolveInfo=" + resolveInfo
76                 + ", docInfo=" + docInfo
77                 + "}";
78     }
79 }
80