summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2015-06-01 18:52:41 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-01 18:52:41 +0000
commitebafff0f5fb7dec144e50b3230a39faf2096c242 (patch)
treeefeba5a9da63fa5519947ac79bebd447e5750517
parent6f5e9e3055677af7b0da3852f4a7995c62e14485 (diff)
parent8c10c403c063aff3f17c4949b0fe9a88536ae580 (diff)
downloadsetupwizard-ebafff0f5fb7dec144e50b3230a39faf2096c242.tar.gz
Merge "[SetupWizardLib] Support for ObjectAnimator" into ub-setupwizard-alatar
-rw-r--r--library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml26
-rw-r--r--library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml26
-rw-r--r--library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml26
-rw-r--r--library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml26
-rw-r--r--library/main/res/animator-v11/suw_slide_back_in.xml26
-rw-r--r--library/main/res/animator-v11/suw_slide_back_out.xml26
-rw-r--r--library/main/res/animator-v11/suw_slide_next_in.xml26
-rw-r--r--library/main/res/animator-v11/suw_slide_next_out.xml26
-rw-r--r--library/main/src/com/android/setupwizardlib/SetupWizardLayout.java51
-rw-r--r--library/main/src/com/android/setupwizardlib/annotations/Keep.java49
-rw-r--r--library/main/src/com/android/setupwizardlib/annotations/VisibleForTesting.java (renamed from library/main/src/com/android/annotations/VisibleForTesting.java)2
-rw-r--r--library/main/src/com/android/setupwizardlib/util/Partner.java2
-rw-r--r--library/main/src/com/android/setupwizardlib/view/BottomScrollView.java2
13 files changed, 311 insertions, 3 deletions
diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml b/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml
new file mode 100644
index 0000000..195c8b1
--- /dev/null
+++ b/library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="1.0"
+ android:valueTo="0" />
diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml b/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml
new file mode 100644
index 0000000..a910233
--- /dev/null
+++ b/library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="0"
+ android:valueTo="-1.0" />
diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml b/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml
new file mode 100644
index 0000000..1b8c68e
--- /dev/null
+++ b/library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="-1.0"
+ android:valueTo="0" />
diff --git a/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml b/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml
new file mode 100644
index 0000000..9442096
--- /dev/null
+++ b/library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="0"
+ android:valueTo="1.0" />
diff --git a/library/main/res/animator-v11/suw_slide_back_in.xml b/library/main/res/animator-v11/suw_slide_back_in.xml
new file mode 100644
index 0000000..1b8c68e
--- /dev/null
+++ b/library/main/res/animator-v11/suw_slide_back_in.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="-1.0"
+ android:valueTo="0" />
diff --git a/library/main/res/animator-v11/suw_slide_back_out.xml b/library/main/res/animator-v11/suw_slide_back_out.xml
new file mode 100644
index 0000000..9442096
--- /dev/null
+++ b/library/main/res/animator-v11/suw_slide_back_out.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="0"
+ android:valueTo="1.0" />
diff --git a/library/main/res/animator-v11/suw_slide_next_in.xml b/library/main/res/animator-v11/suw_slide_next_in.xml
new file mode 100644
index 0000000..195c8b1
--- /dev/null
+++ b/library/main/res/animator-v11/suw_slide_next_in.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="1.0"
+ android:valueTo="0" />
diff --git a/library/main/res/animator-v11/suw_slide_next_out.xml b/library/main/res/animator-v11/suw_slide_next_out.xml
new file mode 100644
index 0000000..a910233
--- /dev/null
+++ b/library/main/res/animator-v11/suw_slide_next_out.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2014 Google Inc.
+
+ 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.
+-->
+
+<!-- Animate the X translation. The view this animator is run on must have the methods
+ setXFraction(float) and getXFraction methods implemented. Also make sure these 2 methods are
+ not stripped out by proguard. -->
+<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="@integer/suwTransitionDuration"
+ android:interpolator="@android:interpolator/decelerate_quad"
+ android:propertyName="xFraction"
+ android:valueFrom="0"
+ android:valueTo="-1.0" />
diff --git a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java
index 60da563..9caff6c 100644
--- a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java
+++ b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java
@@ -36,9 +36,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
+import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.TextView;
+import com.android.setupwizardlib.annotations.Keep;
import com.android.setupwizardlib.util.RequireScrollHelper;
import com.android.setupwizardlib.view.BottomScrollView;
import com.android.setupwizardlib.view.Illustration;
@@ -424,6 +426,55 @@ public class SetupWizardLayout extends FrameLayout {
}
}
+ /* Animator support */
+
+ private float mXFraction;
+ private ViewTreeObserver.OnPreDrawListener mPreDrawListener;
+
+ /**
+ * Set the X translation as a fraction of the width of this view. Make sure this method is not
+ * stripped out by proguard when using ObjectAnimator. You may need to add
+ * -keep @com.android.setupwizardlib.annotations.Keep class *
+ * to your proguard configuration if you are seeing mysterious MethodNotFoundExceptions at
+ * runtime.
+ */
+ @Keep
+ public void setXFraction(float fraction) {
+ mXFraction = fraction;
+ final int width = getWidth();
+ if (width != 0) {
+ setTranslationX(width * fraction);
+ } else {
+ // If we haven't done a layout pass yet, wait for one and then set the fraction before
+ // the draw occurs using an OnPreDrawListener. Don't call translationX until we know
+ // getWidth() has a reliable, non-zero value or else we will see the fragment flicker on
+ // screen.
+ if (mPreDrawListener == null) {
+ mPreDrawListener = new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener);
+ setXFraction(mXFraction);
+ return true;
+ }
+ };
+ getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
+ }
+ }
+ }
+
+ /**
+ * Return the X translation as a fraction of the width, as previously set in setXFraction.
+ *
+ * @see #setXFraction(float)
+ */
+ @Keep
+ public float getXFraction() {
+ return mXFraction;
+ }
+
+ /* Misc */
+
protected static class SavedState extends BaseSavedState {
boolean isProgressBarShown = false;
diff --git a/library/main/src/com/android/setupwizardlib/annotations/Keep.java b/library/main/src/com/android/setupwizardlib/annotations/Keep.java
new file mode 100644
index 0000000..6ad3bf2
--- /dev/null
+++ b/library/main/src/com/android/setupwizardlib/annotations/Keep.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2015 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 com.android.setupwizardlib.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.CLASS;
+
+/**
+ * Denotes that the annotated element should not be removed when
+ * the code is minified at build time. This is typically used
+ * on methods and classes that are accessed only via reflection
+ * so a compiler may think that the code is unused.
+ * <p>
+ * Example:
+ * <pre>{@code
+ * &#64;Keep
+ * public void foo() {
+ * ...
+ * }
+ * }</pre>
+ *
+ * Copied from android.support.annotation.Keep
+ * TODO: Add support annotation library as a dependency and use that.
+ */
+@Retention(CLASS)
+@Target({PACKAGE,TYPE,ANNOTATION_TYPE,CONSTRUCTOR,METHOD,FIELD})
+public @interface Keep {
+}
diff --git a/library/main/src/com/android/annotations/VisibleForTesting.java b/library/main/src/com/android/setupwizardlib/annotations/VisibleForTesting.java
index d3afc6a..7115116 100644
--- a/library/main/src/com/android/annotations/VisibleForTesting.java
+++ b/library/main/src/com/android/setupwizardlib/annotations/VisibleForTesting.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.annotations;
+package com.android.setupwizardlib.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/library/main/src/com/android/setupwizardlib/util/Partner.java b/library/main/src/com/android/setupwizardlib/util/Partner.java
index b41edf9..c3a3984 100644
--- a/library/main/src/com/android/setupwizardlib/util/Partner.java
+++ b/library/main/src/com/android/setupwizardlib/util/Partner.java
@@ -26,7 +26,7 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Log;
-import com.android.annotations.VisibleForTesting;
+import com.android.setupwizardlib.annotations.VisibleForTesting;
/**
* Utilities to discover and interact with partner customizations. There can only be one set of
diff --git a/library/main/src/com/android/setupwizardlib/view/BottomScrollView.java b/library/main/src/com/android/setupwizardlib/view/BottomScrollView.java
index 3683cc9..b08cfc8 100644
--- a/library/main/src/com/android/setupwizardlib/view/BottomScrollView.java
+++ b/library/main/src/com/android/setupwizardlib/view/BottomScrollView.java
@@ -21,7 +21,7 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;
-import com.android.annotations.VisibleForTesting;
+import com.android.setupwizardlib.annotations.VisibleForTesting;
/**
* An extension of ScrollView that will invoke a listener callback when the ScrollView needs