Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 20 /** Start time of the animation, from {@link SystemClock#uptimeMillis()}. */ | 21 /** Start time of the animation, from {@link SystemClock#uptimeMillis()}. */ |
| 21 private final long mStartTimeInMs; | 22 private final long mStartTimeInMs; |
| 22 | 23 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 35 | 36 |
| 36 /** Begins a new animation sequence at position (|pos|). */ | 37 /** Begins a new animation sequence at position (|pos|). */ |
| 37 public static void startAnimation(DesktopView view, | 38 public static void startAnimation(DesktopView view, |
| 38 Point pos, | 39 Point pos, |
| 39 DesktopView.InputFeedbackType feedbackType ) { | 40 DesktopView.InputFeedbackType feedbackType ) { |
| 40 if (feedbackType == DesktopView.InputFeedbackType.NONE) { | 41 if (feedbackType == DesktopView.InputFeedbackType.NONE) { |
| 41 return; | 42 return; |
| 42 } | 43 } |
| 43 | 44 |
| 44 view.onPaint().addSelfRemovable(new FeedbackAnimator( | 45 view.onPaint().addSelfRemovable(new FeedbackAnimator( |
| 45 getInputFeedbackSizeInPixels(feedbackType), pos)); | 46 getInputFeedbackSizeInPixels(feedbackType, view), pos)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 private static float getInputFeedbackSizeInPixels(DesktopView.InputFeedbackT ype feedbackType) { | 49 private static float getInputFeedbackSizeInPixels(DesktopView.InputFeedbackT ype feedbackType, |
| 50 View view) { | |
| 49 switch (feedbackType) { | 51 switch (feedbackType) { |
| 50 case SMALL_ANIMATION: | 52 case SMALL_ANIMATION: |
| 51 return 40.0f; | 53 return view.getResources() |
| 54 .getDimensionPixelSize(R.dimen.feedback_animation_radius _small); | |
|
joedow
2016/07/25 20:24:18
Can you cache these values? I'd assume they don't
Yuwei
2016/07/25 20:57:13
Sure. It probably won't change through the whole l
Yuwei
2016/07/25 21:21:56
Done.
| |
| 52 | 55 |
| 53 case LARGE_ANIMATION: | 56 case LARGE_ANIMATION: |
| 54 return 160.0f; | 57 return view.getResources() |
| 58 .getDimensionPixelSize(R.dimen.feedback_animation_radius _large); | |
| 55 | 59 |
| 56 default: | 60 default: |
| 57 // Unreachable, but required by Google Java style and findbugs. | 61 // Unreachable, but required by Google Java style and findbugs. |
| 58 assert false : "Unreached"; | 62 assert false : "Unreached"; |
| 59 return 0.0f; | 63 return 0.0f; |
| 60 } | 64 } |
| 61 } | 65 } |
| 62 | 66 |
| 63 @Override | 67 @Override |
| 64 public Boolean run(PaintEventParameter parameter) { | 68 public Boolean run(PaintEventParameter parameter) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 84 int transparentBlack = Color.argb(0, 0, 0, 0); | 88 int transparentBlack = Color.argb(0, 0, 0, 0); |
| 85 int white = Color.argb(alpha, 0xff, 0xff, 0xff); | 89 int white = Color.argb(alpha, 0xff, 0xff, 0xff); |
| 86 int black = Color.argb(alpha, 0, 0, 0); | 90 int black = Color.argb(alpha, 0, 0, 0); |
| 87 mPaint.setShader(new RadialGradient(mPos.x, mPos.y, radius, | 91 mPaint.setShader(new RadialGradient(mPos.x, mPos.y, radius, |
| 88 new int[] {transparentBlack, white, black, transparentBlack}, | 92 new int[] {transparentBlack, white, black, transparentBlack}, |
| 89 new float[] {0.0f, 0.8f, 0.9f, 1.0f}, Shader.TileMode.CLAMP)); | 93 new float[] {0.0f, 0.8f, 0.9f, 1.0f}, Shader.TileMode.CLAMP)); |
| 90 parameter.canvas.drawCircle(mPos.x, mPos.y, radius, mPaint); | 94 parameter.canvas.drawCircle(mPos.x, mPos.y, radius, mPaint); |
| 91 return true; | 95 return true; |
| 92 } | 96 } |
| 93 } | 97 } |
| OLD | NEW |