Debian Codegraph @

core/java/com/android/internal/widget/CallLayout.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.internal.widget;
18
19 import android.annotation.AttrRes;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.StyleRes;
23 import android.app.Notification;
24 import android.app.Person;
25 import android.content.Context;
26 import android.content.res.ColorStateList;
27 import android.graphics.drawable.Icon;
28 import android.os.Bundle;
29 import android.util.AttributeSet;
30 import android.view.RemotableViewMethod;
31 import android.widget.FrameLayout;
32 import android.widget.RemoteViews;
33 import android.widget.TextView;
34
35 import com.android.internal.R;
36
37 /**
38 * A custom-built layout for the Notification.CallStyle.
39 */
40 @RemoteViews.RemoteView
41 public class CallLayout extends FrameLayout {
42 private final PeopleHelper mPeopleHelper = new PeopleHelper();
43
44 private int mLayoutColor;
45 private Icon mLargeIcon;
46 private Person mUser;
47
48 private CachingIconView mConversationIconView;
49 private CachingIconView mIcon;
50 private CachingIconView mConversationIconBadgeBg;
51 private TextView mConversationText;
52
53 public CallLayout(@NonNull Context context) {
54 super(context);
55 }
56
57 public CallLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
58 super(context, attrs);
59 }
60
61 public CallLayout(@NonNull Context context, @Nullable AttributeSet attrs,
62 @AttrRes int defStyleAttr) {
63 super(context, attrs, defStyleAttr);
64 }
65
66 public CallLayout(@NonNull Context context, @Nullable AttributeSet attrs,
67 @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
68 super(context, attrs, defStyleAttr, defStyleRes);
69 }
70
71 @Override
72 protected void onFinishInflate() {
73 super.onFinishInflate();
74 mPeopleHelper.init(getContext());
75 mConversationText = findViewById(R.id.conversation_text);
76 mConversationIconView = findViewById(R.id.conversation_icon);
77 mIcon = findViewById(R.id.icon);
78 mConversationIconBadgeBg = findViewById(R.id.conversation_icon_badge_bg);
79
80 // When the small icon is gone, hide the rest of the badge
81 mIcon.setOnForceHiddenChangedListener((forceHidden) -> {
82 mPeopleHelper.animateViewForceHidden(mConversationIconBadgeBg, forceHidden);
83 });
84 }
85
86 private void updateCallLayout() {
87 CharSequence callerName = "";
88 String symbol = "";
89 Icon icon = null;
90 if (mUser != null) {
91 icon = mUser.getIcon();
92 callerName = mUser.getName();
93 symbol = mPeopleHelper.findNamePrefix(callerName, "");
94 }
95 if (icon == null) {
96 icon = mLargeIcon;
97 }
98 if (icon == null) {
99 icon = mPeopleHelper.createAvatarSymbol(callerName, symbol, mLayoutColor);
100 }
101 // TODO(b/179178086): crop/clip the icon to a circle?
102 mConversationIconView.setImageIcon(icon);
103 }
104
105 @RemotableViewMethod
106 public void setLayoutColor(int color) {
107 mLayoutColor = color;
108 }
109
110 /**
111 * @param color the color of the notification background
112 */
113 @RemotableViewMethod
114 public void setNotificationBackgroundColor(int color) {
115 mConversationIconBadgeBg.setImageTintList(ColorStateList.valueOf(color));
116 }
117
118 @RemotableViewMethod
119 public void setLargeIcon(Icon largeIcon) {
120 mLargeIcon = largeIcon;
121 }
122
123 /**
124 * Set the notification extras so that this layout has access
125 */
126 @RemotableViewMethod
127 public void setData(Bundle extras) {
128 setUser(extras.getParcelable(Notification.EXTRA_CALL_PERSON));
129 updateCallLayout();
130 }
131
132 private void setUser(Person user) {
133 mUser = user;
134 }
135
136 }