| 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..122e3a9aea03038373ca3b85279603d869bedf2c
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/appmenu/PulseDrawableFactory.java
|
| @@ -0,0 +1,68 @@
|
| +// 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() {
|
| + 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;
|
| + canvas.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), radius, paint);
|
| + }
|
| + };
|
| +
|
| + return new PulseDrawable(ContextUtils.getApplicationContext().getResources(),
|
| + R.color.google_blue_500, PathInterpolatorCompat.create(.8f, 0.f, .6f, 1.f),
|
| + painter);
|
| + }
|
| +}
|
|
|