aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-10-12 01:57:54 +0200
committerJorge Ruesga <jorge@ruesga.com>2013-10-12 01:57:54 +0200
commitc0e139c277a9858c8d7f6e73a10f62b599d36fee (patch)
tree9fcb15c428cfa79dc66f785da24f291648cdd64e /src
parentf417e531084570685e97f99fad2d2dc28a2f9df5 (diff)
downloadandroid_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>
Diffstat (limited to 'src')
-rw-r--r--src/com/ruesga/android/wallpapers/photophase/PhotoPhaseRenderer.java54
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() {