1 /*
2  * Copyright (C) 2020 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.systemui.people;
18 
19 import android.app.people.PeopleSpaceTile;
20 import android.content.Context;
21 import android.content.pm.LauncherApps;
22 import android.graphics.Bitmap;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.ImageView;
27 import android.widget.LinearLayout;
28 import android.widget.TextView;
29 
30 import com.android.systemui.R;
31 
32 /**
33  * PeopleSpaceTileView renders an individual person's tile with associated status.
34  */
35 public class PeopleSpaceTileView extends LinearLayout {
36 
37     private View mTileView;
38     private TextView mNameView;
39     private ImageView mPersonIconView;
40 
PeopleSpaceTileView(Context context, ViewGroup view, String shortcutId, boolean isLast)41     public PeopleSpaceTileView(Context context, ViewGroup view, String shortcutId, boolean isLast) {
42         super(context);
43         mTileView = view.findViewWithTag(shortcutId);
44         if (mTileView == null) {
45             LayoutInflater inflater = LayoutInflater.from(context);
46             mTileView = inflater.inflate(R.layout.people_space_tile_view, view, false);
47             view.addView(mTileView, LayoutParams.MATCH_PARENT,
48                     LayoutParams.MATCH_PARENT);
49             mTileView.setTag(shortcutId);
50 
51             // If it's not the last conversation in this section, add a divider.
52             if (!isLast) {
53                 inflater.inflate(R.layout.people_space_activity_list_divider, view, true);
54             }
55         }
56         mNameView = mTileView.findViewById(R.id.tile_view_name);
57         mPersonIconView = mTileView.findViewById(R.id.tile_view_person_icon);
58     }
59 
60     /** Sets the name text on the tile. */
setName(String name)61     public void setName(String name) {
62         mNameView.setText(name);
63     }
64 
65     /** Sets the person and package drawable on the tile. */
setPersonIcon(Bitmap bitmap)66     public void setPersonIcon(Bitmap bitmap) {
67         mPersonIconView.setImageBitmap(bitmap);
68     }
69 
70     /** Sets the click listener of the tile. */
setOnClickListener(LauncherApps launcherApps, PeopleSpaceTile tile)71     public void setOnClickListener(LauncherApps launcherApps, PeopleSpaceTile tile) {
72         mTileView.setOnClickListener(v ->
73                 launcherApps.startShortcut(tile.getPackageName(), tile.getId(), null, null,
74                         tile.getUserHandle()));
75     }
76 
77     /** Sets the click listener of the tile directly. */
setOnClickListener(OnClickListener onClickListener)78     public void setOnClickListener(OnClickListener onClickListener) {
79         mTileView.setOnClickListener(onClickListener);
80     }
81 }
82