diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-10-12 01:57:54 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-10-12 01:57:54 +0200 |
commit | c0e139c277a9858c8d7f6e73a10f62b599d36fee (patch) | |
tree | 9fcb15c428cfa79dc66f785da24f291648cdd64e | |
parent | f417e531084570685e97f99fad2d2dc28a2f9df5 (diff) | |
download | android_packages_wallpapers_PhotoPhase-c0e139c277a9858c8d7f6e73a10f62b599d36fee.tar.gz android_packages_wallpapers_PhotoPhase-c0e139c277a9858c8d7f6e73a10f62b599d36fee.tar.bz2 android_packages_wallpapers_PhotoPhase-c0e139c277a9858c8d7f6e73a10f62b599d36fee.zip |
Fix NPE when photo frame has not a valid texture info
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r-- | src/com/ruesga/android/wallpapers/photophase/PhotoPhaseRenderer.java | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/com/ruesga/android/wallpapers/photophase/PhotoPhaseRenderer.java b/src/com/ruesga/android/wallpapers/photophase/PhotoPhaseRenderer.java index c56299d..1ca7656 100644 --- a/src/com/ruesga/android/wallpapers/photophase/PhotoPhaseRenderer.java +++ b/src/com/ruesga/android/wallpapers/photophase/PhotoPhaseRenderer.java @@ -38,6 +38,7 @@ import android.util.Log; import com.ruesga.android.wallpapers.photophase.utils.GLESUtil; import com.ruesga.android.wallpapers.photophase.utils.GLESUtil.GLColor; +import com.ruesga.android.wallpapers.photophase.utils.GLESUtil.GLESTextureInfo; import com.ruesga.android.wallpapers.photophase.utils.Utils; import com.ruesga.android.wallpapers.photophase.preferences.PreferencesProvider; import com.ruesga.android.wallpapers.photophase.preferences.PreferencesProvider.Preferences; @@ -320,12 +321,14 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { } 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); + Uri uri = getUriFromFrame(frame); + if (uri != null) { + 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); } @@ -333,13 +336,15 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { } 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); + Uri uri = getUriFromFrame(frame); + if (uri != null) { + 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); } @@ -349,6 +354,29 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { } /** + * Method that returns an Uri reference from a photo frame + * + * @param frame The photo frame + * @return Uri The image uri + */ + private static Uri getUriFromFrame(final PhotoFrame frame) { + // Sanity checks + GLESTextureInfo info = frame.getTextureInfo(); + if (info == null) { + Log.e(TAG, "The frame has not a valid reference right now." + + "Touch action is not available."); + return null; + } + if (info.path == null || !info.path.isFile()) { + Log.e(TAG, "The image do not exists. Touch action is not available."); + return null; + } + + // Return the uri from the path + return Uri.fromFile(frame.getTextureInfo().path); + } + + /** * Method that deselect the current transition */ /*package*/ synchronized void deselectCurrentTransition() { |