aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-11-03 01:24:21 +0100
committerJorge Ruesga <jorge@ruesga.com>2013-11-03 01:24:21 +0100
commit2d6d5b71345b21eba2a3265c501499e466653dc5 (patch)
treebcf6904be039900d581c400a784a39643f353165
parent0bc32145ffcc46c3438c080799ad8c641ffa3271 (diff)
downloadandroid_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>
-rw-r--r--res/values-es/strings.xml11
-rw-r--r--res/values/arrays.xml56
-rw-r--r--res/values/strings.xml13
-rw-r--r--res/xml/preferences_layout.xml15
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java2
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java207
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java3
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java50
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/TextureManager.java2
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java2
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java19
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/LayoutPreferenceFragment.java115
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java98
13 files changed, 515 insertions, 78 deletions
diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml
index f6bb32d..41d1358 100644
--- a/res/values-es/strings.xml
+++ b/res/values-es/strings.xml
@@ -27,11 +27,15 @@
<string name="mnu_invert">Invertir</string>
<string name="mnu_select_album">Seleccionar álbum</string>
<string name="mnu_deselect_album">Deseleccionar álbum</string>
+ <string name="format_seconds">%s sec.</string>
+ <string name="format_minutes">%s min.</string>
+ <string name="format_hours">%s h.</string>
+ <string name="format_days">%s d.</string>
+ <string name="format_dim">%s%%</string>
<string name="pref_general">General</string>
<string name="pref_general_summary">Accede a ajustes generales, efectos y transiciones</string>
<string name="pref_general_settings">Ajustes</string>
<string name="pref_general_settings_wallpaper_dim">Oscurecer fondo de escritorio</string>
- <string name="pref_general_settings_wallpaper_dim_format">%s%%</string>
<string name="pref_general_settings_wallpaper_dim_summary">Establece el brillo del fondo de escritorio para una mejor visualización y rendimiento de la batería</string>
<string name="pref_general_settings_background_color">Color del fondo</string>
<string name="pref_general_settings_background_color_summary">Establece el color del fondo de escritorio</string>
@@ -44,7 +48,6 @@
<string name="pref_general_transitions_types_summary">Selecciona los tipos de efectos de transición a aplicar</string>
<string name="pref_general_transitions_interval">Intervalo</string>
<string name="pref_general_transitions_interval_summary">Establece la frecuencia en la que las imágenes son reemplazadas</string>
- <string name="pref_general_transitions_interval_format">%s seg.</string>
<string name="pref_general_effects">Efectos</string>
<string name="pref_general_effects_types">Tipos</string>
<string name="pref_general_effects_types_summary">Selecciona los tipos de efectos a aplicar a las imágenes</string>
@@ -64,6 +67,10 @@
<string name="pref_layout">Disposición</string>
<string name="pref_layout_summary">Selecciona como se mostraran las imágenes en pantalla</string>
<string name="pref_layout_disposition">Disposición</string>
+ <string name="pref_random_dispositions">Disposiciones aleatorias</string>
+ <string name="pref_random_dispositions_summary">Generar disposiciones aleatorias cada cierto tiempo</string>
+ <string name="pref_random_dispositions_interval">Intervalo</string>
+ <string name="pref_random_dispositions_interval_summary">Selecciona cada cuanto tiempo se cambiará la disposición. Establece el valor a 0 para cambiar la disposición cada vez que se rote o se reinicie el equipo</string>
<string name="pref_disposition_portrait">Disposición vertical</string>
<string name="pref_disposition_portrait_summary">Selecciona como se mostraran las imágenes en una pantalla horizontal</string>
<string name="pref_disposition_landscape">Disposición horizontal</string>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 3ab44b2..94efd96 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -141,4 +141,60 @@
<item>0</item>
</string-array>
+ <integer-array name="random_dispositions_intervals_values" translatable="false">
+ <item>0</item>
+ <item>3600000</item>
+ <item>7200000</item>
+ <item>14400000</item>
+ <item>28800000</item>
+ <item>43200000</item>
+ <item>86400000</item>
+ </integer-array>
+
+ <string-array name="portrait_disposition_templates" translatable="false">
+ <item>0x0:2x1|0x2:1x3|0x4:3x6|2x2:3x3|3x0:3x0|3x1:3x1</item>
+ <item>0x0:1x1|0x2:1x3|0x4:3x6|2x0:3x1|2x2:3x3</item>
+ <item>0x0:2x1|0x2:1x3|0x4:3x6|2x2:3x3|3x0:3x1</item>
+ <item>0x0:0x1|0x2:0x4|0x5:0x6|1x0:2x1|1x2:2x4|1x5:2x6|3x0:3x1|3x2:3x4|3x5:3x6</item>
+ <item>0x0:0x0|0x1:3x5|0x6:0x6|1x0:1x0|1x6:1x6|2x0:2x0|2x6:2x6|3x0:3x0|3x6:3x6</item>
+ <item>0x0:3x2|0x3:0x3|0x4:3x6|1x3:1x3|2x3:2x3|3x3:3x3</item>
+ <item>0x0:3x2|0x3:0x3|0x4:3x6|1x3:1x3|2x3:2x3|3x3:3x3</item>
+ <item>0x0:1x2|0x3:0x3|0x4:1x6|1x3:1x3|2x0:3x1|2x2:2x2|2x3:3x6|3x2:3x2</item>
+ <item>0x0:3x3|0x4:3x6</item>
+ <item>0x0:3x6</item>
+ <item>0x0:1x3|0x4:1x6|2x0:3x2|2x3:3x6</item>
+ <item>0x0:0x0|0x1:0x1|0x2:0x2|0x3:0x3|0x4:2x6|1x0:3x2|1x3:1x3|2x3:2x3|3x3:3x3|3x4:3x4|3x5:3x5|3x6:3x6</item>
+ <item>0x0:0x0|0x1:0x1|0x2:0x2|0x3:0x3|0x4:0x4|0x5:0x5|0x6:0x6|1x0:2x2|1x3:1x3|1x4:2x6|2x3:2x3|3x0:3x0|3x1:3x1|3x2:3x2|3x3:3x3|3x4:3x4|3x5:3x5|3x6:3x6</item>
+ <item>0x0:1x1|0x2:1x3|0x4:0x4|0x5:0x5|0x6:0x6|1x4:2x6|2x0:3x1|2x2:3x3|3x4:3x4|3x5:3x5|3x6:3x6</item>
+ <item>0x0:1x1|0x2:1x3|0x4:2x6|2x0:3x1|2x2:3x3|3x4:3x4|3x5:3x5|3x6:3x6</item>
+ <item>0x0:0x0|0x1:0x1|0x2:1x3|0x4:3x6|1x0:1x0|1x1:1x1|2x0:3x1|2x2:2x2|2x3:2x3|3x2:3x2|3x3:3x3</item>
+ <item>0x0:1x1|0x2:3x4|0x5:1x6|2x0:3x1|2x5:3x6</item>
+ <item>0x0:1x0|0x1:3x5|0x6:1x6|2x0:3x0|2x6:3x6</item>
+ <item>0x0:3x1|0x2:3x4|0x5:3x6</item>
+ <item>0x0:2x1|0x2:3x4|0x5:0x6|1x5:3x6|3x0:3x1</item>
+ </string-array>
+
+ <string-array name="landscape_disposition_templates" translatable="false">
+ <item>0x0:2x3|3x0:5x1|3x2:4x3|5x2:6x3|6x0:6x0|6x1:6x1</item>
+ <item>0x0:2x1|0x2:2x3|3x0:4x1|3x2:4x3|5x0:6x1|5x2:6x3</item>
+ <item>0x0:0x0|0x1:0x1|0x2:2x3|1x0:2x1|3x0:5x1|3x2:4x3|5x2:6x3|6x0:6x0|6x1:6x1</item>
+ <item>0x0:2x3|3x0:3x0|3x1:3x1|3x2:3x2|3x3:3x3|4x0:6x3</item>
+ <item>0x0:0x0|0x1:2x2|0x3:0x3|1x0:1x0|1x3:1x3|2x0:2x0|2x3:2x3|3x0:3x0|3x1:3x1|3x2:3x2|3x3:3x3|4x0:6x3</item>
+ <item>0x0:0x0|0x1:0x1|0x2:0x2|0x3:0x3|1x0:1x0|1x1:2x2|1x3:1x3|2x0:2x0|2x3:2x3|3x0:3x0|3x1:3x1|3x2:3x2|3x3:3x3|4x0:4x0|4x1:5x2|4x3:4x3|5x0:5x0|5x3:5x3|6x0:6x0|6x1:6x1|6x2:6x2|6x3:6x3</item>
+ <item>0x0:0x0|0x1:0x1|0x2:0x2|0x3:0x3|1x0:2x3|3x0:3x0|3x1:3x1|3x2:3x2|3x3:3x3|4x0:5x3|6x0:6x0|6x1:6x1|6x2:6x2|6x3:6x3</item>
+ <item>0x0:2x3|3x0:3x0|3x1:3x2|3x3:3x3|4x0:6x3</item>
+ <item>0x0:2x3|3x0:6x3</item>
+ <item>0x0:1x3|2x0:3x1|2x2:3x3|4x0:6x3</item>
+ <item>0x0:0x1|0x2:0x3|1x0:2x1|1x2:2x3|3x0:3x1|3x2:3x3|4x0:5x1|4x2:5x3|6x0:6x1|6x2:6x3</item>
+ <item>0x0:0x1|0x2:0x3|1x0:1x0|1x1:5x3|2x0:2x0|3x0:3x0|4x0:4x0|5x0:5x0|6x0:6x1|6x2:6x3</item>
+ <item>0x0:6x3</item>
+ <item>0x0:1x3|2x0:4x3|5x0:6x3</item>
+ <item>0x0:1x1|0x2:1x3|2x0:4x3|5x0:6x1|5x2:6x3</item>
+ <item>0x0:1x1|0x2:1x3|2x0:4x1|2x2:4x3|5x0:6x1|5x2:6x3</item>
+ <item>0x0:0x0|0x1:0x2|0x3:1x3|1x0:1x1|1x2:1x2|2x0:4x1|2x2:4x3|5x0:5x1|5x2:5x3|6x0:6x0|6x1:6x2|6x3:6x3</item>
+ <item>0x0:0x0|0x1:0x2|0x3:1x3|1x0:1x1|1x2:1x2|2x0:4x1|2x2:4x3|5x0:6x0|5x1:5x1|5x2:5x3|6x1:6x2|6x3:6x3</item>
+ <item>0x0:0x2|0x3:0x3|1x0:1x1|1x2:4x3|2x0:5x1|5x2:5x3|6x0:6x2|6x3:6x3</item>
+ <item>0x0:0x2|0x3:0x3|1x0:2x1|1x2:3x3|3x0:5x1|4x2:5x3|6x0:6x2|6x3:6x3</item>
+ </string-array>
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7ec74dc..e0359ae 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -37,12 +37,18 @@
<string name="mnu_select_album">Select album</string>
<string name="mnu_deselect_album">Deselect album</string>
+ <!-- Formats -->
+ <string name="format_seconds">%s sec.</string>
+ <string name="format_minutes">%s min.</string>
+ <string name="format_hours">%s h.</string>
+ <string name="format_days">%s d.</string>
+ <string name="format_dim">%s%%</string>
+
<!-- Preferences -->
<string name="pref_general">General</string>
<string name="pref_general_summary">Access to general settings, effects and transitions</string>
<string name="pref_general_settings">Settings</string>
<string name="pref_general_settings_wallpaper_dim">Wallpaper dim</string>
- <string name="pref_general_settings_wallpaper_dim_format">%s%%</string>
<string name="pref_general_settings_wallpaper_dim_summary">Set the brightness of the wallpaper for a better visualization and battery performance</string>
<string name="pref_general_settings_background_color">Background color</string>
<string name="pref_general_settings_background_color_summary">Set the background color of the wallpaper</string>
@@ -56,7 +62,6 @@
<string name="pref_general_transitions_types_summary">Select the types of transition effects to be applied</string>
<string name="pref_general_transitions_interval">Interval</string>
<string name="pref_general_transitions_interval_summary">Set how often are triggered the picture transitions</string>
- <string name="pref_general_transitions_interval_format">%s sec.</string>
<string name="pref_general_effects">Effects</string>
<string name="pref_general_effects_types">Types</string>
<string name="pref_general_effects_types_summary">Select the types of image effects to be applied to the pictures</string>
@@ -78,6 +83,10 @@
<string name="pref_layout">Layout</string>
<string name="pref_layout_summary">Select how pictures are disposed on the screen</string>
<string name="pref_layout_disposition">Disposition</string>
+ <string name="pref_random_dispositions">Random dispositions</string>
+ <string name="pref_random_dispositions_summary">Generating random dispositions occasionally</string>
+ <string name="pref_random_dispositions_interval">Interval</string>
+ <string name="pref_random_dispositions_interval_summary">Select how often the layout disposition will be changed. Set to 0 to change the disposition only when the app is loaded or rotated</string>
<string name="pref_disposition_portrait">Portrait disposition</string>
<string name="pref_disposition_portrait_summary">Select how pictures are disposed on a portrait screen</string>
<string name="pref_disposition_landscape">Landscape disposition</string>
diff --git a/res/xml/preferences_layout.xml b/res/xml/preferences_layout.xml
index 02d12e3..8ba4941 100644
--- a/res/xml/preferences_layout.xml
+++ b/res/xml/preferences_layout.xml
@@ -23,6 +23,21 @@
android:key="category_disposition"
android:title="@string/pref_layout_disposition">
+ <!-- Random dispositions -->
+ <CheckBoxPreference
+ android:key="ui_disposition_random"
+ android:title="@string/pref_random_dispositions"
+ android:summary="@string/pref_random_dispositions_summary" />
+
+ <!-- Random dispositions interval -->
+ <org.cyanogenmod.wallpapers.photophase.preferences.SeekBarProgressPreference
+ android:key="ui_disposition_random_interval"
+ android:title="@string/pref_random_dispositions_interval"
+ android:summary="@string/pref_random_dispositions_interval_summary"
+ android:persistent="true"
+ android:defaultValue="0"
+ android:dependency="ui_disposition_random" />
+
<!-- Portrait -->
<Preference
android:key="ui_disposition_portrait"
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java
index 973618d..72f5b97 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java
@@ -67,7 +67,7 @@ public class PhotoPhaseActivity extends Activity implements OnTouchListener {
mGLSurfaceView = new GLSurfaceView(getApplicationContext());
mGLSurfaceView.setEGLContextClientVersion(2);
mGLSurfaceView.setEGLConfigChooser(false);
- mRenderer = new PhotoPhaseRenderer(this, new GLESSurfaceDispatcher(mGLSurfaceView));
+ mRenderer = new PhotoPhaseRenderer(this, new GLESSurfaceDispatcher(mGLSurfaceView), false);
mGLSurfaceView.setRenderer(mRenderer);
mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
mGLSurfaceView.setPreserveEGLContextOnPause(preserveEglCtx);
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java
index c307023..c4950a3 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java
@@ -62,12 +62,19 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
private final long mInstance;
private static long sInstances;
+ private final boolean mIsPreview;
+ boolean mIsPaused;
+ boolean mRecreateWorld;
+
final Context mContext;
EffectContext mEffectContext;
private final Handler mHandler;
final GLESSurfaceDispatcher mDispatcher;
TextureManager mTextureManager;
+ final AlarmManager mAlarmManager;
+ PendingIntent mRecreateDispositionPendingIntent;
+
PhotoPhaseWallpaperWorld mWorld;
ColorShape mOverlay;
OopsShape mOopsShape;
@@ -86,7 +93,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
private final float[] mProjMatrix = new float[16];
private final float[] mVMatrix = new float[16];
- private final Object mDrawing = new Object();
+ final Object mDrawing = new Object();
final Object mMediaSync = new Object();
private PendingIntent mMediaScanIntent;
@@ -95,48 +102,60 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
@Override
public void onReceive(Context context, Intent intent) {
// Check what flags are been requested
- boolean recreateWorld = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_RECREATE_WORLD, false);
+ boolean recreateWorld = intent.getBooleanExtra(
+ PreferencesProvider.EXTRA_FLAG_RECREATE_WORLD, false);
boolean redraw = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_REDRAW, false);
- boolean emptyTextureQueue = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_EMPTY_TEXTURE_QUEUE, false);
- boolean mediaReload = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_RELOAD, false);
- boolean mediaIntervalChanged = intent.getBooleanExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_INTERVAL_CHANGED, false);
+ boolean emptyTextureQueue = intent.getBooleanExtra(
+ PreferencesProvider.EXTRA_FLAG_EMPTY_TEXTURE_QUEUE, false);
+ boolean mediaReload = intent.getBooleanExtra(
+ PreferencesProvider.EXTRA_FLAG_MEDIA_RELOAD, false);
+ boolean mediaIntervalChanged = intent.getBooleanExtra(
+ PreferencesProvider.EXTRA_FLAG_MEDIA_INTERVAL_CHANGED, false);
+ int dispositionInterval = intent.getIntExtra(
+ PreferencesProvider.EXTRA_FLAG_DISPOSITION_INTERVAL_CHANGED, -1);
+
+ // Empty texture queue?
if (emptyTextureQueue) {
if (mTextureManager != null) {
mTextureManager.emptyTextureQueue(true);
}
}
+
+ // Media reload. Purging resources and performs a media query
if (mediaReload) {
synchronized (mMediaSync) {
if (mTextureManager != null) {
- boolean userReloadRequest =
- intent.getBooleanExtra(
- PreferencesProvider.EXTRA_ACTION_MEDIA_USER_RELOAD_REQUEST, false);
+ boolean userReloadRequest = intent.getBooleanExtra(
+ PreferencesProvider.EXTRA_ACTION_MEDIA_USER_RELOAD_REQUEST, false);
mTextureManager.reloadMedia(userReloadRequest);
scheduleOrCancelMediaScan();
}
}
}
+
+ // Media scan interval was changed. Reschedule
if (mediaIntervalChanged) {
scheduleOrCancelMediaScan();
}
+
+ // Media scan interval was changed. Reschedule
+ if (dispositionInterval != -1) {
+ scheduleDispositionRecreation();
+ }
+
+ // Recreate the whole world?
if (recreateWorld && mWorld != null) {
- // Recreate the wallpaper world
- try {
- mWorld.recreateWorld(mWidth, mMeasuredHeight);
- } catch (GLException e) {
- Log.e(TAG, "Cannot recreate the wallpaper world.", e);
- }
+ recreateWorld();
}
+
+ // Performs a redraw?
if (redraw) {
- mDispatcher.requestRender();
+ forceRedraw();
}
}
};
private final Runnable mTransitionThread = new Runnable() {
- /**
- * {@inheritDoc}
- */
@Override
public void run() {
// Run in GLES's thread
@@ -144,12 +163,14 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
@Override
public void run() {
try {
- // Select a new transition
- mWorld.selectRandomTransition();
- mLastRunningTransition = System.currentTimeMillis();
-
- // Now force continuously render while transition is applied
- mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
+ if (!mIsPaused) {
+ // Select a new transition
+ mWorld.selectRandomTransition();
+ mLastRunningTransition = System.currentTimeMillis();
+
+ // Now force continuously render while transition is applied
+ mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
+ }
} catch (Throwable ex) {
Log.e(TAG, "Something was wrong selecting the transition", ex);
}
@@ -163,14 +184,19 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
*
* @param ctx The current context
* @param dispatcher The GLES dispatcher
+ * @param isPreview Indicates if the renderer is in preview mode
*/
- public PhotoPhaseRenderer(Context ctx, GLESSurfaceDispatcher dispatcher) {
+ public PhotoPhaseRenderer(Context ctx, GLESSurfaceDispatcher dispatcher, boolean isPreview) {
super();
mContext = ctx;
mHandler = new Handler();
mDispatcher = dispatcher;
mInstance = sInstances;
+ mIsPreview = isPreview;
+ mIsPaused = true;
+ mRecreateWorld = false;
sInstances++;
+ mAlarmManager = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
}
/**
@@ -256,6 +282,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
*/
public void onPause() {
if (DEBUG) Log.d(TAG, "onPause [" + mInstance + "]");
+ mIsPaused = true;
mHandler.removeCallbacks(mTransitionThread);
if (mTextureManager != null) {
mTextureManager.setPause(true);
@@ -270,6 +297,13 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
if (mTextureManager != null) {
mTextureManager.setPause(false);
}
+ mIsPaused = false;
+ if (mRecreateWorld) {
+ recreateWorld();
+ } else {
+ mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
+ mDispatcher.requestRender();
+ }
}
/**
@@ -334,7 +368,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
mContext.startActivity(intent);
}
} catch (ActivityNotFoundException ex) {
- Log.e(TAG, "Open activity not found for " + frame.getTextureInfo().path, ex);
+ Log.e(TAG, "Open action not found for " + frame.getTextureInfo().path, ex);
}
} else if (touchAction.compareTo(TouchAction.SHARE) == 0) {
@@ -350,7 +384,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
mContext.startActivity(intent);
}
} catch (ActivityNotFoundException ex) {
- Log.e(TAG, "Send activity not found for " + frame.getTextureInfo().path, ex);
+ Log.e(TAG, "Send action not found for " + frame.getTextureInfo().path, ex);
}
}
}
@@ -390,6 +424,11 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
}
void scheduleOrCancelMediaScan() {
+ // Ignored in preview mode
+ if (mIsPreview) {
+ return;
+ }
+
int interval = Preferences.Media.getRefreshFrecuency();
if (interval != Preferences.Media.MEDIA_RELOAD_DISABLED) {
scheduleMediaScan(interval);
@@ -404,14 +443,19 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
* @param interval The new interval
*/
private void scheduleMediaScan(int interval) {
- AlarmManager am = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
+ // Ignored in preview mode
+ if (mIsPreview) {
+ return;
+ }
Intent i = new Intent(PreferencesProvider.ACTION_SETTINGS_CHANGED);
i.putExtra(PreferencesProvider.EXTRA_FLAG_MEDIA_RELOAD, Boolean.TRUE);
- mMediaScanIntent = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
+ mMediaScanIntent = PendingIntent.getBroadcast(
+ mContext, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
long milliseconds = Preferences.Media.getRefreshFrecuency() * 1000L;
- am.set(AlarmManager.RTC, System.currentTimeMillis() + milliseconds, mMediaScanIntent);
+ long nextTime = System.currentTimeMillis() + milliseconds;
+ mAlarmManager.set(AlarmManager.RTC, nextTime, mMediaScanIntent);
}
/**
@@ -419,13 +463,93 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
*/
private void cancelMediaScan() {
if (mMediaScanIntent != null) {
- AlarmManager am = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
- am.cancel(mMediaScanIntent);
+ mAlarmManager.cancel(mMediaScanIntent);
mMediaScanIntent = null;
}
}
/**
+ * Method that schedule a new recreation of the current disposition
+ */
+ void scheduleDispositionRecreation() {
+ // Ignored in preview mode
+ if (mIsPreview) {
+ return;
+ }
+
+ // Cancel current alarm
+ cancelDispositionRecreation();
+
+ // Is random disposition enabled?
+ if (!Preferences.Layout.isRandomDispositions()) {
+ return;
+ }
+
+ // Schedule the next recreation if interval has been configured
+ int interval = Preferences.Layout.getRandomDispositionsInterval();
+ if (interval > 0) {
+ // Created the intent
+ Intent intent = new Intent(PreferencesProvider.ACTION_SETTINGS_CHANGED);
+ intent.putExtra(PreferencesProvider.EXTRA_FLAG_RECREATE_WORLD, Boolean.TRUE);
+ mRecreateDispositionPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
+
+ // Schedule the pending intent
+ long nextTime = System.currentTimeMillis() + interval;
+ mAlarmManager.set(AlarmManager.RTC, nextTime, mRecreateDispositionPendingIntent);
+ }
+ }
+
+ /**
+ * Method that cancels a pending media scan
+ */
+ private void cancelDispositionRecreation() {
+ // Cancel current alarm
+ if (mRecreateDispositionPendingIntent != null) {
+ mAlarmManager.cancel(mRecreateDispositionPendingIntent);
+ }
+ }
+
+ /**
+ * Recreate the world
+ */
+ void recreateWorld() {
+System.out.println("recreateWorld(): " + mIsPaused);
+ if (mIsPaused) {
+ mRecreateWorld = true;
+ return;
+ }
+
+ // Recreate the wallpaper world (under a GLES context)
+ mDispatcher.dispatch(new Runnable() {
+ @Override
+ public void run() {
+ synchronized (mDrawing) {
+ try {
+ mLastRunningTransition = 0;
+ mWorld.recreateWorld(mWidth, mMeasuredHeight);
+ } catch (GLException e) {
+ Log.e(TAG, "Cannot recreate the wallpaper world.", e);
+ } finally {
+ mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
+ mDispatcher.requestRender();
+ }
+ scheduleDispositionRecreation();
+ }
+ }
+ });
+ }
+
+ /**
+ * Force a redraw of the screen
+ */
+ void forceRedraw() {
+ if (!mIsPaused) {
+ mDispatcher.requestRender();
+ }
+ }
+
+ /**
* Method that destroy all the internal references
*/
private void recycle() {
@@ -500,6 +624,9 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
} else {
mTextureManager.updateEffectContext(mEffectContext);
}
+
+ // Schedule dispositions random recreation (if need it)
+ scheduleDispositionRecreation();
}
/**
@@ -585,14 +712,14 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
// Draw the background
drawBackground();
- if (mWorld != null) {
+ if (!mIsPaused && mWorld != null) {
// Now draw the world (all the photo frames with effects)
mWorld.draw(mMVPMatrix);
// Check if we have some pending transition or transition has
// exceed its timeout
if (Preferences.General.Transitions.getTransitionInterval() > 0) {
- if (!mWorld.hasRunningTransition() || firedTransitionTimeout()) {
+ if (!mWorld.hasRunningTransition() || isTransitionTimeoutFired()) {
mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
// Now start a delayed thread to generate the next effect
@@ -603,14 +730,16 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
}
} else {
// Just display the initial frames and never make transitions
- if (!mWorld.hasRunningTransition() || firedTransitionTimeout()) {
+ if (!mWorld.hasRunningTransition() || isTransitionTimeoutFired()) {
mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}
-
- // Draw the overlay
- drawOverlay();
+ } else if (mIsPaused) {
+ mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
+
+ // Draw the overlay
+ drawOverlay();
}
}
@@ -622,7 +751,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer {
*
* @return boolean if the transition has exceed the timeout
*/
- private boolean firedTransitionTimeout() {
+ private boolean isTransitionTimeoutFired() {
long now = System.currentTimeMillis();
long diff = now - mLastRunningTransition;
return mLastRunningTransition != 0 && diff > Transition.MAX_TRANSTION_TIME;
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java
index 5152bc8..e218f11 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java
@@ -227,7 +227,8 @@ public class PhotoPhaseWallpaper
@Override
public Renderer getNewRenderer(GLSurfaceView view) {
if (DEBUG) Log.d(TAG, "getNewRenderer()");
- PhotoPhaseRenderer renderer = new PhotoPhaseRenderer(this, new GLESSurfaceDispatcher(view));
+ PhotoPhaseRenderer renderer = new PhotoPhaseRenderer(this,
+ new GLESSurfaceDispatcher(view), mEngine.isPreview());
renderer.onCreate();
mRenderers.add(renderer);
if (DEBUG) Log.d(TAG, "renderer" + renderer);
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();
+ }
}
diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
index 3731a1b..bfa1edc 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java
@@ -48,7 +48,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener {
private static final String TAG = "TextureManager";
- private static final int QUEUE_SIZE = 3;
+ private static final int QUEUE_SIZE = 8;
final Context mContext;
final Handler mHandler;
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java
index 00d75a6..262002c 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/ChoosePicturesFragment.java
@@ -143,7 +143,7 @@ public class ChoosePicturesFragment extends PreferenceFragment
*/
@Override
protected void onProgressUpdate(Album... albums) {
- for(Album album : albums) {
+ for (Album album : albums) {
mAlbums.add(album);
}
mAlbumAdapter.notifyDataSetChanged();
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
index 4dd6da8..04c6571 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java
@@ -50,7 +50,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
private ListPreference mTouchActions;
private CheckBoxPreference mFixAspectRatio;
private MultiSelectListPreference mTransitionsTypes;
- private SeekBarProgressPreference mTransitionsInterval;
+ SeekBarProgressPreference mTransitionsInterval;
private MultiSelectListPreference mEffectsTypes;
boolean mRedrawFlag;
@@ -109,6 +109,10 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ final String formatSeconds = getString(R.string.format_seconds);
+ final String formatMinutes = getString(R.string.format_minutes);
+ final String formatDim = getString(R.string.format_dim);
+
// Change the preference manager
getPreferenceManager().setSharedPreferencesName(PreferencesProvider.PREFERENCES_FILE);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);
@@ -120,7 +124,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
addPreferencesFromResource(R.xml.preferences_general);
mWallpaperDim = (SeekBarProgressPreference)findPreference("ui_wallpaper_dim");
- mWallpaperDim.setFormat(getString(R.string.pref_general_settings_wallpaper_dim_format));
+ mWallpaperDim.setFormat(formatDim);
mWallpaperDim.setOnPreferenceChangeListener(mOnChangeListener);
mBackgroundColor = (ColorPickerPreference)findPreference("ui_background_color");
@@ -137,7 +141,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
final int[] transitionsIntervals = res.getIntArray(R.array.transitions_intervals_values);
mTransitionsInterval = (SeekBarProgressPreference)findPreference("ui_transition_interval");
- mTransitionsInterval.setFormat(getString(R.string.pref_general_transitions_interval_format));
+ mTransitionsInterval.setFormat(getString(R.string.format_seconds));
mTransitionsInterval.setMax(transitionsIntervals.length - 1);
int transitionInterval = prefs.getInt("ui_transition_interval",
Preferences.General.Transitions.DEFAULT_TRANSITION_INTERVAL_INDEX);
@@ -148,7 +152,14 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
mTransitionsInterval.setOnDisplayProgress(new OnDisplayProgress() {
@Override
public String onDisplayProgress(int progress) {
- return String.valueOf(transitionsIntervals[progress] / 1000);
+ if (transitionsIntervals[progress] < 60000) {
+ // Seconds
+ mTransitionsInterval.setFormat(formatSeconds);
+ return String.valueOf(transitionsIntervals[progress] / 1000);
+ }
+ // Minutes
+ mTransitionsInterval.setFormat(formatMinutes);
+ return String.valueOf(transitionsIntervals[progress] / 1000 / 60);
}
});
mTransitionsInterval.setOnPreferenceChangeListener(mOnChangeListener);
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/LayoutPreferenceFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/LayoutPreferenceFragment.java
index 564c425..226fb43 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/LayoutPreferenceFragment.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/LayoutPreferenceFragment.java
@@ -17,16 +17,76 @@
package org.cyanogenmod.wallpapers.photophase.preferences;
import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.res.Resources;
import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.Preference;
import android.preference.PreferenceFragment;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.util.Log;
import org.cyanogenmod.wallpapers.photophase.R;
+import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider.Preferences;
+import org.cyanogenmod.wallpapers.photophase.preferences.SeekBarProgressPreference.OnDisplayProgress;
/**
* A fragment class with the layout disposition
*/
public class LayoutPreferenceFragment extends PreferenceFragment {
+ private static final String TAG = "LayoutPreferenceFragment";
+
+ private static final boolean DEBUG = false;
+
+ private CheckBoxPreference mRandomDispositions;
+ SeekBarProgressPreference mRandomDispositionsInterval;
+ Preference mPortraitDisposition;
+ Preference mLandscapeDisposition;
+
+ boolean mRedrawFlag;
+ boolean mDispositionIntervalFlag;
+
+ private final OnPreferenceChangeListener mOnChangeListener = new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(final Preference preference, Object newValue) {
+ String key = preference.getKey();
+ if (DEBUG) Log.d(TAG, "Preference changed: " + key + "=" + newValue);
+ if (key.compareTo("ui_disposition_random") == 0) {
+ boolean randomDispositions = ((Boolean)newValue).booleanValue();
+ mPortraitDisposition.setEnabled(!randomDispositions);
+ mLandscapeDisposition.setEnabled(!randomDispositions);
+ mRedrawFlag = true;
+ } else if (key.compareTo("ui_disposition_random_interval") == 0) {
+ mDispositionIntervalFlag = true;
+ }
+ return true;
+ }
+ };
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ // Reload the settings
+ PreferencesProvider.reload(getActivity());
+
+ // Notify that the settings was changed
+ Intent intent = new Intent(PreferencesProvider.ACTION_SETTINGS_CHANGED);
+ if (mRedrawFlag) {
+ intent.putExtra(PreferencesProvider.EXTRA_FLAG_REDRAW, Boolean.TRUE);
+ }
+ if (mDispositionIntervalFlag) {
+ int interval = Preferences.Layout.getRandomDispositionsInterval();
+ intent.putExtra(PreferencesProvider.EXTRA_FLAG_DISPOSITION_INTERVAL_CHANGED, interval);
+ }
+ getActivity().sendBroadcast(intent);
+ }
+
/**
* {@inheritDoc}
*/
@@ -34,11 +94,66 @@ public class LayoutPreferenceFragment extends PreferenceFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ final String formatSeconds = getString(R.string.format_seconds);
+ final String formatMinutes = getString(R.string.format_minutes);
+ final String formatHours = getString(R.string.format_hours);
+ final String formatDays = getString(R.string.format_days);
+
// Change the preference manager
getPreferenceManager().setSharedPreferencesName(PreferencesProvider.PREFERENCES_FILE);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_PRIVATE);
+ final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
+ final Resources res = getActivity().getResources();
+
// Add the preferences
addPreferencesFromResource(R.xml.preferences_layout);
+
+ // -- Random dispositions
+ mRandomDispositions = (CheckBoxPreference)findPreference("ui_disposition_random");
+ mRandomDispositions.setOnPreferenceChangeListener(mOnChangeListener);
+
+ // -- Interval
+ final int[] randomDispositionsIntervals =
+ res.getIntArray(R.array.random_dispositions_intervals_values);
+ mRandomDispositionsInterval =
+ (SeekBarProgressPreference)findPreference("ui_disposition_random_interval");
+ mRandomDispositionsInterval.setMax(randomDispositionsIntervals.length - 1);
+ int transitionInterval = prefs.getInt("ui_disposition_random_interval",
+ Preferences.Layout.DEFAULT_RANDOM_DISPOSITIONS_INTERVAL_INDEX);
+ if (transitionInterval > (randomDispositionsIntervals.length - 1)) {
+ mRandomDispositionsInterval.setProgress(
+ Preferences.Layout.DEFAULT_RANDOM_DISPOSITIONS_INTERVAL_INDEX);
+ }
+ mRandomDispositionsInterval.setOnDisplayProgress(new OnDisplayProgress() {
+ @Override
+ public String onDisplayProgress(int progress) {
+ if (randomDispositionsIntervals[progress] < 60000) {
+ // Seconds
+ mRandomDispositionsInterval.setFormat(formatSeconds);
+ return String.valueOf(randomDispositionsIntervals[progress] / 1000);
+ } else if (randomDispositionsIntervals[progress] < 3600000) {
+ // Minutes
+ mRandomDispositionsInterval.setFormat(formatMinutes);
+ return String.valueOf(randomDispositionsIntervals[progress] / 1000 / 60);
+ } else if (randomDispositionsIntervals[progress] < 86400000) {
+ // Hours
+ mRandomDispositionsInterval.setFormat(formatHours);
+ return String.valueOf(randomDispositionsIntervals[progress] / 1000 / 60 / 60);
+ }
+ // Days
+ mRandomDispositionsInterval.setFormat(formatDays);
+ return String.valueOf(randomDispositionsIntervals[progress] / 1000 / 60 / 60 / 24);
+ }
+ });
+ mRandomDispositionsInterval.setOnPreferenceChangeListener(mOnChangeListener);
+
+ // -- Portrait
+ mPortraitDisposition = findPreference("ui_disposition_portrait");
+ mPortraitDisposition.setEnabled(!Preferences.Layout.isRandomDispositions());
+
+ // -- Landscape
+ mLandscapeDisposition = findPreference("ui_disposition_landscape");
+ mLandscapeDisposition.setEnabled(!Preferences.Layout.isRandomDispositions());
}
}
diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
index 0edc8b7..d1b2056 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java
@@ -45,10 +45,12 @@ public final class PreferencesProvider {
* @see #EXTRA_FLAG_REDRAW
* {@hide}
*/
- public static final String ACTION_SETTINGS_CHANGED = "org.cyanogenmod.wallpapers.photophase.actions.SETTINGS_CHANGED";
+ public static final String ACTION_SETTINGS_CHANGED =
+ "org.cyanogenmod.wallpapers.photophase.actions.SETTINGS_CHANGED";
/**
- * An extra setting that indicates that the changed setting request a whole recreation of the wallpaper world
+ * An extra setting that indicates that the changed setting request a whole recreation
+ * of the wallpaper world
* {@hide}
*/
public static final String EXTRA_FLAG_RECREATE_WORLD = "flag_recreate_world";
@@ -84,7 +86,16 @@ public final class PreferencesProvider {
* @see #EXTRA_FLAG_MEDIA_RELOAD
* {@hide}
*/
- public static final String EXTRA_ACTION_MEDIA_USER_RELOAD_REQUEST = "action_media_user_reload_req";
+ public static final String EXTRA_ACTION_MEDIA_USER_RELOAD_REQUEST =
+ "action_media_user_reload_req";
+
+ /**
+ * An extra setting that indicates that the changed setting changed the disposition
+ * interval time. Contains the new interval time
+ * {@hide}
+ */
+ public static final String EXTRA_FLAG_DISPOSITION_INTERVAL_CHANGED =
+ "flag_disposition_interval_changed";
/**
* The shared preferences file
@@ -97,6 +108,10 @@ public final class PreferencesProvider {
* @hide
*/
static int[] TRANSITIONS_INTERVALS;
+ /**
+ * @hide
+ */
+ static int[] RANDOM_DISPOSITIONS_INTERVALS;
/**
* Method that loads the all the preferences of the application
@@ -110,6 +125,8 @@ public final class PreferencesProvider {
final Resources res = context.getResources();
TRANSITIONS_INTERVALS = res.getIntArray(R.array.transitions_intervals_values);
+ RANDOM_DISPOSITIONS_INTERVALS = res.getIntArray(
+ R.array.random_dispositions_intervals_values);
}
/**
@@ -306,7 +323,8 @@ public final class PreferencesProvider {
* @return int The interval in seconds between updates. 0 means that updates are disabled
*/
public static int getRefreshFrecuency() {
- return Integer.valueOf(getString("ui_media_refresh_interval", String.valueOf(MEDIA_RELOAD_DISABLED)));
+ return Integer.valueOf(getString("ui_media_refresh_interval",
+ String.valueOf(MEDIA_RELOAD_DISABLED)));
}
/**
@@ -334,7 +352,8 @@ public final class PreferencesProvider {
* @param context The current context
* @param selection The new list of albums and pictures to be displayed
*/
- public static synchronized void setSelectedMedia(Context context, Set<String> selection) {
+ public static synchronized void setSelectedMedia(
+ Context context, Set<String> selection) {
SharedPreferences preferences =
context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
Editor editor = preferences.edit();
@@ -351,7 +370,8 @@ public final class PreferencesProvider {
*/
public static Set<String> getLastDiscorevedAlbums() {
// FIXME Typo. Remove when version 1005 is obsolete and unused
- Set<String> oldKey = getStringSet("media_last_disvored_albums", new HashSet<String>());
+ Set<String> oldKey = getStringSet("media_last_disvored_albums",
+ new HashSet<String>());
if (oldKey.size() > 0) {
return oldKey;
}
@@ -365,7 +385,8 @@ public final class PreferencesProvider {
* @param context The current context
* @param albums The albums seen by the last media discovery scan
*/
- public static synchronized void setLastDiscorevedAlbums(Context context, Set<String> albums) {
+ public static synchronized void setLastDiscorevedAlbums(
+ Context context, Set<String> albums) {
SharedPreferences preferences =
context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
Editor editor = preferences.edit();
@@ -384,11 +405,26 @@ public final class PreferencesProvider {
private static final int DEFAULT_COLS = 4;
private static final int DEFAULT_ROWS = 7;
- public static final String DEFAULT_PORTRAIT_DISPOSITION = "0x0:2x1|0x2:1x3|0x4:3x6|2x2:3x3|3x0:3x0|3x1:3x1";
- public static final String DEFAULT_LANDSCAPE_DISPOSITION = "0x0:2x3|3x0:5x1|3x2:4x3|5x2:6x3|6x0:6x0|6x1:6x1";
+ private static final boolean DEFAULT_RANDOM_DISPOSITION = false;
+
+ /**
+ * The default portrait disposition
+ */
+ public static final String DEFAULT_PORTRAIT_DISPOSITION =
+ "0x0:2x1|0x2:1x3|0x4:3x6|2x2:3x3|3x0:3x0|3x1:3x1";
+ /**
+ * The default landscape disposition
+ */
+ public static final String DEFAULT_LANDSCAPE_DISPOSITION =
+ "0x0:2x3|3x0:5x1|3x2:4x3|5x2:6x3|6x0:6x0|6x1:6x1";
+
+ /**
+ * The default transition interval
+ */
+ public static final int DEFAULT_RANDOM_DISPOSITIONS_INTERVAL_INDEX = 0;
/**
- * Method that returns the rows of the wallpaper.
+ * Returns the number of rows of the wallpaper.
*
* @return int The rows of the wallpaper
*/
@@ -397,7 +433,7 @@ public final class PreferencesProvider {
}
/**
- * Method that returns the columns of the wallpaper.
+ * Returns the number columns of the wallpaper.
*
* @return int The columns of the wallpaper
*/
@@ -406,9 +442,29 @@ public final class PreferencesProvider {
}
/**
+ * Returns if the device should generate random dispositions
+ *
+ * @return boolean If the system should generate random dispositions
+ */
+ public static boolean isRandomDispositions() {
+ return getBoolean("ui_disposition_random", DEFAULT_RANDOM_DISPOSITION);
+ }
+
+ /**
+ * Method that returns how often the random dispositions are triggered.
+ *
+ * @return int The milliseconds in which the next transition will be triggered
+ */
+ public static int getRandomDispositionsInterval() {
+ int interval = getInt("ui_disposition_random_interval",
+ DEFAULT_RANDOM_DISPOSITIONS_INTERVAL_INDEX);
+ return RANDOM_DISPOSITIONS_INTERVALS[interval];
+ }
+
+ /**
* Returns the disposition of the photo frames in the wallpaper on portrait screen. The
- * setting is stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means (position x=0, y=0,
- * 1 cells width, 2 cells height, ...).
+ * setting is stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means
+ * (position x=0, y=0, 1 cells width, 2 cells height, ...).
*
* @return List<Disposition> The photo frames dispositions
*/
@@ -423,7 +479,8 @@ public final class PreferencesProvider {
* @param context The current context
* @param dispositions The photo frames dispositions
*/
- public static void setPortraitDisposition(Context context, List<Disposition> dispositions) {
+ public static void setPortraitDisposition(Context context,
+ List<Disposition> dispositions) {
SharedPreferences preferences =
context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
Editor editor = preferences.edit();
@@ -434,15 +491,15 @@ public final class PreferencesProvider {
}
/**
- * Returns the disposition of the photo frames in the wallpaper on landscape screen. The
- * setting is stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means (position x=0, y=0,
- * 1 cells width, 2 cells height, ...).
+ * Returns the disposition of the photo frames in the wallpaper on landscape screen.
+ * The setting is stored as <code>0x0:1x2|2x2:3x4|...</code>, which it means
+ * (position x=0, y=0, 1 cells width, 2 cells height, ...).
*
* @return List<Disposition> The photo frames dispositions
*/
public static List<Disposition> getLandscapeDisposition() {
- return DispositionUtil.toDispositions(
- getString("ui_layout_landscape_disposition", DEFAULT_LANDSCAPE_DISPOSITION));
+ return DispositionUtil.toDispositions(getString("ui_layout_landscape_disposition",
+ DEFAULT_LANDSCAPE_DISPOSITION));
}
/**
@@ -451,7 +508,8 @@ public final class PreferencesProvider {
* @param context The current context
* @param dispositions The photo frames dispositions
*/
- public static void setLandscapeDisposition(Context context, List<Disposition> dispositions) {
+ public static void setLandscapeDisposition(Context context,
+ List<Disposition> dispositions) {
SharedPreferences preferences =
context.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
Editor editor = preferences.edit();