summaryrefslogtreecommitdiff
path: root/src/com/android/dreams/phototable
diff options
context:
space:
mode:
authorChris Wren <cwren@android.com>2012-09-13 12:06:10 -0400
committerChris Wren <cwren@android.com>2012-09-13 12:35:06 -0400
commit76086400f8e68b810bf1b3db0dc4f7133c8644ae (patch)
tree29e48bbfc8c5503b1b7c0adeda5e7ff9fa956417 /src/com/android/dreams/phototable
parent5b4b44688dac0053be77b282b7501bd291efb0d3 (diff)
downloadPhotoTable-76086400f8e68b810bf1b3db0dc4f7133c8644ae.tar.gz
New animation curves for photo table.
Change-Id: I971fa42d44b5b0d4649f0666267cb72219db1f0e
Diffstat (limited to 'src/com/android/dreams/phototable')
-rw-r--r--src/com/android/dreams/phototable/PhotoTable.java27
-rw-r--r--src/com/android/dreams/phototable/SoftLandingInterpolator.java67
2 files changed, 89 insertions, 5 deletions
diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java
index 7e6faea..32d4bf1 100644
--- a/src/com/android/dreams/phototable/PhotoTable.java
+++ b/src/com/android/dreams/phototable/PhotoTable.java
@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
+import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
@@ -71,11 +72,15 @@ public class PhotoTable extends FrameLayout {
private final float mImageRatio;
private final float mTableRatio;
private final float mImageRotationLimit;
+ private final float mThrowRotation;
+ private final float mThrowSpeed;
private final boolean mTapToExit;
private final int mTableCapacity;
private final int mInset;
private final PhotoSourcePlexor mPhotoSource;
private final Resources mResources;
+ private final Interpolator mThrowInterpolator;
+ private final Interpolator mDropInterpolator;
private PhotoLaunchTask mPhotoLaunchTask;
private boolean mStarted;
private boolean mIsLandscape;
@@ -99,8 +104,15 @@ public class PhotoTable extends FrameLayout {
mImageRatio = mResources.getInteger(R.integer.image_ratio) / 1000000f;
mTableRatio = mResources.getInteger(R.integer.table_ratio) / 1000000f;
mImageRotationLimit = (float) mResources.getInteger(R.integer.max_image_rotation);
+ mThrowSpeed = mResources.getDimension(R.dimen.image_throw_speed);
+ mThrowRotation = (float) mResources.getInteger(R.integer.image_throw_rotatioan);
mTableCapacity = mResources.getInteger(R.integer.table_capacity);
mTapToExit = mResources.getBoolean(R.bool.enable_tap_to_exit);
+ mThrowInterpolator = new SoftLandingInterpolator(
+ mResources.getInteger(R.integer.soft_landing_time) / 1000000f,
+ mResources.getInteger(R.integer.soft_landing_distance) / 1000000f);
+ mDropInterpolator = new DecelerateInterpolator(
+ (float) mResources.getInteger(R.integer.drop_deceleration_exponent));
mOnTable = new LinkedList<View>();
mOptions = new BitmapFactory.Options();
mOptions.inTempStorage = new byte[32768];
@@ -317,13 +329,18 @@ public class PhotoTable extends FrameLayout {
log("start offscreen");
int width = ((Integer) photo.getTag(R.id.photo_width));
int height = ((Integer) photo.getTag(R.id.photo_height));
- photo.setRotation(-100.0f);
+ photo.setRotation(mThrowRotation);
photo.setX(-mLongSide);
photo.setY(-mLongSide);
- dropOnTable(photo);
+
+ dropOnTable(photo, mThrowInterpolator);
}
public void dropOnTable(final View photo) {
+ dropOnTable(photo, mDropInterpolator);
+ }
+
+ public void dropOnTable(final View photo, final Interpolator interpolator) {
float angle = randfrange(-mImageRotationLimit, mImageRotationLimit);
PointF p = randInCenter((float) sRNG.nextGaussian(), (float) sRNG.nextGaussian(),
mWidth, mHeight);
@@ -345,7 +362,7 @@ public class PhotoTable extends FrameLayout {
float dy = y - y0;
float dist = (float) (Math.sqrt(dx * dx + dy * dy));
- int duration = (int) (1000f * dist / 400f);
+ int duration = (int) (1000f * dist / mThrowSpeed);
duration = Math.max(duration, 1000);
log("animate it");
@@ -358,7 +375,7 @@ public class PhotoTable extends FrameLayout {
.x(x)
.y(y)
.setDuration(duration)
- .setInterpolator(new DecelerateInterpolator(3f))
+ .setInterpolator(interpolator)
.withEndAction(new Runnable() {
@Override
public void run() {
@@ -393,7 +410,7 @@ public class PhotoTable extends FrameLayout {
float dy = y - y0;
float dist = (float) (Math.sqrt(dx * dx + dy * dy));
- int duration = (int) (1000f * dist / 1000f);
+ int duration = (int) (1000f * dist / 600f);
duration = Math.max(duration, 500);
photo.setRotation(wrapAngle(photo.getRotation()));
diff --git a/src/com/android/dreams/phototable/SoftLandingInterpolator.java b/src/com/android/dreams/phototable/SoftLandingInterpolator.java
new file mode 100644
index 0000000..bb2c1bd
--- /dev/null
+++ b/src/com/android/dreams/phototable/SoftLandingInterpolator.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007 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.dreams.phototable;
+
+import android.view.animation.Interpolator;
+import android.view.animation.DecelerateInterpolator;
+import android.view.animation.LinearInterpolator;
+import android.util.Log;
+
+/**
+ * An interpolator where the rate of change starts out quickly and
+ * and then decelerates.
+ *
+ */
+public class SoftLandingInterpolator implements Interpolator {
+ private final LinearInterpolator fly;
+ private final DecelerateInterpolator slide;
+ private final float mI;
+ private final float mO;
+ private final float lowerRange;
+ private final float upperRange;
+ private final float bottom;
+ private final float top;
+
+ public SoftLandingInterpolator(float i, float o) {
+ fly = new LinearInterpolator();
+ slide = new DecelerateInterpolator();
+ mI = i;
+ mO = o;
+ final float epsilon = Math.min(mI / 2f, (1f - mI) / 2f);
+ bottom = mI - epsilon;
+ top = mI + epsilon;
+ lowerRange = top;
+ upperRange = 1f - bottom;
+ }
+
+ public float getInterpolation(float input) {
+ final float f = fly.getInterpolation(input / upperRange) * mO;
+ final float s = slide.getInterpolation((input - bottom) / upperRange) * (1f - mO) + mO;
+
+ float value;
+ if (input < bottom) {
+ value = f;
+ } else if (input < top) {
+ final float alpha = (input - bottom) / (top - bottom);
+ value = (1f - alpha) * f + alpha * s;
+ } else {
+ value = s;
+ }
+
+ return value;
+ }
+}