Index: chrome/android/java/src/org/chromium/chrome/browser/appmenu/PulseDrawableFactory.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/appmenu/PulseDrawableFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/PulseDrawableFactory.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..09901038580124ca0607f4237fd2484edb811cae |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/PulseDrawableFactory.java |
@@ -0,0 +1,70 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.appmenu; |
+ |
+import android.graphics.Canvas; |
+import android.graphics.Paint; |
+import android.graphics.Rect; |
+import android.support.v4.view.animation.FastOutSlowInInterpolator; |
+import android.support.v4.view.animation.PathInterpolatorCompat; |
+ |
+import org.chromium.base.ContextUtils; |
+import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.util.MathUtils; |
+ |
+/** |
+ * A helper factory to create {@link PulseDrawable}s. |
+ */ |
+public class PulseDrawableFactory { |
+ /** |
+ * Creates a {@link PulseDrawable} that will fill the bounds with a pulsing color. |
+ * @return A new {@link PulseDrawable} instance. |
+ */ |
+ public static PulseDrawable createHighlight() { |
Ted C
2017/04/12 18:05:57
Any reason these aren't statics in PulseDrawable?
David Trainor- moved to gerrit
2017/04/12 18:59:37
Sure sounds good.
|
+ PulseDrawable.Painter painter = new PulseDrawable.Painter() { |
+ @Override |
+ public void modifyDrawable(PulseDrawable drawable, float interpolation) { |
+ drawable.setAlpha((int) MathUtils.interpolate(12, 75, interpolation)); |
+ } |
+ |
+ @Override |
+ public void draw( |
+ PulseDrawable drawable, Paint paint, Canvas canvas, float interpolation) { |
+ canvas.drawRect(drawable.getBounds(), paint); |
+ } |
+ }; |
+ |
+ return new PulseDrawable(ContextUtils.getApplicationContext().getResources(), |
+ R.color.google_blue_500, new FastOutSlowInInterpolator(), painter); |
+ } |
+ |
+ /** |
+ * Creates a {@link PulseDrawable} that will draw a pulsing circle inside the bounds. |
+ * @return A new {@link PulseDrawable} instance. |
+ */ |
+ public static PulseDrawable createCircle() { |
+ PulseDrawable.Painter painter = new PulseDrawable.Painter() { |
+ @Override |
+ public void modifyDrawable(PulseDrawable drawable, float interpolation) { |
+ drawable.invalidateSelf(); |
+ } |
+ |
+ @Override |
+ public void draw( |
+ PulseDrawable drawable, Paint paint, Canvas canvas, float interpolation) { |
+ Rect bounds = drawable.getBounds(); |
+ float scale = MathUtils.interpolate(0.8f, 1.f, interpolation); |
+ float radius = Math.min(bounds.width(), bounds.height()) * scale / 2.f; |
+ canvas.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), radius, paint); |
+ } |
+ }; |
+ |
+ PulseDrawable drawable = new PulseDrawable( |
+ ContextUtils.getApplicationContext().getResources(), R.color.google_blue_500, |
+ PathInterpolatorCompat.create(.8f, 0.f, .6f, 1.f), painter); |
+ drawable.setAlpha(76); |
+ return drawable; |
+ } |
+} |