summaryrefslogtreecommitdiffstats
path: root/src/com/android/photos/shims
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/photos/shims')
-rw-r--r--src/com/android/photos/shims/BitmapJobDrawable.java180
-rw-r--r--src/com/android/photos/shims/LoaderCompatShim.java31
-rw-r--r--src/com/android/photos/shims/MediaItemsLoader.java190
-rw-r--r--src/com/android/photos/shims/MediaSetLoader.java191
4 files changed, 0 insertions, 592 deletions
diff --git a/src/com/android/photos/shims/BitmapJobDrawable.java b/src/com/android/photos/shims/BitmapJobDrawable.java
deleted file mode 100644
index 32dbc8078..000000000
--- a/src/com/android/photos/shims/BitmapJobDrawable.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2013 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.photos.shims;
-
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.ColorFilter;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-
-import com.android.gallery3d.data.MediaItem;
-import com.android.gallery3d.ui.BitmapLoader;
-import com.android.gallery3d.util.Future;
-import com.android.gallery3d.util.FutureListener;
-import com.android.gallery3d.util.ThreadPool;
-import com.android.photos.data.GalleryBitmapPool;
-
-
-public class BitmapJobDrawable extends Drawable implements Runnable {
-
- private ThumbnailLoader mLoader;
- private MediaItem mItem;
- private Bitmap mBitmap;
- private Paint mPaint = new Paint();
- private Matrix mDrawMatrix = new Matrix();
- private int mRotation = 0;
-
- public BitmapJobDrawable() {
- }
-
- public void setMediaItem(MediaItem item) {
- if (mItem == item) return;
-
- if (mLoader != null) {
- mLoader.cancelLoad();
- }
- mItem = item;
- if (mBitmap != null) {
- GalleryBitmapPool.getInstance().put(mBitmap);
- mBitmap = null;
- }
- if (mItem != null) {
- // TODO: Figure out why ThumbnailLoader doesn't like to be re-used
- mLoader = new ThumbnailLoader(this);
- mLoader.startLoad();
- mRotation = mItem.getRotation();
- }
- invalidateSelf();
- }
-
- @Override
- public void run() {
- Bitmap bitmap = mLoader.getBitmap();
- if (bitmap != null) {
- mBitmap = bitmap;
- updateDrawMatrix();
- }
- }
-
- @Override
- protected void onBoundsChange(Rect bounds) {
- super.onBoundsChange(bounds);
- updateDrawMatrix();
- }
-
- @Override
- public void draw(Canvas canvas) {
- Rect bounds = getBounds();
- if (mBitmap != null) {
- canvas.save();
- canvas.clipRect(bounds);
- canvas.concat(mDrawMatrix);
- canvas.rotate(mRotation, bounds.centerX(), bounds.centerY());
- canvas.drawBitmap(mBitmap, 0, 0, mPaint);
- canvas.restore();
- } else {
- mPaint.setColor(0xFFCCCCCC);
- canvas.drawRect(bounds, mPaint);
- }
- }
-
- private void updateDrawMatrix() {
- Rect bounds = getBounds();
- if (mBitmap == null || bounds.isEmpty()) {
- mDrawMatrix.reset();
- return;
- }
-
- float scale;
- float dx = 0, dy = 0;
-
- int dwidth = mBitmap.getWidth();
- int dheight = mBitmap.getHeight();
- int vwidth = bounds.width();
- int vheight = bounds.height();
-
- // Calculates a matrix similar to ScaleType.CENTER_CROP
- if (dwidth * vheight > vwidth * dheight) {
- scale = (float) vheight / (float) dheight;
- dx = (vwidth - dwidth * scale) * 0.5f;
- } else {
- scale = (float) vwidth / (float) dwidth;
- dy = (vheight - dheight * scale) * 0.5f;
- }
-
- mDrawMatrix.setScale(scale, scale);
- mDrawMatrix.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
- invalidateSelf();
- }
-
- @Override
- public int getIntrinsicWidth() {
- return MediaItem.getTargetSize(MediaItem.TYPE_MICROTHUMBNAIL);
- }
-
- @Override
- public int getIntrinsicHeight() {
- return MediaItem.getTargetSize(MediaItem.TYPE_MICROTHUMBNAIL);
- }
-
- @Override
- public int getOpacity() {
- Bitmap bm = mBitmap;
- return (bm == null || bm.hasAlpha() || mPaint.getAlpha() < 255) ?
- PixelFormat.TRANSLUCENT : PixelFormat.OPAQUE;
- }
-
- @Override
- public void setAlpha(int alpha) {
- int oldAlpha = mPaint.getAlpha();
- if (alpha != oldAlpha) {
- mPaint.setAlpha(alpha);
- invalidateSelf();
- }
- }
-
- @Override
- public void setColorFilter(ColorFilter cf) {
- mPaint.setColorFilter(cf);
- invalidateSelf();
- }
-
- private static class ThumbnailLoader extends BitmapLoader {
- private static final ThreadPool sThreadPool = new ThreadPool(0, 2);
- private BitmapJobDrawable mParent;
-
- public ThumbnailLoader(BitmapJobDrawable parent) {
- mParent = parent;
- }
-
- @Override
- protected Future<Bitmap> submitBitmapTask(FutureListener<Bitmap> l) {
- return sThreadPool.submit(
- mParent.mItem.requestImage(MediaItem.TYPE_MICROTHUMBNAIL), this);
- }
-
- @Override
- protected void onLoadComplete(Bitmap bitmap) {
- mParent.scheduleSelf(mParent, 0);
- }
- }
-
-}
diff --git a/src/com/android/photos/shims/LoaderCompatShim.java b/src/com/android/photos/shims/LoaderCompatShim.java
deleted file mode 100644
index d5bf710de..000000000
--- a/src/com/android/photos/shims/LoaderCompatShim.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2013 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.photos.shims;
-
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-
-import java.util.ArrayList;
-
-
-public interface LoaderCompatShim<T> {
- Drawable drawableForItem(T item, Drawable recycle);
- Uri uriForItem(T item);
- ArrayList<Uri> urisForSubItems(T item);
- void deleteItemWithPath(Object path);
- Object getPathForItem(T item);
-}
diff --git a/src/com/android/photos/shims/MediaItemsLoader.java b/src/com/android/photos/shims/MediaItemsLoader.java
deleted file mode 100644
index 6142355a9..000000000
--- a/src/com/android/photos/shims/MediaItemsLoader.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) 2013 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.photos.shims;
-
-import android.content.AsyncTaskLoader;
-import android.content.Context;
-import android.database.Cursor;
-import android.database.MatrixCursor;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.provider.MediaStore.Files.FileColumns;
-import android.util.SparseArray;
-
-import com.android.gallery3d.data.ContentListener;
-import com.android.gallery3d.data.DataManager;
-import com.android.gallery3d.data.MediaItem;
-import com.android.gallery3d.data.MediaObject;
-import com.android.gallery3d.data.MediaSet;
-import com.android.gallery3d.data.MediaSet.ItemConsumer;
-import com.android.gallery3d.data.MediaSet.SyncListener;
-import com.android.gallery3d.data.Path;
-import com.android.gallery3d.util.Future;
-import com.android.photos.data.PhotoSetLoader;
-
-import java.util.ArrayList;
-
-/**
- * Returns all MediaItems in a MediaSet, wrapping them in a cursor to appear
- * like a PhotoSetLoader
- */
-public class MediaItemsLoader extends AsyncTaskLoader<Cursor> implements LoaderCompatShim<Cursor> {
-
- private static final SyncListener sNullListener = new SyncListener() {
- @Override
- public void onSyncDone(MediaSet mediaSet, int resultCode) {
- }
- };
-
- private final MediaSet mMediaSet;
- private final DataManager mDataManager;
- private Future<Integer> mSyncTask = null;
- private ContentListener mObserver = new ContentListener() {
- @Override
- public void onContentDirty() {
- onContentChanged();
- }
- };
- private SparseArray<MediaItem> mMediaItems;
-
- public MediaItemsLoader(Context context) {
- super(context);
- mDataManager = DataManager.from(context);
- String path = mDataManager.getTopSetPath(DataManager.INCLUDE_ALL);
- mMediaSet = mDataManager.getMediaSet(path);
- }
-
- public MediaItemsLoader(Context context, String parentPath) {
- super(context);
- mDataManager = DataManager.from(getContext());
- mMediaSet = mDataManager.getMediaSet(parentPath);
- }
-
- @Override
- protected void onStartLoading() {
- super.onStartLoading();
- mMediaSet.addContentListener(mObserver);
- mSyncTask = mMediaSet.requestSync(sNullListener);
- forceLoad();
- }
-
- @Override
- protected boolean onCancelLoad() {
- if (mSyncTask != null) {
- mSyncTask.cancel();
- mSyncTask = null;
- }
- return super.onCancelLoad();
- }
-
- @Override
- protected void onStopLoading() {
- super.onStopLoading();
- cancelLoad();
- mMediaSet.removeContentListener(mObserver);
- }
-
- @Override
- protected void onReset() {
- super.onReset();
- onStopLoading();
- }
-
- @Override
- public Cursor loadInBackground() {
- // TODO: This probably doesn't work
- mMediaSet.reload();
- final MatrixCursor cursor = new MatrixCursor(PhotoSetLoader.PROJECTION);
- final Object[] row = new Object[PhotoSetLoader.PROJECTION.length];
- final SparseArray<MediaItem> mediaItems = new SparseArray<MediaItem>();
- mMediaSet.enumerateTotalMediaItems(new ItemConsumer() {
- @Override
- public void consume(int index, MediaItem item) {
- row[PhotoSetLoader.INDEX_ID] = index;
- row[PhotoSetLoader.INDEX_DATA] = item.getContentUri().toString();
- row[PhotoSetLoader.INDEX_DATE_ADDED] = item.getDateInMs();
- row[PhotoSetLoader.INDEX_HEIGHT] = item.getHeight();
- row[PhotoSetLoader.INDEX_WIDTH] = item.getWidth();
- row[PhotoSetLoader.INDEX_WIDTH] = item.getWidth();
- int rawMediaType = item.getMediaType();
- int mappedMediaType = FileColumns.MEDIA_TYPE_NONE;
- if (rawMediaType == MediaItem.MEDIA_TYPE_IMAGE) {
- mappedMediaType = FileColumns.MEDIA_TYPE_IMAGE;
- } else if (rawMediaType == MediaItem.MEDIA_TYPE_VIDEO) {
- mappedMediaType = FileColumns.MEDIA_TYPE_VIDEO;
- }
- row[PhotoSetLoader.INDEX_MEDIA_TYPE] = mappedMediaType;
- row[PhotoSetLoader.INDEX_SUPPORTED_OPERATIONS] =
- item.getSupportedOperations();
- cursor.addRow(row);
- mediaItems.append(index, item);
- }
- });
- synchronized (mMediaSet) {
- mMediaItems = mediaItems;
- }
- return cursor;
- }
-
- @Override
- public Drawable drawableForItem(Cursor item, Drawable recycle) {
- BitmapJobDrawable drawable = null;
- if (recycle == null || !(recycle instanceof BitmapJobDrawable)) {
- drawable = new BitmapJobDrawable();
- } else {
- drawable = (BitmapJobDrawable) recycle;
- }
- int index = item.getInt(PhotoSetLoader.INDEX_ID);
- drawable.setMediaItem(mMediaItems.get(index));
- return drawable;
- }
-
- public static int getThumbnailSize() {
- return MediaItem.getTargetSize(MediaItem.TYPE_MICROTHUMBNAIL);
- }
-
- @Override
- public Uri uriForItem(Cursor item) {
- int index = item.getInt(PhotoSetLoader.INDEX_ID);
- MediaItem mi = mMediaItems.get(index);
- return mi == null ? null : mi.getContentUri();
- }
-
- @Override
- public ArrayList<Uri> urisForSubItems(Cursor item) {
- return null;
- }
-
- @Override
- public void deleteItemWithPath(Object path) {
- MediaObject o = mDataManager.getMediaObject((Path) path);
- if (o != null) {
- o.delete();
- }
- }
-
- @Override
- public Object getPathForItem(Cursor item) {
- int index = item.getInt(PhotoSetLoader.INDEX_ID);
- MediaItem mi = mMediaItems.get(index);
- if (mi != null) {
- return mi.getPath();
- }
- return null;
- }
-
-}
diff --git a/src/com/android/photos/shims/MediaSetLoader.java b/src/com/android/photos/shims/MediaSetLoader.java
deleted file mode 100644
index 9093bc139..000000000
--- a/src/com/android/photos/shims/MediaSetLoader.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (C) 2013 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.photos.shims;
-
-import android.content.AsyncTaskLoader;
-import android.content.Context;
-import android.database.Cursor;
-import android.database.MatrixCursor;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-
-import com.android.gallery3d.data.ContentListener;
-import com.android.gallery3d.data.DataManager;
-import com.android.gallery3d.data.MediaItem;
-import com.android.gallery3d.data.MediaObject;
-import com.android.gallery3d.data.MediaSet;
-import com.android.gallery3d.data.Path;
-import com.android.gallery3d.data.MediaSet.SyncListener;
-import com.android.gallery3d.util.Future;
-import com.android.photos.data.AlbumSetLoader;
-
-import java.util.ArrayList;
-
-/**
- * Returns all MediaSets in a MediaSet, wrapping them in a cursor to appear
- * like a AlbumSetLoader.
- */
-public class MediaSetLoader extends AsyncTaskLoader<Cursor> implements LoaderCompatShim<Cursor>{
-
- private static final SyncListener sNullListener = new SyncListener() {
- @Override
- public void onSyncDone(MediaSet mediaSet, int resultCode) {
- }
- };
-
- private final MediaSet mMediaSet;
- private final DataManager mDataManager;
- private Future<Integer> mSyncTask = null;
- private ContentListener mObserver = new ContentListener() {
- @Override
- public void onContentDirty() {
- onContentChanged();
- }
- };
-
- private ArrayList<MediaItem> mCoverItems;
-
- public MediaSetLoader(Context context) {
- super(context);
- mDataManager = DataManager.from(context);
- String path = mDataManager.getTopSetPath(DataManager.INCLUDE_ALL);
- mMediaSet = mDataManager.getMediaSet(path);
- }
-
- public MediaSetLoader(Context context, String path) {
- super(context);
- mDataManager = DataManager.from(getContext());
- mMediaSet = mDataManager.getMediaSet(path);
- }
-
- @Override
- protected void onStartLoading() {
- super.onStartLoading();
- mMediaSet.addContentListener(mObserver);
- mSyncTask = mMediaSet.requestSync(sNullListener);
- forceLoad();
- }
-
- @Override
- protected boolean onCancelLoad() {
- if (mSyncTask != null) {
- mSyncTask.cancel();
- mSyncTask = null;
- }
- return super.onCancelLoad();
- }
-
- @Override
- protected void onStopLoading() {
- super.onStopLoading();
- cancelLoad();
- mMediaSet.removeContentListener(mObserver);
- }
-
- @Override
- protected void onReset() {
- super.onReset();
- onStopLoading();
- }
-
- @Override
- public Cursor loadInBackground() {
- // TODO: This probably doesn't work
- mMediaSet.reload();
- final MatrixCursor cursor = new MatrixCursor(AlbumSetLoader.PROJECTION);
- final Object[] row = new Object[AlbumSetLoader.PROJECTION.length];
- int count = mMediaSet.getSubMediaSetCount();
- ArrayList<MediaItem> coverItems = new ArrayList<MediaItem>(count);
- for (int i = 0; i < count; i++) {
- MediaSet m = mMediaSet.getSubMediaSet(i);
- m.reload();
- row[AlbumSetLoader.INDEX_ID] = i;
- row[AlbumSetLoader.INDEX_TITLE] = m.getName();
- row[AlbumSetLoader.INDEX_COUNT] = m.getMediaItemCount();
- row[AlbumSetLoader.INDEX_SUPPORTED_OPERATIONS] = m.getSupportedOperations();
- MediaItem coverItem = m.getCoverMediaItem();
- if (coverItem != null) {
- row[AlbumSetLoader.INDEX_TIMESTAMP] = coverItem.getDateInMs();
- }
- coverItems.add(coverItem);
- cursor.addRow(row);
- }
- synchronized (mMediaSet) {
- mCoverItems = coverItems;
- }
- return cursor;
- }
-
- @Override
- public Drawable drawableForItem(Cursor item, Drawable recycle) {
- BitmapJobDrawable drawable = null;
- if (recycle == null || !(recycle instanceof BitmapJobDrawable)) {
- drawable = new BitmapJobDrawable();
- } else {
- drawable = (BitmapJobDrawable) recycle;
- }
- int index = item.getInt(AlbumSetLoader.INDEX_ID);
- drawable.setMediaItem(mCoverItems.get(index));
- return drawable;
- }
-
- public static int getThumbnailSize() {
- return MediaItem.getTargetSize(MediaItem.TYPE_MICROTHUMBNAIL);
- }
-
- @Override
- public Uri uriForItem(Cursor item) {
- int index = item.getInt(AlbumSetLoader.INDEX_ID);
- MediaSet ms = mMediaSet.getSubMediaSet(index);
- return ms == null ? null : ms.getContentUri();
- }
-
- @Override
- public ArrayList<Uri> urisForSubItems(Cursor item) {
- int index = item.getInt(AlbumSetLoader.INDEX_ID);
- MediaSet ms = mMediaSet.getSubMediaSet(index);
- if (ms == null) return null;
- final ArrayList<Uri> result = new ArrayList<Uri>();
- ms.enumerateMediaItems(new MediaSet.ItemConsumer() {
- @Override
- public void consume(int index, MediaItem item) {
- if (item != null) {
- result.add(item.getContentUri());
- }
- }
- });
- return result;
- }
-
- @Override
- public void deleteItemWithPath(Object path) {
- MediaObject o = mDataManager.getMediaObject((Path) path);
- if (o != null) {
- o.delete();
- }
- }
-
- @Override
- public Object getPathForItem(Cursor item) {
- int index = item.getInt(AlbumSetLoader.INDEX_ID);
- MediaSet ms = mMediaSet.getSubMediaSet(index);
- if (ms != null) {
- return ms.getPath();
- }
- return null;
- }
-}