Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/FeedbackAnimator.java

Issue 2256943002: [Remoting Android] Remove old renderer code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chromoting;
6
7 import android.graphics.Color;
8 import android.graphics.Paint;
9 import android.graphics.Point;
10 import android.graphics.RadialGradient;
11 import android.graphics.Shader;
12 import android.os.SystemClock;
13
14 /** Helper class for displaying the press feedback animations. */
15 public final class FeedbackAnimator
16 implements Event.ParameterCallback<Boolean, PaintEventParameter> {
17 /** Total duration of the animation, in milliseconds. */
18 private static final float TOTAL_DURATION_MS = 220;
19
20 /** Start time of the animation, from {@link SystemClock#uptimeMillis()}. */
21 private final long mStartTimeInMs;
22
23 /** Contains the size of the feedback animation for the most recent request. */
24 private final float mFeedbackSizeInPixels;
25
26 private final Paint mPaint = new Paint();
27
28 private final Point mPos;
29
30 private FeedbackAnimator(float feedbackSizeInPixels, Point pos) {
31 mStartTimeInMs = SystemClock.uptimeMillis();
32 mFeedbackSizeInPixels = feedbackSizeInPixels;
33 mPos = pos;
34 }
35
36 /** Begins a new animation sequence at position (|pos|). */
37 public static void startAnimation(DesktopView view,
38 Point pos,
39 float feedbackRadius) {
40 if (feedbackRadius <= 0.0f) {
41 return;
42 }
43
44 view.onPaint().addSelfRemovable(new FeedbackAnimator(feedbackRadius, pos ));
45 }
46
47 @Override
48 public Boolean run(PaintEventParameter parameter) {
49 float elapsedTimeInMs = SystemClock.uptimeMillis() - mStartTimeInMs;
50 if (elapsedTimeInMs < 1) {
51 return true;
52 }
53
54 // |progress| is 0 at the beginning, 1 at the end.
55 float progress = elapsedTimeInMs / TOTAL_DURATION_MS;
56 if (progress >= 1) {
57 return false;
58 }
59
60 float size = mFeedbackSizeInPixels / parameter.scale;
61
62 // Animation grows from 0 to |size|, and goes from fully opaque to trans parent for a
63 // seamless fading-out effect. The animation needs to have more than one color so it's
64 // visible over any background color.
65 float radius = size * progress;
66 int alpha = (int) ((1 - progress) * 0xff);
67
68 int transparentBlack = Color.argb(0, 0, 0, 0);
69 int white = Color.argb(alpha, 0xff, 0xff, 0xff);
70 int black = Color.argb(alpha, 0, 0, 0);
71 mPaint.setShader(new RadialGradient(mPos.x, mPos.y, radius,
72 new int[] {transparentBlack, white, black, transparentBlack},
73 new float[] {0.0f, 0.8f, 0.9f, 1.0f}, Shader.TileMode.CLAMP));
74 parameter.canvas.drawCircle(mPos.x, mPos.y, radius, mPaint);
75 return true;
76 }
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698