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 @@ + + + + + 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 @@ + + + + + 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 @@ + + + + + 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 @@ + + + + + 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 @@ + + + + + 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 @@ + + + + + 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 @@ + + + + + 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 @@ + + + + + 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. + *

+ * Example: + *

{@code
+ *  @Keep
+ *  public void foo() {
+ *      ...
+ *  }
+ * }
+ * + * 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 similarity index 97% rename from library/main/src/com/android/annotations/VisibleForTesting.java rename to 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