aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/cyanogenmod
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-08-07 00:40:29 +0200
committerJorge Ruesga <jorge@ruesga.com>2013-08-07 00:40:29 +0200
commit3c46e3e43e86bfd00c503caf8a31529f8f1ce18c (patch)
treeb96b75bbcd346021e85ba5822620b4e3e795a43e /src/org/cyanogenmod
parente3e640aa2e7b1357903663705bfdce8e8f95dc43 (diff)
downloadandroid_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')
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java2
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java2
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java4
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java17
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/transitions/Transitions.java72
5 files changed, 69 insertions, 28 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java
index 85437dd..56a7736 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java
@@ -166,7 +166,7 @@ public class PhotoPhaseWallpaperWorld {
Transition transition = null;
boolean isSelectable = false;
while (transition == null || !isSelectable) {
- boolean isRandom = Preferences.General.Transitions.getTransitionTypes() == TRANSITIONS.RANDOM.ordinal();
+ boolean isRandom = Preferences.General.Transitions.getTransitionTypes().length > 1;
TRANSITIONS type = Transitions.getNextTypeOfTransition(frame);
transition = getOrCreateTransition(type, frame);
isSelectable = transition.isSelectable(frame);
diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java b/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java
index 266bd66..e76d394 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java
@@ -126,8 +126,6 @@ public class Effects {
// Get an effect based on the user preference
List<EFFECTS> effects = Arrays.asList(Preferences.General.Effects.getEffectTypes());
-
- // Get an effect based on the user preference
EFFECTS nextEffect = null;
if (effects.size() > 0) {
int low = 0;
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
index e30e9c8..edf4880 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
@@ -46,7 +46,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
private SeekBarProgressPreference mWallpaperDim;
private ColorPickerPreference mBackgroundColor;
private ListPreference mTouchActions;
- private ListPreference mTransitionsTypes;
+ private MultiSelectListPreference mTransitionsTypes;
private SeekBarProgressPreference mTransitionsInterval;
private MultiSelectListPreference mEffectsTypes;
@@ -125,7 +125,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
mTouchActions = (ListPreference)findPreference("ui_touch_action");
mTouchActions.setOnPreferenceChangeListener(mOnChangeListener);
- mTransitionsTypes = (ListPreference)findPreference("ui_transition_types");
+ mTransitionsTypes = (MultiSelectListPreference)findPreference("ui_transition_types");
mTransitionsTypes.setOnPreferenceChangeListener(mOnChangeListener);
mTransitionsInterval = (SeekBarProgressPreference)findPreference("ui_transition_interval");
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
index ab18a48..78d3686 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
@@ -217,10 +217,21 @@ public final class PreferencesProvider {
* Return the current user preference about the transition to apply to
* the pictures of the wallpaper.
*
- * @return int The transition to apply to the wallpaper's pictures
+ * @return TRANSITIONS[] The transition to apply to the wallpaper's pictures
*/
- public static int getTransitionTypes() {
- return Integer.valueOf(getString("ui_transition_types", String.valueOf(TRANSITIONS.RANDOM.ordinal())));
+ public static TRANSITIONS[] getTransitionTypes() {
+ Set<String> set = getStringSet("ui_transition_types", new HashSet<String>());
+ if (set.isEmpty()) {
+ // Return all the transitions if no one is selected
+ return TRANSITIONS.getValidTranstions();
+ }
+ String[] values = set.toArray(new String[set.size()]);
+ int count = values.length;
+ TRANSITIONS[] transitions = new TRANSITIONS[count];
+ for (int i = 0; i < count; i++) {
+ transitions[i] = TRANSITIONS.fromOrdinal(Integer.valueOf(values[i]));
+ }
+ return transitions;
}
/**
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);