summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui/Paper.java
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2015-10-17 23:40:33 -0700
committerSteve Kondik <steve@cyngn.com>2015-10-17 23:40:33 -0700
commitbcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398 (patch)
tree85d07b2095695fe79235ab16e627f8b22c7bfd8d /src/com/android/gallery3d/ui/Paper.java
parenta3fcd50080c0546ebd5f0caf932eef02fabdd7ad (diff)
parent8de528917bf03cca93ac2a3dd19b7a5719d1a26e (diff)
downloadandroid_packages_apps_Gallery2-bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398.tar.gz
android_packages_apps_Gallery2-bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398.tar.bz2
android_packages_apps_Gallery2-bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398.zip
Merge branch 'cm-12.1' of git://github.com/CyanogenMod/android_packages_apps_Gallery2 into cm-13.0
Change-Id: Ib8caa024d2e6feca332e3645038f226fd5a910a2
Diffstat (limited to 'src/com/android/gallery3d/ui/Paper.java')
-rw-r--r--src/com/android/gallery3d/ui/Paper.java62
1 files changed, 43 insertions, 19 deletions
diff --git a/src/com/android/gallery3d/ui/Paper.java b/src/com/android/gallery3d/ui/Paper.java
index b36f5c3a2..6ed5013a2 100644
--- a/src/com/android/gallery3d/ui/Paper.java
+++ b/src/com/android/gallery3d/ui/Paper.java
@@ -28,53 +28,76 @@ class Paper {
@SuppressWarnings("unused")
private static final String TAG = "Paper";
private static final int ROTATE_FACTOR = 4;
- private EdgeAnimation mAnimationLeft = new EdgeAnimation();
- private EdgeAnimation mAnimationRight = new EdgeAnimation();
+ private EdgeAnimation mAnimationBegin = new EdgeAnimation();
+ private EdgeAnimation mAnimationEnd = new EdgeAnimation();
private int mWidth;
+ private int mHeight;
private float[] mMatrix = new float[16];
+ private final boolean mIsWide;
+
+ public Paper(boolean wide) {
+ mIsWide = wide;
+ }
+
public void overScroll(float distance) {
distance /= mWidth; // make it relative to width
if (distance < 0) {
- mAnimationLeft.onPull(-distance);
+ mAnimationBegin.onPull(-distance);
} else {
- mAnimationRight.onPull(distance);
+ mAnimationEnd.onPull(distance);
}
}
public void edgeReached(float velocity) {
velocity /= mWidth; // make it relative to width
if (velocity < 0) {
- mAnimationRight.onAbsorb(-velocity);
+ mAnimationEnd.onAbsorb(-velocity);
} else {
- mAnimationLeft.onAbsorb(velocity);
+ mAnimationBegin.onAbsorb(velocity);
}
}
public void onRelease() {
- mAnimationLeft.onRelease();
- mAnimationRight.onRelease();
+ mAnimationBegin.onRelease();
+ mAnimationEnd.onRelease();
}
public boolean advanceAnimation() {
// Note that we use "|" because we want both animations get updated.
- return mAnimationLeft.update() | mAnimationRight.update();
+ return mAnimationBegin.update() | mAnimationEnd.update();
}
public void setSize(int width, int height) {
mWidth = width;
+ mHeight = height;
}
- public float[] getTransform(Rect rect, float scrollX) {
- float left = mAnimationLeft.getValue();
- float right = mAnimationRight.getValue();
- float screenX = rect.centerX() - scrollX;
- // We linearly interpolate the value [left, right] for the screenX
- // range int [-1/4, 5/4]*mWidth. So if part of the thumbnail is outside
+ public float[] getTransform(Rect rect, float scroll) {
+ Log.d(TAG, rect.toString());
+ float start = mAnimationBegin.getValue();
+ float end = mAnimationEnd.getValue();
+ int center = 0;
+ int screenWidth = mWidth;
+ int rotateX = 0;
+ int rotateY = 0;
+ final boolean wide = mIsWide;
+ if (wide) {
+ center = rect.centerX();
+ rotateY = 1;
+ } else {
+ center = rect.centerY();
+ rotateX = 1;
+ screenWidth = mHeight;
+ }
+ float screen = center - scroll;
+ // We linearly interpolate the value [start, end] for the screen
+ // range int [-1/4, 5/4]*screenWidth. So if part of the thumbnail is outside
// the screen, we still get some transform.
- float x = screenX + mWidth / 4;
- int range = 3 * mWidth / 2;
- float t = ((range - x) * left - x * right) / range;
+ float x = screen + screenWidth / 4;
+ int range = 3 * screenWidth / 2;
+ float t = ((range - x) * start - x * end) / range;
+
// compress t to the range (-1, 1) by the function
// f(t) = (1 / (1 + e^-t) - 0.5) * 2
// then multiply by 90 to make the range (-45, 45)
@@ -82,8 +105,9 @@ class Paper {
(1 / (1 + (float) Math.exp(-t * ROTATE_FACTOR)) - 0.5f) * 2 * -45;
Matrix.setIdentityM(mMatrix, 0);
Matrix.translateM(mMatrix, 0, mMatrix, 0, rect.centerX(), rect.centerY(), 0);
- Matrix.rotateM(mMatrix, 0, degrees, 0, 1, 0);
+ Matrix.rotateM(mMatrix, 0, degrees, rotateX, rotateY, 0);
Matrix.translateM(mMatrix, 0, mMatrix, 0, -rect.width() / 2, -rect.height() / 2, 0);
+
return mMatrix;
}
}