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.ValueAnimator;
22 import android.content.Context;
23 import android.support.annotation.Nullable;
24 import android.util.AttributeSet;
25 import android.view.MotionEvent;
26 import android.view.View;
27 import android.widget.LinearLayout;
28 import android.widget.TextView;
30 import com.android.launcher3.Launcher;
31 import com.android.launcher3.LauncherAnimUtils;
32 import com.android.launcher3.LauncherViewPropertyAnimator;
33 import com.android.launcher3.R;
34 import com.android.launcher3.graphics.IconPalette;
37 * A {@link LinearLayout} that contains a single notification, e.g. icon + title + text.
39 public class NotificationMainView extends LinearLayout implements SwipeHelper.Callback {
41 private NotificationInfo mNotificationInfo;
42 private TextView mTitleView;
43 private TextView mTextView;
44 private IconPalette mIconPalette;
46 public NotificationMainView(Context context) {
47 this(context, null, 0);
50 public NotificationMainView(Context context, AttributeSet attrs) {
51 this(context, attrs, 0);
54 public NotificationMainView(Context context, AttributeSet attrs, int defStyle) {
55 super(context, attrs, defStyle);
59 protected void onFinishInflate() {
60 super.onFinishInflate();
62 mTitleView = (TextView) findViewById(R.id.title);
63 mTextView = (TextView) findViewById(R.id.text);
66 public void applyColors(IconPalette iconPalette) {
67 setBackgroundColor(iconPalette.backgroundColor);
68 mIconPalette = iconPalette;
71 public void applyNotificationInfo(NotificationInfo mainNotification, View iconView) {
72 applyNotificationInfo(mainNotification, iconView, false);
76 * Sets the content of this view, animating it after a new icon shifts up if necessary.
78 public void applyNotificationInfo(NotificationInfo mainNotification, View iconView,
81 mTitleView.setAlpha(0);
82 mTextView.setAlpha(0);
83 setBackgroundColor(mIconPalette.secondaryColor);
85 mNotificationInfo = mainNotification;
86 mTitleView.setText(mNotificationInfo.title);
87 mTextView.setText(mNotificationInfo.text);
88 iconView.setBackground(mNotificationInfo.getIconForBackground(
89 getContext(), mIconPalette.backgroundColor));
90 setOnClickListener(mNotificationInfo);
93 AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
94 Animator textFade = new LauncherViewPropertyAnimator(mTextView).alpha(1);
95 Animator titleFade = new LauncherViewPropertyAnimator(mTitleView).alpha(1);
96 ValueAnimator colorChange = ValueAnimator.ofArgb(mIconPalette.secondaryColor,
97 mIconPalette.backgroundColor);
98 colorChange.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
100 public void onAnimationUpdate(ValueAnimator valueAnimator) {
101 setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
104 animation.playTogether(textFade, titleFade, colorChange);
105 animation.setDuration(150);
110 public NotificationInfo getNotificationInfo() {
111 return mNotificationInfo;
115 // SwipeHelper.Callback's
118 public View getChildAtPosition(MotionEvent ev) {
123 public boolean canChildBeDismissed(View v) {
124 return mNotificationInfo.dismissable;
128 public boolean isAntiFalsingNeeded() {
133 public void onBeginDrag(View v) {
137 public void onChildDismissed(View v) {
138 Launcher.getLauncher(getContext()).getPopupDataProvider().cancelNotification(
139 mNotificationInfo.notificationKey);
143 public void onDragCancelled(View v) {
147 public void onChildSnappedBack(View animView, float targetLeft) {
151 public boolean updateSwipeProgress(View animView, boolean dismissable, float swipeProgress) {
157 public float getFalsingThresholdFactor() {