OSDN Git Service

Avoid building FilmstripItems when data is null
authorAlan Newberger <alann@google.com>
Thu, 29 Jan 2015 19:32:22 +0000 (11:32 -0800)
committerAlan Newberger <alann@google.com>
Thu, 29 Jan 2015 19:32:22 +0000 (11:32 -0800)
Items should not have null data. Code exists to handle null
items generated, and skip them, but if data is null, items
are still added to caches and cause exceptions later.

Bug: 19097423
Change-Id: I171ec40369cdcc5a5567968380a600943d4991e4

src/com/android/camera/data/FilmstripContentQueries.java
src/com/android/camera/data/PhotoDataFactory.java
src/com/android/camera/data/PhotoItemFactory.java
src/com/android/camera/data/VideoItemFactory.java

index ca53bb0..a3c273c 100644 (file)
@@ -69,9 +69,9 @@ public class FilmstripContentQueries {
         List<I> result = new ArrayList<>();
         if (cursor != null) {
             while (cursor.moveToNext()) {
-                I data = factory.get(cursor);
-                if (data != null) {
-                    result.add(data);
+                I item = factory.get(cursor);
+                if (item != null) {
+                    result.add(item);
                 } else {
                     final int dataIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
                     Log.e(TAG, "Error loading data:" + cursor.getString(dataIndex));
index c54f0d2..05b1aef 100644 (file)
@@ -105,7 +105,7 @@ public class PhotoDataFactory {
             Bitmap b = BitmapFactory.decodeFile(filePath);
             if (b == null) {
                 Log.w(TAG, "PhotoData skipped."
-                      + " Decoding " + filePath + "failed.");
+                      + " Decoding " + filePath + " failed.");
                 return null;
             }
             width = b.getWidth();
index 6f7dfbd..a955f84 100644 (file)
@@ -22,10 +22,13 @@ import android.database.Cursor;
 import android.net.Uri;
 
 import com.android.camera.data.FilmstripContentQueries.CursorToFilmstripItemFactory;
+import com.android.camera.debug.Log;
 
 import java.util.List;
 
 public class PhotoItemFactory implements CursorToFilmstripItemFactory<PhotoItem> {
+    private static final Log.Tag TAG = new Log.Tag("PhotoItemFact");
+
     private final Context mContext;
     private final ContentResolver mContentResolver;
     private final PhotoDataFactory mPhotoDataFactory;
@@ -40,7 +43,12 @@ public class PhotoItemFactory implements CursorToFilmstripItemFactory<PhotoItem>
     @Override
     public PhotoItem get(Cursor c) {
         FilmstripItemData data = mPhotoDataFactory.fromCursor(c);
-        return new PhotoItem(mContext, data, this);
+        if (data != null) {
+            return new PhotoItem(mContext, data, this);
+        } else {
+            Log.w(TAG, "skipping item with null data, returning null for item");
+            return null;
+        }
     }
 
     public PhotoItem get(Uri uri) {
index 72e5c60..87df3bc 100644 (file)
@@ -46,7 +46,12 @@ public class VideoItemFactory implements CursorToFilmstripItemFactory<VideoItem>
     @Override
     public VideoItem get(Cursor c) {
         VideoItemData data = mVideoDataFactory.fromCursor(c);
-        return new VideoItem(mContext, data, this);
+        if (data != null) {
+            return new VideoItem(mContext, data, this);
+        } else {
+            Log.w(TAG, "skipping item with null data, returning null for item");
+            return null;
+        }
     }
 
     /** Query for a single video data item */