OSDN Git Service

Added the dozemode for the new notification templates
authorSelim Cinek <cinek@google.com>
Fri, 20 Nov 2015 20:47:59 +0000 (12:47 -0800)
committerSelim Cinek <cinek@google.com>
Tue, 1 Dec 2015 01:45:15 +0000 (17:45 -0800)
Previously things were not correctly inverted when dozing,
because of the new template design.

Change-Id: I05211a463c4c7aa3bcba669506975844c389097b

packages/SystemUI/res/values/colors.xml
packages/SystemUI/src/com/android/systemui/ViewInvertHelper.java
packages/SystemUI/src/com/android/systemui/statusbar/NotificationBigMediaNarrowViewWrapper.java [deleted file]
packages/SystemUI/src/com/android/systemui/statusbar/NotificationBigPictureViewWrapper.java [deleted file]
packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaViewWrapper.java [deleted file]
packages/SystemUI/src/com/android/systemui/statusbar/NotificationTemplateViewWrapper.java
packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewWrapper.java

index 26a0577..bfd8af9 100644 (file)
     <color name="assist_orb_color">#ffffff</color>
 
     <color name="keyguard_user_switcher_background_gradient_color">#77000000</color>
-    <color name="doze_small_icon_background_color">#ff434343</color>
 
     <!-- The color of the navigation bar icons. Need to be in sync with ic_sysbar_* -->
     <color name="navigation_bar_icon_color">#E5FFFFFF</color>
index eddf2b1..5b8d3d6 100644 (file)
@@ -26,6 +26,8 @@ import android.view.View;
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
 
+import java.util.ArrayList;
+
 /**
  * Helper to invert the colors of views and fade between the states.
  */
@@ -33,14 +35,24 @@ public class ViewInvertHelper {
 
     private final Paint mDarkPaint = new Paint();
     private final Interpolator mLinearOutSlowInInterpolator;
-    private final View mTarget;
+    private final ArrayList<View> mTargets;
     private final ColorMatrix mMatrix = new ColorMatrix();
     private final ColorMatrix mGrayscaleMatrix = new ColorMatrix();
     private final long mFadeDuration;
 
     public ViewInvertHelper(View target, long fadeDuration) {
-        mTarget = target;
-        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(mTarget.getContext(),
+        this(constructArray(target), fadeDuration);
+    }
+
+    private static ArrayList<View> constructArray(View target) {
+        final ArrayList<View> views = new ArrayList<>();
+        views.add(target);
+        return views;
+    }
+
+    public ViewInvertHelper(ArrayList<View> targets, long fadeDuration) {
+        mTargets = targets;
+        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(mTargets.get(0).getContext(),
                 android.R.interpolator.linear_out_slow_in);
         mFadeDuration = fadeDuration;
     }
@@ -53,14 +65,18 @@ public class ViewInvertHelper {
             @Override
             public void onAnimationUpdate(ValueAnimator animation) {
                 updateInvertPaint((Float) animation.getAnimatedValue());
-                mTarget.setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
+                for (int i = 0; i < mTargets.size(); i++) {
+                    mTargets.get(i).setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
+                }
             }
         });
         animator.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
                 if (!invert) {
-                    mTarget.setLayerType(View.LAYER_TYPE_NONE, null);
+                    for (int i = 0; i < mTargets.size(); i++) {
+                        mTargets.get(i).setLayerType(View.LAYER_TYPE_NONE, null);
+                    }
                 }
             }
         });
@@ -73,16 +89,16 @@ public class ViewInvertHelper {
     public void update(boolean invert) {
         if (invert) {
             updateInvertPaint(1f);
-            mTarget.setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
+            for (int i = 0; i < mTargets.size(); i++) {
+                mTargets.get(i).setLayerType(View.LAYER_TYPE_HARDWARE, mDarkPaint);
+            }
         } else {
-            mTarget.setLayerType(View.LAYER_TYPE_NONE, null);
+            for (int i = 0; i < mTargets.size(); i++) {
+                mTargets.get(i).setLayerType(View.LAYER_TYPE_NONE, null);
+            }
         }
     }
 
-    public View getTarget() {
-        return mTarget;
-    }
-
     private void updateInvertPaint(float intensity) {
         float components = 1 - 2 * intensity;
         final float[] invert = {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBigMediaNarrowViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBigMediaNarrowViewWrapper.java
deleted file mode 100644 (file)
index 91e5404..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.systemui.statusbar;
-
-import android.content.Context;
-import android.view.View;
-
-/**
- * Wraps a big media narrow notification template layout.
- */
-public class NotificationBigMediaNarrowViewWrapper extends NotificationMediaViewWrapper {
-
-    protected NotificationBigMediaNarrowViewWrapper(Context ctx,
-            View view) {
-        super(ctx, view);
-    }
-
-    @Override
-    public boolean needsRoundRectClipping() {
-        return true;
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBigPictureViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationBigPictureViewWrapper.java
deleted file mode 100644 (file)
index ffe0cd1..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.systemui.statusbar;
-
-import android.content.Context;
-import android.view.View;
-
-/**
- * Wraps a notification view inflated from a big picture style template.
- */
-public class NotificationBigPictureViewWrapper extends NotificationTemplateViewWrapper {
-
-    protected NotificationBigPictureViewWrapper(Context ctx, View view) {
-        super(ctx, view);
-    }
-
-    @Override
-    public boolean needsRoundRectClipping() {
-        return true;
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaViewWrapper.java
deleted file mode 100644 (file)
index 953c373..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.systemui.statusbar;
-
-import android.content.Context;
-import android.view.View;
-
-/**
- * Wraps a media notification.
- */
-public class NotificationMediaViewWrapper extends NotificationTemplateViewWrapper {
-
-    protected NotificationMediaViewWrapper(Context ctx, View view) {
-        super(ctx, view);
-    }
-
-    @Override
-    public void setDark(boolean dark, boolean fade, long delay) {
-
-        // Only update the large icon, because the rest is already inverted.
-        setPictureGrayscale(dark, fade, delay);
-    }
-}
index 68282d0..9b52e04 100644 (file)
@@ -20,6 +20,7 @@ import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.ValueAnimator;
 import android.content.Context;
+import android.content.res.ColorStateList;
 import android.graphics.Color;
 import android.graphics.ColorFilter;
 import android.graphics.ColorMatrix;
@@ -32,9 +33,11 @@ import android.text.TextUtils;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
+import android.view.ViewGroup;
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
 import android.widget.ImageView;
+import android.widget.ProgressBar;
 import android.widget.TextView;
 
 import com.android.systemui.R;
@@ -52,7 +55,8 @@ public class NotificationTemplateViewWrapper extends NotificationViewWrapper {
     private final PorterDuffColorFilter mIconColorFilter = new PorterDuffColorFilter(
             0, PorterDuff.Mode.SRC_ATOP);
     private final int mIconDarkAlpha;
-    private final int mIconDarkColor;
+    private final int mIconDarkColor = 0xffffffff;
+    private final int mDarkProgressTint = 0xffffffff;
     private final Interpolator mLinearOutSlowInInterpolator;
 
     private int mColor;
@@ -60,39 +64,40 @@ public class NotificationTemplateViewWrapper extends NotificationViewWrapper {
     private ImageView mIcon;
     protected ImageView mPicture;
 
-    /**
-     * Whether the icon needs to be forced grayscale when in dark mode.
-     */
-    private boolean mIconForceGraysaleWhenDark;
     private TextView mSubText;
     private View mSubTextDivider;
     private ImageView mExpandButton;
-    private View mNotificationHeader;
+    private ViewGroup mNotificationHeader;
     private View.OnClickListener mExpandClickListener;
     private HeaderTouchListener mHeaderTouchListener;
+    private ProgressBar mProgressBar;
 
     protected NotificationTemplateViewWrapper(Context ctx, View view) {
         super(view);
         mIconDarkAlpha = ctx.getResources().getInteger(R.integer.doze_small_icon_alpha);
-        mIconDarkColor =
-                ctx.getColor(R.color.doze_small_icon_background_color);
         mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(ctx,
                 android.R.interpolator.linear_out_slow_in);
+
         resolveViews();
     }
 
     private void resolveViews() {
         View mainColumn = mView.findViewById(com.android.internal.R.id.notification_main_column);
-        mInvertHelper = mainColumn != null
-                ? new ViewInvertHelper(mainColumn, NotificationPanelView.DOZE_ANIMATION_DURATION)
-                : null;
         mIcon = (ImageView) mView.findViewById(com.android.internal.R.id.icon);
         mPicture = (ImageView) mView.findViewById(com.android.internal.R.id.right_icon);
         mSubText = (TextView) mView.findViewById(com.android.internal.R.id.header_sub_text);
         mSubTextDivider = mView.findViewById(com.android.internal.R.id.sub_text_divider);
         mExpandButton = (ImageView) mView.findViewById(com.android.internal.R.id.expand_button);
         mColor = resolveColor(mExpandButton);
-        mNotificationHeader = mView.findViewById(com.android.internal.R.id.notification_header);
+        final View progress = mView.findViewById(com.android.internal.R.id.progress);
+        if (progress instanceof ProgressBar) {
+            mProgressBar = (ProgressBar) progress;
+        } else {
+            // It's still a viewstub
+            mProgressBar = null;
+        }
+        mNotificationHeader = (ViewGroup) mView.findViewById(
+                com.android.internal.R.id.notification_header);
         // Post to make sure the parent lays out its children before we get their bounds
         mHeaderTouchListener = new HeaderTouchListener();
         mExpandButton.post(new Runnable() {
@@ -102,11 +107,18 @@ public class NotificationTemplateViewWrapper extends NotificationViewWrapper {
                 mHeaderTouchListener.bindTouchRects(mNotificationHeader, mIcon, mExpandButton);
             }
         });
-
-        // If the icon already has a color filter, we assume that we already forced the icon to be
-        // white when we created the notification.
-        final Drawable iconDrawable = mIcon != null ? mIcon.getDrawable() : null;
-        mIconForceGraysaleWhenDark = iconDrawable != null && iconDrawable.getColorFilter() != null;
+        ArrayList<View> viewsToInvert = new ArrayList<>();
+        if (mainColumn != null) {
+            viewsToInvert.add(mainColumn);
+        }
+        for (int i = 0; i < mNotificationHeader.getChildCount(); i++) {
+            View child = mNotificationHeader.getChildAt(i);
+            if (child != mIcon) {
+                viewsToInvert.add(child);
+            }
+        }
+        mInvertHelper = new ViewInvertHelper(viewsToInvert,
+                NotificationPanelView.DOZE_ANIMATION_DURATION);
     }
 
     private int resolveColor(ImageView icon) {
@@ -140,18 +152,43 @@ public class NotificationTemplateViewWrapper extends NotificationViewWrapper {
             if (fade) {
                 fadeIconColorFilter(mIcon, dark, delay);
                 fadeIconAlpha(mIcon, dark, delay);
-                if (!mIconForceGraysaleWhenDark) {
-                    fadeGrayscale(mIcon, dark, delay);
-                }
             } else {
                 updateIconColorFilter(mIcon, dark);
                 updateIconAlpha(mIcon, dark);
-                if (!mIconForceGraysaleWhenDark) {
-                    updateGrayscale(mIcon, dark);
-                }
             }
         }
         setPictureGrayscale(dark, fade, delay);
+        setProgressBarDark(dark, fade, delay);
+    }
+
+    private void setProgressBarDark(boolean dark, boolean fade, long delay) {
+        if (mProgressBar != null) {
+            if (fade) {
+                fadeProgressDark(mProgressBar, dark, delay);
+            } else {
+                updateProgressDark(mProgressBar, dark);
+            }
+        }
+    }
+
+    private void fadeProgressDark(final ProgressBar target, final boolean dark, long delay) {
+        startIntensityAnimation(new ValueAnimator.AnimatorUpdateListener() {
+            @Override
+            public void onAnimationUpdate(ValueAnimator animation) {
+                float t = (float) animation.getAnimatedValue();
+                updateProgressDark(target, t);
+            }
+        }, dark, delay, null /* listener */);
+    }
+
+    private void updateProgressDark(ProgressBar target, float intensity) {
+        int color = interpolateColor(mColor, mDarkProgressTint, intensity);
+        target.getIndeterminateDrawable().mutate().setTint(color);
+        target.getProgressDrawable().mutate().setTint(color);
+    }
+
+    private void updateProgressDark(ProgressBar target, boolean dark) {
+        updateProgressDark(target, dark ? 1f : 0f);
     }
 
     protected void setPictureGrayscale(boolean grayscale, boolean fade, long delay) {
@@ -224,8 +261,8 @@ public class NotificationTemplateViewWrapper extends NotificationViewWrapper {
         mIconColorFilter.setColor(color);
         Drawable iconDrawable = target.getDrawable();
 
-        // The background might be null for legacy notifications. Also, the notification might have
-        // been modified during the animation, so background might be null here.
+        // Also, the notification might have been modified during the animation, so background
+        // might be null here.
         if (iconDrawable != null) {
             iconDrawable.mutate().setColorFilter(mIconColorFilter);
         }
index 2fb3127..e83ecb7 100644 (file)
@@ -34,15 +34,7 @@ public abstract class NotificationViewWrapper {
 
     public static NotificationViewWrapper wrap(Context ctx, View v) {
         if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
-            if (TAG_BIG_MEDIA_NARROW.equals(v.getTag())) {
-                return new NotificationBigMediaNarrowViewWrapper(ctx, v);
-            } else if (TAG_MEDIA.equals(v.getTag())) {
-                return new NotificationMediaViewWrapper(ctx, v);
-            } else if (TAG_BIG_PICTURE.equals(v.getTag())) {
-                return new NotificationBigMediaNarrowViewWrapper(ctx, v);
-            } else {
-                return new NotificationTemplateViewWrapper(ctx, v);
-            }
+            return new NotificationTemplateViewWrapper(ctx, v);
         } else {
             return new NotificationCustomViewWrapper(v);
         }