diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-11-02 02:20:56 +0100 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-11-02 02:20:56 +0100 |
commit | 4effddfe30fd045834232f6bb66070edf079578d (patch) | |
tree | 2e57f74d55685891a49b02ec069c118cf5b15110 /src/org/cyanogenmod/wallpapers/photophase/animations | |
parent | ca2f0060cc367ac8174a27a3124cd0124e49c627 (diff) | |
download | android_packages_wallpapers_PhotoPhase-4effddfe30fd045834232f6bb66070edf079578d.tar.gz android_packages_wallpapers_PhotoPhase-4effddfe30fd045834232f6bb66070edf079578d.tar.bz2 android_packages_wallpapers_PhotoPhase-4effddfe30fd045834232f6bb66070edf079578d.zip |
Multiples fixes
- Fully rewrite the album selection preference
- Fix multiple style
- Fix lints
- Resources cleanup
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/animations')
-rw-r--r-- | src/org/cyanogenmod/wallpapers/photophase/animations/Flip3dAnimationController.java (renamed from src/org/cyanogenmod/wallpapers/photophase/animations/AlbumsFlip3dAnimationController.java) | 113 | ||||
-rw-r--r-- | src/org/cyanogenmod/wallpapers/photophase/animations/Rotate3dAnimation.java | 93 |
2 files changed, 144 insertions, 62 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/animations/AlbumsFlip3dAnimationController.java b/src/org/cyanogenmod/wallpapers/photophase/animations/Flip3dAnimationController.java index 228f827..69f023d 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/animations/AlbumsFlip3dAnimationController.java +++ b/src/org/cyanogenmod/wallpapers/photophase/animations/Flip3dAnimationController.java @@ -16,20 +16,14 @@ package org.cyanogenmod.wallpapers.photophase.animations; import android.view.View; -import android.view.View.OnClickListener; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; -import org.cyanogenmod.wallpapers.photophase.model.Album; -import org.cyanogenmod.wallpapers.photophase.widgets.AlbumInfo; -import org.cyanogenmod.wallpapers.photophase.widgets.AlbumPictures; -import org.cyanogenmod.wallpapers.photophase.widgets.AlbumPictures.CallbacksListener; - /** - * A class that manages a flip 3d effect of an album + * A class that manages a flip 3d effect of two views */ -public class AlbumsFlip3dAnimationController { +public class Flip3dAnimationController { private static final int DURATION = 200; @@ -37,13 +31,15 @@ public class AlbumsFlip3dAnimationController { View mBack; boolean mFrontFace; + final Object mLock = new Object(); + /** - * Constructor of <code>AlbumsFlip3dAnimationController</code> + * Constructor of <code>Flip3dAnimationController</code> * * @param front The front view * @param back The back view */ - public AlbumsFlip3dAnimationController(AlbumInfo front, AlbumPictures back) { + public Flip3dAnimationController(View front, View back) { super(); mFront = front; mBack = back; @@ -51,45 +47,48 @@ public class AlbumsFlip3dAnimationController { mFrontFace = true; } + public boolean isFrontFace() { + return mFrontFace; + } + /** - * Method that register the controller + * Method that reset the controller */ - public void register() { - getFrontView().setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - getBackView().setVisibility(View.INVISIBLE); - applyAnimation(false); - } - }); - ((AlbumPictures)getBackView()).addCallBackListener(new CallbacksListener() { - @Override - public void onBackButtonClick(View v) { - getBackView().setVisibility(View.INVISIBLE); - applyAnimation(true); - } - - @Override - public void onSelectionChanged(Album album) { - // Ignore - } - }); + public void reset() { + changeToFrontFace(true); } /** - * Method that unregister the controller + * Method that change the view to the front face + * + * @param animate Do with animation */ - public void unregister() { - getFrontView().setOnClickListener(null); - getBackView().setOnClickListener(null); + public void changeToFrontFace(boolean animate) { + if (!mFrontFace) { + if (animate) { + applyAnimation(true); + } else { + mBack.setVisibility(View.GONE); + mFront.setVisibility(View.VISIBLE); + mFrontFace = true; + } + } } /** - * Method that reset the controller + * Method that change the view to the back face + * + * @param animate Do with animation */ - public void reset() { - if (!mFrontFace) { - applyAnimation(true); + public void changeToBackFace(boolean animate) { + if (mFrontFace) { + if (animate) { + applyAnimation(true); + } else { + mFront.setVisibility(View.GONE); + mBack.setVisibility(View.VISIBLE); + mFrontFace = false; + } } } @@ -98,11 +97,11 @@ public class AlbumsFlip3dAnimationController { * * @param inverse Applies the inverse animation */ - /*package*/ void applyAnimation(boolean inverse) { + void applyAnimation(boolean inverse) { applyTransformation(getFrontView(), 0, 90 * (inverse ? -1 : 1), true); } - /*package*/ void applyTransformation(final View v, float start, float end, final boolean step1) { + void applyTransformation(final View v, float start, float end, final boolean step1) { final float centerX = v.getWidth() / 2.0f; final float centerY = v.getHeight() / 2.0f; @@ -117,8 +116,6 @@ public class AlbumsFlip3dAnimationController { if (!step1) { getBackView().setVisibility(View.VISIBLE); } - getFrontView().setOnClickListener(null); - getBackView().setOnClickListener(null); } @Override @@ -128,24 +125,16 @@ public class AlbumsFlip3dAnimationController { @Override public void onAnimationEnd(Animation animation) { - getFrontView().setAnimation(null); - getBackView().setAnimation(null); - if (step1) { - getFrontView().setVisibility(View.INVISIBLE); - applyTransformation(getBackView(), -90 * (!mFrontFace ? -1 : 1), 0, false); - } else { - mFrontFace = !mFrontFace; - getBackView().setVisibility(View.GONE); - if (mFrontFace) { - getFrontView().setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - getBackView().setVisibility(View.INVISIBLE); - applyAnimation(false); - } - }); + synchronized (mLock) { + getFrontView().setAnimation(null); + getBackView().setAnimation(null); + if (step1) { + getFrontView().setVisibility(View.INVISIBLE); + applyTransformation(getBackView(), + -90 * (!mFrontFace ? -1 : 1), 0, false); } else { - ((AlbumPictures)getFrontView()).onShow(); + mFrontFace = !mFrontFace; + getBackView().setVisibility(View.GONE); } } } @@ -153,11 +142,11 @@ public class AlbumsFlip3dAnimationController { v.startAnimation(anim); } - /*package*/ View getFrontView() { + View getFrontView() { return mFrontFace ? mFront : mBack; } - /*package*/ View getBackView() { + View getBackView() { return !mFrontFace ? mFront : mBack; } } diff --git a/src/org/cyanogenmod/wallpapers/photophase/animations/Rotate3dAnimation.java b/src/org/cyanogenmod/wallpapers/photophase/animations/Rotate3dAnimation.java new file mode 100644 index 0000000..814ef0f --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/animations/Rotate3dAnimation.java @@ -0,0 +1,93 @@ +/* + * 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 org.cyanogenmod.wallpapers.photophase.animations; + +import android.view.animation.Animation; +import android.view.animation.Transformation; +import android.graphics.Camera; +import android.graphics.Matrix; + +/** + * An animation that rotates the view on the Y axis between two specified angles. + * This animation also adds a translation on the Z axis (depth) to improve the effect. + */ +public class Rotate3dAnimation extends Animation { + private final float mFromDegrees; + private final float mToDegrees; + private final float mCenterX; + private final float mCenterY; + private final float mDepthZ; + private final boolean mReverse; + private Camera mCamera; + + /** + * Creates a new 3D rotation on the Y axis. The rotation is defined by its + * start angle and its end angle. Both angles are in degrees. The rotation + * is performed around a center point on the 2D space, definied by a pair + * of X and Y coordinates, called centerX and centerY. When the animation + * starts, a translation on the Z axis (depth) is performed. The length + * of the translation can be specified, as well as whether the translation + * should be reversed in time. + * + * @param fromDegrees the start angle of the 3D rotation + * @param toDegrees the end angle of the 3D rotation + * @param centerX the X center of the 3D rotation + * @param centerY the Y center of the 3D rotation + * @param reverse true if the translation should be reversed, false otherwise + */ + public Rotate3dAnimation(float fromDegrees, float toDegrees, + float centerX, float centerY, float depthZ, boolean reverse) { + mFromDegrees = fromDegrees; + mToDegrees = toDegrees; + mCenterX = centerX; + mCenterY = centerY; + mDepthZ = depthZ; + mReverse = reverse; + } + + @Override + public void initialize(int width, int height, int parentWidth, int parentHeight) { + super.initialize(width, height, parentWidth, parentHeight); + mCamera = new Camera(); + } + + @Override + protected void applyTransformation(float interpolatedTime, Transformation t) { + final float fromDegrees = mFromDegrees; + float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); + + final float centerX = mCenterX; + final float centerY = mCenterY; + final Camera camera = mCamera; + + final Matrix matrix = t.getMatrix(); + + camera.save(); + if (mReverse) { + camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime); + } else { + camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime)); + } + camera.rotateY(degrees); + camera.getMatrix(matrix); + camera.restore(); + + matrix.preTranslate(-centerX, -centerY); + matrix.postTranslate(centerX, centerY); + } +} + |