From 48280e71c21d1dfcd04b593a16ea06f9f47dea14 Mon Sep 17 00:00:00 2001 From: Alexey Kuznetsov Date: Sat, 26 Mar 2016 20:41:33 +0300 Subject: [PATCH] apply animation only when visible --- .../activities/RecordingActivity.java | 5 +---- .../animations/MarginBottomAnimation.java | 3 +-- .../animations/StepAnimation.java | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java index 040c766..72e9c5b 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java +++ b/app/src/main/java/com/github/axet/audiorecorder/activities/RecordingActivity.java @@ -349,10 +349,7 @@ public class RecordingActivity extends AppCompatActivity { pitch.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { - View box = findViewById(R.id.recording_edit_box); - Animation a = box.getAnimation(); - boolean animate = box.getVisibility() == View.GONE || (a != null && !a.hasEnded()); - edit(true, animate); + edit(true, true); editSample = pitch.edit(event.getX()) * samplesUpdate; return true; } diff --git a/app/src/main/java/com/github/axet/audiorecorder/animations/MarginBottomAnimation.java b/app/src/main/java/com/github/axet/audiorecorder/animations/MarginBottomAnimation.java index 1bd2314..d465637 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/animations/MarginBottomAnimation.java +++ b/app/src/main/java/com/github/axet/audiorecorder/animations/MarginBottomAnimation.java @@ -82,9 +82,8 @@ public class MarginBottomAnimation extends StepAnimation { w = View.MeasureSpec.makeMeasureSpec(Math.max(width, parentWidth), View.MeasureSpec.AT_MOST); view.measure(w, h); - vh = view.getMeasuredHeight(); - view.measure(w, h); + vh = view.getMeasuredHeight(); } @Override diff --git a/app/src/main/java/com/github/axet/audiorecorder/animations/StepAnimation.java b/app/src/main/java/com/github/axet/audiorecorder/animations/StepAnimation.java index 665fbd7..5e80e29 100644 --- a/app/src/main/java/com/github/axet/audiorecorder/animations/StepAnimation.java +++ b/app/src/main/java/com/github/axet/audiorecorder/animations/StepAnimation.java @@ -28,14 +28,18 @@ public class StepAnimation extends Animation { if (animate) { if (m.hasEnded()) { - StepAnimation mm = c.create(); - mm.startAnimation(v); + if ((expand && v.getVisibility() == View.GONE) || (!expand && v.getVisibility() == View.VISIBLE)) { + StepAnimation mm = c.create(); + mm.startAnimation(v); + } else { + // do nothing, already visible view + } } else { if (m.expand != expand) { m.expand = expand; m.setStartOffset(offset); } else { - // keep rolling do nothing + // keep rolling. do nothing } } } else { @@ -50,7 +54,11 @@ public class StepAnimation extends Animation { } else { StepAnimation mm = c.create(); if (animate) { - mm.startAnimation(v); + if ((expand && v.getVisibility() == View.GONE) || (!expand && v.getVisibility() == View.VISIBLE)) { + mm.startAnimation(v); + } else { + // do nothing. already visible + } } else { mm.restore(); mm.end(); @@ -67,7 +75,7 @@ public class StepAnimation extends Animation { init(); // do first step to hide view (we animation does it). // - // but some androids API does not start animation on 0dp views. + // but some old androids API does not start animation on 0dp views. calc(0.01f, new Transformation()); v.startAnimation(this); }