diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-08-07 00:40:29 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-08-07 00:40:29 +0200 |
commit | 3c46e3e43e86bfd00c503caf8a31529f8f1ce18c (patch) | |
tree | b96b75bbcd346021e85ba5822620b4e3e795a43e /src/org/cyanogenmod/wallpapers/photophase/transitions | |
parent | e3e640aa2e7b1357903663705bfdce8e8f95dc43 (diff) | |
download | android_packages_wallpapers_PhotoPhase-3c46e3e43e86bfd00c503caf8a31529f8f1ce18c.tar.gz android_packages_wallpapers_PhotoPhase-3c46e3e43e86bfd00c503caf8a31529f8f1ce18c.tar.bz2 android_packages_wallpapers_PhotoPhase-3c46e3e43e86bfd00c503caf8a31529f8f1ce18c.zip |
Multiple transition selection (#13)
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/transitions')
-rw-r--r-- | src/org/cyanogenmod/wallpapers/photophase/transitions/Transitions.java | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/transitions/Transitions.java b/src/org/cyanogenmod/wallpapers/photophase/transitions/Transitions.java index e29bfce..37c2e93 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/transitions/Transitions.java +++ b/src/org/cyanogenmod/wallpapers/photophase/transitions/Transitions.java @@ -22,6 +22,9 @@ import org.cyanogenmod.wallpapers.photophase.PhotoFrame; import org.cyanogenmod.wallpapers.photophase.TextureManager; import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider.Preferences; +import java.util.Arrays; +import java.util.List; + /** * A class that manages all the supported transitions @@ -33,10 +36,6 @@ public class Transitions { */ public enum TRANSITIONS { /** - * A random combination of all supported transitions - */ - RANDOM, - /** * @see NullTransition */ NO_TRANSITION, @@ -52,28 +51,63 @@ public class Transitions { * @see TranslateTransition */ TRANSLATION; + + /** + * Method that returns the transition from its ordinal position + * + * @param ordinal The ordinal position + * @return TRANSITIONS The transition or null if wasn't found + */ + public static TRANSITIONS fromOrdinal(int ordinal) { + for (TRANSITIONS transition : TRANSITIONS.values()) { + if (transition.ordinal() == ordinal){ + return transition; + } + } + return null; + } + + /** + * Method that the returns an array with all the valid transitions (NO_TRANSITION is not + * a valid one). + * + * @return TRANSITIONS[] The valid transitions + */ + public static TRANSITIONS[] getValidTranstions() { + TRANSITIONS[] src = TRANSITIONS.values(); + TRANSITIONS[] dst = new TRANSITIONS[src.length-1]; + System.arraycopy(src, 1, dst, 0, src.length-1); + return dst; + } } /** * Method that return the next type of transition to apply the picture. * - * @param frame The frame which the effect will be applied to + * @param frame The frame which the translation will be applied to * @return TRANSITIONS The next type of transition to apply */ public static TRANSITIONS getNextTypeOfTransition(PhotoFrame frame) { - int transition = Preferences.General.Transitions.getTransitionTypes(); - if (transition == TRANSITIONS.RANDOM.ordinal()) { - int low = TRANSITIONS.SWAP.ordinal(); - int hight = TRANSITIONS.values().length - 1; - transition = low + (int)(Math.random() * ((hight - low) + 1)); + // Get a transition based on the user preference + List<TRANSITIONS> transitions = + Arrays.asList(Preferences.General.Transitions.getTransitionTypes()); + TRANSITIONS nextTransition = null; + if (transitions.size() > 0) { + int low = 0; + int hight = transitions.size() - 1; + int pos = low + (int)(Math.random() * ((hight - low) + 1)); + nextTransition = transitions.get(pos); } - if (transition == TRANSITIONS.SWAP.ordinal()) { - return TRANSITIONS.SWAP; + if (nextTransition == null) { + return TRANSITIONS.NO_TRANSITION; } - if (transition == TRANSITIONS.FADE.ordinal()) { + + // Select the transition if is available + if (nextTransition.compareTo(TRANSITIONS.SWAP) == 0) { + return TRANSITIONS.SWAP; + } else if (nextTransition.compareTo(TRANSITIONS.FADE) == 0) { return TRANSITIONS.FADE; - } - if (transition == TRANSITIONS.TRANSLATION.ordinal()) { + } else if (nextTransition.compareTo(TRANSITIONS.TRANSLATION) == 0) { return TRANSITIONS.TRANSLATION; } return TRANSITIONS.NO_TRANSITION; @@ -85,18 +119,16 @@ public class Transitions { * @param ctx The current context * @param tm The texture manager * @param type The type of transition - * @param frame The frame which the effect will be applied to + * @param frame The frame which the translation will be applied to * @return Transition The next transition to apply */ public static Transition createTransition( Context ctx, TextureManager tm, TRANSITIONS type, PhotoFrame frame) { if (type.compareTo(TRANSITIONS.SWAP) == 0) { return new SwapTransition(ctx, tm); - } - if (type.compareTo(TRANSITIONS.FADE) == 0) { + } else if (type.compareTo(TRANSITIONS.FADE) == 0) { return new FadeTransition(ctx, tm); - } - if (type.compareTo(TRANSITIONS.TRANSLATION) == 0) { + } else if (type.compareTo(TRANSITIONS.TRANSLATION) == 0) { return new TranslateTransition(ctx, tm); } return new NullTransition(ctx, tm); |