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

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

Issue 2175353003: [Remoting Android] Define feedback animation size in dp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.graphics.Color; 7 import android.graphics.Color;
8 import android.graphics.Paint; 8 import android.graphics.Paint;
9 import android.graphics.Point; 9 import android.graphics.Point;
10 import android.graphics.RadialGradient; 10 import android.graphics.RadialGradient;
11 import android.graphics.Shader; 11 import android.graphics.Shader;
12 import android.os.SystemClock; 12 import android.os.SystemClock;
13 import android.view.View;
13 14
14 /** Helper class for displaying the press feedback animations. */ 15 /** Helper class for displaying the press feedback animations. */
15 public final class FeedbackAnimator 16 public final class FeedbackAnimator
16 implements Event.ParameterCallback<Boolean, PaintEventParameter> { 17 implements Event.ParameterCallback<Boolean, PaintEventParameter> {
17 /** Total duration of the animation, in milliseconds. */ 18 /** Total duration of the animation, in milliseconds. */
18 private static final float TOTAL_DURATION_MS = 220; 19 private static final float TOTAL_DURATION_MS = 220;
19 20
21 private static float sSmallFeedbackPixelRadius = -1;
22 private static float sLargeFeedbackPixelRadius = -1;
23
20 /** Start time of the animation, from {@link SystemClock#uptimeMillis()}. */ 24 /** Start time of the animation, from {@link SystemClock#uptimeMillis()}. */
21 private final long mStartTimeInMs; 25 private final long mStartTimeInMs;
22 26
23 /** Contains the size of the feedback animation for the most recent request. */ 27 /** Contains the size of the feedback animation for the most recent request. */
24 private final float mFeedbackSizeInPixels; 28 private final float mFeedbackSizeInPixels;
25 29
26 private final Paint mPaint = new Paint(); 30 private final Paint mPaint = new Paint();
27 31
28 private final Point mPos; 32 private final Point mPos;
29 33
30 private FeedbackAnimator(float feedbackSizeInPixels, Point pos) { 34 private FeedbackAnimator(float feedbackSizeInPixels, Point pos) {
31 mStartTimeInMs = SystemClock.uptimeMillis(); 35 mStartTimeInMs = SystemClock.uptimeMillis();
32 mFeedbackSizeInPixels = feedbackSizeInPixels; 36 mFeedbackSizeInPixels = feedbackSizeInPixels;
33 mPos = pos; 37 mPos = pos;
34 } 38 }
35 39
36 /** Begins a new animation sequence at position (|pos|). */ 40 /** Begins a new animation sequence at position (|pos|). */
37 public static void startAnimation(DesktopView view, 41 public static void startAnimation(DesktopView view,
38 Point pos, 42 Point pos,
39 DesktopView.InputFeedbackType feedbackType ) { 43 DesktopView.InputFeedbackType feedbackType ) {
40 if (feedbackType == DesktopView.InputFeedbackType.NONE) { 44 if (feedbackType == DesktopView.InputFeedbackType.NONE) {
41 return; 45 return;
42 } 46 }
43 47
44 view.onPaint().addSelfRemovable(new FeedbackAnimator( 48 view.onPaint().addSelfRemovable(new FeedbackAnimator(
45 getInputFeedbackSizeInPixels(feedbackType), pos)); 49 getInputFeedbackSizeInPixels(feedbackType, view), pos));
46 } 50 }
47 51
48 private static float getInputFeedbackSizeInPixels(DesktopView.InputFeedbackT ype feedbackType) { 52 private static float getInputFeedbackSizeInPixels(DesktopView.InputFeedbackT ype feedbackType,
53 View view) {
Lambros 2016/07/25 22:14:32 I think it's more idiomatic to pass a Context rath
49 switch (feedbackType) { 54 switch (feedbackType) {
50 case SMALL_ANIMATION: 55 case SMALL_ANIMATION:
51 return 40.0f; 56 if (sSmallFeedbackPixelRadius < 0) {
57 sSmallFeedbackPixelRadius = view.getResources()
58 .getDimensionPixelSize(R.dimen.feedback_animation_ra dius_small);
Lambros 2016/07/25 22:14:32 The dp/pixel scaling factor is dependent on the Co
Lambros 2016/07/25 22:28:45 Actually, I'm not sure about this. The scaling fac
59 }
60 return sSmallFeedbackPixelRadius;
52 61
53 case LARGE_ANIMATION: 62 case LARGE_ANIMATION:
54 return 160.0f; 63 if (sLargeFeedbackPixelRadius < 0) {
64 sLargeFeedbackPixelRadius = view.getResources()
65 .getDimensionPixelSize(R.dimen.feedback_animation_ra dius_large);
66 }
67 return sLargeFeedbackPixelRadius;
55 68
56 default: 69 default:
57 // Unreachable, but required by Google Java style and findbugs. 70 // Unreachable, but required by Google Java style and findbugs.
58 assert false : "Unreached"; 71 assert false : "Unreached";
59 return 0.0f; 72 return 0.0f;
60 } 73 }
61 } 74 }
62 75
63 @Override 76 @Override
64 public Boolean run(PaintEventParameter parameter) { 77 public Boolean run(PaintEventParameter parameter) {
(...skipping 19 matching lines...) Expand all
84 int transparentBlack = Color.argb(0, 0, 0, 0); 97 int transparentBlack = Color.argb(0, 0, 0, 0);
85 int white = Color.argb(alpha, 0xff, 0xff, 0xff); 98 int white = Color.argb(alpha, 0xff, 0xff, 0xff);
86 int black = Color.argb(alpha, 0, 0, 0); 99 int black = Color.argb(alpha, 0, 0, 0);
87 mPaint.setShader(new RadialGradient(mPos.x, mPos.y, radius, 100 mPaint.setShader(new RadialGradient(mPos.x, mPos.y, radius,
88 new int[] {transparentBlack, white, black, transparentBlack}, 101 new int[] {transparentBlack, white, black, transparentBlack},
89 new float[] {0.0f, 0.8f, 0.9f, 1.0f}, Shader.TileMode.CLAMP)); 102 new float[] {0.0f, 0.8f, 0.9f, 1.0f}, Shader.TileMode.CLAMP));
90 parameter.canvas.drawCircle(mPos.x, mPos.y, radius, mPaint); 103 parameter.canvas.drawCircle(mPos.x, mPos.y, radius, mPaint);
91 return true; 104 return true;
92 } 105 }
93 } 106 }
OLDNEW
« no previous file with comments | « remoting/android/java/res/values/dimens.xml ('k') | remoting/android/java/src/org/chromium/chromoting/GlDesktopView.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698