Rename MediaSets and MediaItems and add copyright headers.
Change-Id: I3dd3f78f053ec837db7aae162ef17d98d61aa275
diff --git a/new3d/src/com/android/gallery3d/data/BucketMediaSet.java b/new3d/src/com/android/gallery3d/data/BucketMediaSet.java
deleted file mode 100644
index 1e8f7dd..0000000
--- a/new3d/src/com/android/gallery3d/data/BucketMediaSet.java
+++ /dev/null
@@ -1,120 +0,0 @@
- // Copyright 2010 Google Inc. All Rights Reserved.
-
-package com.android.gallery3d.data;
-
-import android.content.ContentResolver;
-import android.database.Cursor;
-
-import com.android.gallery3d.app.GalleryContext;
-import com.android.gallery3d.util.Utils;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-
-public class BucketMediaSet extends DatabaseMediaSet {
- private static final int MAX_NUM_COVER_ITEMS = 4;
-
- public static final Comparator<BucketMediaSet> sNameComparator = new MyComparator();
-
- private final int mBucketId;
- private final String mBucketTitle;
-
- private final ArrayList<DatabaseMediaItem> mMediaItems =
- new ArrayList<DatabaseMediaItem>();
- private ArrayList<DatabaseMediaItem> mLoadBuffer =
- new ArrayList<DatabaseMediaItem>();
-
- public BucketMediaSet(GalleryContext context, int id, String title) {
- super(context);
- mBucketId = id;
- mBucketTitle= title;
- }
-
- public MediaItem[] getCoverMediaItems() {
- int size = Math.min(MAX_NUM_COVER_ITEMS, mMediaItems.size());
- MediaItem items[] = new MediaItem[size];
- for (int i = 0; i < size; ++i) {
- items[i] = mMediaItems.get(i);
- }
- return items;
- }
-
- public MediaItem getMediaItem(int index) {
- return mMediaItems.get(index);
- }
-
- public int getMediaItemCount() {
- return mMediaItems.size();
- }
-
- public MediaSet getSubMediaSet(int index) {
- throw new IndexOutOfBoundsException();
- }
-
- public int getSubMediaSetCount() {
- return 0;
- }
-
- public String getTitle() {
- return mBucketTitle;
- }
-
- public int getTotalMediaItemCount() {
- return mMediaItems.size();
- }
-
- @Override
- protected void onLoadFromDatabase() {
- ArrayList<DatabaseMediaItem> items = new ArrayList<DatabaseMediaItem>();
- mLoadBuffer = items;
-
- ContentResolver resolver = mContext.getContentResolver();
- ImageService imageService = mContext.getImageService();
-
- Cursor cursor = ImageMediaItem.queryImageInBucket(resolver, mBucketId);
- try {
- while (cursor.moveToNext()) {
- items.add(ImageMediaItem.load(imageService, cursor));
- }
- } finally {
- cursor.close();
- }
-
- cursor = VideoMediaItem.queryVideoInBucket(resolver, mBucketId);
- try {
- while (cursor.moveToNext()) {
- items.add(VideoMediaItem.load(imageService, cursor));
- }
- } finally {
- cursor.close();
- }
-
- Collections.sort(items, new Comparator<DatabaseMediaItem>() {
-
- public int compare(DatabaseMediaItem o1, DatabaseMediaItem o2) {
- // sort items in descending order based on their taken time.
- long result = -(o1.mDateTakenInMs - o2.mDateTakenInMs);
- return result == 0
- ? o1.mId - o2.mId
- : result > 0 ? 1 : -1;
- }
- });
- }
-
- @Override
- protected void onUpdateContent() {
- Utils.Assert(mLoadBuffer != null);
- mMediaItems.clear();
- mMediaItems.addAll(mLoadBuffer);
- mLoadBuffer = null;
- }
-
- private static class MyComparator implements Comparator<BucketMediaSet> {
-
- public int compare(BucketMediaSet s1, BucketMediaSet s2) {
- int result = s1.mBucketTitle.compareTo(s2.mBucketTitle);
- return result != 0 ? result : s1.mBucketId - s2.mBucketId;
- }
- }
-}
diff --git a/new3d/src/com/android/gallery3d/data/ComboMediaSet.java b/new3d/src/com/android/gallery3d/data/ComboMediaSet.java
index a1b57f2..1df9b25 100644
--- a/new3d/src/com/android/gallery3d/data/ComboMediaSet.java
+++ b/new3d/src/com/android/gallery3d/data/ComboMediaSet.java
@@ -1,9 +1,23 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
// Merge multiple media sets into one.
-public class ComboMediaSet implements MediaSet {
+public class ComboMediaSet extends MediaSet {
private final MediaSet[] mSets;
diff --git a/new3d/src/com/android/gallery3d/data/DataManager.java b/new3d/src/com/android/gallery3d/data/DataManager.java
index 4d14489..17941d8 100644
--- a/new3d/src/com/android/gallery3d/data/DataManager.java
+++ b/new3d/src/com/android/gallery3d/data/DataManager.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -19,11 +33,11 @@
public MediaSet getRootSet() {
if (mRootSet == null) {
- PicasaUserAlbums picasaRoot = new PicasaUserAlbums(mContext);
- RootMediaSet mediaRoot = new RootMediaSet(mContext);
- picasaRoot.invalidate();
+ PicasaAlbumSet picasaSet = new PicasaAlbumSet(mContext);
+ LocalAlbumSet localSet = new LocalAlbumSet(mContext);
+ picasaSet.invalidate();
- mRootSet = new ComboMediaSet(mediaRoot, picasaRoot);
+ mRootSet = new ComboMediaSet(localSet, picasaSet);
}
return mRootSet;
}
diff --git a/new3d/src/com/android/gallery3d/data/DatabaseMediaItem.java b/new3d/src/com/android/gallery3d/data/DatabaseMediaItem.java
deleted file mode 100644
index 45610b1..0000000
--- a/new3d/src/com/android/gallery3d/data/DatabaseMediaItem.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.android.gallery3d.data;
-
-
-
-public abstract class DatabaseMediaItem extends AbstractMediaItem {
-
- protected int mId;
- protected String mCaption;
- protected String mMimeType;
- protected double mLatitude;
- protected double mLongitude;
- protected long mDateTakenInMs;
- protected long mDateAddedInSec;
- protected long mDateModifiedInSec;
- protected String mFilePath;
-
- protected DatabaseMediaItem(ImageService imageService) {
- super(imageService);
- }
-
- public String getTitle() {
- return mCaption;
- }
-}
diff --git a/new3d/src/com/android/gallery3d/data/DatabaseMediaSet.java b/new3d/src/com/android/gallery3d/data/DatabaseMediaSet.java
index 9cf3eb1..e916bed 100644
--- a/new3d/src/com/android/gallery3d/data/DatabaseMediaSet.java
+++ b/new3d/src/com/android/gallery3d/data/DatabaseMediaSet.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -11,7 +25,7 @@
import java.util.concurrent.atomic.AtomicInteger;
-public abstract class DatabaseMediaSet implements MediaSet {
+public abstract class DatabaseMediaSet extends MediaSet {
private static final int MSG_LOAD_DATABASE = 0;
private static final int MSG_UPDATE_CONTENT = 1;
diff --git a/new3d/src/com/android/gallery3d/data/DecodeService.java b/new3d/src/com/android/gallery3d/data/DecodeService.java
index 9bbe4b5..d236af8 100644
--- a/new3d/src/com/android/gallery3d/data/DecodeService.java
+++ b/new3d/src/com/android/gallery3d/data/DecodeService.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
diff --git a/new3d/src/com/android/gallery3d/data/DownloadService.java b/new3d/src/com/android/gallery3d/data/DownloadService.java
index 7bfcee3..2e9ea23 100644
--- a/new3d/src/com/android/gallery3d/data/DownloadService.java
+++ b/new3d/src/com/android/gallery3d/data/DownloadService.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
diff --git a/new3d/src/com/android/gallery3d/data/ImageService.java b/new3d/src/com/android/gallery3d/data/ImageService.java
index 3a4998e..f8b3930 100644
--- a/new3d/src/com/android/gallery3d/data/ImageService.java
+++ b/new3d/src/com/android/gallery3d/data/ImageService.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -49,7 +63,7 @@
mDecodeThread.start();
}
- protected int requestImage(AbstractMediaItem item, int type) {
+ protected int requestImage(LocalMediaItem item, int type) {
DecodeTask task = new DecodeTask();
task.mRequestId = ++mTimeSerial;
task.mItem = item;
@@ -109,7 +123,7 @@
while (true) {
DecodeTask task = nextDecodeTask();
if (task == null) break;
- AbstractMediaItem item = task.mItem;
+ LocalMediaItem item = task.mItem;
try {
mCurrentTask = task;
mHandler.sendEmptyMessageDelayed(
@@ -162,7 +176,7 @@
int mTimeout;
int mType;
volatile boolean mCanceled;
- AbstractMediaItem mItem;
+ LocalMediaItem mItem;
public int compareTo(DecodeTask task) {
return mTimeout != task.mTimeout
diff --git a/new3d/src/com/android/gallery3d/data/LocalAlbum.java b/new3d/src/com/android/gallery3d/data/LocalAlbum.java
new file mode 100644
index 0000000..17a9e0e
--- /dev/null
+++ b/new3d/src/com/android/gallery3d/data/LocalAlbum.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
+
+import android.content.ContentResolver;
+import android.database.Cursor;
+
+import com.android.gallery3d.app.GalleryContext;
+import com.android.gallery3d.util.Utils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+public class LocalAlbum extends DatabaseMediaSet {
+ private static final int MAX_NUM_COVER_ITEMS = 4;
+
+ public static final Comparator<LocalAlbum> sNameComparator = new MyComparator();
+
+ private final int mBucketId;
+ private final String mBucketTitle;
+
+ private final ArrayList<LocalMediaItem> mMediaItems =
+ new ArrayList<LocalMediaItem>();
+ private ArrayList<LocalMediaItem> mLoadBuffer =
+ new ArrayList<LocalMediaItem>();
+
+ public LocalAlbum(GalleryContext context, int id, String title) {
+ super(context);
+ mBucketId = id;
+ mBucketTitle= title;
+ }
+
+ public MediaItem[] getCoverMediaItems() {
+ int size = Math.min(MAX_NUM_COVER_ITEMS, mMediaItems.size());
+ MediaItem items[] = new MediaItem[size];
+ for (int i = 0; i < size; ++i) {
+ items[i] = mMediaItems.get(i);
+ }
+ return items;
+ }
+
+ public MediaItem getMediaItem(int index) {
+ return mMediaItems.get(index);
+ }
+
+ public int getMediaItemCount() {
+ return mMediaItems.size();
+ }
+
+ public MediaSet getSubMediaSet(int index) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ public int getSubMediaSetCount() {
+ return 0;
+ }
+
+ public String getTitle() {
+ return mBucketTitle;
+ }
+
+ public int getTotalMediaItemCount() {
+ return mMediaItems.size();
+ }
+
+ @Override
+ protected void onLoadFromDatabase() {
+ ArrayList<LocalMediaItem> items = new ArrayList<LocalMediaItem>();
+ mLoadBuffer = items;
+
+ ContentResolver resolver = mContext.getContentResolver();
+ ImageService imageService = mContext.getImageService();
+
+ Cursor cursor = LocalImage.queryImageInBucket(resolver, mBucketId);
+ try {
+ while (cursor.moveToNext()) {
+ items.add(LocalImage.load(imageService, cursor));
+ }
+ } finally {
+ cursor.close();
+ }
+
+ cursor = LocalVideo.queryVideoInBucket(resolver, mBucketId);
+ try {
+ while (cursor.moveToNext()) {
+ items.add(LocalVideo.load(imageService, cursor));
+ }
+ } finally {
+ cursor.close();
+ }
+
+ Collections.sort(items, new Comparator<LocalMediaItem>() {
+
+ public int compare(LocalMediaItem o1, LocalMediaItem o2) {
+ // sort items in descending order based on their taken time.
+ long result = -(o1.mDateTakenInMs - o2.mDateTakenInMs);
+ return result == 0
+ ? o1.mId - o2.mId
+ : result > 0 ? 1 : -1;
+ }
+ });
+ }
+
+ @Override
+ protected void onUpdateContent() {
+ Utils.Assert(mLoadBuffer != null);
+ mMediaItems.clear();
+ mMediaItems.addAll(mLoadBuffer);
+ mLoadBuffer = null;
+ }
+
+ private static class MyComparator implements Comparator<LocalAlbum> {
+
+ public int compare(LocalAlbum s1, LocalAlbum s2) {
+ int result = s1.mBucketTitle.compareTo(s2.mBucketTitle);
+ return result != 0 ? result : s1.mBucketId - s2.mBucketId;
+ }
+ }
+}
diff --git a/new3d/src/com/android/gallery3d/data/RootMediaSet.java b/new3d/src/com/android/gallery3d/data/LocalAlbumSet.java
similarity index 79%
rename from new3d/src/com/android/gallery3d/data/RootMediaSet.java
rename to new3d/src/com/android/gallery3d/data/LocalAlbumSet.java
index 56bcb5c..5ae40f3 100644
--- a/new3d/src/com/android/gallery3d/data/RootMediaSet.java
+++ b/new3d/src/com/android/gallery3d/data/LocalAlbumSet.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -17,7 +31,7 @@
import java.util.HashMap;
import java.util.Map;
-public class RootMediaSet extends DatabaseMediaSet {
+public class LocalAlbumSet extends DatabaseMediaSet {
private static final String TITLE = "RootSet";
// Must preserve order between these indices and the order of the terms in
@@ -36,12 +50,12 @@
private int mTotalCountCached = -1;
- private final ArrayList<BucketMediaSet>
- mSubsets = new ArrayList<BucketMediaSet>();
+ private final ArrayList<LocalAlbum>
+ mSubsets = new ArrayList<LocalAlbum>();
private HashMap<Integer, String> mLoadBuffer;
- public RootMediaSet(GalleryContext context) {
+ public LocalAlbumSet(GalleryContext context) {
super(context);
invalidate();
}
@@ -123,14 +137,14 @@
GalleryContext context = mContext;
for (Map.Entry<Integer, String> entry : map.entrySet()) {
- mSubsets.add(new BucketMediaSet(
+ mSubsets.add(new LocalAlbum(
context, entry.getKey(), entry.getValue()));
}
mLoadBuffer = null;
- Collections.sort(mSubsets, BucketMediaSet.sNameComparator);
+ Collections.sort(mSubsets, LocalAlbum.sNameComparator);
- for (BucketMediaSet mediaset : mSubsets) {
+ for (LocalAlbum mediaset : mSubsets) {
mediaset.invalidate();
}
}
diff --git a/new3d/src/com/android/gallery3d/data/ImageMediaItem.java b/new3d/src/com/android/gallery3d/data/LocalImage.java
similarity index 85%
rename from new3d/src/com/android/gallery3d/data/ImageMediaItem.java
rename to new3d/src/com/android/gallery3d/data/LocalImage.java
index c8427ef..8f9636a 100644
--- a/new3d/src/com/android/gallery3d/data/ImageMediaItem.java
+++ b/new3d/src/com/android/gallery3d/data/LocalImage.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
import com.android.gallery3d.util.Utils;
@@ -14,14 +30,14 @@
import java.io.FileInputStream;
import java.io.IOException;
-public class ImageMediaItem extends DatabaseMediaItem {
+public class LocalImage extends LocalMediaItem {
private static final int MICRO_TARGET_PIXELS = 128 * 128;
private static final int JPEG_MARK_POSITION = 60 * 1024;
private static final int FULLIMAGE_TARGET_SIZE = 2048;
private static final int FULLIMAGE_MAX_NUM_PIXELS = 5 * 1024 * 1024;
- private static final String TAG = "ImageMediaItem";
+ private static final String TAG = "LocalImage";
// Must preserve order between these indices and the order of the terms in
// PROJECTION_IMAGES.
@@ -52,7 +68,7 @@
private int mRotation;
- protected ImageMediaItem(ImageService imageService) {
+ protected LocalImage(ImageService imageService) {
super(imageService);
}
@@ -124,8 +140,8 @@
}
}
- public static ImageMediaItem load(ImageService imageService, Cursor cursor) {
- ImageMediaItem item = new ImageMediaItem(imageService);
+ public static LocalImage load(ImageService imageService, Cursor cursor) {
+ LocalImage item = new LocalImage(imageService);
item.mId = cursor.getInt(INDEX_ID);
item.mCaption = cursor.getString(INDEX_CAPTION);
diff --git a/new3d/src/com/android/gallery3d/data/AbstractMediaItem.java b/new3d/src/com/android/gallery3d/data/LocalMediaItem.java
similarity index 64%
rename from new3d/src/com/android/gallery3d/data/AbstractMediaItem.java
rename to new3d/src/com/android/gallery3d/data/LocalMediaItem.java
index 4143c59..56ba886 100644
--- a/new3d/src/com/android/gallery3d/data/AbstractMediaItem.java
+++ b/new3d/src/com/android/gallery3d/data/LocalMediaItem.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -10,24 +24,40 @@
import com.android.gallery3d.util.FutureListener;
//
-//AbstractMediaItem is an abstract class captures those common fields
-//in ImageMediaItem and VideoMediaItem.
+// LocalMediaItem is an abstract class captures those common fields
+// in LocalImage and LocalVideo.
//
-public abstract class AbstractMediaItem implements MediaItem {
+public abstract class LocalMediaItem extends MediaItem {
- private static final String TAG = AbstractMediaItem.class.getSimpleName();
+ private static final String TAG = LocalMediaItem.class.getSimpleName();
+
+ // database fields
+ protected int mId;
+ protected String mCaption;
+ protected String mMimeType;
+ protected double mLatitude;
+ protected double mLongitude;
+ protected long mDateTakenInMs;
+ protected long mDateAddedInSec;
+ protected long mDateModifiedInSec;
+ protected String mFilePath;
+
protected int mRequestId[];
private MyFuture mFutureBitmaps[];
protected final ImageService mImageService;
@SuppressWarnings("unchecked")
- protected AbstractMediaItem(ImageService imageService) {
+ protected LocalMediaItem(ImageService imageService) {
mImageService = imageService;
mFutureBitmaps = new MyFuture[TYPE_COUNT];
mRequestId = new int[TYPE_COUNT];
}
+ public String getTitle() {
+ return mCaption;
+ }
+
public synchronized Future<Bitmap>
requestImage(int type, FutureListener<? super Bitmap> listener) {
if (mFutureBitmaps[type] != null) {
diff --git a/new3d/src/com/android/gallery3d/data/VideoMediaItem.java b/new3d/src/com/android/gallery3d/data/LocalVideo.java
similarity index 80%
rename from new3d/src/com/android/gallery3d/data/VideoMediaItem.java
rename to new3d/src/com/android/gallery3d/data/LocalVideo.java
index 2342788..9bebcb4 100644
--- a/new3d/src/com/android/gallery3d/data/VideoMediaItem.java
+++ b/new3d/src/com/android/gallery3d/data/LocalVideo.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
import com.android.gallery3d.util.Utils;
@@ -10,7 +26,7 @@
import android.provider.MediaStore.Images.ImageColumns;
import android.provider.MediaStore.Video.VideoColumns;
-public class VideoMediaItem extends DatabaseMediaItem {
+public class LocalVideo extends LocalMediaItem {
private static final int MICRO_TARGET_PIXELS = 128 * 128;
@@ -41,7 +57,7 @@
public int mDurationInSec;
- protected VideoMediaItem(ImageService imageService) {
+ protected LocalVideo(ImageService imageService) {
super(imageService);
}
@@ -70,8 +86,8 @@
}
}
- public static VideoMediaItem load(ImageService imageService, Cursor cursor) {
- VideoMediaItem item = new VideoMediaItem(imageService);
+ public static LocalVideo load(ImageService imageService, Cursor cursor) {
+ LocalVideo item = new LocalVideo(imageService);
item.mId = cursor.getInt(INDEX_ID);
item.mCaption = cursor.getString(INDEX_CAPTION);
diff --git a/new3d/src/com/android/gallery3d/data/MediaItem.java b/new3d/src/com/android/gallery3d/data/MediaItem.java
index ee3898f..703cf16 100644
--- a/new3d/src/com/android/gallery3d/data/MediaItem.java
+++ b/new3d/src/com/android/gallery3d/data/MediaItem.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
import android.graphics.Bitmap;
@@ -5,7 +21,7 @@
import com.android.gallery3d.util.Future;
import com.android.gallery3d.util.FutureListener;
-public interface MediaItem {
+public abstract class MediaItem {
public static final int TYPE_COUNT = 3;
public static final int TYPE_FULL_IMAGE = 0;
public static final int TYPE_THUMBNAIL = 1;
@@ -15,7 +31,8 @@
public static final int IMAGE_WAIT = 1;
public static final int IMAGE_ERROR = -1;
- public String getTitle();
+ public abstract String getTitle();
- public Future<Bitmap> requestImage(int type, FutureListener<? super Bitmap> listener);
+ public abstract Future<Bitmap>
+ requestImage(int type, FutureListener<? super Bitmap> listener);
}
diff --git a/new3d/src/com/android/gallery3d/data/MediaSet.java b/new3d/src/com/android/gallery3d/data/MediaSet.java
index 8487a81..319ffe4 100644
--- a/new3d/src/com/android/gallery3d/data/MediaSet.java
+++ b/new3d/src/com/android/gallery3d/data/MediaSet.java
@@ -1,7 +1,39 @@
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
-
+// This is currently implemented MediaSet and MediaItem:
//
+// | Local | Picasa
+// ----------+----------------
+// AlbumSet | 1 | 2
+// Album | 3 | 4
+// Image | 5 | 6
+// Video | 7 | (unimplemented)
+//
+// Inheritance relation:
+//
+// MediaSet -- DatabaseMediaSet -- {1,2,3,4}
+// MediaItem -- LocalMediaItem -- {5, 7}
+// -- {6}
+//
+// root = ComboMediaSet (LocalAlbumSet, PicasaAlbumSet);
+
+
// MediaSet is a directory-like data structure.
// It contains MediaItems and sub-MediaSets.
//
@@ -11,25 +43,25 @@
// getCoverMediaItems() return a few representative MediaItems for this
// MediaSet.
//
-public interface MediaSet {
+public abstract class MediaSet {
public interface MediaSetListener {
public void onContentChanged();
}
- public int getMediaItemCount();
+ public abstract int getMediaItemCount();
- public MediaItem getMediaItem(int index);
+ public abstract MediaItem getMediaItem(int index);
- public int getSubMediaSetCount();
+ public abstract int getSubMediaSetCount();
- public MediaSet getSubMediaSet(int index);
+ public abstract MediaSet getSubMediaSet(int index);
- public int getTotalMediaItemCount();
+ public abstract int getTotalMediaItemCount();
- public String getTitle();
+ public abstract String getTitle();
- public MediaItem[] getCoverMediaItems();
+ public abstract MediaItem[] getCoverMediaItems();
- public void setContentListener(MediaSetListener listener);
+ public abstract void setContentListener(MediaSetListener listener);
}
diff --git a/new3d/src/com/android/gallery3d/data/PicasaAlbum.java b/new3d/src/com/android/gallery3d/data/PicasaAlbum.java
index 2f523b3..014853b 100644
--- a/new3d/src/com/android/gallery3d/data/PicasaAlbum.java
+++ b/new3d/src/com/android/gallery3d/data/PicasaAlbum.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -17,8 +31,8 @@
private static final EntrySchema SCHEMA = PhotoEntry.SCHEMA;
private final AlbumEntry mData;
- private final ArrayList<PicasaPhoto> mPhotos = new ArrayList<PicasaPhoto>();
- private final ArrayList<PicasaPhoto> mLoadBuffer = new ArrayList<PicasaPhoto>();
+ private final ArrayList<PicasaImage> mPhotos = new ArrayList<PicasaImage>();
+ private final ArrayList<PicasaImage> mLoadBuffer = new ArrayList<PicasaImage>();
public PicasaAlbum(GalleryContext context, AlbumEntry entry) {
super(context);
@@ -69,7 +83,7 @@
try {
while (cursor.moveToNext()) {
PhotoEntry entry = SCHEMA.cursorToObject(cursor, new PhotoEntry());
- mLoadBuffer.add(new PicasaPhoto(entry));
+ mLoadBuffer.add(new PicasaImage(entry));
}
} finally {
cursor.close();
diff --git a/new3d/src/com/android/gallery3d/data/PicasaUserAlbums.java b/new3d/src/com/android/gallery3d/data/PicasaAlbumSet.java
similarity index 74%
rename from new3d/src/com/android/gallery3d/data/PicasaUserAlbums.java
rename to new3d/src/com/android/gallery3d/data/PicasaAlbumSet.java
index 42dec05..a56378d 100644
--- a/new3d/src/com/android/gallery3d/data/PicasaUserAlbums.java
+++ b/new3d/src/com/android/gallery3d/data/PicasaAlbumSet.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -11,14 +25,14 @@
import java.util.ArrayList;
-public class PicasaUserAlbums extends DatabaseMediaSet {
+public class PicasaAlbumSet extends DatabaseMediaSet {
private final EntrySchema SCHEMA = AlbumEntry.SCHEMA;
private final ArrayList<PicasaAlbum> mAlbums = new ArrayList<PicasaAlbum>();
private int mCachedTotalCount = -1;
private final ArrayList<PicasaAlbum> mLoadBuffer = new ArrayList<PicasaAlbum>();
- public PicasaUserAlbums(GalleryContext context) {
+ public PicasaAlbumSet(GalleryContext context) {
super(context);
}
diff --git a/new3d/src/com/android/gallery3d/data/PicasaPhoto.java b/new3d/src/com/android/gallery3d/data/PicasaImage.java
similarity index 78%
rename from new3d/src/com/android/gallery3d/data/PicasaPhoto.java
rename to new3d/src/com/android/gallery3d/data/PicasaImage.java
index 9afa92c..9224591 100644
--- a/new3d/src/com/android/gallery3d/data/PicasaPhoto.java
+++ b/new3d/src/com/android/gallery3d/data/PicasaImage.java
@@ -1,4 +1,18 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2010 The Android Open Source 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 com.android.gallery3d.data;
@@ -12,12 +26,12 @@
import java.net.MalformedURLException;
import java.net.URL;
-public class PicasaPhoto implements MediaItem {
+public class PicasaImage extends MediaItem {
private final PicasaTask[] mTasks = new PicasaTask[MediaItem.TYPE_COUNT];
private final PhotoEntry mData;
- public PicasaPhoto(PhotoEntry entry) {
+ public PicasaImage(PhotoEntry entry) {
mData = entry;
}
diff --git a/new3d/src/com/android/gallery3d/data/SortCursor.java b/new3d/src/com/android/gallery3d/data/SortCursor.java
deleted file mode 100644
index 0854da7..0000000
--- a/new3d/src/com/android/gallery3d/data/SortCursor.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source 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 com.android.gallery3d.data;
-
-/*
- * Added changes to support numeric comparisons, and also expose the current
- * cursor being used
- */
-
-import android.database.AbstractCursor;
-import android.database.Cursor;
-import android.database.DataSetObserver;
-import android.util.Log;
-
-/**
- * TODO: We may remove the class in the future or simplify the code to fit our
- * need.
- *
- * A variant of MergeCursor that sorts the cursors being merged. If decent
- * performance is ever obtained, it can be put back under android.database.
- */
-public class SortCursor extends AbstractCursor {
- private static final String TAG = "SortCursor";
- private Cursor mCursor; // updated in onMove
- private Cursor[] mCursors;
- private int[] mSortColumns;
- private final int ROWCACHESIZE = 64;
- private int mRowNumCache[] = new int[ROWCACHESIZE];
- private int mCursorCache[] = new int[ROWCACHESIZE];
- private int mCurRowNumCache[][];
- private int mLastCacheHit = -1;
- private int mType;
- private boolean mAscending;
- public static final int TYPE_STRING = 0;
- public static final int TYPE_NUMERIC = 1;
-
- private DataSetObserver mObserver = new DataSetObserver() {
- @Override
- public void onChanged() {
- // Reset our position so the optimizations in move-related code
- // don't screw us over
- mPos = -1;
- }
-
- @Override
- public void onInvalidated() {
- mPos = -1;
- }
- };
- private int mCursorIndex;
-
- public SortCursor(Cursor[] cursors, String sortcolumn, int type, boolean ascending) {
- mAscending = ascending;
- mCursors = cursors;
- mType = type;
- int length = mCursors.length;
- mSortColumns = new int[length];
- for (int i = 0; i < length; i++) {
- if (mCursors[i] == null) {
- continue;
- }
- // Register ourself as a data set observer
- mCursors[i].registerDataSetObserver(mObserver);
- mCursors[i].moveToFirst();
- // We don't catch the exception.
- mSortColumns[i] = mCursors[i].getColumnIndexOrThrow(sortcolumn);
- }
- mCursor = null;
- if (type == TYPE_STRING) {
- String smallest = "";
- for (int j = 0; j < length; j++) {
- if (mCursors[j] == null || mCursors[j].isAfterLast())
- continue;
- String current = mCursors[j].getString(mSortColumns[j]);
- if (mCursor == null || current == null || current.compareToIgnoreCase(smallest) < 0) {
- smallest = current;
- mCursor = mCursors[j];
- mCursorIndex = j;
- }
- }
- } else {
- long smallest = (ascending) ? Long.MAX_VALUE : Long.MIN_VALUE;
- for (int j = 0; j < length; j++) {
- if (mCursors[j] == null || mCursors[j].isAfterLast()) {
- continue;
- }
- long current = mCursors[j].getLong(mSortColumns[j]);
- boolean comparison = (ascending) ? (current < smallest) : (current > smallest);
- if (mCursor == null || comparison) {
- smallest = current;
- mCursor = mCursors[j];
- mCursorIndex = j;
- }
- }
- }
-
- for (int i = mRowNumCache.length - 1; i >= 0; i--) {
- mRowNumCache[i] = -2;
- }
- mCurRowNumCache = new int[ROWCACHESIZE][length];
- }
-
- @Override
- public int getCount() {
- int count = 0;
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] != null) {
- count += mCursors[i].getCount();
- }
- }
- return count;
- }
-
- @Override
- public boolean onMove(int oldPosition, int newPosition) {
- if (oldPosition == newPosition)
- return true;
-
- /*
- * Find the right cursor Because the client of this cursor (the
- * listadapter/view) tends to jump around in the cursor somewhat, a
- * simple cache strategy is used to avoid having to search all cursors
- * from the start. TODO: investigate strategies for optimizing random
- * access and reverse-order access.
- */
-
- int cache_entry = newPosition % ROWCACHESIZE;
-
- if (mRowNumCache[cache_entry] == newPosition) {
- int which = mCursorCache[cache_entry];
- mCursor = mCursors[which];
- mCursorIndex = which;
- if (mCursor == null) {
- Log.w(TAG, "onMove: cache results in a null cursor.");
- return false;
- }
- mCursor.moveToPosition(mCurRowNumCache[cache_entry][which]);
- mLastCacheHit = cache_entry;
- return true;
- }
-
- mCursor = null;
- int length = mCursors.length;
-
- if (mLastCacheHit >= 0) {
- for (int i = 0; i < length; i++) {
- if (mCursors[i] == null)
- continue;
- mCursors[i].moveToPosition(mCurRowNumCache[mLastCacheHit][i]);
- }
- }
-
- if (newPosition < oldPosition || oldPosition == -1) {
- for (int i = 0; i < length; i++) {
- if (mCursors[i] == null)
- continue;
- mCursors[i].moveToFirst();
- }
- oldPosition = 0;
- }
- if (oldPosition < 0) {
- oldPosition = 0;
- }
-
- // search forward to the new position
- int smallestIdx = -1;
- if (mType == TYPE_STRING) {
- for (int i = oldPosition; i <= newPosition; i++) {
- String smallest = "";
- smallestIdx = -1;
- for (int j = 0; j < length; j++) {
- if (mCursors[j] == null || mCursors[j].isAfterLast()) {
- continue;
- }
- String current = mCursors[j].getString(mSortColumns[j]);
- if (smallestIdx < 0 || current == null || current.compareToIgnoreCase(smallest) < 0) {
- smallest = current;
- smallestIdx = j;
- }
- }
- if (i == newPosition) {
- break;
- }
- if (mCursors[smallestIdx] != null) {
- mCursors[smallestIdx].moveToNext();
- }
- }
- } else {
- for (int i = oldPosition; i <= newPosition; i++) {
- long smallest = (mAscending) ? Long.MAX_VALUE : Long.MIN_VALUE;
- smallestIdx = -1;
- for (int j = 0; j < length; j++) {
- if (mCursors[j] == null || mCursors[j].isAfterLast()) {
- continue;
- }
- long current = mCursors[j].getLong(mSortColumns[j]);
- boolean comparison = (mAscending) ? current < smallest : current > smallest;
- if (smallestIdx < 0 || comparison) {
- smallest = current;
- smallestIdx = j;
- }
- }
- if (i == newPosition) {
- break;
- }
- if (mCursors[smallestIdx] != null) {
- mCursors[smallestIdx].moveToNext();
- }
- }
- }
- mCursor = mCursors[smallestIdx];
- mCursorIndex = smallestIdx;
- mRowNumCache[cache_entry] = newPosition;
- mCursorCache[cache_entry] = smallestIdx;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] != null) {
- mCurRowNumCache[cache_entry][i] = mCursors[i].getPosition();
- }
- }
- mLastCacheHit = -1;
- return true;
- }
-
- @Override
- public String getString(int column) {
- return mCursor.getString(column);
- }
-
- @Override
- public short getShort(int column) {
- return mCursor.getShort(column);
- }
-
- @Override
- public int getInt(int column) {
- return mCursor.getInt(column);
- }
-
- @Override
- public long getLong(int column) {
- return mCursor.getLong(column);
- }
-
- @Override
- public float getFloat(int column) {
- return mCursor.getFloat(column);
- }
-
- @Override
- public double getDouble(int column) {
- return mCursor.getDouble(column);
- }
-
- @Override
- public boolean isNull(int column) {
- return mCursor.isNull(column);
- }
-
- @Override
- public byte[] getBlob(int column) {
- return mCursor.getBlob(column);
- }
-
- @Override
- public String[] getColumnNames() {
- if (mCursor != null) {
- return mCursor.getColumnNames();
- } else {
- // All of the cursors may be empty, but they can still return
- // this information.
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] != null) {
- return mCursors[i].getColumnNames();
- }
- }
- throw new IllegalStateException("No cursor that can return names");
- }
- }
-
- @Override
- public void deactivate() {
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] == null)
- continue;
- mCursors[i].deactivate();
- }
- }
-
- @Override
- public void close() {
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] == null)
- continue;
- mCursors[i].close();
- }
- }
-
- @Override
- public void registerDataSetObserver(DataSetObserver observer) {
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] != null) {
- mCursors[i].registerDataSetObserver(observer);
- }
- }
- }
-
- @Override
- public void unregisterDataSetObserver(DataSetObserver observer) {
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] != null) {
- mCursors[i].unregisterDataSetObserver(observer);
- }
- }
- }
-
- @Override
- public boolean requery() {
- int length = mCursors.length;
- for (int i = 0; i < length; i++) {
- if (mCursors[i] == null)
- continue;
-
- if (mCursors[i].requery() == false) {
- return false;
- }
- }
-
- return true;
- }
-
- public int getCurrentCursorIndex() {
- return mCursorIndex;
- }
-}