[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:
parent
657d18359b
commit
8c10c403c0
26
library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml
Normal file
26
library/main/res/animator-ldrtl-v11/suw_slide_back_in.xml
Normal 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" />
|
26
library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml
Normal file
26
library/main/res/animator-ldrtl-v11/suw_slide_back_out.xml
Normal 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" />
|
26
library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml
Normal file
26
library/main/res/animator-ldrtl-v11/suw_slide_next_in.xml
Normal 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" />
|
26
library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml
Normal file
26
library/main/res/animator-ldrtl-v11/suw_slide_next_out.xml
Normal 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" />
|
26
library/main/res/animator-v11/suw_slide_back_in.xml
Normal file
26
library/main/res/animator-v11/suw_slide_back_in.xml
Normal 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" />
|
26
library/main/res/animator-v11/suw_slide_back_out.xml
Normal file
26
library/main/res/animator-v11/suw_slide_back_out.xml
Normal 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" />
|
26
library/main/res/animator-v11/suw_slide_next_in.xml
Normal file
26
library/main/res/animator-v11/suw_slide_next_in.xml
Normal 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" />
|
26
library/main/res/animator-v11/suw_slide_next_out.xml
Normal file
26
library/main/res/animator-v11/suw_slide_next_out.xml
Normal 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" />
|
|
@ -36,9 +36,11 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewStub;
|
import android.view.ViewStub;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.setupwizardlib.annotations.Keep;
|
||||||
import com.android.setupwizardlib.util.RequireScrollHelper;
|
import com.android.setupwizardlib.util.RequireScrollHelper;
|
||||||
import com.android.setupwizardlib.view.BottomScrollView;
|
import com.android.setupwizardlib.view.BottomScrollView;
|
||||||
import com.android.setupwizardlib.view.Illustration;
|
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 {
|
protected static class SavedState extends BaseSavedState {
|
||||||
|
|
||||||
boolean isProgressBarShown = false;
|
boolean isProgressBarShown = false;
|
||||||
|
|
|
@ -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
|
||||||
|
* @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 {
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.annotations;
|
package com.android.setupwizardlib.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
|
@ -26,7 +26,7 @@ import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.Log;
|
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
|
* Utilities to discover and interact with partner customizations. There can only be one set of
|
||||||
|
|
|
@ -21,7 +21,7 @@ import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ScrollView;
|
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
|
* An extension of ScrollView that will invoke a listener callback when the ScrollView needs
|
||||||
|
|
Loading…
Reference in a new issue