From: Owen Lin Date: Wed, 4 Apr 2012 02:24:08 +0000 (+0800) Subject: Refactor. Merge SelectionDrawer with SlotRenderer. X-Git-Tag: android-x86-6.0-r3~2044^2~1434 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=48503a022b1e32e9a8a7597ff2c272eb7a6cab58;p=android-x86%2Fpackages-apps-Camera2.git Refactor. Merge SelectionDrawer with SlotRenderer. Change-Id: Iaa50b2a78beb95fc83208a5f74cf612650cd8643 --- diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 3d8c86d4b..af6cb5057 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -47,8 +47,6 @@ import com.android.gallery3d.ui.DetailsHelper.CloseListener; import com.android.gallery3d.ui.GLCanvas; import com.android.gallery3d.ui.GLRoot; import com.android.gallery3d.ui.GLView; -import com.android.gallery3d.ui.GridDrawer; -import com.android.gallery3d.ui.HighlightDrawer; import com.android.gallery3d.ui.RelativePosition; import com.android.gallery3d.ui.ScreenNailHolder; import com.android.gallery3d.ui.SelectionManager; @@ -87,8 +85,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster protected SelectionManager mSelectionManager; private Vibrator mVibrator; - private GridDrawer mGridDrawer; - private HighlightDrawer mHighlightDrawer; private boolean mGetContent; private boolean mShowClusterMenu; @@ -127,7 +123,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster if (mShowDetails) { mDetailsHelper.layout(left, slotViewTop, right, bottom); } else { - mAlbumView.setSelectionDrawer(mGridDrawer); + mAlbumView.setHighlightItemPath(null); } // Set the mSlotView as a reference point to the open animation @@ -160,15 +156,11 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } private void onDown(int index) { - MediaItem item = mAlbumDataAdapter.get(index); - Path path = (item == null) ? null : item.getPath(); - mSelectionManager.setPressedPath(path); - mSlotView.invalidate(); + mAlbumView.setPressedIndex(index); } private void onUp() { - mSelectionManager.setPressedPath(null); - mSlotView.invalidate(); + mAlbumView.setPressedIndex(-1); } private void onSingleTapUp(int slotIndex) { @@ -178,7 +170,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster return; } if (mShowDetails) { - mHighlightDrawer.setHighlightItem(item.getPath()); + mAlbumView.setHighlightItemPath(item.getPath()); mDetailsHelper.reloadDetails(slotIndex); } else if (!mSelectionManager.inSelectionMode()) { if (mGetContent) { @@ -349,12 +341,10 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private void initializeViews() { mSelectionManager = new SelectionManager(mActivity, false); mSelectionManager.setSelectionListener(this); - mGridDrawer = new GridDrawer((Context) mActivity, mSelectionManager); Config.AlbumPage config = Config.AlbumPage.get((Context) mActivity); mSlotView = new SlotView((Context) mActivity, config.slotViewSpec); - mAlbumView = new AlbumView(mActivity, mSlotView); + mAlbumView = new AlbumView(mActivity, mSlotView, mSelectionManager); mSlotView.setSlotRenderer(mAlbumView); - mAlbumView.setSelectionDrawer(mGridDrawer); mRootPane.addComponent(mSlotView); mSlotView.setListener(new SlotView.SimpleListener() { @Override @@ -401,8 +391,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private void showDetails() { mShowDetails = true; if (mDetailsHelper == null) { - mHighlightDrawer = new HighlightDrawer(mActivity.getAndroidContext(), - mSelectionManager); mDetailsHelper = new DetailsHelper(mActivity, mRootPane, mDetailsSource); mDetailsHelper.setCloseListener(new CloseListener() { public void onClose() { @@ -410,14 +398,13 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } }); } - mAlbumView.setSelectionDrawer(mHighlightDrawer); mDetailsHelper.show(); } private void hideDetails() { mShowDetails = false; mDetailsHelper.hide(); - mAlbumView.setSelectionDrawer(mGridDrawer); + mAlbumView.setHighlightItemPath(null); mSlotView.invalidate(); } @@ -640,7 +627,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster public MediaDetails getDetails() { MediaObject item = mAlbumDataAdapter.get(mIndex); if (item != null) { - mHighlightDrawer.setHighlightItem(item.getPath()); + mAlbumView.setHighlightItemPath(item.getPath()); return item.getDetails(); } else { return null; diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index 6b4bb00f9..7cdb85628 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -46,8 +46,6 @@ import com.android.gallery3d.ui.DetailsHelper.CloseListener; import com.android.gallery3d.ui.GLCanvas; import com.android.gallery3d.ui.GLRoot; import com.android.gallery3d.ui.GLView; -import com.android.gallery3d.ui.GridDrawer; -import com.android.gallery3d.ui.HighlightDrawer; import com.android.gallery3d.ui.SelectionManager; import com.android.gallery3d.ui.SlotView; import com.android.gallery3d.util.Future; @@ -84,8 +82,6 @@ public class AlbumSetPage extends ActivityState implements protected SelectionManager mSelectionManager; private AlbumSetDataAdapter mAlbumSetDataAdapter; - private GridDrawer mGridDrawer; - private HighlightDrawer mHighlightDrawer; private boolean mGetContent; private boolean mGetAlbum; @@ -127,7 +123,7 @@ public class AlbumSetPage extends ActivityState implements if (mShowDetails) { mDetailsHelper.layout(left, slotViewTop, right, bottom); } else { - mAlbumSetView.setSelectionDrawer(mGridDrawer); + mAlbumSetView.setHighlightItemPath(null); } mSlotView.layout(0, slotViewTop, slotViewRight, slotViewBottom); @@ -180,8 +176,7 @@ public class AlbumSetPage extends ActivityState implements if (targetSet == null) return; // Content is dirty, we shall reload soon if (mShowDetails) { - Path path = targetSet.getPath(); - mHighlightDrawer.setHighlightItem(path); + mAlbumSetView.setHighlightItemPath(targetSet.getPath()); mDetailsHelper.reloadDetails(slotIndex); } else if (!mSelectionManager.inSelectionMode()) { Bundle data = new Bundle(getData()); @@ -218,15 +213,11 @@ public class AlbumSetPage extends ActivityState implements } private void onDown(int index) { - MediaSet set = mAlbumSetDataAdapter.getMediaSet(index); - Path path = (set == null) ? null : set.getPath(); - mSelectionManager.setPressedPath(path); - mSlotView.invalidate(); + mAlbumSetView.setPressedIndex(index); } private void onUp() { - mSelectionManager.setPressedPath(null); - mSlotView.invalidate(); + mAlbumSetView.setPressedIndex(-1); } public void onLongTap(int slotIndex) { @@ -351,11 +342,10 @@ public class AlbumSetPage extends ActivityState implements mSelectionManager = new SelectionManager(mActivity, true); mSelectionManager.setSelectionListener(this); - mGridDrawer = new GridDrawer((Context) mActivity, mSelectionManager); Config.AlbumSetPage config = Config.AlbumSetPage.get((Context) mActivity); mSlotView = new SlotView((Context) mActivity, config.slotViewSpec); mAlbumSetView = new AlbumSetView( - mActivity, mGridDrawer, mSlotView, config.labelSpec); + mActivity, mSelectionManager, mSlotView, config.labelSpec); mSlotView.setSlotRenderer(mAlbumSetView); mSlotView.setListener(new SlotView.SimpleListener() { @Override @@ -545,15 +535,13 @@ public class AlbumSetPage extends ActivityState implements private void hideDetails() { mShowDetails = false; mDetailsHelper.hide(); - mAlbumSetView.setSelectionDrawer(mGridDrawer); + mAlbumSetView.setHighlightItemPath(null); mSlotView.invalidate(); } private void showDetails() { mShowDetails = true; if (mDetailsHelper == null) { - mHighlightDrawer = new HighlightDrawer(mActivity.getAndroidContext(), - mSelectionManager); mDetailsHelper = new DetailsHelper(mActivity, mRootPane, mDetailsSource); mDetailsHelper.setCloseListener(new CloseListener() { @Override @@ -562,7 +550,6 @@ public class AlbumSetPage extends ActivityState implements } }); } - mAlbumSetView.setSelectionDrawer(mHighlightDrawer); mDetailsHelper.show(); } @@ -637,7 +624,7 @@ public class AlbumSetPage extends ActivityState implements public MediaDetails getDetails() { MediaObject item = mAlbumSetDataAdapter.getMediaSet(mIndex); if (item != null) { - mHighlightDrawer.setHighlightItem(item.getPath()); + mAlbumSetView.setHighlightItemPath(item.getPath()); return item.getDetails(); } else { return null; diff --git a/src/com/android/gallery3d/app/ManageCachePage.java b/src/com/android/gallery3d/app/ManageCachePage.java index 718c59fbf..c998cd83a 100644 --- a/src/com/android/gallery3d/app/ManageCachePage.java +++ b/src/com/android/gallery3d/app/ManageCachePage.java @@ -36,13 +36,11 @@ import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.MediaObject; import com.android.gallery3d.data.MediaSet; import com.android.gallery3d.data.Path; -import com.android.gallery3d.ui.AlbumSetView; import com.android.gallery3d.ui.CacheStorageUsageInfo; import com.android.gallery3d.ui.GLCanvas; import com.android.gallery3d.ui.GLView; import com.android.gallery3d.ui.ManageCacheDrawer; import com.android.gallery3d.ui.MenuExecutor; -import com.android.gallery3d.ui.SelectionDrawer; import com.android.gallery3d.ui.SelectionManager; import com.android.gallery3d.ui.SlotView; import com.android.gallery3d.ui.SynchronizedHandler; @@ -67,12 +65,10 @@ public class ManageCachePage extends ActivityState implements private static final int PROGRESS_BAR_MAX = 10000; private SlotView mSlotView; - private AlbumSetView mAlbumSetView; - private MediaSet mMediaSet; protected SelectionManager mSelectionManager; - protected SelectionDrawer mSelectionDrawer; + protected ManageCacheDrawer mSelectionDrawer; private AlbumSetDataAdapter mAlbumSetDataAdapter; private float mUserDistance; // in pixel @@ -137,6 +133,7 @@ public class ManageCachePage extends ActivityState implements } }; + @Override public void onEyePositionChanged(float x, float y, float z) { mRootPane.lockRendering(); mX = x; @@ -147,15 +144,11 @@ public class ManageCachePage extends ActivityState implements } private void onDown(int index) { - MediaSet set = mAlbumSetDataAdapter.getMediaSet(index); - Path path = (set == null) ? null : set.getPath(); - mSelectionManager.setPressedPath(path); - mSlotView.invalidate(); + mSelectionDrawer.setPressedIndex(index); } private void onUp() { - mSelectionManager.setPressedPath(null); - mSlotView.invalidate(); + mSelectionDrawer.setPressedIndex(-1); } public void onSingleTapUp(int slotIndex) { @@ -233,7 +226,7 @@ public class ManageCachePage extends ActivityState implements public void onPause() { super.onPause(); mAlbumSetDataAdapter.pause(); - mAlbumSetView.pause(); + mSelectionDrawer.pause(); mEyePosition.pause(); if (mUpdateStorageInfo != null) { @@ -263,7 +256,7 @@ public class ManageCachePage extends ActivityState implements super.onResume(); setContentPane(mRootPane); mAlbumSetDataAdapter.resume(); - mAlbumSetView.resume(); + mSelectionDrawer.resume(); mEyePosition.resume(); mUpdateStorageInfo = mActivity.getThreadPool().submit(mUpdateStorageInfoJob); FrameLayout layout = (FrameLayout) ((Activity) mActivity).findViewById(R.id.footer); @@ -283,7 +276,7 @@ public class ManageCachePage extends ActivityState implements mAlbumSetDataAdapter = new AlbumSetDataAdapter( mActivity, mMediaSet, DATA_CACHE_SIZE); - mAlbumSetView.setModel(mAlbumSetDataAdapter); + mSelectionDrawer.setModel(mAlbumSetDataAdapter); } private void initializeViews() { @@ -293,12 +286,10 @@ public class ManageCachePage extends ActivityState implements mSelectionManager.setSelectionListener(this); Config.ManageCachePage config = Config.ManageCachePage.get(activity); - mSelectionDrawer = new ManageCacheDrawer((Context) mActivity, - mSelectionManager, config.cachePinSize, config.cachePinMargin); mSlotView = new SlotView((Context) mActivity, config.slotViewSpec); - mAlbumSetView = new AlbumSetView(mActivity, mSelectionDrawer, - mSlotView, config.labelSpec); - mSlotView.setSlotRenderer(mAlbumSetView); + mSelectionDrawer = new ManageCacheDrawer(mActivity, mSelectionManager, mSlotView, + config.labelSpec, config.cachePinSize, config.cachePinMargin); + mSlotView.setSlotRenderer(mSelectionDrawer); mSlotView.setListener(new SlotView.SimpleListener() { @Override public void onDown(int index) { @@ -390,17 +381,20 @@ public class ManageCachePage extends ActivityState implements } } + @Override public void onProgressComplete(int result) { onBackPressed(); } + @Override public void onProgressUpdate(int index) { } + @Override public void onSelectionModeChange(int mode) { } + @Override public void onSelectionChange(Path path, boolean selected) { } - } diff --git a/src/com/android/gallery3d/data/DataSourceType.java b/src/com/android/gallery3d/data/DataSourceType.java new file mode 100644 index 000000000..27611880d --- /dev/null +++ b/src/com/android/gallery3d/data/DataSourceType.java @@ -0,0 +1,48 @@ +/* + * 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.MediaSetUtils; + +public final class DataSourceType { + public static final int TYPE_NOT_CATEGORIZED = 0; + public static final int TYPE_LOCAL = 1; + public static final int TYPE_PICASA = 2; + public static final int TYPE_MTP = 3; + public static final int TYPE_CAMERA = 4; + + private static final Path PICASA_ROOT = Path.fromString("/picasa"); + private static final Path LOCAL_ROOT = Path.fromString("/local"); + private static final Path MTP_ROOT = Path.fromString("/mtp"); + + public static int identifySourceType(MediaSet set) { + if (set == null) { + return TYPE_NOT_CATEGORIZED; + } + + Path path = set.getPath(); + if (MediaSetUtils.isCameraSource(path)) return TYPE_CAMERA; + + Path prefix = path.getPrefixPath(); + + if (prefix == PICASA_ROOT) return TYPE_PICASA; + if (prefix == MTP_ROOT) return TYPE_MTP; + if (prefix == LOCAL_ROOT) return TYPE_LOCAL; + + return TYPE_NOT_CATEGORIZED; + } +} diff --git a/src/com/android/gallery3d/data/Path.java b/src/com/android/gallery3d/data/Path.java index a09df10ad..dfb91315e 100644 --- a/src/com/android/gallery3d/data/Path.java +++ b/src/com/android/gallery3d/data/Path.java @@ -175,13 +175,20 @@ public class Path { } public String getPrefix() { + if (this == sRoot) return ""; + return getPrefixPath().mSegment; + } + + public Path getPrefixPath() { synchronized (Path.class) { Path current = this; - if (current == sRoot) return ""; + if (current == sRoot) { + throw new IllegalStateException(); + } while (current.mParent != sRoot) { current = current.mParent; } - return current.mSegment; + return current; } } diff --git a/src/com/android/gallery3d/ui/AbstractSlotRenderer.java b/src/com/android/gallery3d/ui/AbstractSlotRenderer.java new file mode 100644 index 000000000..0b880b1d3 --- /dev/null +++ b/src/com/android/gallery3d/ui/AbstractSlotRenderer.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2012 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.ui; + +import android.content.Context; +import android.graphics.Rect; + +import com.android.gallery3d.R; + +public abstract class AbstractSlotRenderer implements SlotView.SlotRenderer { + + private final ResourceTexture mVideoOverlay; + private final ResourceTexture mVideoPlayIcon; + private final NinePatchTexture mPanoramaBorder; + private final NinePatchTexture mFramePressed; + private final NinePatchTexture mFrameSelected; + + protected AbstractSlotRenderer(Context context) { + mVideoOverlay = new ResourceTexture(context, R.drawable.ic_video_thumb); + mVideoPlayIcon = new ResourceTexture(context, R.drawable.ic_gallery_play); + mPanoramaBorder = new NinePatchTexture(context, R.drawable.ic_pan_thumb); + mFramePressed = new NinePatchTexture(context, R.drawable.grid_pressed); + mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected); + } + + protected void drawContent(GLCanvas canvas, + Texture content, int width, int height, int rotation) { + canvas.save(GLCanvas.SAVE_FLAG_MATRIX); + + if (rotation != 0) { + canvas.rotate(rotation, 0, 0, 1); + if (((rotation % 90) & 1) != 0) { + int temp = height; + height = width; + width = height; + } + } + + // Fit the content into the box + float scale = Math.min( + (float) width / content.getWidth(), + (float) height / content.getHeight()); + canvas.scale(scale, scale, 1); + content.draw(canvas, 0, 0); + + canvas.restore(); + } + + protected void drawVideoOverlay(GLCanvas canvas, int width, int height) { + // Scale the video overlay to the height of the thumbnail and put it + // on the left side. + ResourceTexture v = mVideoOverlay; + float scale = (float) height / v.getHeight(); + int w = Math.round(scale * v.getWidth()); + int h = Math.round(scale * v.getHeight()); + v.draw(canvas, 0, 0, w, h); + + int s = Math.min(width, height) / 6; + mVideoPlayIcon.draw(canvas, (width - s) / 2, (height - s) / 2, s, s); + } + + protected void drawPanoramaBorder(GLCanvas canvas, int width, int height) { + float scale = (float) width / mPanoramaBorder.getWidth(); + int w = Math.round(scale * mPanoramaBorder.getWidth()); + int h = Math.round(scale * mPanoramaBorder.getHeight()); + // draw at the top + mPanoramaBorder.draw(canvas, 0, 0, w, h); + // draw at the bottom + mPanoramaBorder.draw(canvas, 0, height - h, w, h); + } + + protected void drawPressedFrame(GLCanvas canvas, int width, int height) { + drawFrame(canvas, mFramePressed, 0, 0, width, height); + } + + protected void drawSelectedFrame(GLCanvas canvas, int width, int height) { + drawFrame(canvas, mFrameSelected, 0, 0, width, height); + } + + protected static void drawFrame(GLCanvas canvas, NinePatchTexture frame, + int x, int y, int width, int height) { + Rect p = frame.getPaddings(); + frame.draw(canvas, x - p.left, y - p.top, width + p.left + p.right, + height + p.top + p.bottom); + } +} diff --git a/src/com/android/gallery3d/ui/AlbumLabelMaker.java b/src/com/android/gallery3d/ui/AlbumLabelMaker.java index 68fa6958a..4eac3cbeb 100644 --- a/src/com/android/gallery3d/ui/AlbumLabelMaker.java +++ b/src/com/android/gallery3d/ui/AlbumLabelMaker.java @@ -15,6 +15,7 @@ import android.text.TextUtils; import com.android.gallery3d.R; import com.android.gallery3d.common.Utils; +import com.android.gallery3d.data.DataSourceType; import com.android.gallery3d.data.MediaSet; import com.android.gallery3d.util.ThreadPool; import com.android.gallery3d.util.ThreadPool.JobContext; @@ -50,13 +51,13 @@ public class AlbumLabelMaker { private Bitmap getOverlayAlbumIcon(int sourceType) { switch (sourceType) { - case SelectionDrawer.DATASOURCE_TYPE_CAMERA: + case DataSourceType.TYPE_CAMERA: return mCameraIcon.get(); - case SelectionDrawer.DATASOURCE_TYPE_LOCAL: + case DataSourceType.TYPE_LOCAL: return mLocalSetIcon.get(); - case SelectionDrawer.DATASOURCE_TYPE_MTP: + case DataSourceType.TYPE_MTP: return mMtpIcon.get(); - case SelectionDrawer.DATASOURCE_TYPE_PICASA: + case DataSourceType.TYPE_PICASA: return mPicasaIcon.get(); } return null; diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java index 467b52233..606ab5925 100644 --- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java @@ -22,6 +22,7 @@ import android.os.Message; import com.android.gallery3d.R; import com.android.gallery3d.app.GalleryActivity; import com.android.gallery3d.common.Utils; +import com.android.gallery3d.data.DataSourceType; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.data.MediaObject; import com.android.gallery3d.data.MediaSet; @@ -29,7 +30,6 @@ import com.android.gallery3d.data.Path; import com.android.gallery3d.util.Future; import com.android.gallery3d.util.FutureListener; import com.android.gallery3d.util.GalleryUtils; -import com.android.gallery3d.util.MediaSetUtils; import com.android.gallery3d.util.ThreadPool; public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { @@ -85,8 +85,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } public AlbumSetSlidingWindow(GalleryActivity activity, - AlbumSetView.LabelSpec labelSpec, SelectionDrawer drawer, - AlbumSetView.Model source, int cacheSize) { + AlbumSetView.Model source, AlbumSetView.LabelSpec labelSpec, int cacheSize) { source.setModelListener(this); mSource = source; mData = new AlbumSetEntry[cacheSize]; @@ -231,7 +230,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { int slotIndex, MediaSet album, MediaItem cover) { entry.album = album; entry.setDataVersion = getDataVersion(album); - entry.sourceType = identifySourceType(album); + entry.sourceType = DataSourceType.identifySourceType(album); entry.cacheFlag = identifyCacheFlag(album); entry.cacheStatus = identifyCacheStatus(album); entry.setPath = (album == null) ? null : album.getPath(); @@ -348,7 +347,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { public BitmapTexture getLoadingTexture() { if (mLoadingLabel == null) { Bitmap bitmap = mLabelMaker.requestLabel(mLoadingText, null, - SelectionDrawer.DATASOURCE_TYPE_NOT_CATEGORIZED) + DataSourceType.TYPE_NOT_CATEGORIZED) .run(ThreadPool.JOB_CONTEXT_STUB); mLoadingLabel = new BitmapTexture(bitmap); mLoadingLabel.setOpaque(false); @@ -421,30 +420,6 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } } - private static int identifySourceType(MediaSet set) { - if (set == null) { - return SelectionDrawer.DATASOURCE_TYPE_NOT_CATEGORIZED; - } - - Path path = set.getPath(); - if (MediaSetUtils.isCameraSource(path)) { - return SelectionDrawer.DATASOURCE_TYPE_CAMERA; - } - - int type = SelectionDrawer.DATASOURCE_TYPE_NOT_CATEGORIZED; - String prefix = path.getPrefix(); - - if (prefix.equals("picasa")) { - type = SelectionDrawer.DATASOURCE_TYPE_PICASA; - } else if (prefix.equals("local") || prefix.equals("merge")) { - type = SelectionDrawer.DATASOURCE_TYPE_LOCAL; - } else if (prefix.equals("mtp")) { - type = SelectionDrawer.DATASOURCE_TYPE_MTP; - } - - return type; - } - private static int identifyCacheFlag(MediaSet set) { if (set == null || (set.getSupportedOperations() & MediaSet.SUPPORT_CACHE) == 0) { diff --git a/src/com/android/gallery3d/ui/AlbumSetView.java b/src/com/android/gallery3d/ui/AlbumSetView.java index 8a169b11a..440487e98 100644 --- a/src/com/android/gallery3d/ui/AlbumSetView.java +++ b/src/com/android/gallery3d/ui/AlbumSetView.java @@ -17,30 +17,35 @@ package com.android.gallery3d.ui; import android.content.Context; -import android.util.FloatMath; import com.android.gallery3d.R; import com.android.gallery3d.app.GalleryActivity; 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.ui.AlbumSetSlidingWindow.AlbumSetEntry; // TODO: rename to AlbumSetRenderer -public class AlbumSetView implements SlotView.SlotRenderer { +public class AlbumSetView extends AbstractSlotRenderer { @SuppressWarnings("unused") private static final String TAG = "AlbumSetView"; private static final int CACHE_SIZE = 64; private static final int PLACEHOLDER_COLOR = 0xFF222222; private final ColorTexture mWaitLoadingTexture; - private AlbumSetSlidingWindow mDataWindow; private final GalleryActivity mActivity; - private final LabelSpec mLabelSpec; + private final SelectionManager mSelectionManager; + protected final LabelSpec mLabelSpec; - private SelectionDrawer mSelectionDrawer; + protected AlbumSetSlidingWindow mDataWindow; private SlotView mSlotView; private NinePatchTexture mDarkStrip; + private int mPressedIndex = -1; + private Path mHighlightItemPath = null; + private boolean mInSelectionMode; + public static interface Model { public MediaItem getCoverItem(int index); public MediaSet getMediaSet(int index); @@ -64,23 +69,30 @@ public class AlbumSetView implements SlotView.SlotRenderer { public int iconSize; } - public AlbumSetView(GalleryActivity activity, SelectionDrawer drawer, + public AlbumSetView(GalleryActivity activity, SelectionManager selectionManager, SlotView slotView, LabelSpec labelSpec) { + super ((Context) activity); mActivity = activity; - mLabelSpec = labelSpec; + mSelectionManager = selectionManager; mSlotView = slotView; + mLabelSpec = labelSpec; mWaitLoadingTexture = new ColorTexture(PLACEHOLDER_COLOR); mWaitLoadingTexture.setSize(1, 1); Context context = activity.getAndroidContext(); mDarkStrip = new NinePatchTexture(context, R.drawable.dark_strip); + } - setSelectionDrawer(drawer); + public void setPressedIndex(int index) { + if (mPressedIndex == index) return; + mPressedIndex = index; + mSlotView.invalidate(); } - public void setSelectionDrawer(SelectionDrawer drawer) { - mSelectionDrawer = drawer; + public void setHighlightItemPath(Path path) { + if (mHighlightItemPath == path) return; + mHighlightItemPath = path; mSlotView.invalidate(); } @@ -91,8 +103,8 @@ public class AlbumSetView implements SlotView.SlotRenderer { mSlotView.setSlotCount(0); } if (model != null) { - mDataWindow = new AlbumSetSlidingWindow(mActivity, mLabelSpec, - mSelectionDrawer, model, CACHE_SIZE); + mDataWindow = new AlbumSetSlidingWindow( + mActivity, model, mLabelSpec, CACHE_SIZE); mDataWindow.setListener(new MyCacheListener()); mSlotView.setSlotCount(mDataWindow.size()); } @@ -108,53 +120,59 @@ public class AlbumSetView implements SlotView.SlotRenderer { @Override public int renderSlot(GLCanvas canvas, int index, int pass, int width, int height) { AlbumSetEntry entry = mDataWindow.get(index); - return renderContent(canvas, pass, entry, width, height) - | renderLabel(canvas, pass, entry, width, height); + int renderRequestFlags = 0; + renderRequestFlags |= renderContent(canvas, entry, width, height); + renderRequestFlags |= renderLabel(canvas, entry, width, height); + renderRequestFlags |= renderOverlay(canvas, index, entry, width, height); + return renderRequestFlags; + } + + protected int renderOverlay( + GLCanvas canvas, int index, AlbumSetEntry entry, int width, int height) { + Path path = entry.setPath; + if (mPressedIndex == index) { + drawPressedFrame(canvas, width, height); + } else if ((path != null) && (mHighlightItemPath == path)) { + drawSelectedFrame(canvas, width, height); + } else if (mInSelectionMode && mSelectionManager.isItemSelected(path)) { + drawSelectedFrame(canvas, width, height); + } + return 0; } - private int renderContent(GLCanvas canvas, - int pass, AlbumSetEntry entry, int width, int height) { - Texture content = checkTexture(canvas, entry.content); + protected int renderContent( + GLCanvas canvas, AlbumSetEntry entry, int width, int height) { + int renderRequestFlags = 0; + Texture content = checkTexture(canvas, entry.content); if (content == null) { content = mWaitLoadingTexture; entry.isWaitLoadingDisplayed = true; } else if (entry.isWaitLoadingDisplayed) { entry.isWaitLoadingDisplayed = false; entry.content = new FadeInTexture( - PLACEHOLDER_COLOR, (BitmapTexture) content); + PLACEHOLDER_COLOR, (BitmapTexture) entry.content); content = entry.content; } - - // Fit the content into the box - int w = content.getWidth(); - int h = content.getHeight(); - - float scale = Math.min(width / (float) w, height / (float) h); - - w = (int) FloatMath.floor(w * scale); - h = (int) FloatMath.floor(h * scale); - - canvas.translate(width / 2, height / 2); - // Now draw it - mSelectionDrawer.draw(canvas, content, width, height, - entry.rotation, entry.setPath, entry.sourceType, entry.mediaType, - entry.isPanorama, mLabelSpec.labelBackgroundHeight, - entry.cacheFlag == MediaSet.CACHE_FLAG_FULL, - (entry.cacheFlag == MediaSet.CACHE_FLAG_FULL) - && (entry.cacheStatus != MediaSet.CACHE_STATUS_CACHED_FULL)); - canvas.translate(-width / 2, -height / 2); - + drawContent(canvas, content, width, height, entry.rotation); if ((content instanceof FadeInTexture) && ((FadeInTexture) content).isAnimating()) { - return SlotView.RENDER_MORE_FRAME; + renderRequestFlags |= SlotView.RENDER_MORE_FRAME; } - return 0; - } - private int renderLabel(GLCanvas canvas, - int pass, AlbumSetEntry entry, int width, int height) { + if (entry.mediaType == MediaObject.MEDIA_TYPE_VIDEO) { + drawVideoOverlay(canvas, width, height); + } + + if (entry.isPanorama) { + drawPanoramaBorder(canvas, width, height); + } + + return renderRequestFlags; + } + protected int renderLabel( + GLCanvas canvas, AlbumSetEntry entry, int width, int height) { // We show the loading message only when the album is still loading // (Not when we are still preparing the label) Texture content = checkTexture(canvas, entry.label); @@ -163,7 +181,7 @@ public class AlbumSetView implements SlotView.SlotRenderer { } if (content != null) { int h = mLabelSpec.labelBackgroundHeight; - SelectionDrawer.drawFrame(canvas, mDarkStrip, 0, height - h, width, h); + drawFrame(canvas, mDarkStrip, 0, height - h, width, h); content.draw(canvas, 0, height - h, width, h); } return 0; @@ -171,7 +189,7 @@ public class AlbumSetView implements SlotView.SlotRenderer { @Override public void prepareDrawing() { - mSelectionDrawer.prepareDrawing(); + mInSelectionMode = mSelectionManager.inSelectionMode(); } private class MyCacheListener implements AlbumSetSlidingWindow.Listener { diff --git a/src/com/android/gallery3d/ui/AlbumView.java b/src/com/android/gallery3d/ui/AlbumView.java index 1ed3ded29..7402280c6 100644 --- a/src/com/android/gallery3d/ui/AlbumView.java +++ b/src/com/android/gallery3d/ui/AlbumView.java @@ -16,12 +16,14 @@ package com.android.gallery3d.ui; -import android.util.FloatMath; +import android.content.Context; import com.android.gallery3d.app.GalleryActivity; import com.android.gallery3d.data.MediaItem; +import com.android.gallery3d.data.MediaObject; +import com.android.gallery3d.data.Path; -public class AlbumView implements SlotView.SlotRenderer { +public class AlbumView extends AbstractSlotRenderer { private static final int PLACEHOLDER_COLOR = 0xFF222222; @SuppressWarnings("unused") @@ -32,9 +34,11 @@ public class AlbumView implements SlotView.SlotRenderer { private final GalleryActivity mActivity; private final ColorTexture mWaitLoadingTexture; private final SlotView mSlotView; + private final SelectionManager mSelectionManager; - private SelectionDrawer mSelectionDrawer; - private int mFocusIndex = -1; + private int mPressedIndex = -1; + private Path mHighlightItemPath = null; + private boolean mInSelectionMode; public static interface Model { public int size(); @@ -48,16 +52,27 @@ public class AlbumView implements SlotView.SlotRenderer { public void onSizeChanged(int size); } - public AlbumView(GalleryActivity activity, SlotView slotView) { - mSlotView = slotView; + public AlbumView(GalleryActivity activity, SlotView slotView, + SelectionManager selectionManager) { + super((Context) activity); mActivity = activity; + mSlotView = slotView; + mSelectionManager = selectionManager; mWaitLoadingTexture = new ColorTexture(PLACEHOLDER_COLOR); mWaitLoadingTexture.setSize(1, 1); } - public void setSelectionDrawer(SelectionDrawer drawer) { - mSelectionDrawer = drawer; + public void setPressedIndex(int index) { + if (mPressedIndex == index) return; + mPressedIndex = index; + mSlotView.invalidate(); + } + + public void setHighlightItemPath(Path path) { + if (mHighlightItemPath == path) return; + mHighlightItemPath = path; + mSlotView.invalidate(); } public void setModel(Model model) { @@ -73,12 +88,6 @@ public class AlbumView implements SlotView.SlotRenderer { } } - public void setFocusIndex(int slotIndex) { - if (mFocusIndex == slotIndex) return; - mFocusIndex = slotIndex; - mSlotView.invalidate(); - } - private static Texture checkTexture(GLCanvas canvas, Texture texture) { return ((texture == null) || ((texture instanceof UploadedTexture) && !((UploadedTexture) texture).isContentValid(canvas))) @@ -89,8 +98,10 @@ public class AlbumView implements SlotView.SlotRenderer { @Override public int renderSlot(GLCanvas canvas, int index, int pass, int width, int height) { AlbumSlidingWindow.AlbumEntry entry = mDataWindow.get(index); - Texture content = checkTexture(canvas, entry.content); + int renderRequestFlags = 0; + + Texture content = checkTexture(canvas, entry.content); if (content == null) { content = mWaitLoadingTexture; entry.isWaitDisplayed = true; @@ -100,37 +111,29 @@ public class AlbumView implements SlotView.SlotRenderer { PLACEHOLDER_COLOR, (BitmapTexture) entry.content); content = entry.content; } + drawContent(canvas, content, width, height, entry.rotation); + if ((content instanceof FadeInTexture) && + ((FadeInTexture) content).isAnimating()) { + renderRequestFlags |= SlotView.RENDER_MORE_FRAME; + } - // Fit the content into the box - int w = content.getWidth(); - int h = content.getHeight(); - - float scale = Math.min((float) width / w, (float) height / h); - - w = (int) FloatMath.floor(w * scale); - h = (int) FloatMath.floor(h * scale); - - // Now draw it - if (pass == 0) { - canvas.translate(width / 2, height / 2); - mSelectionDrawer.draw(canvas, content, w, h, - entry.rotation, entry.path, entry.mediaType, entry.isPanorama); - canvas.translate(-width / 2, -height / 2); - int result = 0; - if (mFocusIndex == index) { - result |= SlotView.RENDER_MORE_PASS; - } - if ((content instanceof FadeInTexture) && - ((FadeInTexture) content).isAnimating()) { - result |= SlotView.RENDER_MORE_FRAME; - } - return result; - } else if (pass == 1) { - canvas.translate(width / 2, height / 2); - mSelectionDrawer.drawFocus(canvas, width, height); - canvas.translate(-width / 2, -height / 2); + if (entry.mediaType == MediaObject.MEDIA_TYPE_VIDEO) { + drawVideoOverlay(canvas, width, height); } - return 0; + + if (entry.isPanorama) { + drawPanoramaBorder(canvas, width, height); + } + + if (mPressedIndex == index) { + drawPressedFrame(canvas, width, height); + } else if ((entry.path != null) && (mHighlightItemPath == entry.path)) { + drawSelectedFrame(canvas, width, height); + } else if (mInSelectionMode && mSelectionManager.isItemSelected(entry.path)) { + drawSelectedFrame(canvas, width, height); + } + + return renderRequestFlags; } private class MyDataModelListener implements AlbumSlidingWindow.Listener { @@ -155,7 +158,7 @@ public class AlbumView implements SlotView.SlotRenderer { @Override public void prepareDrawing() { - mSelectionDrawer.prepareDrawing(); + mInSelectionMode = mSelectionManager.inSelectionMode(); } @Override diff --git a/src/com/android/gallery3d/ui/GridDrawer.java b/src/com/android/gallery3d/ui/GridDrawer.java deleted file mode 100644 index c5e921e8c..000000000 --- a/src/com/android/gallery3d/ui/GridDrawer.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.ui; - -import android.content.Context; -import android.graphics.Color; -import android.text.Layout; - -import com.android.gallery3d.R; -import com.android.gallery3d.data.Path; - -public class GridDrawer extends IconDrawer { - private Texture mImportLabel; - private int mGridWidth; - private final SelectionManager mSelectionManager; - private final Context mContext; - private final int IMPORT_FONT_SIZE = 14; - private final int IMPORT_FONT_COLOR = Color.WHITE; - private final int IMPORT_LABEL_MARGIN = 10; - private boolean mSelectionMode; - - public GridDrawer(Context context, SelectionManager selectionManager) { - super(context); - mContext = context; - mSelectionManager = selectionManager; - } - - @Override - public void prepareDrawing() { - mSelectionMode = mSelectionManager.inSelectionMode(); - } - - @Override - public void draw(GLCanvas canvas, Texture content, int width, - int height, int rotation, Path path, - int dataSourceType, int mediaType, boolean isPanorama, - int labelBackgroundHeight, boolean wantCache, boolean isCaching) { - - int x = -width / 2; - int y = -height / 2; - - drawWithRotation(canvas, content, x, y, width, height, rotation); - - if (((rotation / 90) & 0x01) == 1) { - int temp = width; - width = height; - height = temp; - x = -width / 2; - y = -height / 2; - } - - drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); - - if (dataSourceType == DATASOURCE_TYPE_MTP) { - drawImportLabel(canvas, width, height); - } - - if (mSelectionManager.isPressedPath(path)) { - drawPressedFrame(canvas, x, y, width, height); - } else if (mSelectionMode && mSelectionManager.isItemSelected(path)) { - drawSelectedFrame(canvas, x, y, width, height); - } - } - - // Draws the "click to import" label at the center of the frame - private void drawImportLabel(GLCanvas canvas, int width, int height) { - if (mImportLabel == null || mGridWidth != width) { - mGridWidth = width; - mImportLabel = MultiLineTexture.newInstance( - mContext.getString(R.string.click_import), - width - 2 * IMPORT_LABEL_MARGIN, - IMPORT_FONT_SIZE, IMPORT_FONT_COLOR, - Layout.Alignment.ALIGN_CENTER); - } - int w = mImportLabel.getWidth(); - int h = mImportLabel.getHeight(); - mImportLabel.draw(canvas, -w / 2, -h / 2); - } - - @Override - public void drawFocus(GLCanvas canvas, int width, int height) { - } -} diff --git a/src/com/android/gallery3d/ui/HighlightDrawer.java b/src/com/android/gallery3d/ui/HighlightDrawer.java deleted file mode 100644 index 65afd1814..000000000 --- a/src/com/android/gallery3d/ui/HighlightDrawer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.ui; - -import android.content.Context; - -import com.android.gallery3d.data.Path; - -public class HighlightDrawer extends IconDrawer { - private SelectionManager mSelectionManager; - private Path mHighlightItem; - - public HighlightDrawer(Context context, SelectionManager selectionManager) { - super(context); - mSelectionManager = selectionManager; - } - - public void setHighlightItem(Path item) { - mHighlightItem = item; - } - - @Override - public void draw(GLCanvas canvas, Texture content, int width, - int height, int rotation, Path path, - int dataSourceType, int mediaType, boolean isPanorama, - int labelBackgroundHeight, boolean wantCache, boolean isCaching) { - int x = -width / 2; - int y = -height / 2; - - drawWithRotation(canvas, content, x, y, width, height, rotation); - - if (((rotation / 90) & 0x01) == 1) { - int temp = width; - width = height; - height = temp; - x = -width / 2; - y = -height / 2; - } - - drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); - - if (mSelectionManager.isPressedPath(path)) { - drawPressedFrame(canvas, x, y, width, height); - } else if (path == mHighlightItem) { - drawSelectedFrame(canvas, x, y, width, height); - } - } -} diff --git a/src/com/android/gallery3d/ui/IconDrawer.java b/src/com/android/gallery3d/ui/IconDrawer.java deleted file mode 100644 index dffcbfdd1..000000000 --- a/src/com/android/gallery3d/ui/IconDrawer.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.ui; - -import android.content.Context; - -import com.android.gallery3d.R; -import com.android.gallery3d.data.MediaObject; - -public abstract class IconDrawer extends SelectionDrawer { - private static final String TAG = "IconDrawer"; - - private final NinePatchTexture mFramePressed; - private final NinePatchTexture mFrameSelected; - private final NinePatchTexture mDarkStrip; - private final NinePatchTexture mPanoramaBorder; - private final Texture mVideoOverlay; - private final Texture mVideoPlayIcon; - - public static class IconDimension { - int x; - int y; - int width; - int height; - } - - public IconDrawer(Context context) { - mVideoOverlay = new ResourceTexture(context, R.drawable.ic_video_thumb); - mVideoPlayIcon = new ResourceTexture(context, R.drawable.ic_gallery_play); - mPanoramaBorder = new NinePatchTexture(context, R.drawable.ic_pan_thumb); - mFramePressed = new NinePatchTexture(context, R.drawable.grid_pressed); - mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected); - mDarkStrip = new NinePatchTexture(context, R.drawable.dark_strip); - } - - @Override - public void prepareDrawing() { - } - - protected void drawMediaTypeOverlay(GLCanvas canvas, int mediaType, - boolean isPanorama, int x, int y, int width, int height) { - if (mediaType == MediaObject.MEDIA_TYPE_VIDEO) { - drawVideoOverlay(canvas, x, y, width, height); - } - if (isPanorama) { - drawPanoramaBorder(canvas, x, y, width, height); - } - } - - protected void drawVideoOverlay(GLCanvas canvas, int x, int y, - int width, int height) { - // Scale the video overlay to the height of the thumbnail and put it - // on the left side. - float scale = (float) height / mVideoOverlay.getHeight(); - int w = Math.round(scale * mVideoOverlay.getWidth()); - int h = Math.round(scale * mVideoOverlay.getHeight()); - mVideoOverlay.draw(canvas, x, y, w, h); - - int side = Math.min(width, height) / 6; - mVideoPlayIcon.draw(canvas, -side / 2, -side / 2, side, side); - } - - protected void drawPanoramaBorder(GLCanvas canvas, int x, int y, - int width, int height) { - float scale = (float) width / mPanoramaBorder.getWidth(); - int w = Math.round(scale * mPanoramaBorder.getWidth()); - int h = Math.round(scale * mPanoramaBorder.getHeight()); - // draw at the top - mPanoramaBorder.draw(canvas, x, y, w, h); - // draw at the bottom - mPanoramaBorder.draw(canvas, x, y + width - h, w, h); - } - - protected void drawLabelBackground(GLCanvas canvas, int width, int height, - int drawLabelBackground) { - int x = -width / 2; - int y = (height + 1) / 2 - drawLabelBackground; - drawFrame(canvas, mDarkStrip, x, y, width, drawLabelBackground); - } - - protected void drawPressedFrame(GLCanvas canvas, int x, int y, int width, - int height) { - drawFrame(canvas, mFramePressed, x, y, width, height); - } - - protected void drawSelectedFrame(GLCanvas canvas, int x, int y, int width, - int height) { - drawFrame(canvas, mFrameSelected, x, y, width, height); - } - - @Override - public void drawFocus(GLCanvas canvas, int width, int height) { - } -} diff --git a/src/com/android/gallery3d/ui/ManageCacheDrawer.java b/src/com/android/gallery3d/ui/ManageCacheDrawer.java index 208c527da..d6495e8e9 100644 --- a/src/com/android/gallery3d/ui/ManageCacheDrawer.java +++ b/src/com/android/gallery3d/ui/ManageCacheDrawer.java @@ -19,9 +19,13 @@ package com.android.gallery3d.ui; import android.content.Context; import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryActivity; +import com.android.gallery3d.data.DataSourceType; +import com.android.gallery3d.data.MediaSet; import com.android.gallery3d.data.Path; +import com.android.gallery3d.ui.AlbumSetSlidingWindow.AlbumSetEntry; -public class ManageCacheDrawer extends IconDrawer { +public class ManageCacheDrawer extends AlbumSetView { private final ResourceTexture mCheckedItem; private final ResourceTexture mUnCheckedItem; private final SelectionManager mSelectionManager; @@ -32,12 +36,16 @@ public class ManageCacheDrawer extends IconDrawer { private final int mCachePinSize; private final int mCachePinMargin; - public ManageCacheDrawer(Context context, SelectionManager selectionManager, - int cachePinSize, int cachePinMargin) { - super(context); - mCheckedItem = new ResourceTexture(context, R.drawable.btn_make_offline_normal_on_holo_dark); - mUnCheckedItem = new ResourceTexture(context, R.drawable.btn_make_offline_normal_off_holo_dark); - mLocalAlbumIcon = new ResourceTexture(context, R.drawable.btn_make_offline_disabled_on_holo_dark); + public ManageCacheDrawer(GalleryActivity activity, SelectionManager selectionManager, + SlotView slotView, LabelSpec labelSpec, int cachePinSize, int cachePinMargin) { + super(activity, selectionManager, slotView, labelSpec); + Context context = (Context) activity; + mCheckedItem = new ResourceTexture( + context, R.drawable.btn_make_offline_normal_on_holo_dark); + mUnCheckedItem = new ResourceTexture( + context, R.drawable.btn_make_offline_normal_off_holo_dark); + mLocalAlbumIcon = new ResourceTexture( + context, R.drawable.btn_make_offline_disabled_on_holo_dark); String cachingLabel = context.getString(R.string.caching_label); mCachingText = StringTexture.newInstance(cachingLabel, 12, 0xffffffff); mSelectionManager = selectionManager; @@ -45,59 +53,42 @@ public class ManageCacheDrawer extends IconDrawer { mCachePinMargin = cachePinMargin; } - @Override - public void prepareDrawing() { - } - private static boolean isLocal(int dataSourceType) { - return dataSourceType != DATASOURCE_TYPE_PICASA; + return dataSourceType != DataSourceType.TYPE_PICASA; } @Override - public void draw(GLCanvas canvas, Texture content, int width, - int height, int rotation, Path path, - int dataSourceType, int mediaType, boolean isPanorama, - int labelBackgroundHeight, boolean wantCache, boolean isCaching) { + public int renderSlot(GLCanvas canvas, int index, int pass, int width, int height) { + AlbumSetEntry entry = mDataWindow.get(index); - boolean selected = mSelectionManager.isItemSelected(path); + boolean wantCache = entry.cacheFlag == MediaSet.CACHE_FLAG_FULL; + boolean isCaching = wantCache && ( + entry.cacheStatus != MediaSet.CACHE_STATUS_CACHED_FULL); + boolean selected = mSelectionManager.isItemSelected(entry.setPath); boolean chooseToCache = wantCache ^ selected; - boolean available = isLocal(dataSourceType) || chooseToCache; + boolean available = isLocal(entry.sourceType) || chooseToCache; - int x = -width / 2; - int y = -height / 2; + int renderRequestFlags = 0; if (!available) { canvas.save(GLCanvas.SAVE_FLAG_ALPHA); canvas.multiplyAlpha(0.6f); } + renderRequestFlags |= renderContent(canvas, entry, width, height); + if (!available) canvas.restore(); - drawWithRotation(canvas, content, x, y, width, height, rotation); - - if (!available) { - canvas.restore(); - } - - if (((rotation / 90) & 0x01) == 1) { - int temp = width; - width = height; - height = temp; - x = -width / 2; - y = -height / 2; - } + renderRequestFlags |= renderLabel(canvas, entry, width, height); - drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); - drawCachingPin(canvas, path, dataSourceType, isCaching, chooseToCache, - width, height); + drawCachingPin(canvas, entry.setPath, + entry.sourceType, isCaching, chooseToCache, width, height); - if (mSelectionManager.isPressedPath(path)) { - drawPressedFrame(canvas, x, y, width, height); - } + renderRequestFlags |= renderOverlay(canvas, index, entry, width, height); + return renderRequestFlags; } private void drawCachingPin(GLCanvas canvas, Path path, int dataSourceType, boolean isCaching, boolean chooseToCache, int width, int height) { - - ResourceTexture icon = null; + ResourceTexture icon; if (isLocal(dataSourceType)) { icon = mLocalAlbumIcon; } else if (chooseToCache) { @@ -106,26 +97,16 @@ public class ManageCacheDrawer extends IconDrawer { icon = mUnCheckedItem; } - int w = mCachePinSize; - int h = mCachePinSize; - int right = (width + 1) / 2; - int bottom = (height + 1) / 2; - int x = right - w - mCachePinMargin; - int y = bottom - h - mCachePinMargin; - - icon.draw(canvas, x, y, w, h); + // show the icon in right bottom + int s = mCachePinSize; + int m = mCachePinMargin; + icon.draw(canvas, width - m - s, height - s, s, s); if (isCaching) { - int textWidth = mCachingText.getWidth(); - int textHeight = mCachingText.getHeight(); - // Align the center of the text to the center of the pin icon - x = right - mCachePinMargin - (textWidth + mCachePinSize) / 2; - y = bottom - textHeight; - mCachingText.draw(canvas, x, y); + int w = mCachingText.getWidth(); + int h = mCachingText.getHeight(); + // Show the caching text in bottom center + mCachingText.draw(canvas, (width - w) / 2, height - h); } } - - @Override - public void drawFocus(GLCanvas canvas, int width, int height) { - } } diff --git a/src/com/android/gallery3d/ui/SelectionDrawer.java b/src/com/android/gallery3d/ui/SelectionDrawer.java deleted file mode 100644 index e69a90282..000000000 --- a/src/com/android/gallery3d/ui/SelectionDrawer.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.ui; - -import android.graphics.Rect; - -import com.android.gallery3d.data.Path; - -/** - * Drawer class responsible for drawing selectable frame. - */ -public abstract class SelectionDrawer { - public static final int DATASOURCE_TYPE_NOT_CATEGORIZED = 0; - public static final int DATASOURCE_TYPE_LOCAL = 1; - public static final int DATASOURCE_TYPE_PICASA = 2; - public static final int DATASOURCE_TYPE_MTP = 3; - public static final int DATASOURCE_TYPE_CAMERA = 4; - - public abstract void prepareDrawing(); - public abstract void draw(GLCanvas canvas, Texture content, - int width, int height, int rotation, Path path, - int dataSourceType, int mediaType, boolean isPanorama, - int labelBackgroundHeight, boolean wantCache, boolean isCaching); - public abstract void drawFocus(GLCanvas canvas, int width, int height); - - public void draw(GLCanvas canvas, Texture content, int width, int height, - int rotation, Path path, int mediaType, boolean isPanorama) { - draw(canvas, content, width, height, rotation, path, - DATASOURCE_TYPE_NOT_CATEGORIZED, mediaType, isPanorama, - 0, false, false); - } - - public static void drawWithRotation(GLCanvas canvas, Texture content, - int x, int y, int width, int height, int rotation) { - if (rotation != 0) { - canvas.save(GLCanvas.SAVE_FLAG_MATRIX); - canvas.rotate(rotation, 0, 0, 1); - } - - content.draw(canvas, x, y, width, height); - - if (rotation != 0) { - canvas.restore(); - } - } - - public static void drawFrame(GLCanvas canvas, NinePatchTexture frame, - int x, int y, int width, int height) { - Rect p = frame.getPaddings(); - frame.draw(canvas, x - p.left, y - p.top, width + p.left + p.right, - height + p.top + p.bottom); - } -} diff --git a/src/com/android/gallery3d/ui/SelectionManager.java b/src/com/android/gallery3d/ui/SelectionManager.java index f695372fd..1783b1111 100644 --- a/src/com/android/gallery3d/ui/SelectionManager.java +++ b/src/com/android/gallery3d/ui/SelectionManager.java @@ -43,7 +43,6 @@ public class SelectionManager { private boolean mInSelectionMode; private boolean mAutoLeave = true; private int mTotal; - private Path mPressedPath; public interface SelectionListener { public void onSelectionModeChange(int mode); @@ -135,14 +134,6 @@ public class SelectionManager { } } - public void setPressedPath(Path path) { - mPressedPath = path; - } - - public boolean isPressedPath(Path path) { - return path != null && path == mPressedPath; - } - private static void expandMediaSet(ArrayList items, MediaSet set) { int subCount = set.getSubMediaSetCount(); for (int i = 0; i < subCount; i++) {