[SetupWizardLib] Support for ObjectAnimator

Support for animator to animate SetupWizardLayout horizontally, which
requires adding a setXFraction method, changing the translationX with
respect to the width of the view.

Also moved annotations to com.android.setupwizardlib.annotations
package to avoid class loading problems in clients that use support
annotation library.

Bug: 20110840
Change-Id: Ibfb900323bcf4f32c8ded4c4a6dbf4765f17751a
This commit is contained in:
Maurice Lam 2015-05-29 14:09:37 -07:00
parent 657d18359b
commit 8c10c403c0
13 changed files with 311 additions and 3 deletions

View file

@ -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" />

View file

@ -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" />

View file

@ -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" />

View file

@ -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" />

View file

@ -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" />

View file

@ -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" />

View file

@ -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" />

View file

@ -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" />

View file

@ -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;

View file

@ -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 {
}

View file

@ -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;

View file

@ -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

View file

@ -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