diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-11-03 01:24:21 +0100 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-11-03 01:24:21 +0100 |
commit | 2d6d5b71345b21eba2a3265c501499e466653dc5 (patch) | |
tree | bcf6904be039900d581c400a784a39643f353165 /src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java | |
parent | 0bc32145ffcc46c3438c080799ad8c641ffa3271 (diff) | |
download | android_packages_wallpapers_PhotoPhase-2d6d5b71345b21eba2a3265c501499e466653dc5.tar.gz android_packages_wallpapers_PhotoPhase-2d6d5b71345b21eba2a3265c501499e466653dc5.tar.bz2 android_packages_wallpapers_PhotoPhase-2d6d5b71345b21eba2a3265c501499e466653dc5.zip |
Random dispositions
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java')
-rw-r--r-- | src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java index 0310b58..45d3d74 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java @@ -18,6 +18,7 @@ package org.cyanogenmod.wallpapers.photophase; import android.content.Context; import android.content.res.Configuration; +import android.content.res.Resources; import android.graphics.PointF; import android.graphics.RectF; import android.util.Log; @@ -27,6 +28,7 @@ import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider.Pre import org.cyanogenmod.wallpapers.photophase.transitions.Transition; import org.cyanogenmod.wallpapers.photophase.transitions.Transitions; import org.cyanogenmod.wallpapers.photophase.transitions.Transitions.TRANSITIONS; +import org.cyanogenmod.wallpapers.photophase.utils.DispositionUtil; import org.cyanogenmod.wallpapers.photophase.utils.Utils; import java.util.ArrayList; @@ -60,6 +62,9 @@ public class PhotoPhaseWallpaperWorld { private boolean mRecycled; + private String[] mPortraitDispositions; + private String[] mLandscapeDispositions; + /** * Constructor <code>PhotoPhaseWallpaperWorld</code> * @@ -74,6 +79,10 @@ public class PhotoPhaseWallpaperWorld { mCurrent = -1; mUnusedTransitions = new ArrayList<Transition>(); mRecycled = false; + + Resources res = ctx.getResources(); + mPortraitDispositions = res.getStringArray(R.array.portrait_disposition_templates); + mLandscapeDispositions = res.getStringArray(R.array.landscape_disposition_templates); } /** @@ -200,7 +209,8 @@ public class PhotoPhaseWallpaperWorld { mUnusedTransitions.add(currentTransition); if (finalTarget != null) { - Transition transition = getOrCreateTransition(TRANSITIONS.NO_TRANSITION, finalTarget); + Transition transition = getOrCreateTransition( + TRANSITIONS.NO_TRANSITION, finalTarget); mTransitions.set(mCurrent, transition); currentTarget.recycle(); @@ -287,11 +297,11 @@ public class PhotoPhaseWallpaperWorld { int rows = portrait ? Preferences.Layout.getRows() : Preferences.Layout.getCols(); float cellw = 2.0f / cols; float cellh = 2.0f / rows; - List<Disposition> dispositions = portrait - ? Preferences.Layout.getPortraitDisposition() - : Preferences.Layout.getLandscapeDisposition(); - if (DEBUG) Log.d(TAG, - "Dispositions: " + dispositions.size() + " | " + String.valueOf(dispositions)); + List<Disposition> dispositions = getWorldDispositions(portrait); + if (DEBUG) { + Log.d(TAG, "Dispositions: " + dispositions.size() + " | " + + String.valueOf(dispositions)); + } mPhotoFrames = new ArrayList<PhotoFrame>(dispositions.size()); mTransitions = new ArrayList<Transition>(dispositions.size()); mTransitionsQueue = new ArrayList<Integer>(dispositions.size()); @@ -300,7 +310,8 @@ public class PhotoPhaseWallpaperWorld { for (Disposition disposition : dispositions) { // Create the photo frame float[] frameVertices = getVerticesFromDisposition(disposition, cellw, cellh); - float[] photoVertices = getFramePadding(frameVertices, portrait ? w : h, portrait ? h : w); + float[] photoVertices = getFramePadding(frameVertices, + portrait ? w : h, portrait ? h : w); PhotoFrame frame = new PhotoFrame( mContext, @@ -416,4 +427,29 @@ public class PhotoPhaseWallpaperWorld { paddingCoords[7] -= pxh; return paddingCoords; } + + /** + * Method that returns the dispositions to draw in the world + * + * @param portrait If the orientation is portrait (true) or landscape (false) + * @return List<Disposition> The list of dispositions + */ + private List<Disposition> getWorldDispositions(boolean portrait) { + // If user selected a random disposition, then use one of the predefined layouts + if (Preferences.Layout.isRandomDispositions()) { + // Random + if (portrait) { + // Portrait + int next = Utils.getNextRandom(0, mPortraitDispositions.length -1); + return DispositionUtil.toDispositions(mPortraitDispositions[next]); + } + // Landscape + int next = Utils.getNextRandom(0, mLandscapeDispositions.length -1); + return DispositionUtil.toDispositions(mLandscapeDispositions[next]); + } + // User-defined + return portrait + ? Preferences.Layout.getPortraitDisposition() + : Preferences.Layout.getLandscapeDisposition(); + } } |