diff options
16 files changed, 449 insertions, 34 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4090bd2..ec25ca7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -27,6 +27,7 @@ <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <uses-permission android:name="android.permission.VIBRATE"/> + <uses-permission android:name="android.permission.GET_TASKS"/> <application android:icon="@drawable/ic_launcher" diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 1f0c866..ecfbb65 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -34,6 +34,20 @@ <item>604800</item> </string-array> + <string-array name="touch_actions_labels" translatable="false"> + <item>@string/touch_actions_none</item> + <item>@string/touch_actions_transition</item> + <item>@string/touch_actions_open</item> + <item>@string/touch_actions_share</item> + </string-array> + + <string-array name="touch_actions_values" translatable="false"> + <item>0</item> + <item>1</item> + <item>2</item> + <item>3</item> + </string-array> + <string-array name="transitions_labels" translatable="false"> <item>@string/transitions_random</item> <item>@string/transitions_swap</item> diff --git a/res/values/strings.xml b/res/values/strings.xml index 0e4d33d..aff0185 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -43,6 +43,8 @@ <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> + <string name="pref_general_touch_action">Touch action</string> + <string name="pref_general_touch_action_summary">Select the action to apply when touch a frame</string> <string name="pref_general_transitions">Transitions</string> <string name="pref_general_transitions_types">Types</string> @@ -94,6 +96,12 @@ <string name="refresh_intervals_2d">2 days</string> <string name="refresh_intervals_1w">1 week</string> + <!-- Touch actions --> + <string name="touch_actions_none">None</string> + <string name="touch_actions_transition">Do transition</string> + <string name="touch_actions_open">Open</string> + <string name="touch_actions_share">Share</string> + <!-- Transitions --> <string name="transitions_random">Random</string> <string name="transitions_swap">Swap</string> diff --git a/res/xml/preferences_general.xml b/res/xml/preferences_general.xml index 5877d52..b6d60f8 100644 --- a/res/xml/preferences_general.xml +++ b/res/xml/preferences_general.xml @@ -29,6 +29,7 @@ android:persistent="true" android:defaultValue="0" /> + <!-- Background color --> <org.cyanogenmod.wallpapers.photophase.widgets.ColorPickerPreference android:key="ui_background_color" android:title="@string/pref_general_settings_background_color" @@ -36,6 +37,16 @@ android:persistent="true" android:defaultValue="@color/wallpaper_background_color" /> + <!-- Touch action --> + <ListPreference + android:key="ui_touch_action" + android:title="@string/pref_general_touch_action" + android:summary="@string/pref_general_touch_action_summary" + android:persistent="true" + android:entries="@array/touch_actions_labels" + android:entryValues="@array/touch_actions_values" + android:defaultValue="0" /> + </PreferenceCategory> <!-- Transitions --> diff --git a/src/org/cyanogenmod/wallpapers/photophase/GLESUtil.java b/src/org/cyanogenmod/wallpapers/photophase/GLESUtil.java index a24e585..25fe366 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/GLESUtil.java +++ b/src/org/cyanogenmod/wallpapers/photophase/GLESUtil.java @@ -163,6 +163,10 @@ public final class GLESUtil { * The bitmap reference */ public Bitmap bitmap; + /** + * The path to the texture + */ + public File path; } /** @@ -319,7 +323,9 @@ public final class GLESUtil { bitmap = effect.apply(bitmap); if (DEBUG) Log.d(TAG, "image: " + file.getAbsolutePath()); - return loadTexture(bitmap); + GLESTextureInfo ti = loadTexture(bitmap); + ti.path = file; + return ti; } catch (Exception e) { String msg = "Failed to generate a valid texture from file: " + file.getAbsolutePath(); @@ -358,7 +364,8 @@ public final class GLESUtil { } if (DEBUG) Log.d(TAG, "resourceId: " + resourceId); - return loadTexture(bitmap); + GLESTextureInfo ti = loadTexture(bitmap); + return ti; } catch (Exception e) { String msg = "Failed to generate a valid texture from resource: " + resourceId; @@ -428,6 +435,7 @@ public final class GLESUtil { GLESTextureInfo ti = new GLESTextureInfo(); ti.handle = textureNames[0]; ti.bitmap = bitmap; + ti.path = null; return ti; } diff --git a/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java b/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java index 5c94519..ba51749 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java +++ b/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java @@ -156,6 +156,15 @@ public abstract class GLESWallpaperService extends EGLWallpaperService { } /** + * Returns the renderer used by the engine + * + * @return Renderer The renderer + */ + protected Renderer getRenderer() { + return mRenderer; + } + + /** * {@inheritDoc} */ @Override diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoFrame.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoFrame.java index 26ba641..3cac77f 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoFrame.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoFrame.java @@ -17,7 +17,6 @@ package org.cyanogenmod.wallpapers.photophase; import android.content.Context; -import android.graphics.Bitmap; import android.opengl.GLES20; import org.cyanogenmod.wallpapers.photophase.GLESUtil.GLColor; @@ -126,7 +125,6 @@ public class PhotoFrame implements TextureRequestor { } // Full frame picture - // TODO Apply some type of ratio correction to the texture coordinates setTextureHandle(ti, DEFAULT_TEXTURE_COORDS); mLoaded = true; } @@ -217,15 +215,12 @@ public class PhotoFrame implements TextureRequestor { } /** - * Method that returns the bitmap handle + * Method that returns the texture info * - * @return int The bitmap handle + * @return GLESTextureInfo The texture info */ - public Bitmap getTextureBitmap() { - if (mTextureInfo != null) { - return mTextureInfo.bitmap; - } - return null; + public GLESTextureInfo getTextureInfo() { + return mTextureInfo; } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java index 6ea835c..53d2ce1 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseActivity.java @@ -24,6 +24,9 @@ import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnTouchListener; import android.view.Window; import android.view.WindowManager; @@ -33,7 +36,7 @@ import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider; /** * A testing activity to simulate the PhotoPhase Live Wallpaper inside an GLES activity. */ -public class PhotoPhaseActivity extends Activity { +public class PhotoPhaseActivity extends Activity implements OnTouchListener { private static final String TAG = "PhotoPhaseActivity"; @@ -68,6 +71,7 @@ public class PhotoPhaseActivity extends Activity { mGLSurfaceView.setRenderer(mRenderer); mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); mGLSurfaceView.setPreserveEGLContextOnPause(preserveEglCtx); + mGLSurfaceView.setOnTouchListener(this); setContentView(mGLSurfaceView); mRenderer.onCreate(); @@ -133,4 +137,23 @@ public class PhotoPhaseActivity extends Activity { return super.onOptionsItemSelected(item); } } + + /** + * {@inheritDoc} + */ + @Override + public boolean onTouch(View v, MotionEvent event) { + int action = event.getAction(); + float x = event.getX(); + float y = event.getY(); + switch (action) { + case MotionEvent.ACTION_UP: + mRenderer.onTouch(x, y); + return true; + + default: + break; + } + return false; + } } diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java index f584f84..c1b40e7 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java @@ -18,12 +18,16 @@ package org.cyanogenmod.wallpapers.photophase; import android.app.AlarmManager; import android.app.PendingIntent; +import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; +import android.content.res.Resources.NotFoundException; +import android.graphics.PointF; import android.graphics.Rect; +import android.net.Uri; import android.opengl.GLES20; import android.opengl.GLException; import android.opengl.GLSurfaceView; @@ -33,6 +37,7 @@ import android.util.Log; import org.cyanogenmod.wallpapers.photophase.GLESUtil.GLColor; import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider; +import org.cyanogenmod.wallpapers.photophase.preferences.TouchAction; import org.cyanogenmod.wallpapers.photophase.shapes.ColorShape; import org.cyanogenmod.wallpapers.photophase.transitions.Transition; @@ -124,7 +129,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { @Override public void run() { // Select a new transition - mWorld.selectTransition(); + mWorld.selectRandomTransition(); mLastRunningTransition = System.currentTimeMillis(); // Now force continuously render while transition is applied @@ -237,6 +242,84 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { } } + /** + * Method called when the renderer should process a touch event over the screen + * + * @param x The x coordinate + * @param y The y coordinate + */ + public void onTouch(float x , float y) { + if (mWorld != null) { + // Do user action + TouchAction touchAction = PreferencesProvider.Preferences.General.getTouchAction(); + if (touchAction.compareTo(TouchAction.NONE) == 0) { + //Ignore + } else { + // Retrieve the photo frame for its coordinates + final PhotoFrame frame = mWorld.getFrameFromCoordinates(new PointF(x, y)); + if (frame == null) { + Log.w(TAG, "No frame from coordenates"); + return; + } + + // Apply the action + if (touchAction.compareTo(TouchAction.TRANSITION) == 0) { + try { + // Check if the frame has pending transitions + if (!mWorld.hasRunningTransition(frame)) { + Log.w(TAG, "The frame has pending transitions " + frame.getTextureInfo().path); + return; + } + + // Select the frame with a transition + // Run in GLES's thread + mDispatcher.dispatch(new Runnable() { + @Override + public void run() { + // Select a new transition + mWorld.selectTransition(frame); + mLastRunningTransition = System.currentTimeMillis(); + + // Now force continuously render while transition is applied + mDispatcher.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); + } + }); + + } catch (NotFoundException ex) { + Log.e(TAG, "The frame not exists " + frame.getTextureInfo().path, ex); + } + + } else if (touchAction.compareTo(TouchAction.OPEN) == 0) { + // Open the image + try { + Uri uri = Uri.fromFile(frame.getTextureInfo().path); + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + intent.setDataAndType(uri, "image/*"); + mContext.startActivity(intent); + } catch (ActivityNotFoundException ex) { + Log.e(TAG, "Open activity not found for " + frame.getTextureInfo().path, ex); + } + + } else if (touchAction.compareTo(TouchAction.SHARE) == 0) { + // Send the image + try { + Uri uri = Uri.fromFile(frame.getTextureInfo().path); + Intent intent = new Intent(Intent.ACTION_SEND); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + intent.setType("image/*"); + intent.putExtra(Intent.EXTRA_STREAM, uri); + mContext.startActivity(intent); + } catch (ActivityNotFoundException ex) { + Log.e(TAG, "Send activity not found for " + frame.getTextureInfo().path, ex); + } + } + } + } + } + void scheduleOrCancelMediaScan() { int interval = PreferencesProvider.Preferences.Media.getRefreshFrecuency(); if (interval != PreferencesProvider.Preferences.Media.MEDIA_RELOAD_DISABLED) { diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java index 01f81c7..ea65f9d 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java @@ -16,10 +16,15 @@ package org.cyanogenmod.wallpapers.photophase; +import android.app.ActivityManager; +import android.app.WallpaperManager; import android.content.Context; import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView.Renderer; +import android.os.Bundle; +import android.os.Handler; import android.util.Log; +import android.view.ViewConfiguration; import org.cyanogenmod.wallpapers.photophase.GLESWallpaperService.GLESEngineListener; import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider; @@ -43,6 +48,10 @@ public class PhotoPhaseWallpaper private boolean mPreserveEGLContext; + // List of the current top activities. Tap should be ignored when this acitivities are + // in the foreground + static final String[] TOP_ACTIVITIES = {"com.android.internal.app.ChooserActivity"}; + /** * {@inheritDoc} */ @@ -85,6 +94,10 @@ public class PhotoPhaseWallpaper * A wallpaper engine implementation using GLES. */ class PhotoPhaseWallpaperEngine extends GLES20WallpaperService.GLES20Engine { + + private final Handler mHandler; + /*package*/ final ActivityManager mActivityManager; + /** * Constructor of <code>PhotoPhaseWallpaperEngine<code> * @@ -92,7 +105,9 @@ public class PhotoPhaseWallpaper */ PhotoPhaseWallpaperEngine(PhotoPhaseWallpaper wallpaper) { super(); - setOffsetNotificationsEnabled(true); + mHandler = new Handler(); + mActivityManager = (ActivityManager)getApplication().getSystemService(ACTIVITY_SERVICE); + setOffsetNotificationsEnabled(false); setTouchEventsEnabled(false); setGLESEngineListener(wallpaper); setWallpaperGLSurfaceView(new PhotoPhaseWallpaperGLSurfaceView(wallpaper)); @@ -112,6 +127,38 @@ public class PhotoPhaseWallpaper super(context); } } + + /** + * {@inheritDoc} + */ + @Override + public Bundle onCommand(final String action, final int x, final int y, final int z, + final Bundle extras, final boolean resultRequested) { + if (action.compareTo(WallpaperManager.COMMAND_TAP) == 0) { + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + // Only if the wallpaper is visible after a long press and + // not in preview mode + if(isVisible() && !isPreview()) { + List<ActivityManager.RunningTaskInfo> taskInfo = + mActivityManager.getRunningTasks(1); + String topActivity = taskInfo.get(0).topActivity.getClassName(); + for (String activity : TOP_ACTIVITIES) { + if (activity.compareTo(topActivity) == 0) { + // Ignore tap event + return; + } + } + + // Pass the x and y position to the renderer + ((PhotoPhaseRenderer)getRenderer()).onTouch(x, y); + } + } + }, ViewConfiguration.getLongPressTimeout() + 100L); + } + return super.onCommand(action, x, y, z, extras, resultRequested); + } } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java index 0d98a49..427c96a 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java @@ -18,14 +18,18 @@ package org.cyanogenmod.wallpapers.photophase; import android.content.Context; import android.content.res.Configuration; -import android.graphics.Bitmap; +import android.content.res.Resources.NotFoundException; +import android.graphics.PointF; +import android.graphics.RectF; import android.util.Log; +import org.cyanogenmod.wallpapers.photophase.GLESUtil.GLESTextureInfo; import org.cyanogenmod.wallpapers.photophase.model.Disposition; import org.cyanogenmod.wallpapers.photophase.preferences.PreferencesProvider.Preferences; 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.Utils; import java.util.ArrayList; import java.util.List; @@ -53,6 +57,9 @@ public class PhotoPhaseWallpaperWorld { private List<Integer> mUsedTransitionsQueue; private int mCurrent; + private int mWidth; + private int mHeight; + private boolean mRecycled; /** @@ -104,22 +111,58 @@ public class PhotoPhaseWallpaperWorld { } /** - * Method that selects a transition and assign it to a photo frame. + * Method that ensures the transitions queue */ - public void selectTransition() { - // Ensure queue + private void ensureTransitionsQueue() { if (mTransitionsQueue.isEmpty()) { mTransitionsQueue.addAll(mUsedTransitionsQueue); mUsedTransitionsQueue.clear(); } + } + + /** + * Method that selects a transition and assign it to a random photo frame. + */ + public void selectRandomTransition() { + // Ensure queue + ensureTransitionsQueue(); // Get a random frame to which apply the transition int r = 0 + (int)(Math.random() * (((mTransitionsQueue.size()-1) - 0) + 1)); int pos = mTransitionsQueue.remove(r).intValue(); mUsedTransitionsQueue.add(Integer.valueOf(pos)); + PhotoFrame frame = mPhotoFrames.get(pos); + + // Select the transition + selectTransition(frame, pos); + } + + /** + * Method that selects a transition and assign it to the photo frame. + * + * @param frame The photo frame to select + */ + public void selectTransition(PhotoFrame frame) { + // Ensure queue + ensureTransitionsQueue(); + + // Get a random frame to which apply the transition + int pos = mPhotoFrames.indexOf(frame); + mTransitionsQueue.remove(Integer.valueOf(pos)); + mUsedTransitionsQueue.add(Integer.valueOf(pos)); + // Select the transition + selectTransition(frame, pos); + } + + /** + * Method that selects a transition and assign it to a photo frame. + * + * @param frame The frame to select + * @param pos The position + */ + private void selectTransition(PhotoFrame frame, int pos) { // Create or use a transition - PhotoFrame frame = mPhotoFrames.get(pos); Transition transition = null; boolean isSelectable = false; while (transition == null || !isSelectable) { @@ -195,9 +238,9 @@ public class PhotoPhaseWallpaperWorld { int cc = mPhotoFrames.size()-1; for (int i = cc; i >= 0; i--) { PhotoFrame frame = mPhotoFrames.get(i); - Bitmap bitmap = frame.getTextureBitmap(); - if (bitmap != null) { - mTextureManager.releaseBitmap(frame.getTextureBitmap()); + GLESTextureInfo info = frame.getTextureInfo(); + if (info != null && info.bitmap != null) { + mTextureManager.releaseBitmap(info); } frame.recycle(); mPhotoFrames.remove(i); @@ -229,6 +272,22 @@ public class PhotoPhaseWallpaperWorld { } /** + * Method that returns if there are any transition running in the world. + * + * @return boolean If there are any transition running in the world + * @throws NotFoundException If the frame was not found + */ + public boolean hasRunningTransition(PhotoFrame frame) throws NotFoundException { + int pos = mPhotoFrames.indexOf(frame); + if (pos == -1) { + throw new NotFoundException(); + } + synchronized (mUsedTransitionsQueue) { + return mUsedTransitionsQueue.indexOf(Integer.valueOf(pos)) != -1; + } + } + + /** * Method that creates and fills the world with {@link PhotoFrame} objects. * * @param w The new width dimension @@ -243,6 +302,10 @@ public class PhotoPhaseWallpaperWorld { mRecycled = false; } + // Save the new dimensions of the wallpaper + mWidth = w; + mHeight = h; + // Calculate the new world int orientation = mContext.getResources().getConfiguration().orientation; boolean portrait = orientation == Configuration.ORIENTATION_PORTRAIT; @@ -262,7 +325,7 @@ public class PhotoPhaseWallpaperWorld { int i = 0; for (Disposition disposition : dispositions) { // Create the photo frame - float[] frameVertices = getVerticesFromDisposition(disposition, portrait, cellw, cellh); + float[] frameVertices = getVerticesFromDisposition(disposition, cellw, cellh); float[] pictureVertices = getFramePadding(frameVertices, portrait ? w : h, portrait ? h : w); PhotoFrame frame = new PhotoFrame( @@ -284,6 +347,27 @@ public class PhotoPhaseWallpaperWorld { } /** + * Method that returns a photo frame from a coordinates in screen + * + * @param coordinates The coordinates + * @return The photo frame reference or null if none found + */ + public PhotoFrame getFrameFromCoordinates(PointF coordinates) { + // Translate pixels coordinates to GLES coordinates + float tx = ((coordinates.x * 2) / mWidth) - 1; + float ty = (((coordinates.y * 2) / mHeight) - 1) * -1; + + // Locate the frame + for (PhotoFrame frame : mPhotoFrames) { + RectF vertex = Utils.rectFromVertex(frame.getFrameVertex()); + if (vertex.left < tx && vertex.right > tx && vertex.top > ty && vertex.bottom < ty) { + return frame; + } + } + return null; + } + + /** * Method that draws all the photo frames. * * @param matrix The model-view-projection matrix @@ -302,13 +386,12 @@ public class PhotoPhaseWallpaperWorld { * Method that returns a coordinates per vertex array from a disposition * * @param disposition The source disposition - * @param portrait If the device is in portrait mode * @param cellw The cell width based on the surface * @param cellh The cell height based on the surface * @return float[] The coordinates per vertex array */ private static float[] getVerticesFromDisposition( - Disposition disposition, boolean portrait, float cellw, float cellh) { + Disposition disposition, float cellw, float cellh) { return new float[] { // top left diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java index de8261b..ac05b77 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java +++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java @@ -17,7 +17,6 @@ package org.cyanogenmod.wallpapers.photophase; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.Rect; import android.opengl.GLES20; import android.util.Log; @@ -42,7 +41,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { private static final int QUEUE_SIZE = 3; - static final List<Bitmap> sRecycledBitmaps = new ArrayList<Bitmap>(); + static final List<GLESTextureInfo> sRecycledBitmaps = new ArrayList<GLESTextureInfo>(); final Context mContext; final Object mSync; @@ -74,7 +73,10 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { // If we have bitmap to reused then pick up from the recycled list if (sRecycledBitmaps.size() > 0) { // Bind to the GLES context - ti = GLESUtil.loadTexture(sRecycledBitmaps.remove(0)); + GLESTextureInfo oldTextureInfo = sRecycledBitmaps.remove(0); + ti = GLESUtil.loadTexture(oldTextureInfo.bitmap); + ti.path = oldTextureInfo.path; + oldTextureInfo.bitmap = null; } else { // Load and bind to the GLES context ti = GLESUtil.loadTexture(mImage, mDimensions, Effects.getNextEffect(), false); @@ -172,12 +174,12 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { /** * Method that returns a bitmap to be reused * - * @param bitmap The bitmap to release + * @param ti The bitmap to release */ @SuppressWarnings("static-method") - public void releaseBitmap(Bitmap bitmap) { - if (bitmap != null) { - sRecycledBitmaps.add(0, bitmap); + public void releaseBitmap(GLESTextureInfo ti) { + if (ti != null && ti.bitmap != null) { + sRecycledBitmaps.add(0, ti); } } @@ -225,8 +227,8 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { // Ignore } // Recycle the bitmaps - for (Bitmap bitmap : sRecycledBitmaps) { - bitmap.recycle(); + for (GLESTextureInfo ti : sRecycledBitmaps) { + ti.bitmap.recycle(); } sRecycledBitmaps.clear(); diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java index 069d648..1d50da3 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/GeneralPreferenceFragment.java @@ -44,6 +44,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment { private SeekBarProgressPreference mWallpaperDim; private ColorPickerPreference mBackgroundColor; + private ListPreference mTouchActions; private ListPreference mTransitionsTypes; private SeekBarProgressPreference mTransitionsInterval; private ListPreference mEffectsTypes; @@ -120,6 +121,9 @@ public class GeneralPreferenceFragment extends PreferenceFragment { mBackgroundColor = (ColorPickerPreference)findPreference("ui_background_color"); mBackgroundColor.setOnPreferenceChangeListener(mOnChangeListener); + mTouchActions = (ListPreference)findPreference("ui_touch_action"); + mTouchActions.setOnPreferenceChangeListener(mOnChangeListener); + mTransitionsTypes = (ListPreference)findPreference("ui_transition_types"); mTransitionsTypes.setOnPreferenceChangeListener(mOnChangeListener); diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java index 811f1c8..0b3e439 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/PreferencesProvider.java @@ -188,6 +188,15 @@ public final class PreferencesProvider { } /** + * Return the current user preference of the action to do when a frame is tap. + * + * @return TouchAction The action (default NONE) + */ + public static TouchAction getTouchAction() { + return TouchAction.fromValue(Integer.valueOf(getString("ui_touch_action", "0"))) ; + } + + /** * Transitions preferences */ public static class Transitions { diff --git a/src/org/cyanogenmod/wallpapers/photophase/preferences/TouchAction.java b/src/org/cyanogenmod/wallpapers/photophase/preferences/TouchAction.java new file mode 100644 index 0000000..c2a08d9 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/preferences/TouchAction.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.wallpapers.photophase.preferences; + +/** + * An enumeration with all the touch actions supported + */ +public enum TouchAction { + NONE(0), + TRANSITION(1), + OPEN(2), + SHARE(3); + + private final int mValue; + + /** + * Constructor of <code>TouchAction</code> + * + * @param id The unique identifier + */ + private TouchAction(int value) { + mValue = value; + } + + /** + * Method that returns the value + * + * @return int The value + */ + public int getValue() { + return mValue; + } + + /** + * Method that gets the reference of a TouchAction from its value + * + * @param value The value + * @return TouchAction The reference + */ + public static final TouchAction fromValue(int value) { + if (value == TRANSITION.mValue) return TRANSITION; + if (value == OPEN.mValue) return OPEN; + if (value == SHARE.mValue) return SHARE; + return NONE; + } +} diff --git a/src/org/cyanogenmod/wallpapers/photophase/utils/Utils.java b/src/org/cyanogenmod/wallpapers/photophase/utils/Utils.java new file mode 100644 index 0000000..03aa8c6 --- /dev/null +++ b/src/org/cyanogenmod/wallpapers/photophase/utils/Utils.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.wallpapers.photophase.utils; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.RectF; +import android.util.DisplayMetrics; + +/** + * A helper class with utilities + */ +public class Utils { + + /** + * This method converts dp unit to equivalent device specific value in pixels. + * + * @param ctx The current context + * @param dp A value in dp (Device independent pixels) unit + * @return float A float value to represent Pixels equivalent to dp according to device + */ + public static float convertDpToPixel(Context ctx, float dp) { + Resources resources = ctx.getResources(); + DisplayMetrics metrics = resources.getDisplayMetrics(); + return dp * (metrics.densityDpi / 160f); + } + + + + /** + * Method that converts a rect from a vertex data + * + * @param vertex The vertex array + * @return RectF The rect data + */ + public static RectF rectFromVertex(float[] vertex) { + RectF rect = new RectF(); + rect.left = vertex[0]; + rect.top = vertex[1]; + rect.right = vertex[6]; + rect.bottom = vertex[7]; + return rect; + } +}
\ No newline at end of file |