apply animation only when visible

This commit is contained in:
Alexey Kuznetsov 2016-03-26 20:41:33 +03:00
commit 48280e71c2
3 changed files with 15 additions and 11 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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);
}