2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.launcher3.notification;
19 import android.animation.Animator;
20 import android.animation.AnimatorSet;
21 import android.animation.ArgbEvaluator;
22 import android.animation.ObjectAnimator;
23 import android.animation.ValueAnimator;
24 import android.content.Context;
25 import android.graphics.drawable.ColorDrawable;
26 import android.util.AttributeSet;
27 import android.view.MotionEvent;
28 import android.view.View;
29 import android.widget.LinearLayout;
30 import android.widget.TextView;
32 import com.android.launcher3.ItemInfo;
33 import com.android.launcher3.Launcher;
34 import com.android.launcher3.LauncherAnimUtils;
35 import com.android.launcher3.LauncherViewPropertyAnimator;
36 import com.android.launcher3.R;
37 import com.android.launcher3.graphics.IconPalette;
38 import com.android.launcher3.userevent.nano.LauncherLogProto;
41 * A {@link LinearLayout} that contains a single notification, e.g. icon + title + text.
43 public class NotificationMainView extends LinearLayout implements SwipeHelper.Callback {
45 private final ArgbEvaluator mArgbEvaluator = new ArgbEvaluator();
47 private NotificationInfo mNotificationInfo;
48 private TextView mTitleView;
49 private TextView mTextView;
50 private IconPalette mIconPalette;
51 private ColorDrawable mColorBackground;
53 public NotificationMainView(Context context) {
54 this(context, null, 0);
57 public NotificationMainView(Context context, AttributeSet attrs) {
58 this(context, attrs, 0);
61 public NotificationMainView(Context context, AttributeSet attrs, int defStyle) {
62 super(context, attrs, defStyle);
66 protected void onFinishInflate() {
67 super.onFinishInflate();
69 mTitleView = (TextView) findViewById(R.id.title);
70 mTextView = (TextView) findViewById(R.id.text);
73 public void applyColors(IconPalette iconPalette) {
74 mColorBackground = new ColorDrawable(iconPalette.backgroundColor);
75 setBackground(mColorBackground);
76 mIconPalette = iconPalette;
79 public void applyNotificationInfo(NotificationInfo mainNotification, View iconView) {
80 applyNotificationInfo(mainNotification, iconView, false);
84 * Sets the content of this view, animating it after a new icon shifts up if necessary.
86 public void applyNotificationInfo(NotificationInfo mainNotification, View iconView,
89 mTitleView.setAlpha(0);
90 mTextView.setAlpha(0);
91 mColorBackground.setColor(mIconPalette.secondaryColor);
93 mNotificationInfo = mainNotification;
94 mTitleView.setText(mNotificationInfo.title);
95 mTextView.setText(mNotificationInfo.text);
96 iconView.setBackground(mNotificationInfo.getIconForBackground(
97 getContext(), mIconPalette.backgroundColor));
98 setOnClickListener(mNotificationInfo);
100 // Add a dummy ItemInfo so that logging populates the correct container and item types
101 // instead of DEFAULT_CONTAINERTYPE and DEFAULT_ITEMTYPE, respectively.
102 setTag(new ItemInfo());
104 AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
105 Animator textFade = new LauncherViewPropertyAnimator(mTextView).alpha(1);
106 Animator titleFade = new LauncherViewPropertyAnimator(mTitleView).alpha(1);
107 ValueAnimator colorChange = ObjectAnimator.ofObject(mColorBackground, "color",
108 mArgbEvaluator, mIconPalette.secondaryColor, mIconPalette.backgroundColor);
109 animation.playTogether(textFade, titleFade, colorChange);
110 animation.setDuration(150);
115 public NotificationInfo getNotificationInfo() {
116 return mNotificationInfo;
120 // SwipeHelper.Callback's
123 public View getChildAtPosition(MotionEvent ev) {
128 public boolean canChildBeDismissed(View v) {
129 return mNotificationInfo.dismissable;
133 public boolean isAntiFalsingNeeded() {
138 public void onBeginDrag(View v) {
142 public void onChildDismissed(View v) {
143 Launcher launcher = Launcher.getLauncher(getContext());
144 launcher.getPopupDataProvider().cancelNotification(
145 mNotificationInfo.notificationKey);
146 launcher.getUserEventDispatcher().logActionOnItem(
147 LauncherLogProto.Action.Touch.SWIPE,
148 LauncherLogProto.Action.Direction.RIGHT, // Assume all swipes are right for logging.
149 LauncherLogProto.ItemType.NOTIFICATION);
153 public void onDragCancelled(View v) {
157 public void onChildSnappedBack(View animView, float targetLeft) {
161 public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
167 public float getFalsingThresholdFactor() {