diff --git a/api/current.xml b/api/current.xml index 2260abb5abab1..ab2857df7f37e 100644 --- a/api/current.xml +++ b/api/current.xml @@ -1361,6 +1361,39 @@ visibility="public" > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + depth) @@ -126,23 +125,21 @@ public class AnimationUtils { } - public static LayoutAnimationController loadLayoutAnimation( - Context context, int id) throws NotFoundException { + public static LayoutAnimationController loadLayoutAnimation(Context context, int id) + throws NotFoundException { XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return createLayoutAnimationFromXml(context, parser); } catch (XmlPullParserException ex) { - NotFoundException rnf = new NotFoundException( - "Can't load animation resource ID #0x" + - Integer.toHexString(id)); + NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch (IOException ex) { - NotFoundException rnf = new NotFoundException( - "Can't load animation resource ID #0x" + - Integer .toHexString(id)); + NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { @@ -150,24 +147,21 @@ public class AnimationUtils { } } - private static LayoutAnimationController createLayoutAnimationFromXml( - Context c, XmlPullParser parser) - throws XmlPullParserException, IOException { - return createLayoutAnimationFromXml(c, parser, - Xml.asAttributeSet(parser)); + private static LayoutAnimationController createLayoutAnimationFromXml(Context c, + XmlPullParser parser) throws XmlPullParserException, IOException { + + return createLayoutAnimationFromXml(c, parser, Xml.asAttributeSet(parser)); } - private static LayoutAnimationController createLayoutAnimationFromXml( - Context c, XmlPullParser parser, AttributeSet attrs) - throws XmlPullParserException, IOException { + private static LayoutAnimationController createLayoutAnimationFromXml(Context c, + XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { LayoutAnimationController controller = null; int type; int depth = parser.getDepth(); - while (((type = parser.next()) != XmlPullParser.END_TAG - || parser.getDepth() > depth) + while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { @@ -181,8 +175,7 @@ public class AnimationUtils { } else if ("gridLayoutAnimation".equals(name)) { controller = new GridLayoutAnimationController(c, attrs); } else { - throw new RuntimeException("Unknown layout animation name: " + - name); + throw new RuntimeException("Unknown layout animation name: " + name); } } @@ -197,9 +190,7 @@ public class AnimationUtils { * @param fromLeft is the object to be animated coming from the left * @return The new animation */ - public static Animation makeInAnimation(Context c, boolean fromLeft) - { - + public static Animation makeInAnimation(Context c, boolean fromLeft) { Animation a; if (fromLeft) { a = AnimationUtils.loadAnimation(c, com.android.internal.R.anim.slide_in_left); @@ -220,9 +211,7 @@ public class AnimationUtils { * @param toRight is the object to be animated exiting to the right * @return The new animation */ - public static Animation makeOutAnimation(Context c, boolean toRight) - { - + public static Animation makeOutAnimation(Context c, boolean toRight) { Animation a; if (toRight) { a = AnimationUtils.loadAnimation(c, com.android.internal.R.anim.slide_out_right); @@ -243,9 +232,7 @@ public class AnimationUtils { * @param c Context for loading resources * @return The new animation */ - public static Animation makeInChildBottomAnimation(Context c) - { - + public static Animation makeInChildBottomAnimation(Context c) { Animation a; a = AnimationUtils.loadAnimation(c, com.android.internal.R.anim.slide_in_child_bottom); a.setInterpolator(new AccelerateInterpolator()); @@ -261,23 +248,19 @@ public class AnimationUtils { * @return The animation object reference by the specified id * @throws NotFoundException */ - public static Interpolator loadInterpolator(Context context, int id) - throws NotFoundException { - + public static Interpolator loadInterpolator(Context context, int id) throws NotFoundException { XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return createInterpolatorFromXml(context, parser); } catch (XmlPullParserException ex) { - NotFoundException rnf = new NotFoundException( - "Can't load animation resource ID #0x" - + Integer.toHexString(id)); + NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch (IOException ex) { - NotFoundException rnf = new NotFoundException( - "Can't load animation resource ID #0x" - + Integer.toHexString(id)); + NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { @@ -287,12 +270,12 @@ public class AnimationUtils { } private static Interpolator createInterpolatorFromXml(Context c, XmlPullParser parser) - throws XmlPullParserException, IOException { + throws XmlPullParserException, IOException { Interpolator interpolator = null; // Make sure we are on a start tag. - int type = parser.getEventType(); + int type; int depth = parser.getDepth(); while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) @@ -317,6 +300,14 @@ public class AnimationUtils { interpolator = new AccelerateDecelerateInterpolator(c, attrs); } else if (name.equals("cycleInterpolator")) { interpolator = new CycleInterpolator(c, attrs); + } else if (name.equals("anticipateInterpolator")) { + interpolator = new AnticipateInterpolator(c, attrs); + } else if (name.equals("overshootInterpolator")) { + interpolator = new OvershootInterpolator(c, attrs); + } else if (name.equals("anticipateOvershootInterpolator")) { + interpolator = new AnticipateOvershootInterpolator(c, attrs); + } else if (name.equals("bounceInterpolator")) { + interpolator = new BounceInterpolator(c, attrs); } else { throw new RuntimeException("Unknown interpolator name: " + parser.getName()); } diff --git a/core/java/android/view/animation/AnticipateInterpolator.java b/core/java/android/view/animation/AnticipateInterpolator.java new file mode 100644 index 0000000000000..a6f110e8c4a69 --- /dev/null +++ b/core/java/android/view/animation/AnticipateInterpolator.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2009 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.view.animation; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; + +/** + * An interpolator where the change starts backward then flings forward. + */ +public class AnticipateInterpolator implements Interpolator { + private final float mTension; + + public AnticipateInterpolator() { + mTension = 2.0f; + } + + /** + * @param tension Amount of anticipation. When tension equals 0.0f, there is + * no anticipation and the interpolator becomes a simple + * acceleration interpolator. + */ + public AnticipateInterpolator(float tension) { + mTension = tension; + } + + public AnticipateInterpolator(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, + com.android.internal.R.styleable.AnticipateInterpolator); + + mTension = + a.getFloat(com.android.internal.R.styleable.AnticipateInterpolator_tension, 2.0f); + + a.recycle(); + } + + public float getInterpolation(float t) { + // a(t) = t * t * ((tension + 1) * t - tension) + return t * t * ((mTension + 1) * t - mTension); + } +} diff --git a/core/java/android/view/animation/AnticipateOvershootInterpolator.java b/core/java/android/view/animation/AnticipateOvershootInterpolator.java new file mode 100644 index 0000000000000..3dc972278b787 --- /dev/null +++ b/core/java/android/view/animation/AnticipateOvershootInterpolator.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2009 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.view.animation; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_extraTension; +import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_tension; +import static com.android.internal.R.styleable.AnticipateOvershootInterpolator; + +/** + * An interpolator where the change starts backward then flings forward and overshoots + * the target value and finally goes back to the final value. + */ +public class AnticipateOvershootInterpolator implements Interpolator { + private final float mTension; + + public AnticipateOvershootInterpolator() { + mTension = 2.0f * 1.5f; + } + + /** + * @param tension Amount of anticipation/overshoot. When tension equals 0.0f, + * there is no anticipation/overshoot and the interpolator becomes + * a simple acceleration/deceleration interpolator. + */ + public AnticipateOvershootInterpolator(float tension) { + mTension = tension * 1.5f; + } + + /** + * @param tension Amount of anticipation/overshoot. When tension equals 0.0f, + * there is no anticipation/overshoot and the interpolator becomes + * a simple acceleration/deceleration interpolator. + * @param extraTension Amount by which to multiply the tension. For instance, + * to get the same overshoot as an OvershootInterpolator with + * a tension of 2.0f, you would use an extraTension of 1.5f. + */ + public AnticipateOvershootInterpolator(float tension, float extraTension) { + mTension = tension * extraTension; + } + + public AnticipateOvershootInterpolator(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, AnticipateOvershootInterpolator); + + mTension = a.getFloat(AnticipateOvershootInterpolator_tension, 2.0f) * + a.getFloat(AnticipateOvershootInterpolator_extraTension, 1.5f); + + a.recycle(); + } + + private static float a(float t, float s) { + return t * t * ((s + 1) * t - s); + } + + private static float o(float t, float s) { + return t * t * ((s + 1) * t + s); + } + + public float getInterpolation(float t) { + // a(t, s) = t * t * ((s + 1) * t - s) + // o(t, s) = t * t * ((s + 1) * t + s) + // f(t) = 0.5 * a(t * 2, tension * extraTension), when t < 0.5 + // f(t) = 0.5 * (o(t * 2 - 2, tension * extraTension) + 2), when t <= 1.0 + if (t < 0.5f) return 0.5f * a(t * 2.0f, mTension); + else return 0.5f * (o(t * 2.0f - 2.0f, mTension) + 2.0f); + } +} diff --git a/core/java/android/view/animation/BounceInterpolator.java b/core/java/android/view/animation/BounceInterpolator.java new file mode 100644 index 0000000000000..f79e7303f4787 --- /dev/null +++ b/core/java/android/view/animation/BounceInterpolator.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2009 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.view.animation; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; + +/** + * An interpolator where the change bounces at the end. + */ +public class BounceInterpolator implements Interpolator { + public BounceInterpolator() { + } + + @SuppressWarnings({"UnusedDeclaration"}) + public BounceInterpolator(Context context, AttributeSet attrs) { + } + + private static float bounce(float t) { + return t * t * 8.0f; + } + + public float getInterpolation(float t) { + // _b(t) = t * t * 8 + // bs(t) = _b(t) for t < 0.3535 + // bs(t) = _b(t - 0.54719) + 0.7 for t < 0.7408 + // bs(t) = _b(t - 0.8526) + 0.9 for t < 0.9644 + // bs(t) = _b(t - 1.0435) + 0.95 for t <= 1.0 + // b(t) = bs(t * 1.1226) + t *= 1.1226f; + if (t < 0.3535f) return bounce(t); + else if (t < 0.7408f) return bounce(t - 0.54719f) + 0.7f; + else if (t < 0.9644f) return bounce(t - 0.8526f) + 0.9f; + else return bounce(t - 1.0435f) + 0.95f; + } +} \ No newline at end of file diff --git a/core/java/android/view/animation/OvershootInterpolator.java b/core/java/android/view/animation/OvershootInterpolator.java new file mode 100644 index 0000000000000..494f8ab5a05b2 --- /dev/null +++ b/core/java/android/view/animation/OvershootInterpolator.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2009 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.view.animation; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; + +/** + * An interpolator where the change flings forward and overshoots the last value + * then comes back. + */ +public class OvershootInterpolator implements Interpolator { + private final float mTension; + + public OvershootInterpolator() { + mTension = 2.0f; + } + + /** + * @param tension Amount of overshoot. When tension equals 0.0f, there is + * no overshoot and the interpolator becomes a simple + * deceleration interpolator. + */ + public OvershootInterpolator(float tension) { + mTension = tension; + } + + public OvershootInterpolator(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, + com.android.internal.R.styleable.OvershootInterpolator); + + mTension = + a.getFloat(com.android.internal.R.styleable.OvershootInterpolator_tension, 2.0f); + + a.recycle(); + } + + public float getInterpolation(float t) { + // _o(t) = t * t * ((tension + 1) * t + tension) + // o(t) = _o(t - 1) + 1 + t -= 1.0f; + return t * t * ((mTension + 1) * t + mTension) + 1.0f; + } +} diff --git a/core/res/res/anim/anticipate_interpolator.xml b/core/res/res/anim/anticipate_interpolator.xml new file mode 100644 index 0000000000000..50a555a6766c0 --- /dev/null +++ b/core/res/res/anim/anticipate_interpolator.xml @@ -0,0 +1,21 @@ + + + + diff --git a/core/res/res/anim/anticipate_overshoot_interpolator.xml b/core/res/res/anim/anticipate_overshoot_interpolator.xml new file mode 100644 index 0000000000000..440a899f95491 --- /dev/null +++ b/core/res/res/anim/anticipate_overshoot_interpolator.xml @@ -0,0 +1,21 @@ + + + + diff --git a/core/res/res/anim/bounce_interpolator.xml b/core/res/res/anim/bounce_interpolator.xml new file mode 100644 index 0000000000000..406fbb9fd1591 --- /dev/null +++ b/core/res/res/anim/bounce_interpolator.xml @@ -0,0 +1,21 @@ + + + + diff --git a/core/res/res/anim/overshoot_interpolator.xml b/core/res/res/anim/overshoot_interpolator.xml new file mode 100644 index 0000000000000..c614e0b8f0d33 --- /dev/null +++ b/core/res/res/anim/overshoot_interpolator.xml @@ -0,0 +1,21 @@ + + + + diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 485edca8ff6b1..310948960ae22 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2525,12 +2525,12 @@ - + - + @@ -2538,6 +2538,23 @@ + + + + + + + + + + + + + + + + + diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index ed35986f8faae..09012c92f9ed5 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -1051,7 +1051,7 @@ - @@ -1104,4 +1104,18 @@ + + + + + + + + + + + +