1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.animation; 17 18 import android.os.Handler; 19 import android.test.suitebuilder.annotation.MediumTest; 20 import android.test.suitebuilder.annotation.SmallTest; 21 import android.widget.Button; 22 import com.android.frameworks.coretests.R; 23 24 import java.util.concurrent.TimeUnit; 25 26 /** 27 * Listener tests for AnimatorSet. 28 */ 29 public class AnimatorSetEventsTest extends EventsTest { 30 31 Button button; 32 ObjectAnimator xAnim = ObjectAnimator.ofFloat(this, "translationX", 0, 100); 33 ObjectAnimator yAnim = ObjectAnimator.ofFloat(this, "translationY", 0, 100); 34 35 @Override setUp()36 public void setUp() throws Exception { 37 button = (Button) getActivity().findViewById(R.id.animatingButton); 38 mAnimator = new AnimatorSet(); 39 ((AnimatorSet)mAnimator).playSequentially(xAnim, yAnim); 40 41 super.setUp(); 42 } 43 44 @Override getTimeout()45 protected long getTimeout() { 46 return (xAnim.getDuration() + yAnim.getDuration()) + 47 (xAnim.getStartDelay() + yAnim.getStartDelay()) + 48 ANIM_DELAY + FUTURE_RELEASE_DELAY; 49 } 50 51 /** 52 * Tests that an AnimatorSet can be correctly canceled during the delay of one of 53 * its children 54 */ 55 @MediumTest testPlayingCancelDuringChildDelay()56 public void testPlayingCancelDuringChildDelay() throws Exception { 57 yAnim.setStartDelay(500); 58 final AnimatorSet animSet = new AnimatorSet(); 59 animSet.playSequentially(xAnim, yAnim); 60 mFutureListener = new FutureReleaseListener(mFuture); 61 getActivity().runOnUiThread(new Runnable() { 62 @Override 63 public void run() { 64 try { 65 Handler handler = new Handler(); 66 animSet.addListener(mFutureListener); 67 mRunning = true; 68 animSet.start(); 69 handler.postDelayed(new Canceler(animSet, mFuture), ANIM_DURATION + 250); 70 } catch (junit.framework.AssertionFailedError e) { 71 mFuture.setException(new RuntimeException(e)); 72 } 73 } 74 }); 75 mFuture.get(getTimeout(), TimeUnit.MILLISECONDS); 76 } 77 setTranslationX(float value)78 public void setTranslationX(float value) { 79 button.setTranslationX(value); 80 } 81 82 setTranslationY(float value)83 public void setTranslationY(float value) { 84 button.setTranslationY(value); 85 } 86 87 88 } 89