summaryrefslogtreecommitdiffstats
path: root/core/tests
diff options
context:
space:
mode:
authorYigit Boyar <yboyar@google.com>2014-05-06 16:56:08 -0700
committerYigit Boyar <yboyar@google.com>2014-05-07 16:52:17 -0700
commitf4c5bf30b445874cf353e1b96cab94185a39ce6d (patch)
treebc4fab1d918ed4dc3c27f08de970d3f6b665e970 /core/tests
parent7d3387bc13427b61708d5a39fc4f626ee869ecdc (diff)
downloadframeworks_base-f4c5bf30b445874cf353e1b96cab94185a39ce6d.zip
frameworks_base-f4c5bf30b445874cf353e1b96cab94185a39ce6d.tar.gz
frameworks_base-f4c5bf30b445874cf353e1b96cab94185a39ce6d.tar.bz2
State based animators for Views
Set quantum theme buttons to elevate 2dp on press Change-Id: Ibf4f5ef166b901382c304d392eba075836a96a35
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/coretests/res/anim/reset_state_anim.xml6
-rw-r--r--core/tests/coretests/res/anim/test_state_anim.xml19
-rw-r--r--core/tests/coretests/src/android/animation/StateListAnimatorTest.java102
3 files changed, 127 insertions, 0 deletions
diff --git a/core/tests/coretests/res/anim/reset_state_anim.xml b/core/tests/coretests/res/anim/reset_state_anim.xml
new file mode 100644
index 0000000..918d0a3
--- /dev/null
+++ b/core/tests/coretests/res/anim/reset_state_anim.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <objectAnimator android:propertyName="x" android:duration="100" android:valueTo="0" android:valueType="floatType"/>
+ <objectAnimator android:propertyName="y" android:duration="100" android:valueTo="0" android:valueType="floatType"/>
+ <objectAnimator android:propertyName="z" android:duration="100" android:valueTo="0" android:valueType="floatType"/>
+</set> \ No newline at end of file
diff --git a/core/tests/coretests/res/anim/test_state_anim.xml b/core/tests/coretests/res/anim/test_state_anim.xml
new file mode 100644
index 0000000..9e08f68
--- /dev/null
+++ b/core/tests/coretests/res/anim/test_state_anim.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true">
+ <set>
+ <objectAnimator android:propertyName="x" android:duration="100" android:valueTo="10" android:valueType="floatType"/>
+ <objectAnimator android:propertyName="y" android:duration="100" android:valueTo="20" android:valueType="floatType"/>
+ <objectAnimator android:propertyName="z" android:duration="100" android:valueTo="20" android:valueType="floatType"/>
+ </set>
+ </item>
+ <item android:state_enabled="true" android:state_pressed="false">
+ <set>
+ <objectAnimator android:propertyName="x" android:duration="100" android:valueTo="0" android:valueType="floatType"/>
+ <objectAnimator android:propertyName="y" android:duration="100" android:valueTo="0" android:valueType="floatType"/>
+ <objectAnimator android:propertyName="z" android:duration="100" android:valueTo="0" android:valueType="floatType"/>
+ </set>
+ </item>
+ <!-- base state-->
+ <item android:animation="@anim/reset_state_anim"/>
+</selector> \ No newline at end of file
diff --git a/core/tests/coretests/src/android/animation/StateListAnimatorTest.java b/core/tests/coretests/src/android/animation/StateListAnimatorTest.java
new file mode 100644
index 0000000..38df78d
--- /dev/null
+++ b/core/tests/coretests/src/android/animation/StateListAnimatorTest.java
@@ -0,0 +1,102 @@
+/*
+* Copyright (C) 2014 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+package android.animation;
+
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
+import android.util.StateSet;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.frameworks.coretests.R;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+public class StateListAnimatorTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity> {
+
+ public StateListAnimatorTest() {
+ super(BasicAnimatorActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testInflateFromAnimator() throws Exception {
+ StateListAnimator stateListAnimator = AnimatorInflater
+ .loadStateListAnimator(getActivity(), R.anim.test_state_anim);
+ assertNotNull("A state list animator should be returned", stateListAnimator);
+ assertEquals("State list animator should have three items", 3,
+ stateListAnimator.getTuples().size());
+ }
+
+ @UiThreadTest
+ public void testAttachDetach() throws Exception {
+ View view = new View(getActivity());
+ final AtomicInteger setStateCount = new AtomicInteger(0);
+ StateListAnimator stateListAnimator = new StateListAnimator() {
+ @Override
+ public void setState(int[] state) {
+ setStateCount.incrementAndGet();
+ super.setState(state);
+ }
+ };
+ view.setStateListAnimator(stateListAnimator);
+ assertNotNull("State list animator should have a reference to view even if it is detached",
+ stateListAnimator.getTarget());
+ ViewGroup viewGroup = (ViewGroup) getActivity().findViewById(android.R.id.content);
+ int preSetStateCount = setStateCount.get();
+ viewGroup.addView(view);
+ assertTrue("When view is attached, state list drawable's setState should be called",
+ preSetStateCount < setStateCount.get());
+
+ StateListAnimator stateListAnimator2 = new StateListAnimator();
+ view.setStateListAnimator(stateListAnimator2);
+ assertNull("When a new state list animator is assigned, previous one should be detached",
+ stateListAnimator.getTarget());
+ assertNull("Any running animator should be removed on detach",
+ stateListAnimator.getRunningAnimator());
+ assertEquals("The new state list animator should be attached to the view",
+ view, stateListAnimator2.getTarget());
+ viewGroup.removeView(view);
+ assertNotNull("When view is detached from window, state list animator should still keep the"
+ + " reference",
+ stateListAnimator2.getTarget());
+ }
+
+ public void testStateListLoading() throws InterruptedException {
+ StateListAnimator stateListAnimator = AnimatorInflater
+ .loadStateListAnimator(getActivity(), R.anim.test_state_anim);
+ assertNotNull("A state list animator should be returned", stateListAnimator);
+ assertEquals("Steate list animator should have two items", 3,
+ stateListAnimator.getTuples().size());
+ StateListAnimator.Tuple tuple1 = stateListAnimator.getTuples().get(0);
+ assertEquals("first tuple should have one state", 1, tuple1.getSpecs().length);
+ assertEquals("first spec in tuple 1 should be pressed",
+ com.android.internal.R.attr.state_pressed, tuple1.getSpecs()[0]);
+
+ StateListAnimator.Tuple tuple2 = stateListAnimator.getTuples().get(1);
+ assertEquals("Second tuple should have two specs", 2, tuple2.getSpecs().length);
+ assertTrue("Tuple two should match the expected state",
+ StateSet.stateSetMatches(tuple2.getSpecs(),
+ new int[]{-com.android.internal.R.attr.state_pressed,
+ com.android.internal.R.attr.state_enabled}));
+ }
+}