aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/arrays.xml8
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/xml/preferences_general.xml4
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java73
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java5
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java13
6 files changed, 63 insertions, 42 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 96420a0..1351be3 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -63,8 +63,6 @@
</string-array>
<string-array name="effects_labels" translatable="false">
- <item>@string/effects_none</item>
- <item>@string/effects_random</item>
<item>@string/effects_autofix</item>
<item>@string/effects_crossprocess</item>
<item>@string/effects_documentary</item>
@@ -83,8 +81,8 @@
</string-array>
<string-array name="effects_values" translatable="false">
- <item>1</item>
<item>0</item>
+ <item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
@@ -98,8 +96,8 @@
<item>12</item>
<item>13</item>
<item>14</item>
- <item>15</item>
- <item>16</item>
</string-array>
+ <string-array name="effects_default" translatable="false"/>
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 77d78c0..08cbeaf 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -109,8 +109,6 @@
<string name="transitions_translation">Translation</string>
<!-- Effects -->
- <string name="effects_none">None</string>
- <string name="effects_random">Random</string>
<string name="effects_autofix">Autofix</string>
<string name="effects_crossprocess">Cross process</string>
<string name="effects_documentary">Documentary</string>
diff --git a/res/xml/preferences_general.xml b/res/xml/preferences_general.xml
index b6d60f8..1c9d675 100644
--- a/res/xml/preferences_general.xml
+++ b/res/xml/preferences_general.xml
@@ -80,14 +80,14 @@
android:title="@string/pref_general_effects">
<!-- Transitions -->
- <ListPreference
+ <MultiSelectListPreference
android:key="ui_effect_types"
android:title="@string/pref_general_effects_types"
android:summary="@string/pref_general_effects_types_summary"
android:persistent="true"
android:entries="@array/effects_labels"
android:entryValues="@array/effects_values"
- android:defaultValue="1" />
+ android:defaultValue="@array/effects_default" />
</PreferenceCategory>
diff --git a/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java b/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java
index 42d4d98..266bd66 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/effects/Effects.java
@@ -23,6 +23,9 @@ import android.media.effect.EffectFactory;
import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider.Preferences;
+import java.util.Arrays;
+import java.util.List;
+
/**
* A class that manages all the supported effects
*/
@@ -33,14 +36,6 @@ public class Effects {
*/
public enum EFFECTS {
/**
- * A random combination of all supported effects
- */
- RANDOM,
- /**
- * No effect
- */
- NO_EFFECT,
- /**
* @see EffectFactory#EFFECT_AUTOFIX
*/
AUTOFIX,
@@ -100,6 +95,21 @@ public class Effects {
* @see EffectFactory#EFFECT_VIGNETTE
*/
VIGNETTE;
+
+ /**
+ * Method that returns the effect from its ordinal position
+ *
+ * @param ordinal The ordinal position
+ * @return EFFECTS The effect or null if wasn't found
+ */
+ public static EFFECTS fromOrdinal(int ordinal) {
+ for (EFFECTS effect : EFFECTS.values()) {
+ if (effect.ordinal() == ordinal){
+ return effect;
+ }
+ }
+ return null;
+ }
}
@@ -115,79 +125,86 @@ public class Effects {
EffectFactory effectFactory = effectContext.getFactory();
// Get an effect based on the user preference
- int type = Preferences.General.Effects.getEffectTypes();
- if (type == EFFECTS.RANDOM.ordinal()) {
- int low = EFFECTS.NO_EFFECT.ordinal();
- int hight = EFFECTS.values().length - 1;
- type = low + (int)(Math.random() * ((hight - low) + 1));
+ 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;
+ int hight = effects.size() - 1;
+ int pos = low + (int)(Math.random() * ((hight - low) + 1));
+ nextEffect = effects.get(pos);
+ }
+ if (nextEffect == null) {
+ return null;
}
// Select the effect if is available
Effect effect = null;
- if (type == EFFECTS.AUTOFIX.ordinal()) {
+ if (nextEffect.compareTo(EFFECTS.AUTOFIX) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_AUTOFIX)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX);
effect.setParameter("scale", 0.5f);
}
- } else if (type == EFFECTS.CROSSPROCESS.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.CROSSPROCESS) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_CROSSPROCESS)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_CROSSPROCESS);
}
- } else if (type == EFFECTS.DOCUMENTARY.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.DOCUMENTARY) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_DOCUMENTARY)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_DOCUMENTARY);
}
- } else if (type == EFFECTS.DUOTONE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.DUOTONE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_DUOTONE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_DUOTONE);
effect.setParameter("first_color", Color.parseColor("#FF8CACFF"));
effect.setParameter("second_color", Color.WHITE);
}
- } else if (type == EFFECTS.FISHEYE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.FISHEYE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_FISHEYE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE);
effect.setParameter("scale", 1.0f);
}
- } else if (type == EFFECTS.GRAIN.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.GRAIN) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_GRAIN)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN);
effect.setParameter("strength", 1.0f);
}
- } else if (type == EFFECTS.GRAYSCALE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.GRAYSCALE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_GRAYSCALE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_GRAYSCALE);
}
- } else if (type == EFFECTS.LOMOISH.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.LOMOISH) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_LOMOISH)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_LOMOISH);
}
- } else if (type == EFFECTS.NEGATIVE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.NEGATIVE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_NEGATIVE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE);
}
- } else if (type == EFFECTS.POSTERIZE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.POSTERIZE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_POSTERIZE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_POSTERIZE);
}
- } else if (type == EFFECTS.SATURATE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.SATURATE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_SATURATE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_SATURATE);
effect.setParameter("scale", .5f);
}
- } else if (type == EFFECTS.SEPIA.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.SEPIA) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_SEPIA)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_SEPIA);
}
- } else if (type == EFFECTS.TEMPERATURE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.TEMPERATURE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_TEMPERATURE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_TEMPERATURE);
effect.setParameter("scale", .9f);
}
- } else if (type == EFFECTS.TINT.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.TINT) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_TINT)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
}
- } else if (type == EFFECTS.VIGNETTE.ordinal()) {
+ } else if (nextEffect.compareTo(EFFECTS.VIGNETTE) == 0) {
if (EffectFactory.isEffectSupported(EffectFactory.EFFECT_VIGNETTE)) {
effect = effectFactory.createEffect(EffectFactory.EFFECT_VIGNETTE);
effect.setParameter("scale", .5f);
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
index 1d50da3..e30e9c8 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.ListPreference;
+import android.preference.MultiSelectListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
@@ -47,7 +48,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
private ListPreference mTouchActions;
private ListPreference mTransitionsTypes;
private SeekBarProgressPreference mTransitionsInterval;
- private ListPreference mEffectsTypes;
+ private MultiSelectListPreference mEffectsTypes;
boolean mRedrawFlag;
boolean mEmptyTextureQueueFlag;
@@ -141,7 +142,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
});
mTransitionsInterval.setOnPreferenceChangeListener(mOnChangeListener);
- mEffectsTypes = (ListPreference)findPreference("ui_effect_types");
+ mEffectsTypes = (MultiSelectListPreference)findPreference("ui_effect_types");
mEffectsTypes.setOnPreferenceChangeListener(mOnChangeListener);
}
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
index 0b3e439..ab18a48 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
@@ -243,10 +243,17 @@ public final class PreferencesProvider {
* Return the current user preference about the effect to apply to
* the pictures of the wallpaper.
*
- * @return int The effect to apply to the wallpaper's pictures
+ * @return EFFECTS[] The effects to apply to the wallpaper's pictures
*/
- public static int getEffectTypes() {
- return Integer.valueOf(getString("ui_effect_types", String.valueOf(EFFECTS.NO_EFFECT.ordinal())));
+ public static EFFECTS[] getEffectTypes() {
+ Set<String> set = getStringSet("ui_effect_types", new HashSet<String>());
+ String[] values = set.toArray(new String[set.size()]);
+ int count = values.length;
+ EFFECTS[] effects = new EFFECTS[count];
+ for (int i = 0; i < count; i++) {
+ effects[i] = EFFECTS.fromOrdinal(Integer.valueOf(values[i]));
+ }
+ return effects;
}
}
}