1a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach/* 2a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * Copyright (C) 2008 The Android Open Source Project 3a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * 4a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * Licensed under the Apache License, Version 2.0 (the "License"); 5a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * you may not use this file except in compliance with the License. 6a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * You may obtain a copy of the License at 7a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * 8a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * http://www.apache.org/licenses/LICENSE-2.0 9a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * 10a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * Unless required by applicable law or agreed to in writing, software 11a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * distributed under the License is distributed on an "AS IS" BASIS, 12a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * See the License for the specific language governing permissions and 14a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * limitations under the License. 15a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach */ 16a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 17a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachpackage android.view.animation.cts; 18a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 19a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport com.android.cts.stub.R; 20a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 21a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 22a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.app.ListActivity; 23a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.content.Context; 24a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.content.res.XmlResourceParser; 25a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.test.ActivityInstrumentationTestCase2; 26a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.util.AttributeSet; 27a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.util.Xml; 28a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.View; 29a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.ViewGroup.LayoutParams; 30a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.AccelerateInterpolator; 31a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.Animation; 32a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.AnimationUtils; 33a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.DecelerateInterpolator; 34a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.Interpolator; 35a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.LayoutAnimationController; 36a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.ScaleAnimation; 37a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.Transformation; 38a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.view.animation.LayoutAnimationController.AnimationParameters; 39a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.widget.AbsListView; 40a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachimport android.widget.ListView; 41a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 42a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubachpublic class LayoutAnimationControllerTest 43a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach extends ActivityInstrumentationTestCase2<LayoutAnimStubActivity> { 44a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 45a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private ListActivity mActivity; 46a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private Animation mDefaultAnimation; 47a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private ListView mListView; 48a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private LayoutAnimationController mController; 49a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach /** Duration defined in layout_anim_controller_animation.xml is 1000 */ 50a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final int DURATION = 1000; 51a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final float DELTA = 0.1f; 52a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final int INDEX_OF_CHILD1 = 0; 53a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final int INDEX_OF_CHILD2 = 1; 54a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final int INDEX_OF_CHILD3 = 2; 55a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach /** Default delay of LayoutAnimationController */ 56a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final float DEFAULT_DELAY = 0.5f; 57a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach /** Default max duration of these three children */ 58a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private static final long DEFAULT_MAX_DURATION = 2000; 59a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 60a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public LayoutAnimationControllerTest() { 61a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach super("com.android.cts.stub", LayoutAnimStubActivity.class); 62a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 63a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 64a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach @Override 65a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach protected void setUp() throws Exception { 66a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach super.setUp(); 67a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mActivity = getActivity(); 68a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mListView = mActivity.getListView(); 69a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mDefaultAnimation = AnimationUtils.loadAnimation(mActivity, 70a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach R.anim.layout_anim_controller_animation); 71a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController = new LayoutAnimationController(mDefaultAnimation, DEFAULT_DELAY); 72a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 73a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 74a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testAccessOrder() throws InterruptedException { 75a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 76a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setOrder(LayoutAnimationController.ORDER_NORMAL); 77a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(LayoutAnimationController.ORDER_NORMAL, mController.getOrder()); 78a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 79a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 80a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 81a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 82a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 83a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 84a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 85a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 86a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // Test normal order 87a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long startTime = childAnimation1.getStartTime(); 88a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, childAnimation1.getStartOffset()); 89a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(500, childAnimation2.getStartOffset()); 90a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1000, childAnimation3.getStartOffset()); 91a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 92a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation1 = new Transformation(); 93a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation2 = new Transformation(); 94a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation3 = new Transformation(); 95a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 96a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 has started animation, child2 and child3 haven't started 97a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 500, transformation1); 98a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 500, transformation2); 99a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 500, transformation3); 100a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation1.getAlpha()); 101a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation2.getAlpha(), DELTA); 102a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation3.getAlpha(), DELTA); 103a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 104a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child2 has started animation, child1 has finished and child3 hasn't started 105a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 1000, transformation1); 106a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 1000, transformation2); 107a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 1000, transformation3); 108a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation1.getAlpha(), DELTA); 109a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation2.getAlpha()); 110a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation3.getAlpha(), DELTA); 111a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 112a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child3 has started animation, child1, child2 have finished 113a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 1500, transformation1); 114a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 1500, transformation2); 115a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 1500, transformation3); 116a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation1.getAlpha(), DELTA); 117a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation2.getAlpha(), DELTA); 118a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation3.getAlpha()); 119a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 120a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // Test reverse order 121a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setOrder(LayoutAnimationController.ORDER_REVERSE); 122a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(LayoutAnimationController.ORDER_REVERSE, mController.getOrder()); 123a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 124a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 125a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 126a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach transformation1 = new Transformation(); 127a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach transformation2 = new Transformation(); 128a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach transformation3 = new Transformation(); 129a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 130a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 131a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 132a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach startTime = childAnimation1.getStartTime(); 133a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1000, childAnimation1.getStartOffset()); 134a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(500, childAnimation2.getStartOffset()); 135a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, childAnimation3.getStartOffset()); 136a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 137a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child3 has started animation, child1 and child2 haven't started 138a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 500, transformation1); 139a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 500, transformation2); 140a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 500, transformation3); 141a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation1.getAlpha(), DELTA); 142a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation2.getAlpha(), DELTA); 143a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation3.getAlpha()); 144a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 145a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child2 has started animation, child3 has finished and child1 hasn't started 146a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 1000, transformation1); 147a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 1000, transformation2); 148a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 1000, transformation3); 149a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation1.getAlpha(), DELTA); 150a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation2.getAlpha()); 151a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation3.getAlpha(), DELTA); 152a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 153a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 has started animation, child2 and child3 has finished 154a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 1500, transformation1); 155a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 1500, transformation2); 156a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 1500, transformation3); 157a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation1.getAlpha()); 158a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation2.getAlpha(), DELTA); 159a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation3.getAlpha(), DELTA); 160a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 161a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 162a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testAccessDelay() throws InterruptedException { 163a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setOrder(LayoutAnimationController.ORDER_NORMAL); 164a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float delay = 1.5f; 165a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setDelay(delay); 166a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(delay, mController.getDelay()); 167a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long maxDuration = (long) (delay * INDEX_OF_CHILD3 * DURATION + DURATION); 168a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 169a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach maxDuration); 170a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 171a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 172a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 173a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 174a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 175a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long startTime = childAnimation1.getStartTime(); 176a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long offsetTime1 = childAnimation1.getStartOffset(); 177a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long offsetTime2 = childAnimation2.getStartOffset(); 178a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long offsetTime3 = childAnimation3.getStartOffset(); 179a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child animation delay = child index * delay * animation duration 180a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, offsetTime1); 181a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1500, offsetTime2); 182a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(3000, offsetTime3); 183a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 184a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation1 = new Transformation(); 185a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation2 = new Transformation(); 186a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation3 = new Transformation(); 187a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 188a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 has started animation, child2 and child3 haven't started 189a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 500, transformation1); 190a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 500, transformation2); 191a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 500, transformation3); 192a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation1.getAlpha()); 193a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation2.getAlpha(), DELTA); 194a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation3.getAlpha(), DELTA); 195a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 196a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 has finished, child2 and child3 haven't started 197a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 1200, transformation1); 198a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 1200, transformation2); 199a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 1200, transformation3); 200a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation1.getAlpha(), DELTA); 201a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation2.getAlpha(), DELTA); 202a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation3.getAlpha(), DELTA); 203a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 204a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 has finished, child2 has started animation, child3 hasn't started. 205a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 2000, transformation1); 206a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 2000, transformation2); 207a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 2000, transformation3); 208a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation1.getAlpha(), DELTA); 209a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation2.getAlpha()); 210a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation3.getAlpha(), DELTA); 211a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 212a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 and child2 have finished, child3 hasn't started 213a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 2700, transformation1); 214a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 2700, transformation2); 215a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 2700, transformation3); 216a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation1.getAlpha(), DELTA); 217a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1.0f, transformation2.getAlpha(), DELTA); 218a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0.0f, transformation3.getAlpha(), DELTA); 219a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 220a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1 and child2 have finished, child3 has started animation 221a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1.getTransformation(startTime + 3500, transformation1); 222a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2.getTransformation(startTime + 3500, transformation2); 223a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3.getTransformation(startTime + 3500, transformation3); 224a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertIsRunningAnimation(transformation3.getAlpha()); 225a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 226a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 227a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private void assertIsRunningAnimation(float alpha) { 228a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(alpha > 0.0f); 229a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(alpha < 1.0f); 230a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 231a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 232a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testAccessAnimation() throws InterruptedException { 233a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.decelerate_alpha); 234a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.setFillAfter(true); 235a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // duration defined in decelerate_alpha.xml is 2000 236a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long duration = 2000; 237a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setAnimation(animation); 238a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertSame(animation, mController.getAnimation()); 239a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long maxDuration = (long) (DEFAULT_DELAY * INDEX_OF_CHILD3 * duration + duration); 240a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 241a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach maxDuration); 242a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 243a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 244a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 245a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 246a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation1, false, duration); 247a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation2, false, duration); 248a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation3, false, duration); 249a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 250a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setAnimation(mActivity, R.anim.layout_anim_controller_animation); 251a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation actualAnimation = mController.getAnimation(); 252a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(DURATION, actualAnimation.getDuration()); 253a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(actualAnimation.getInterpolator() instanceof AccelerateInterpolator); 254a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 255a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 256a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 257a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 258a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 259a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 260a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation1, true, DURATION); 261a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation2, true, DURATION); 262a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation3, true, DURATION); 263a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 264a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 265a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach /** 266a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * This method is used for asserting alpha of accelerate and decelerate animations to 267a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * make sure their accelerate/decelerate functionalities really work. 268a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * @param animation 269a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * @param isAccelerate 270a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach * @param duration 271a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach */ 272a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private void assertAnimation(Animation animation, boolean isAccelerate, long duration) { 273a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Transformation transformation = new Transformation(); 274a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long baseTime = animation.getStartTime() + animation.getStartOffset(); 275a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.getTransformation(baseTime, transformation); 276a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long step = duration / 4; 277a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float alpha1 = transformation.getAlpha(); 278a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.getTransformation(baseTime + step * 1, transformation); 279a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float alpha2 = transformation.getAlpha(); 280a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.getTransformation(baseTime + step * 2, transformation); 281a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float alpha3 = transformation.getAlpha(); 282a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.getTransformation(baseTime + step * 3, transformation); 283a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float alpha4 = transformation.getAlpha(); 284a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.getTransformation(baseTime + step * 4, transformation); 285a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float alpha5 = transformation.getAlpha(); 286a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 287a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // check decelerating delta alpha 288a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float delta1 = alpha2 - alpha1; 289a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float delta2 = alpha3 - alpha2; 290a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float delta3 = alpha4 - alpha3; 291a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach float delta4 = alpha5 - alpha4; 292a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach if (isAccelerate) { 293a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta1 < delta2); 294a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta2 < delta3); 295a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta3 < delta4); 296a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } else { 297a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta1 > delta2); 298a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta2 > delta3); 299a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta3 > delta4); 300a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 301a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 302a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 303a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testAccessInterpolator() throws InterruptedException { 304a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DecelerateInterpolator interpolator = new DecelerateInterpolator(1.0f); 305a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setInterpolator(interpolator); 306a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertSame(interpolator, mController.getInterpolator()); 307a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 308a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 309a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 310a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 311a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 312a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 313a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 314a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long delta1 = childAnimation2.getStartOffset() - childAnimation1.getStartOffset(); 315a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long delta2 = childAnimation3.getStartOffset() - childAnimation2.getStartOffset(); 316a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta2 < delta1); 317a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 318a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setInterpolator(mActivity, android.R.anim.accelerate_interpolator); 319a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(mController.getInterpolator() instanceof AccelerateInterpolator); 320a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 321a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 322a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 323a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 324a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 325a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 326a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 327a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach delta1 = childAnimation2.getStartOffset() - childAnimation1.getStartOffset(); 328a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach delta2 = childAnimation3.getStartOffset() - childAnimation2.getStartOffset(); 329a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(delta2 > delta1); 330a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 331a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 332a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testConstructor() { 333a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach XmlResourceParser parser = mActivity.getResources().getAnimation( 334a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach R.anim.accelerate_decelerate_alpha); 335a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AttributeSet attrs = Xml.asAttributeSet(parser); 336a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach new LayoutAnimationController(mActivity, attrs); 337a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach new LayoutAnimationController(mDefaultAnimation, DEFAULT_DELAY); 338a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach LayoutAnimationController controller = new LayoutAnimationController(mDefaultAnimation); 339a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(DEFAULT_DELAY, controller.getDelay()); 340a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 341a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 342a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testGetDelayForView() throws Throwable { 343a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.decelerate_alpha); 344a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.setFillAfter(true); 345a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach MyLayoutAnimationController controller = new MyLayoutAnimationController(animation); 346a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 347a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child1's animationParams 348a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final AbsListView.LayoutParams layoutParams1 = setAnimationParameters(0); 349a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child2's animationParams 350a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final AbsListView.LayoutParams layoutParams2 = setAnimationParameters(1); 351a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child3's animationParams 352a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final AbsListView.LayoutParams layoutParams3 = setAnimationParameters(2); 353a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 354a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final View child1 = mListView.getChildAt(INDEX_OF_CHILD1); 355a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final View child2 = mListView.getChildAt(INDEX_OF_CHILD2); 356a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final View child3 = mListView.getChildAt(INDEX_OF_CHILD3); 357a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach runTestOnUiThread(new Runnable() { 358a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void run() { 359a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach child1.setLayoutParams(layoutParams1); 360a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach child2.setLayoutParams(layoutParams2); 361a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach child3.setLayoutParams(layoutParams3); 362a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 363a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach }); 364a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 365a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, controller, 366a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 367a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 368a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, controller.getDelayForView(child1)); 369a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1000, controller.getDelayForView(child2)); 370a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(2000, controller.getDelayForView(child3)); 371a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 372a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 373a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private AbsListView.LayoutParams setAnimationParameters(int index) { 374a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationParameters animationParams = new AnimationParameters(); 375a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = index; 376a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.count = 3; 377a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach final AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams( 3780cbe49a83ac10de466b8efa8d8775d8686353186Romain Guy LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 379a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach layoutParams.layoutAnimationParameters = animationParams; 380a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach return layoutParams; 381a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 382a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 383a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testGetTransformedIndex() { 384a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.decelerate_alpha); 385a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.setFillAfter(true); 386a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach MyLayoutAnimationController controller = new MyLayoutAnimationController(animation); 387a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationParameters animationParams = new AnimationParameters(); 388a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.count = 3; 389a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 390a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // Test getTransformedIndex in ORDER_NORMAL condition, child1_index == 0, child2_index == 1, 391a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child3_index == 2 392a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = 0; 393a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, controller.getTransformedIndex(animationParams)); 394a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = 1; 395a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1, controller.getTransformedIndex(animationParams)); 396a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = 2; 397a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(2, controller.getTransformedIndex(animationParams)); 398a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // Test getTransformedIndex in ORDER_REVERSE condition, child1_index == 2, 399a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // child2_index == 1, child3_index == 0 400a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach controller.setOrder(LayoutAnimationController.ORDER_REVERSE); 401a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = 0; 402a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(2, controller.getTransformedIndex(animationParams)); 403a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = 1; 404a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1, controller.getTransformedIndex(animationParams)); 405a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animationParams.index = 2; 406a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, controller.getTransformedIndex(animationParams)); 407a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 408a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 409a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testStart() { 410a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation animation = new ScaleAnimation(0.0f, 10.0f, 0.0f, 20.0f); 411a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.setStartTime(500); 412a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach LayoutAnimationController controller = new LayoutAnimationController(animation); 413a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 414a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(Animation.START_ON_FIRST_FRAME != controller.getAnimation().getStartTime()); 415a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 416a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach controller.start(); 417a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(Animation.START_ON_FIRST_FRAME, controller.getAnimation().getStartTime()); 418a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 419a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 420a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testIsDone() throws InterruptedException { 421a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 422a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 423a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(mController.isDone()); 424a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 425a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 426a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testGetAnimationForView() throws InterruptedException { 427a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation animation = AnimationUtils.loadAnimation(mActivity, R.anim.decelerate_alpha); 428a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach animation.setFillAfter(true); 429a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach mController.setAnimation(animation); 430a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach AnimationTestUtils.assertRunController(getInstrumentation(), mListView, mController, 431a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach DEFAULT_MAX_DURATION); 432a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation1 = mListView.getChildAt(INDEX_OF_CHILD1).getAnimation(); 433a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation2 = mListView.getChildAt(INDEX_OF_CHILD2).getAnimation(); 434a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach Animation childAnimation3 = mListView.getChildAt(INDEX_OF_CHILD3).getAnimation(); 435a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach // duration defined in decelerate_alpha.xml is 2000 436a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach long duration = 2000; 437a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation1, false, duration); 438a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation2, false, duration); 439a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertAnimation(childAnimation3, false, duration); 440a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(0, childAnimation1.getStartOffset()); 441a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(1000, childAnimation2.getStartOffset()); 442a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertEquals(2000, childAnimation3.getStartOffset()); 443a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 444a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 445a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public void testWillOverlap() { 446a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach LayoutAnimationController controller = new LayoutAnimationController(mDefaultAnimation); 447a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 448a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach controller.setDelay(0.5f); 449a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertTrue(controller.willOverlap()); 450a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 451a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach controller.setDelay(1.0f); 452a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertFalse(controller.willOverlap()); 453a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 454a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach controller.setDelay(1.5f); 455a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach assertFalse(controller.willOverlap()); 456a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 457a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 458a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach private class MyLayoutAnimationController extends LayoutAnimationController { 459a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach public MyLayoutAnimationController(Animation animation) { 460a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach super(animation); 461a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 462a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 463a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach protected int getTransformedIndex(AnimationParameters params) { 464a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach return super.getTransformedIndex(params); 465a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 466a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach 467a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach protected long getDelayForView(View view) { 468a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach return super.getDelayForView(view); 469a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 470a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach } 471a97f97f1707bac6c00770c6ae4d28ef217b48659Phil Dubach} 472