Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions lib/java/com/google/android/material/timepicker/ClockHandView.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.view.ViewConfiguration;
import androidx.annotation.Dimension;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.core.view.ViewCompat;
Expand All @@ -57,7 +58,7 @@ class ClockHandView extends View {
private static final int DEFAULT_ANIMATION_DURATION = 200;
private final int animationDuration;
private final TimeInterpolator animationInterpolator;
private final ValueAnimator rotationAnimator = new ValueAnimator();
@NonNull private final ValueAnimator rotationAnimator = new ValueAnimator();
private boolean animatingOnTouchUp;
private float downX;
private float downY;
Expand Down Expand Up @@ -134,6 +135,23 @@ public ClockHandView(Context context, @Nullable AttributeSet attrs, int defStyle
scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
a.recycle();

initRotationAnimator();
}

private void initRotationAnimator() {
rotationAnimator.addUpdateListener(
animation -> {
float animatedValue = (float) animation.getAnimatedValue();
setHandRotationInternal(animatedValue, true);
});

rotationAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
animation.end();
}
});
}

@Override
Expand All @@ -150,9 +168,7 @@ public void setHandRotation(@FloatRange(from = 0f, to = 360f) float degrees) {
}

public void setHandRotation(@FloatRange(from = 0f, to = 360f) float degrees, boolean animate) {
if (rotationAnimator != null) {
rotationAnimator.cancel();
}
rotationAnimator.cancel();

if (!animate) {
setHandRotationInternal(degrees, false);
Expand All @@ -163,19 +179,6 @@ public void setHandRotation(@FloatRange(from = 0f, to = 360f) float degrees, boo
rotationAnimator.setFloatValues(animationValues.first, animationValues.second);
rotationAnimator.setDuration(animationDuration);
rotationAnimator.setInterpolator(animationInterpolator);
rotationAnimator.addUpdateListener(
animation -> {
float animatedValue = (float) animation.getAnimatedValue();
setHandRotationInternal(animatedValue, true);
});

rotationAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
animation.end();
}
});

rotationAnimator.start();
}

Expand Down