diff options
author | Chih-Chung Chang <chihchung@google.com> | 2011-09-16 01:21:04 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-09-16 01:21:04 -0700 |
commit | e7117abd9e9b3d5d9616c5387c4ad6402d4a1a58 (patch) | |
tree | be9a1bf78fb9414f594a5611fdb50184af517ca4 | |
parent | cc1621240b297bf0790ba7e375615693220b596c (diff) | |
parent | 9201679ed1c485767f2e334aa618bd733024af03 (diff) | |
download | android_packages_apps_Gallery2-e7117abd9e9b3d5d9616c5387c4ad6402d4a1a58.tar.gz android_packages_apps_Gallery2-e7117abd9e9b3d5d9616c5387c4ad6402d4a1a58.tar.bz2 android_packages_apps_Gallery2-e7117abd9e9b3d5d9616c5387c4ad6402d4a1a58.zip |
Merge "New UI for Gallery."
55 files changed, 339 insertions, 242 deletions
diff --git a/res/drawable-hdpi/album_frame.9.png b/res/drawable-hdpi/album_frame.9.png Binary files differdeleted file mode 100644 index 3a456ceb8..000000000 --- a/res/drawable-hdpi/album_frame.9.png +++ /dev/null diff --git a/res/drawable-hdpi/frame_overlay_gallery_camera.png b/res/drawable-hdpi/frame_overlay_gallery_camera.png Binary files differnew file mode 100644 index 000000000..895de5f8e --- /dev/null +++ b/res/drawable-hdpi/frame_overlay_gallery_camera.png diff --git a/res/drawable-hdpi/frame_overlay_gallery_folder.png b/res/drawable-hdpi/frame_overlay_gallery_folder.png Binary files differnew file mode 100644 index 000000000..c5f9490a2 --- /dev/null +++ b/res/drawable-hdpi/frame_overlay_gallery_folder.png diff --git a/res/drawable-hdpi/frame_overlay_gallery_picasa.png b/res/drawable-hdpi/frame_overlay_gallery_picasa.png Binary files differnew file mode 100644 index 000000000..b6d78a176 --- /dev/null +++ b/res/drawable-hdpi/frame_overlay_gallery_picasa.png diff --git a/res/drawable-hdpi/grid_selected.9.png b/res/drawable-hdpi/grid_selected.9.png Binary files differindex 4211b5e28..c8eac675f 100644 --- a/res/drawable-hdpi/grid_selected.9.png +++ b/res/drawable-hdpi/grid_selected.9.png diff --git a/res/drawable-hdpi/grid_selected_top.9.png b/res/drawable-hdpi/grid_selected_top.9.png Binary files differdeleted file mode 100644 index 1ed629702..000000000 --- a/res/drawable-hdpi/grid_selected_top.9.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_album_overlay_camera_holo.png b/res/drawable-hdpi/ic_album_overlay_camera_holo.png Binary files differdeleted file mode 100644 index 189aa3d37..000000000 --- a/res/drawable-hdpi/ic_album_overlay_camera_holo.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_album_overlay_folder_holo.png b/res/drawable-hdpi/ic_album_overlay_folder_holo.png Binary files differdeleted file mode 100644 index 469b22225..000000000 --- a/res/drawable-hdpi/ic_album_overlay_folder_holo.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_album_overlay_picassa_holo.png b/res/drawable-hdpi/ic_album_overlay_picassa_holo.png Binary files differdeleted file mode 100644 index 7cdf8e4ec..000000000 --- a/res/drawable-hdpi/ic_album_overlay_picassa_holo.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_gallery_play.png b/res/drawable-hdpi/ic_gallery_play.png Binary files differnew file mode 100644 index 000000000..e475e1fc0 --- /dev/null +++ b/res/drawable-hdpi/ic_gallery_play.png diff --git a/res/drawable-hdpi/ic_pan_thumb.png b/res/drawable-hdpi/ic_pan_thumb.png Binary files differnew file mode 100644 index 000000000..937d4a800 --- /dev/null +++ b/res/drawable-hdpi/ic_pan_thumb.png diff --git a/res/drawable-hdpi/ic_video_thumb.png b/res/drawable-hdpi/ic_video_thumb.png Binary files differnew file mode 100644 index 000000000..69f904781 --- /dev/null +++ b/res/drawable-hdpi/ic_video_thumb.png diff --git a/res/drawable-hdpi/import_translucent.9.png b/res/drawable-hdpi/import_translucent.9.png Binary files differdeleted file mode 100644 index cb3152ba6..000000000 --- a/res/drawable-hdpi/import_translucent.9.png +++ /dev/null diff --git a/res/drawable-hdpi/manage_frame.9.png b/res/drawable-hdpi/manage_frame.9.png Binary files differdeleted file mode 100644 index 879c47ba1..000000000 --- a/res/drawable-hdpi/manage_frame.9.png +++ /dev/null diff --git a/res/drawable-hdpi/thumbnail_album_video_overlay_holo.png b/res/drawable-hdpi/thumbnail_album_video_overlay_holo.png Binary files differdeleted file mode 100644 index 567a69aaa..000000000 --- a/res/drawable-hdpi/thumbnail_album_video_overlay_holo.png +++ /dev/null diff --git a/res/drawable-hdpi/videooverlay.png b/res/drawable-hdpi/videooverlay.png Binary files differdeleted file mode 100644 index 17188323d..000000000 --- a/res/drawable-hdpi/videooverlay.png +++ /dev/null diff --git a/res/drawable-mdpi/album_frame.9.png b/res/drawable-mdpi/album_frame.9.png Binary files differdeleted file mode 100644 index 3a456ceb8..000000000 --- a/res/drawable-mdpi/album_frame.9.png +++ /dev/null diff --git a/res/drawable-mdpi/frame_overlay_gallery_camera.png b/res/drawable-mdpi/frame_overlay_gallery_camera.png Binary files differnew file mode 100644 index 000000000..9e7105331 --- /dev/null +++ b/res/drawable-mdpi/frame_overlay_gallery_camera.png diff --git a/res/drawable-mdpi/frame_overlay_gallery_folder.png b/res/drawable-mdpi/frame_overlay_gallery_folder.png Binary files differnew file mode 100644 index 000000000..99873f97b --- /dev/null +++ b/res/drawable-mdpi/frame_overlay_gallery_folder.png diff --git a/res/drawable-mdpi/frame_overlay_gallery_picasa.png b/res/drawable-mdpi/frame_overlay_gallery_picasa.png Binary files differnew file mode 100644 index 000000000..20b7b5c7f --- /dev/null +++ b/res/drawable-mdpi/frame_overlay_gallery_picasa.png diff --git a/res/drawable-mdpi/grid_selected.9.png b/res/drawable-mdpi/grid_selected.9.png Binary files differindex 4211b5e28..ca8943ae0 100644 --- a/res/drawable-mdpi/grid_selected.9.png +++ b/res/drawable-mdpi/grid_selected.9.png diff --git a/res/drawable-mdpi/grid_selected_top.9.png b/res/drawable-mdpi/grid_selected_top.9.png Binary files differdeleted file mode 100644 index 1ed629702..000000000 --- a/res/drawable-mdpi/grid_selected_top.9.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_album_overlay_camera_holo.png b/res/drawable-mdpi/ic_album_overlay_camera_holo.png Binary files differdeleted file mode 100644 index 15bdedfac..000000000 --- a/res/drawable-mdpi/ic_album_overlay_camera_holo.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_album_overlay_folder_holo.png b/res/drawable-mdpi/ic_album_overlay_folder_holo.png Binary files differdeleted file mode 100644 index 99b208837..000000000 --- a/res/drawable-mdpi/ic_album_overlay_folder_holo.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_album_overlay_picassa_holo.png b/res/drawable-mdpi/ic_album_overlay_picassa_holo.png Binary files differdeleted file mode 100644 index 8e1e43272..000000000 --- a/res/drawable-mdpi/ic_album_overlay_picassa_holo.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_gallery_play.png b/res/drawable-mdpi/ic_gallery_play.png Binary files differnew file mode 100644 index 000000000..183d75e9a --- /dev/null +++ b/res/drawable-mdpi/ic_gallery_play.png diff --git a/res/drawable-mdpi/ic_pan_thumb.png b/res/drawable-mdpi/ic_pan_thumb.png Binary files differnew file mode 100644 index 000000000..893386ee5 --- /dev/null +++ b/res/drawable-mdpi/ic_pan_thumb.png diff --git a/res/drawable-mdpi/ic_video_thumb.png b/res/drawable-mdpi/ic_video_thumb.png Binary files differnew file mode 100644 index 000000000..f32917565 --- /dev/null +++ b/res/drawable-mdpi/ic_video_thumb.png diff --git a/res/drawable-mdpi/import_translucent.9.png b/res/drawable-mdpi/import_translucent.9.png Binary files differdeleted file mode 100644 index 94a14aebe..000000000 --- a/res/drawable-mdpi/import_translucent.9.png +++ /dev/null diff --git a/res/drawable-mdpi/manage_frame.9.png b/res/drawable-mdpi/manage_frame.9.png Binary files differdeleted file mode 100644 index 879c47ba1..000000000 --- a/res/drawable-mdpi/manage_frame.9.png +++ /dev/null diff --git a/res/drawable-mdpi/thumbnail_album_video_overlay_holo.png b/res/drawable-mdpi/thumbnail_album_video_overlay_holo.png Binary files differdeleted file mode 100644 index a4541c145..000000000 --- a/res/drawable-mdpi/thumbnail_album_video_overlay_holo.png +++ /dev/null diff --git a/res/drawable-mdpi/videooverlay.png b/res/drawable-mdpi/videooverlay.png Binary files differdeleted file mode 100644 index 8b39eed6f..000000000 --- a/res/drawable-mdpi/videooverlay.png +++ /dev/null diff --git a/res/values-xlarge/dimensions.xml b/res/values-xlarge/dimensions.xml index 4ead09c71..a0160549f 100644 --- a/res/values-xlarge/dimensions.xml +++ b/res/values-xlarge/dimensions.xml @@ -20,16 +20,14 @@ <dimen name="stack_photo_height">190dp</dimen> <!-- configuration for album set page --> - <dimen name="albumset_display_item_size">144dp</dimen> - <dimen name="albumset_slot_width">220dp</dimen> - <dimen name="albumset_slot_height">220dp</dimen> - <dimen name="albumset_label_font_size">14dp</dimen> - <dimen name="albumset_label_offset_y">110dp</dimen> + <integer name="albumset_rows_land">3</integer> + <integer name="albumset_rows_port">5</integer> + <dimen name="albumset_slot_gap">1dp</dimen> <!-- configuration for album page --> - <dimen name="album_display_item_size">176dp</dimen> - <dimen name="album_slot_width">192dp</dimen> - <dimen name="album_slot_height">192dp</dimen> + <integer name="album_rows_land">3</integer> + <integer name="album_rows_port">5</integer> + <dimen name="album_slot_gap">1dp</dimen> <!-- configuration for manage page --> <dimen name="cache_bar_height">48dp</dimen> diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml index 90c3064d7..7cbd87506 100644 --- a/res/values/dimensions.xml +++ b/res/values/dimensions.xml @@ -20,17 +20,22 @@ <dimen name="stack_photo_height">110dp</dimen> <!-- configuration for album set page --> - <dimen name="albumset_display_item_size">80dp</dimen> - <dimen name="albumset_slot_width">135dp</dimen> - <dimen name="albumset_slot_height">135dp</dimen> - <dimen name="albumset_label_font_size">11dp</dimen> - <dimen name="albumset_label_offset_y">70dp</dimen> - <dimen name="albumset_label_margin">10dp</dimen> + <integer name="albumset_rows_land">2</integer> + <integer name="albumset_rows_port">4</integer> + <dimen name="albumset_slot_gap">1dp</dimen> + + <dimen name="albumset_dark_strip_height">40dp</dimen> + <dimen name="albumset_title_offset">3dp</dimen> + <dimen name="albumset_number_offset">4dp</dimen> + <dimen name="albumset_title_font_size">14sp</dimen> + <dimen name="albumset_number_font_size">12sp</dimen> + <dimen name="albumset_left_margin">6dp</dimen> + <dimen name="albumset_icon_size">26dp</dimen> <!-- configuration for album page --> - <dimen name="album_display_item_size">108dp</dimen> - <dimen name="album_slot_width">122dp</dimen> - <dimen name="album_slot_height">122dp</dimen> + <integer name="album_rows_land">2</integer> + <integer name="album_rows_port">4</integer> + <dimen name="album_slot_gap">1dp</dimen> <!-- configuration for manage page --> <dimen name="cache_bar_height">32dp</dimen> diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 672c0da99..7d7054897 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -357,8 +357,8 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster mSelectionManager.setSelectionListener(this); mGridDrawer = new GridDrawer((Context) mActivity, mSelectionManager); Config.AlbumPage config = Config.AlbumPage.get((Context) mActivity); - mAlbumView = new AlbumView(mActivity, - config.slotWidth, config.slotHeight, config.displayItemSize); + mAlbumView = new AlbumView(mActivity, config.slotViewSpec, + 0 /* don't cache thumbnail */); mAlbumView.setSelectionDrawer(mGridDrawer); mRootPane.addComponent(mAlbumView); mAlbumView.setListener(new SlotView.SimpleListener() { diff --git a/src/com/android/gallery3d/app/AlbumSetDataAdapter.java b/src/com/android/gallery3d/app/AlbumSetDataAdapter.java index 85f3bf532..8322d2b19 100644 --- a/src/com/android/gallery3d/app/AlbumSetDataAdapter.java +++ b/src/com/android/gallery3d/app/AlbumSetDataAdapter.java @@ -41,7 +41,7 @@ public class AlbumSetDataAdapter implements AlbumSetView.Model { private static final int INDEX_NONE = -1; private static final int MIN_LOAD_COUNT = 4; - private static final int MAX_COVER_COUNT = 4; + private static final int MAX_COVER_COUNT = 1; private static final int MSG_LOAD_START = 1; private static final int MSG_LOAD_FINISH = 2; diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index 097057293..b9f7a1a20 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -313,9 +313,7 @@ public class AlbumSetPage extends ActivityState implements mGridDrawer = new GridDrawer((Context) mActivity, mSelectionManager); Config.AlbumSetPage config = Config.AlbumSetPage.get((Context) mActivity); mAlbumSetView = new AlbumSetView(mActivity, mGridDrawer, - config.slotWidth, config.slotHeight, - config.displayItemSize, config.labelFontSize, - config.labelOffsetY, config.labelMargin); + config.slotViewSpec, config.labelSpec); mAlbumSetView.setListener(new SlotView.SimpleListener() { @Override public void onSingleTapUp(int slotIndex) { diff --git a/src/com/android/gallery3d/app/Config.java b/src/com/android/gallery3d/app/Config.java index 4586235f6..0cea6c852 100644 --- a/src/com/android/gallery3d/app/Config.java +++ b/src/com/android/gallery3d/app/Config.java @@ -17,6 +17,8 @@ package com.android.gallery3d.app; import com.android.gallery3d.R; +import com.android.gallery3d.ui.SlotView; +import com.android.gallery3d.ui.AlbumSetView; import android.content.Context; import android.content.res.Resources; @@ -25,12 +27,8 @@ final class Config { public static class AlbumSetPage { private static AlbumSetPage sInstance; - public final int slotWidth; - public final int slotHeight; - public final int displayItemSize; - public final int labelFontSize; - public final int labelOffsetY; - public final int labelMargin; + public SlotView.Spec slotViewSpec; + public AlbumSetView.LabelSpec labelSpec; public static synchronized AlbumSetPage get(Context context) { if (sInstance == null) { @@ -41,21 +39,34 @@ final class Config { private AlbumSetPage(Context context) { Resources r = context.getResources(); - slotWidth = r.getDimensionPixelSize(R.dimen.albumset_slot_width); - slotHeight = r.getDimensionPixelSize(R.dimen.albumset_slot_height); - displayItemSize = r.getDimensionPixelSize(R.dimen.albumset_display_item_size); - labelFontSize = r.getDimensionPixelSize(R.dimen.albumset_label_font_size); - labelOffsetY = r.getDimensionPixelSize(R.dimen.albumset_label_offset_y); - labelMargin = r.getDimensionPixelSize(R.dimen.albumset_label_margin); + + slotViewSpec = new SlotView.Spec(); + slotViewSpec.rowsLand = r.getInteger(R.integer.albumset_rows_land); + slotViewSpec.rowsPort = r.getInteger(R.integer.albumset_rows_port); + slotViewSpec.slotGap = r.getDimensionPixelSize(R.dimen.albumset_slot_gap); + + labelSpec = new AlbumSetView.LabelSpec(); + labelSpec.darkStripHeight = r.getDimensionPixelSize( + R.dimen.albumset_dark_strip_height); + labelSpec.titleOffset = r.getDimensionPixelSize( + R.dimen.albumset_title_offset); + labelSpec.numberOffset = r.getDimensionPixelSize( + R.dimen.albumset_number_offset); + labelSpec.titleFontSize = r.getDimensionPixelSize( + R.dimen.albumset_title_font_size); + labelSpec.numberFontSize = r.getDimensionPixelSize( + R.dimen.albumset_number_font_size); + labelSpec.leftMargin = r.getDimensionPixelSize( + R.dimen.albumset_left_margin); + labelSpec.iconSize = r.getDimensionPixelSize( + R.dimen.albumset_icon_size); } } public static class AlbumPage { private static AlbumPage sInstance; - public final int slotWidth; - public final int slotHeight; - public final int displayItemSize; + public SlotView.Spec slotViewSpec; public static synchronized AlbumPage get(Context context) { if (sInstance == null) { @@ -66,9 +77,11 @@ final class Config { private AlbumPage(Context context) { Resources r = context.getResources(); - slotWidth = r.getDimensionPixelSize(R.dimen.album_slot_width); - slotHeight = r.getDimensionPixelSize(R.dimen.album_slot_height); - displayItemSize = r.getDimensionPixelSize(R.dimen.album_display_item_size); + + slotViewSpec = new SlotView.Spec(); + slotViewSpec.rowsLand = r.getInteger(R.integer.album_rows_land); + slotViewSpec.rowsPort = r.getInteger(R.integer.album_rows_port); + slotViewSpec.slotGap = r.getDimensionPixelSize(R.dimen.album_slot_gap); } } diff --git a/src/com/android/gallery3d/app/ManageCachePage.java b/src/com/android/gallery3d/app/ManageCachePage.java index 940f1be08..7e301f28c 100644 --- a/src/com/android/gallery3d/app/ManageCachePage.java +++ b/src/com/android/gallery3d/app/ManageCachePage.java @@ -283,9 +283,7 @@ public class ManageCachePage extends ActivityState implements (Context) mActivity, mSelectionManager); Config.ManageCachePage config = Config.ManageCachePage.get(activity); mAlbumSetView = new AlbumSetView(mActivity, mSelectionDrawer, - config.slotWidth, config.slotHeight, - config.displayItemSize, config.labelFontSize, - config.labelOffsetY, config.labelMargin); + config.slotViewSpec, config.labelSpec); mAlbumSetView.setListener(new SlotView.SimpleListener() { @Override public void onSingleTapUp(int slotIndex) { diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java index 92d8b4156..9ad0937d1 100644 --- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java @@ -45,9 +45,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { private final AlbumSetView.Model mSource; private int mSize; - private int mLabelWidth; - private int mDisplayItemSize; - private int mLabelFontSize; + private AlbumSetView.LabelSpec mLabelSpec; private int mContentStart = 0; private int mContentEnd = 0; @@ -75,13 +73,11 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { public int cacheStatus; } - public AlbumSetSlidingWindow(GalleryActivity activity, int labelWidth, - int displayItemSize, int labelFontSize, SelectionDrawer drawer, + public AlbumSetSlidingWindow(GalleryActivity activity, + AlbumSetView.LabelSpec labelSpec, SelectionDrawer drawer, AlbumSetView.Model source, int cacheSize) { source.setModelListener(this); - mLabelWidth = labelWidth; - mDisplayItemSize = displayItemSize; - mLabelFontSize = labelFontSize; + mLabelSpec = labelSpec; mLoadingLabel = activity.getAndroidContext().getString(R.string.loading); mSource = source; mSelectionDrawer = drawer; @@ -367,20 +363,22 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { private void updateContent(Texture content) { mContent = content; + } - int width = content.getWidth(); - int height = content.getHeight(); + @Override + public boolean render(GLCanvas canvas, int pass) { + // Fit the content into the box + int width = mContent.getWidth(); + int height = mContent.getHeight(); - float scale = (float) mDisplayItemSize / Math.max(width, height); + float scalex = mBoxWidth / (float) width; + float scaley = mBoxHeight / (float) height; + float scale = Math.min(scalex, scaley); width = (int) Math.floor(width * scale); height = (int) Math.floor(height * scale); - setSize(width, height); - } - - @Override - public boolean render(GLCanvas canvas, int pass) { + // Now draw it int sourceType = SelectionDrawer.DATASOURCE_TYPE_NOT_CATEGORIZED; int cacheFlag = MediaSet.CACHE_FLAG_NO; int cacheStatus = MediaSet.CACHE_STATUS_NOT_CACHED; @@ -392,8 +390,9 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { cacheStatus = set.cacheStatus; } - mSelectionDrawer.draw(canvas, mContent, mWidth, mHeight, + mSelectionDrawer.draw(canvas, mContent, width, height, getRotation(), path, mCoverIndex, sourceType, mMediaType, + mLabelSpec.darkStripHeight, cacheFlag == MediaSet.CACHE_FLAG_FULL, (cacheFlag == MediaSet.CACHE_FLAG_FULL) && (cacheStatus != MediaSet.CACHE_STATUS_CACHED_FULL)); @@ -471,37 +470,61 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { } private class LabelDisplayItem extends DisplayItem { - private static final int FONT_COLOR = Color.WHITE; - - private StringTexture mTexture; - private String mLabel; - private String mPostfix; + private static final int FONT_COLOR_TITLE = Color.WHITE; + private static final int FONT_COLOR_NUMBER = 0x80FFFFFF; // 50% white + + private StringTexture mTextureTitle; + private StringTexture mTextureNumber; + private String mTitle; + private String mNumber; + private int mLastWidth; private final int mSlotIndex; public LabelDisplayItem(int slotIndex) { mSlotIndex = slotIndex; - updateContent(); } public boolean updateContent() { - String label = mLoadingLabel; - String postfix = null; + String title = mLoadingLabel; + String number = ""; MediaSet set = mSource.getMediaSet(mSlotIndex); if (set != null) { - label = Utils.ensureNotNull(set.getName()); - postfix = " (" + set.getTotalMediaItemCount() + ")"; + title = Utils.ensureNotNull(set.getName()); + number = "" + set.getTotalMediaItemCount(); + } + if (Utils.equals(title, mTitle) + && Utils.equals(number, mNumber) + && Utils.equals(mBoxWidth, mLastWidth)) { + return false; } - if (Utils.equals(label, mLabel) - && Utils.equals(postfix, mPostfix)) return false; - mTexture = StringTexture.newInstance( - label, postfix, mLabelFontSize, FONT_COLOR, mLabelWidth, true); - setSize(mTexture.getWidth(), mTexture.getHeight()); + mTitle = title; + mNumber = number; + mLastWidth = mBoxWidth; + + AlbumSetView.LabelSpec s = mLabelSpec; + mTextureTitle = StringTexture.newInstance( + title, s.titleFontSize, FONT_COLOR_TITLE, + mBoxWidth - s.leftMargin, false); + mTextureNumber = StringTexture.newInstance( + number, s.numberFontSize, FONT_COLOR_NUMBER, + mBoxWidth - s.leftMargin, true); + return true; } @Override public boolean render(GLCanvas canvas, int pass) { - mTexture.draw(canvas, -mWidth / 2, -mHeight / 2); + if (mBoxWidth != mLastWidth) { + updateContent(); + } + + AlbumSetView.LabelSpec s = mLabelSpec; + int x = -mBoxWidth / 2; + int y = (mBoxHeight + 1) / 2 - s.darkStripHeight; + y += s.titleOffset; + mTextureTitle.draw(canvas, x + s.leftMargin, y); + y += s.titleFontSize + s.numberOffset; + mTextureNumber.draw(canvas, x + s.iconSize, y); return false; } diff --git a/src/com/android/gallery3d/ui/AlbumSetView.java b/src/com/android/gallery3d/ui/AlbumSetView.java index ef066b34c..c122fe777 100644 --- a/src/com/android/gallery3d/ui/AlbumSetView.java +++ b/src/com/android/gallery3d/ui/AlbumSetView.java @@ -40,11 +40,7 @@ public class AlbumSetView extends SlotView { private AlbumSetSlidingWindow mDataWindow; private final GalleryActivity mActivity; - private final int mSlotWidth; - private final int mDisplayItemSize; - private final int mLabelFontSize; - private final int mLabelOffsetY; - private final int mLabelMargin; + private final LabelSpec mLabelSpec; private SelectionDrawer mSelectionDrawer; @@ -67,18 +63,23 @@ public class AlbumSetView extends SlotView { public long setDataVersion; } + public static class LabelSpec { + public int darkStripHeight; + public int titleOffset; + public int numberOffset; + public int titleFontSize; + public int numberFontSize; + public int leftMargin; + public int iconSize; + } + public AlbumSetView(GalleryActivity activity, SelectionDrawer drawer, - int slotWidth, int slotHeight, int displayItemSize, - int labelFontSize, int labelOffsetY, int labelMargin) { + SlotView.Spec slotViewSpec, LabelSpec labelSpec) { super(activity.getAndroidContext()); mActivity = activity; setSelectionDrawer(drawer); - setSlotSize(slotWidth, slotHeight); - mSlotWidth = slotWidth; - mDisplayItemSize = displayItemSize; - mLabelFontSize = labelFontSize; - mLabelOffsetY = labelOffsetY; - mLabelMargin = labelMargin; + setSlotSpec(slotViewSpec); + mLabelSpec = labelSpec; } public void setSelectionDrawer(SelectionDrawer drawer) { @@ -95,8 +96,7 @@ public class AlbumSetView extends SlotView { mDataWindow = null; } if (model != null) { - mDataWindow = new AlbumSetSlidingWindow(mActivity, - mSlotWidth - mLabelMargin * 2, mDisplayItemSize, mLabelFontSize, + mDataWindow = new AlbumSetSlidingWindow(mActivity, mLabelSpec, mSelectionDrawer, model, CACHE_SIZE); mDataWindow.setListener(new MyCacheListener()); setSlotCount(mDataWindow.size()); @@ -119,8 +119,7 @@ public class AlbumSetView extends SlotView { // Put the cover items in reverse order, so that the first item is on // top of the rest. - int labelY = y + mLabelOffsetY - entry.labelItem.getHeight() / 2; - Position position = new Position(x, labelY, 0f); + Position position = new Position(x, y, 0f); putDisplayItem(position, position, entry.labelItem); for (int i = 0, n = items.length; i < n; ++i) { diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java index 9b410e9a8..46d9e9ef7 100644 --- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java @@ -38,7 +38,6 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { private static final int MSG_LOAD_BITMAP_DONE = 0; private static final int MSG_UPDATE_SLOT = 1; - private static final int MIN_THUMB_SIZE = 100; private static final int JOB_LIMIT = 2; public static interface Listener { @@ -66,24 +65,20 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { private SynchronizedHandler mHandler; private JobLimiter mThreadPool; - private int mSlotWidth, mSlotHeight; private int mActiveRequestCount = 0; private boolean mIsActive = false; - private int mDisplayItemSize; // 0: disabled + private int mCacheThumbSize; // 0: Don't cache the thumbnails private LruCache<Path, Bitmap> mImageCache = new LruCache<Path, Bitmap>(1000); public AlbumSlidingWindow(GalleryActivity activity, AlbumView.Model source, int cacheSize, - int slotWidth, int slotHeight, int displayItemSize) { + int cacheThumbSize) { source.setModelListener(this); mSource = source; mData = new AlbumDisplayItem[cacheSize]; mSize = source.size(); - mSlotWidth = slotWidth; - mSlotHeight = slotHeight; - mDisplayItemSize = displayItemSize; mWaitLoadingTexture = new ColorTexture(Color.TRANSPARENT); mWaitLoadingTexture.setSize(1, 1); @@ -317,37 +312,37 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { private void updateContent(Texture content) { mContent = content; + } + @Override + public boolean render(GLCanvas canvas, int pass) { + // Fit the content into the box int width = mContent.getWidth(); int height = mContent.getHeight(); - float scalex = mDisplayItemSize / (float) width; - float scaley = mDisplayItemSize / (float) height; + float scalex = mBoxWidth / (float) width; + float scaley = mBoxHeight / (float) height; float scale = Math.min(scalex, scaley); width = (int) Math.floor(width * scale); height = (int) Math.floor(height * scale); - setSize(width, height); - } - - @Override - public boolean render(GLCanvas canvas, int pass) { + // Now draw it if (pass == 0) { Path path = null; if (mMediaItem != null) path = mMediaItem.getPath(); - mSelectionDrawer.draw(canvas, mContent, mWidth, mHeight, + mSelectionDrawer.draw(canvas, mContent, width, height, getRotation(), path, mMediaType); return (mFocusIndex == mSlotIndex); } else if (pass == 1) { - mSelectionDrawer.drawFocus(canvas, mWidth, mHeight); + mSelectionDrawer.drawFocus(canvas, width, height); } return false; } @Override public void startLoadBitmap() { - if (mDisplayItemSize < MIN_THUMB_SIZE) { + if (mCacheThumbSize > 0) { Path path = mMediaItem.getPath(); if (mImageCache.containsKey(path)) { Bitmap bitmap = mImageCache.get(path); @@ -368,7 +363,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { Bitmap bitmap = job.run(jc); if (bitmap != null) { bitmap = BitmapUtils.resizeDownBySideLength( - bitmap, mDisplayItemSize, true); + bitmap, mCacheThumbSize, true); } return bitmap; } @@ -390,7 +385,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { mFuture = null; Bitmap bitmap = future.get(); boolean isCancelled = future.isCancelled(); - if (mDisplayItemSize < MIN_THUMB_SIZE && (bitmap != null || !isCancelled)) { + if (mCacheThumbSize > 0 && (bitmap != null || !isCancelled)) { Path path = mMediaItem.getPath(); mImageCache.put(path, bitmap); } diff --git a/src/com/android/gallery3d/ui/AlbumView.java b/src/com/android/gallery3d/ui/AlbumView.java index 417611a69..128259a9f 100644 --- a/src/com/android/gallery3d/ui/AlbumView.java +++ b/src/com/android/gallery3d/ui/AlbumView.java @@ -33,8 +33,7 @@ public class AlbumView extends SlotView { private AlbumSlidingWindow mDataWindow; private final GalleryActivity mActivity; private SelectionDrawer mSelectionDrawer; - private int mSlotWidth, mSlotHeight; - private int mDisplayItemSize; + private int mCacheThumbSize; private boolean mIsActive = false; @@ -50,13 +49,11 @@ public class AlbumView extends SlotView { public void onSizeChanged(int size); } - public AlbumView(GalleryActivity activity, - int slotWidth, int slotHeight, int displayItemSize) { + public AlbumView(GalleryActivity activity, SlotView.Spec spec, + int cacheThumbSize) { super(activity.getAndroidContext()); - mSlotWidth = slotWidth; - mSlotHeight = slotHeight; - mDisplayItemSize = displayItemSize; - setSlotSize(slotWidth, slotHeight); + mCacheThumbSize = cacheThumbSize; + setSlotSpec(spec); mActivity = activity; } @@ -74,7 +71,7 @@ public class AlbumView extends SlotView { if (model != null) { mDataWindow = new AlbumSlidingWindow( mActivity, model, CACHE_SIZE, - mSlotWidth, mSlotHeight, mDisplayItemSize); + mCacheThumbSize); mDataWindow.setSelectionDrawer(mSelectionDrawer); mDataWindow.setListener(new MyDataModelListener()); setSlotCount(model.size()); diff --git a/src/com/android/gallery3d/ui/DisplayItem.java b/src/com/android/gallery3d/ui/DisplayItem.java index 3038232f6..50264c4a3 100644 --- a/src/com/android/gallery3d/ui/DisplayItem.java +++ b/src/com/android/gallery3d/ui/DisplayItem.java @@ -18,12 +18,15 @@ package com.android.gallery3d.ui; public abstract class DisplayItem { - protected int mWidth; - protected int mHeight; - - protected void setSize(int width, int height) { - mWidth = width; - mHeight = height; + protected int mBoxWidth; + protected int mBoxHeight; + + // setBox() specifies the box that the DisplayItem should render into. It + // should be called before first render(). It may be called again between + // render() calls to change the size of the box. + public void setBox(int width, int height) { + mBoxWidth = width; + mBoxHeight = height; } // returns true if more pass is needed @@ -31,14 +34,6 @@ public abstract class DisplayItem { public abstract long getIdentity(); - public int getWidth() { - return mWidth; - } - - public int getHeight() { - return mHeight; - } - public int getRotation() { return 0; } diff --git a/src/com/android/gallery3d/ui/FilmStripView.java b/src/com/android/gallery3d/ui/FilmStripView.java index a6be2d10a..6a80564d9 100644 --- a/src/com/android/gallery3d/ui/FilmStripView.java +++ b/src/com/android/gallery3d/ui/FilmStripView.java @@ -73,7 +73,10 @@ public class FilmStripView extends GLView implements SlotView.Listener, mGripSize = gripSize; mStripDrawer = new StripDrawer((Context) activity); - mAlbumView = new AlbumView(activity, thumbSize, thumbSize, thumbSize); + SlotView.Spec spec = new SlotView.Spec(); + spec.slotWidth = thumbSize; + spec.slotHeight = thumbSize; + mAlbumView = new AlbumView(activity, spec, thumbSize); mAlbumView.setOverscrollEffect(SlotView.OVERSCROLL_SYSTEM); mAlbumView.setSelectionDrawer(mStripDrawer); mAlbumView.setListener(this); diff --git a/src/com/android/gallery3d/ui/GLDetailsView.java b/src/com/android/gallery3d/ui/GLDetailsView.java index cb98d4ee7..c0542e1c9 100644 --- a/src/com/android/gallery3d/ui/GLDetailsView.java +++ b/src/com/android/gallery3d/ui/GLDetailsView.java @@ -34,6 +34,7 @@ import com.android.gallery3d.ui.DetailsHelper.CloseListener; import android.content.Context; import android.graphics.Color; import android.graphics.Rect; +import android.text.Layout; import android.text.format.Formatter; import android.view.MotionEvent; import android.view.View.MeasureSpec; @@ -259,7 +260,8 @@ public class GLDetailsView extends GLView implements DetailsViewContainer { context, key), value); } Texture label = MultiLineTexture.newInstance( - value, mMaxDetailLength, FONT_SIZE, FONT_COLOR); + value, mMaxDetailLength, FONT_SIZE, FONT_COLOR, + Layout.Alignment.ALIGN_NORMAL); mItems.add(label); } } @@ -274,7 +276,8 @@ public class GLDetailsView extends GLView implements DetailsViewContainer { public void onAddressAvailable(String address) { mItems.set(mLocationIndex, MultiLineTexture.newInstance( - address, mMaxDetailLength, FONT_SIZE, FONT_COLOR)); + address, mMaxDetailLength, FONT_SIZE, FONT_COLOR, + Layout.Alignment.ALIGN_NORMAL)); GLDetailsView.this.invalidate(); } } diff --git a/src/com/android/gallery3d/ui/GridDrawer.java b/src/com/android/gallery3d/ui/GridDrawer.java index 54b175cb4..cc861844b 100644 --- a/src/com/android/gallery3d/ui/GridDrawer.java +++ b/src/com/android/gallery3d/ui/GridDrawer.java @@ -21,28 +21,23 @@ import com.android.gallery3d.data.Path; import android.content.Context; import android.graphics.Color; +import android.text.Layout; public class GridDrawer extends IconDrawer { - private final NinePatchTexture mFrame; private final NinePatchTexture mFrameSelected; - private final NinePatchTexture mFrameSelectedTop; - private final NinePatchTexture mImportBackground; private Texture mImportLabel; private int mGridWidth; private final SelectionManager mSelectionManager; private final Context mContext; - private final int FONT_SIZE = 14; - private final int FONT_COLOR = Color.WHITE; - private final int IMPORT_LABEL_PADDING = 10; + 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; - mFrame = new NinePatchTexture(context, R.drawable.album_frame); mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected); - mFrameSelectedTop = new NinePatchTexture(context, R.drawable.grid_selected_top); - mImportBackground = new NinePatchTexture(context, R.drawable.import_translucent); mSelectionManager = selectionManager; } @@ -54,7 +49,8 @@ public class GridDrawer extends IconDrawer { @Override public void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, int topIndex, int dataSourceType, - int mediaType, boolean wantCache, boolean isCaching) { + int mediaType, int darkStripHeight, boolean wantCache, + boolean isCaching) { int x = -width / 2; int y = -height / 2; @@ -72,37 +68,34 @@ public class GridDrawer extends IconDrawer { drawVideoOverlay(canvas, mediaType, x, y, width, height, topIndex); - NinePatchTexture frame; if (mSelectionMode && mSelectionManager.isItemSelected(path)) { - frame = topIndex == 0 ? mFrameSelectedTop : mFrameSelected; - } else { - frame = mFrame; + drawFrame(canvas, mFrameSelected, x, y, width, height); } - drawFrame(canvas, frame, x, y, width, height); - if (topIndex == 0) { - ResourceTexture icon = getIcon(dataSourceType); - if (icon != null) { - IconDimension id = getIconDimension(icon, width, height); - if (dataSourceType == DATASOURCE_TYPE_MTP) { - if (mImportLabel == null || mGridWidth != width) { - mGridWidth = width; - mImportLabel = MultiLineTexture.newInstance( - mContext.getString(R.string.click_import), - width - id.width - IMPORT_LABEL_PADDING, FONT_SIZE, FONT_COLOR); - } - int bgHeight = Math.max(id.height, mImportLabel.getHeight()); - mImportBackground.setSize(width, bgHeight); - mImportBackground.draw(canvas, x, -y - bgHeight); - mImportLabel.draw(canvas, x + id.width + IMPORT_LABEL_PADDING, - -y - bgHeight + Math.abs(bgHeight - mImportLabel.getHeight()) / 2); - } - icon.draw(canvas, id.x, id.y, id.width, id.height); + drawDarkStrip(canvas, width, height, darkStripHeight); + drawIcon(canvas, width, height, dataSourceType); + if (dataSourceType == DATASOURCE_TYPE_MTP) { + drawImportLabel(canvas, 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 index 9d5868bcb..52c31f7d4 100644 --- a/src/com/android/gallery3d/ui/HighlightDrawer.java +++ b/src/com/android/gallery3d/ui/HighlightDrawer.java @@ -21,17 +21,13 @@ import com.android.gallery3d.data.Path; import android.content.Context; public class HighlightDrawer extends IconDrawer { - private final NinePatchTexture mFrame; private final NinePatchTexture mFrameSelected; - private final NinePatchTexture mFrameSelectedTop; private SelectionManager mSelectionManager; private Path mHighlightItem; public HighlightDrawer(Context context) { super(context); - mFrame = new NinePatchTexture(context, R.drawable.album_frame); mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected); - mFrameSelectedTop = new NinePatchTexture(context, R.drawable.grid_selected_top); } public void setHighlightItem(Path item) { @@ -40,7 +36,8 @@ public class HighlightDrawer extends IconDrawer { public void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, int topIndex, int dataSourceType, - int mediaType, boolean wantCache, boolean isCaching) { + int mediaType, int darkStripHeight, boolean wantCache, + boolean isCaching) { int x = -width / 2; int y = -height / 2; @@ -57,16 +54,12 @@ public class HighlightDrawer extends IconDrawer { drawVideoOverlay(canvas, mediaType, x, y, width, height, topIndex); - NinePatchTexture frame; if (path == mHighlightItem) { - frame = topIndex == 0 ? mFrameSelectedTop : mFrameSelected; - } else { - frame = mFrame; + drawFrame(canvas, mFrameSelected, x, y, width, height); } - drawFrame(canvas, frame, x, y, width, height); - if (topIndex == 0) { + drawDarkStrip(canvas, width, height, darkStripHeight); drawIcon(canvas, width, height, dataSourceType); } } diff --git a/src/com/android/gallery3d/ui/IconDrawer.java b/src/com/android/gallery3d/ui/IconDrawer.java index 91732d338..86fdf68ca 100644 --- a/src/com/android/gallery3d/ui/IconDrawer.java +++ b/src/com/android/gallery3d/ui/IconDrawer.java @@ -21,13 +21,16 @@ import com.android.gallery3d.data.MediaObject; import android.content.Context; public abstract class IconDrawer extends SelectionDrawer { - private final String TAG = "IconDrawer"; + private static final String TAG = "IconDrawer"; + private static final int DARK_STRIP_COLOR = 0x99000000; // 60% black + private final ResourceTexture mLocalSetIcon; private final ResourceTexture mCameraIcon; private final ResourceTexture mPicasaIcon; private final ResourceTexture mMtpIcon; private final Texture mVideoOverlay; private final Texture mVideoPlayIcon; + private final int mIconSize; public static class IconDimension { int x; @@ -37,14 +40,14 @@ public abstract class IconDrawer extends SelectionDrawer { } public IconDrawer(Context context) { - mLocalSetIcon = new ResourceTexture(context, R.drawable.ic_album_overlay_folder_holo); - mCameraIcon = new ResourceTexture(context, R.drawable.ic_album_overlay_camera_holo); - mPicasaIcon = new ResourceTexture(context, R.drawable.ic_album_overlay_picassa_holo); + mLocalSetIcon = new ResourceTexture(context, R.drawable.frame_overlay_gallery_folder); + mCameraIcon = new ResourceTexture(context, R.drawable.frame_overlay_gallery_camera); + mPicasaIcon = new ResourceTexture(context, R.drawable.frame_overlay_gallery_picasa); mMtpIcon = new ResourceTexture(context, R.drawable.ic_album_overlay_ptp_holo); - mVideoOverlay = new ResourceTexture(context, - R.drawable.thumbnail_album_video_overlay_holo); - mVideoPlayIcon = new ResourceTexture(context, - R.drawable.videooverlay); + mVideoOverlay = new ResourceTexture(context, R.drawable.ic_video_thumb); + mVideoPlayIcon = new ResourceTexture(context, R.drawable.ic_gallery_play); + mIconSize = context.getResources().getDimensionPixelSize( + R.dimen.albumset_icon_size); } @Override @@ -88,9 +91,9 @@ public abstract class IconDrawer extends SelectionDrawer { protected IconDimension getIconDimension(ResourceTexture icon, int width, int height) { IconDimension id = new IconDimension(); - float scale = 0.25f * width / icon.getWidth(); - id.width = (int) (scale * icon.getWidth()); - id.height = (int) (scale * icon.getHeight()); + float scale = (float) mIconSize / icon.getWidth(); + id.width = Math.round(scale * icon.getWidth()); + id.height = Math.round(scale * icon.getHeight()); id.x = -width / 2; id.y = height / 2 - id.height; return id; @@ -99,13 +102,27 @@ public abstract class IconDrawer extends SelectionDrawer { protected void drawVideoOverlay(GLCanvas canvas, int mediaType, int x, int y, int width, int height, int topIndex) { if (mediaType != MediaObject.MEDIA_TYPE_VIDEO) return; - mVideoOverlay.draw(canvas, x, y, width, 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); + if (topIndex == 0) { int side = Math.min(width, height) / 6; mVideoPlayIcon.draw(canvas, -side / 2, -side / 2, side, side); } } + protected void drawDarkStrip(GLCanvas canvas, int width, int height, + int darkStripHeight) { + int x = -width / 2; + int y = (height + 1) / 2 - darkStripHeight; + canvas.fillRect(x, y, width, darkStripHeight, DARK_STRIP_COLOR); + } + @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 cf1e39e24..e25e7793e 100644 --- a/src/com/android/gallery3d/ui/ManageCacheDrawer.java +++ b/src/com/android/gallery3d/ui/ManageCacheDrawer.java @@ -25,7 +25,6 @@ import android.content.Context; public class ManageCacheDrawer extends IconDrawer { private static final int COLOR_CACHING_BACKGROUND = 0x7F000000; private static final int ICON_SIZE = 36; - private final NinePatchTexture mFrame; private final ResourceTexture mCheckedItem; private final ResourceTexture mUnCheckedItem; private final SelectionManager mSelectionManager; @@ -35,7 +34,6 @@ public class ManageCacheDrawer extends IconDrawer { public ManageCacheDrawer(Context context, SelectionManager selectionManager) { super(context); - mFrame = new NinePatchTexture(context, R.drawable.manage_frame); 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); @@ -55,7 +53,8 @@ public class ManageCacheDrawer extends IconDrawer { @Override public void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, int topIndex, int dataSourceType, - int mediaType, boolean wantCache, boolean isCaching) { + int mediaType, int darkStripHeight, boolean wantCache, + boolean isCaching) { boolean selected = mSelectionManager.isItemSelected(path); boolean chooseToCache = wantCache ^ selected; @@ -76,9 +75,8 @@ public class ManageCacheDrawer extends IconDrawer { drawVideoOverlay(canvas, mediaType, x, y, width, height, topIndex); - drawFrame(canvas, mFrame, x, y, width, height); - if (topIndex == 0) { + drawDarkStrip(canvas, width, height, darkStripHeight); drawIcon(canvas, width, height, dataSourceType); } @@ -94,8 +92,8 @@ public class ManageCacheDrawer extends IconDrawer { int w = ICON_SIZE; int h = ICON_SIZE; - x = width / 2 - w / 2; - y = -height / 2 - h / 2; + x = width / 2 - w; + y = -height / 2; icon.draw(canvas, x, y, w, h); diff --git a/src/com/android/gallery3d/ui/MultiLineTexture.java b/src/com/android/gallery3d/ui/MultiLineTexture.java index be62d59c0..b0c3c2bbf 100644 --- a/src/com/android/gallery3d/ui/MultiLineTexture.java +++ b/src/com/android/gallery3d/ui/MultiLineTexture.java @@ -35,10 +35,11 @@ class MultiLineTexture extends CanvasTexture { } public static MultiLineTexture newInstance( - String text, int maxWidth, float textSize, int color) { + String text, int maxWidth, float textSize, int color, + Layout.Alignment alignment) { TextPaint paint = StringTexture.getDefaultPaint(textSize, color); Layout layout = new StaticLayout(text, 0, text.length(), paint, - maxWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0, true, null, 0); + maxWidth, alignment, 1, 0, true, null, 0); return new MultiLineTexture(layout); } diff --git a/src/com/android/gallery3d/ui/SelectionDrawer.java b/src/com/android/gallery3d/ui/SelectionDrawer.java index 2655a221c..05f346cc0 100644 --- a/src/com/android/gallery3d/ui/SelectionDrawer.java +++ b/src/com/android/gallery3d/ui/SelectionDrawer.java @@ -35,14 +35,14 @@ public abstract class SelectionDrawer { public abstract void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, int topIndex, int dataSourceType, int mediaType, - boolean wantCache, boolean isCaching); + int darkStripHeight, 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) { draw(canvas, content, width, height, rotation, path, 0, DATASOURCE_TYPE_NOT_CATEGORIZED, mediaType, - false, false); + 0, false, false); } public static void drawWithRotation(GLCanvas canvas, Texture content, diff --git a/src/com/android/gallery3d/ui/SlotView.java b/src/com/android/gallery3d/ui/SlotView.java index a8ca5f290..11dbfaab7 100644 --- a/src/com/android/gallery3d/ui/SlotView.java +++ b/src/com/android/gallery3d/ui/SlotView.java @@ -126,8 +126,8 @@ public class SlotView extends GLView { updateScrollPosition(position, false); } - public void setSlotSize(int slotWidth, int slotHeight) { - mLayout.setSlotSize(slotWidth, slotHeight); + public void setSlotSpec(Spec spec) { + mLayout.setSlotSpec(spec); } @Override @@ -191,6 +191,7 @@ public class SlotView extends GLView { } public void putDisplayItem(Position target, Position base, DisplayItem item) { + item.setBox(mLayout.getSlotWidth(), mLayout.getSlotHeight()); ItemEntry entry = new ItemEntry(item, target, base); mItemList.insertLast(entry); mItems.put(item, entry); @@ -350,6 +351,41 @@ public class SlotView extends GLView { } } + // This Spec class is used to specify the size of each slot in the SlotView. + // There are two ways to do it: + // + // (1) Specify slotWidth and slotHeight: they specify the width and height + // of each slot. The number of rows and the gap between slots will be + // determined automatically. + // (2) Specify rowsLand, rowsPort, and slotGap: they specify the number + // of rows in landscape/portrait mode and the gap between slots. The + // width and height of each slot is determined automatically. + // + // The initial value of -1 means they are not specified. + public static class Spec { + public int slotWidth = -1; + public int slotHeight = -1; + + public int rowsLand = -1; + public int rowsPort = -1; + public int slotGap = -1; + + static Spec newWithSize(int width, int height) { + Spec s = new Spec(); + s.slotWidth = width; + s.slotHeight = height; + return s; + } + + static Spec newWithRows(int rowsLand, int rowsPort, int slotGap) { + Spec s = new Spec(); + s.rowsLand = rowsLand; + s.rowsPort = rowsPort; + s.slotGap = slotGap; + return s; + } + } + public static class Layout { private int mVisibleStart; @@ -358,6 +394,9 @@ public class SlotView extends GLView { private int mSlotCount; private int mSlotWidth; private int mSlotHeight; + private int mSlotGap; + + private Spec mSpec; private int mWidth; private int mHeight; @@ -369,9 +408,8 @@ public class SlotView extends GLView { private int mVerticalPadding; private int mHorizontalPadding; - public void setSlotSize(int slotWidth, int slotHeight) { - mSlotWidth = slotWidth; - mSlotHeight = slotHeight; + public void setSlotSpec(Spec spec) { + mSpec = spec; } public boolean setSlotCount(int slotCount) { @@ -392,11 +430,19 @@ public class SlotView extends GLView { col = index - row * mUnitCount; } - int x = mHorizontalPadding + col * mSlotWidth; - int y = mVerticalPadding + row * mSlotHeight; + int x = mHorizontalPadding + col * (mSlotWidth + mSlotGap); + int y = mVerticalPadding + row * (mSlotHeight + mSlotGap); return new Rect(x, y, x + mSlotWidth, y + mSlotHeight); } + public int getSlotWidth() { + return mSlotWidth; + } + + public int getSlotHeight() { + return mSlotHeight; + } + public int getContentLength() { return mContentLength; } @@ -417,17 +463,19 @@ public class SlotView extends GLView { int majorLength, int minorLength, /* The view width and height */ int majorUnitSize, int minorUnitSize, /* The slot width and height */ int[] padding) { - int unitCount = minorLength / minorUnitSize; + int unitCount = (minorLength + mSlotGap) / (minorUnitSize + mSlotGap); if (unitCount == 0) unitCount = 1; mUnitCount = unitCount; // We put extra padding above and below the column. int availableUnits = Math.min(mUnitCount, mSlotCount); - padding[0] = (minorLength - availableUnits * minorUnitSize) / 2; + int usedMinorLength = availableUnits * minorUnitSize + + (availableUnits - 1) * mSlotGap; + padding[0] = (minorLength - usedMinorLength) / 2; // Then calculate how many columns we need for all slots. int count = ((mSlotCount + mUnitCount - 1) / mUnitCount); - mContentLength = count * majorUnitSize; + mContentLength = count * majorUnitSize + (count - 1) * mSlotGap; // If the content length is less then the screen width, put // extra padding in left and right. @@ -435,6 +483,18 @@ public class SlotView extends GLView { } private void initLayoutParameters() { + // Initialize mSlotWidth and mSlotHeight from mSpec + if (mSpec.slotWidth != -1) { + mSlotGap = 0; + mSlotWidth = mSpec.slotWidth; + mSlotHeight = mSpec.slotHeight; + } else { + int rows = (mWidth > mHeight) ? mSpec.rowsLand : mSpec.rowsPort; + mSlotGap = mSpec.slotGap; + mSlotHeight = Math.max(1, (mHeight - (rows - 1) * mSlotGap) / rows); + mSlotWidth = mSlotHeight; + } + int[] padding = new int[2]; if (WIDE) { initLayoutParameters(mWidth, mHeight, mSlotWidth, mSlotHeight, padding); @@ -458,14 +518,18 @@ public class SlotView extends GLView { int position = mScrollPosition; if (WIDE) { - int start = Math.max(0, (position / mSlotWidth) * mUnitCount); - int end = Math.min(mSlotCount, mUnitCount - * (position + mWidth + mSlotWidth - 1) / mSlotWidth); + int startCol = position / (mSlotWidth + mSlotGap); + int start = Math.max(0, mUnitCount * startCol); + int endCol = (position + mWidth + mSlotWidth + mSlotGap - 1) / + (mSlotWidth + mSlotGap); + int end = Math.min(mSlotCount, mUnitCount * endCol); setVisibleRange(start, end); } else { - int start = Math.max(0, mUnitCount * (position / mSlotHeight)); - int end = Math.min(mSlotCount, mUnitCount - * (position + mHeight + mSlotHeight - 1) / mSlotHeight); + int startRow = position / (mSlotHeight + mSlotGap); + int start = Math.max(0, mUnitCount * startRow); + int endRow = (position + mHeight + mSlotHeight + mSlotGap - 1) / + (mSlotHeight + mSlotGap); + int end = Math.min(mSlotCount, mUnitCount * endRow); setVisibleRange(start, end); } } @@ -495,21 +559,31 @@ public class SlotView extends GLView { } public int getSlotIndexByPosition(float x, float y) { - float absoluteX = x + (WIDE ? mScrollPosition : 0); + int absoluteX = Math.round(x) + (WIDE ? mScrollPosition : 0); + int absoluteY = Math.round(y) + (WIDE ? 0 : mScrollPosition); + absoluteX -= mHorizontalPadding; - int columnIdx = (int) (absoluteX + 0.5) / mSlotWidth; - if ((absoluteX - mSlotWidth * columnIdx) < 0 - || (!WIDE && columnIdx >= mUnitCount)) { + absoluteY -= mVerticalPadding; + + int columnIdx = absoluteX / (mSlotWidth + mSlotGap); + int rowIdx = absoluteY / (mSlotHeight + mSlotGap); + + if (columnIdx < 0 || (!WIDE && columnIdx >= mUnitCount)) { return INDEX_NONE; } - float absoluteY = y + (WIDE ? 0 : mScrollPosition); - absoluteY -= mVerticalPadding; - int rowIdx = (int) (absoluteY + 0.5) / mSlotHeight; - if (((absoluteY - mSlotHeight * rowIdx) < 0) - || (WIDE && rowIdx >= mUnitCount)) { + if (rowIdx < 0 || (WIDE && rowIdx >= mUnitCount)) { return INDEX_NONE; } + + if (absoluteX % (mSlotWidth + mSlotGap) >= mSlotWidth) { + return INDEX_NONE; + } + + if (absoluteY % (mSlotHeight + mSlotGap) >= mSlotHeight) { + return INDEX_NONE; + } + int index = WIDE ? (columnIdx * mUnitCount + rowIdx) : (rowIdx * mUnitCount + columnIdx); diff --git a/src/com/android/gallery3d/ui/StringTexture.java b/src/com/android/gallery3d/ui/StringTexture.java index 71ab9b351..f576c0172 100644 --- a/src/com/android/gallery3d/ui/StringTexture.java +++ b/src/com/android/gallery3d/ui/StringTexture.java @@ -56,21 +56,14 @@ class StringTexture extends CanvasTexture { } public static StringTexture newInstance( - String text, String postfix, float textSize, int color, + String text, float textSize, int color, float lengthLimit, boolean isBold) { TextPaint paint = getDefaultPaint(textSize, color); if (isBold) { paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); } - if (postfix != null) { - lengthLimit = Math.max(0, - lengthLimit - paint.measureText(postfix)); - text = TextUtils.ellipsize(text, paint, lengthLimit, - TextUtils.TruncateAt.END).toString() + postfix; - } else { - text = TextUtils.ellipsize( - text, paint, lengthLimit, TextUtils.TruncateAt.END).toString(); - } + text = TextUtils.ellipsize( + text, paint, lengthLimit, TextUtils.TruncateAt.END).toString(); return newInstance(text, paint); } diff --git a/src/com/android/gallery3d/ui/StripDrawer.java b/src/com/android/gallery3d/ui/StripDrawer.java index 09106128f..be98ae0de 100644 --- a/src/com/android/gallery3d/ui/StripDrawer.java +++ b/src/com/android/gallery3d/ui/StripDrawer.java @@ -38,7 +38,8 @@ public class StripDrawer extends SelectionDrawer { @Override public void draw(GLCanvas canvas, Texture content, int width, int height, int rotation, Path path, int topIndex, int dataSourceType, - int mediaType, boolean wantCache, boolean isCaching) { + int mediaType, int darkStripHeight, boolean wantCache, + boolean isCaching) { int x = -width / 2; int y = -height / 2; |