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 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 super.setUp(); 41 } 42 43 @Override 44 protected long getTimeout() { 45 return (2 * mAnimator.getDuration()) + (2 * mAnimator.getStartDelay()) + 46 ANIM_DELAY + FUTURE_RELEASE_DELAY; 47 } 48 49 /** 50 * Tests that an AnimatorSet can be correctly canceled during the delay of one of 51 * its children 52 */ 53 @MediumTest 54 public void testPlayingCancelDuringChildDelay() throws Exception { 55 yAnim.setStartDelay(500); 56 final AnimatorSet animSet = new AnimatorSet(); 57 animSet.playSequentially(xAnim, yAnim); 58 mFutureListener = new FutureReleaseListener(mFuture); 59 getActivity().runOnUiThread(new Runnable() { 60 @Override 61 public void run() { 62 try { 63 Handler handler = new Handler(); 64 animSet.addListener(mFutureListener); 65 mRunning = true; 66 animSet.start(); 67 handler.postDelayed(new Canceler(animSet, mFuture), ANIM_DURATION + 250); 68 } catch (junit.framework.AssertionFailedError e) { 69 mFuture.setException(new RuntimeException(e)); 70 } 71 } 72 }); 73 mFuture.get(getTimeout(), TimeUnit.MILLISECONDS); 74 } 75 76 public void setTranslationX(float value) { 77 button.setTranslationX(value); 78 } 79 80 81 public void setTranslationY(float value) { 82 button.setTranslationY(value); 83 } 84 85 86 } 87