diff options
author | cretin45 <cretin45@gmail.com> | 2014-12-17 15:01:26 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2014-12-18 16:19:15 +0000 |
commit | fbf6346583fc5ae4aa3c731abcc360e5762121bc (patch) | |
tree | 342dd9a671d477861a6c5f591eccd2e2ef1c9223 | |
parent | 5a5691a9966be2e39bc3c45a2e48d8e22f69a292 (diff) | |
download | android_packages_apps_Gallery2-fbf6346583fc5ae4aa3c731abcc360e5762121bc.tar.gz android_packages_apps_Gallery2-fbf6346583fc5ae4aa3c731abcc360e5762121bc.tar.bz2 android_packages_apps_Gallery2-fbf6346583fc5ae4aa3c731abcc360e5762121bc.zip |
Gallery2: Make grids scroll vertically by default
- Can optionally be switched back to horizontal via overlay.
Change-Id: I666a2e7cfe95cba630171b6272eda9a786be4cb6
-rw-r--r-- | res/values-xlarge/dimensions.xml | 4 | ||||
-rw-r--r-- | res/values/config.xml | 2 | ||||
-rw-r--r-- | res/values/dimens.xml | 20 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/AlbumPage.java | 17 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/AlbumSetPage.java | 4 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/Config.java | 17 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/Paper.java | 62 | ||||
-rw-r--r-- | src/com/android/gallery3d/ui/SlotView.java | 65 |
8 files changed, 131 insertions, 60 deletions
diff --git a/res/values-xlarge/dimensions.xml b/res/values-xlarge/dimensions.xml index 85329e012..ba654d5a5 100644 --- a/res/values-xlarge/dimensions.xml +++ b/res/values-xlarge/dimensions.xml @@ -22,6 +22,8 @@ <!-- configuration for album set page --> <integer name="albumset_rows_land">3</integer> <integer name="albumset_rows_port">5</integer> + <integer name="albumset_cols_land">5</integer> + <integer name="albumset_cols_port">3</integer> <dimen name="albumset_title_font_size">14sp</dimen> <dimen name="albumset_count_font_size">11sp</dimen> <dimen name="albumset_title_right_margin">23dp</dimen> @@ -30,4 +32,6 @@ <!-- configuration for album page --> <integer name="album_rows_land">3</integer> <integer name="album_rows_port">5</integer> + <integer name="album_cols_land">5</integer> + <integer name="album_cols_port">3</integer> </resources> diff --git a/res/values/config.xml b/res/values/config.xml index 5af45db56..25b8e6a49 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -23,4 +23,6 @@ <!-- Maximum recording length in milliseconds. 0 means unlimited. --> <integer name="max_video_recording_length">0</integer> <bool name="config_show_more_images">false</bool> + + <bool name="config_scroll_horizontal">false</bool> </resources> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index ae8cc219e..308f31c41 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -112,9 +112,13 @@ <!-- configuration for legacy album set page --> <integer name="albumset_rows_land">2</integer> <integer name="albumset_rows_port">3</integer> - <dimen name="albumset_padding_top">7dp</dimen> - <dimen name="albumset_padding_bottom">7dp</dimen> - <dimen name="albumset_slot_gap">7dp</dimen> + <integer name="albumset_cols_land">3</integer> + <integer name="albumset_cols_port">2</integer> + <dimen name="albumset_padding_top">3dp</dimen> + <dimen name="albumset_padding_bottom">3dp</dimen> + <dimen name="albumset_padding_left">3dp</dimen> + <dimen name="albumset_padding_right">3dp</dimen> + <dimen name="albumset_slot_gap">3dp</dimen> <dimen name="albumset_label_background_height">30dp</dimen> <dimen name="albumset_title_offset">10dp</dimen> @@ -126,9 +130,15 @@ <dimen name="albumset_icon_size">25dp</dimen> <!-- configuration for album page --> - <integer name="album_rows_land">2</integer> + <integer name="album_rows_land">3</integer> <integer name="album_rows_port">4</integer> - <dimen name="album_slot_gap">5dp</dimen> + <integer name="album_cols_land">6</integer> + <integer name="album_cols_port">3</integer> + <dimen name="album_padding_top">3dp</dimen> + <dimen name="album_padding_bottom">3dp</dimen> + <dimen name="album_padding_left">3dp</dimen> + <dimen name="album_padding_right">3dp</dimen> + <dimen name="album_slot_gap">3dp</dimen> <!-- configuration for manage page --> <dimen name="cache_pin_size">24dp</dimen> diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java index 0614eef86..7e2f5f9e4 100644 --- a/src/com/android/gallery3d/app/AlbumPage.java +++ b/src/com/android/gallery3d/app/AlbumPage.java @@ -93,6 +93,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private Path mMediaSetPath; private String mParentMediaSetString; private SlotView mSlotView; + private Config.AlbumPage mConfig; private AlbumDataLoader mAlbumDataAdapter; @@ -158,9 +159,9 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster protected void onLayout( boolean changed, int left, int top, int right, int bottom) { - int slotViewTop = mActivity.getGalleryActionBar().getHeight(); - int slotViewBottom = bottom - top; - int slotViewRight = right - left; + int slotViewTop = mActivity.getGalleryActionBar().getHeight() + mConfig.paddingTop; + int slotViewBottom = bottom - top - mConfig.paddingBottom; + int slotViewRight = right - left - mConfig.paddingRight; if (mShowDetails) { mDetailsHelper.layout(left, slotViewTop, right, bottom); @@ -169,8 +170,8 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster } // Set the mSlotView as a reference point to the open animation - mOpenCenter.setReferencePosition(0, slotViewTop); - mSlotView.layout(0, slotViewTop, slotViewRight, slotViewBottom); + mOpenCenter.setReferencePosition(mConfig.paddingLeft, slotViewTop); + mSlotView.layout(mConfig.paddingLeft, slotViewTop, slotViewRight, slotViewBottom); GalleryUtils.setViewPointMatrix(mMatrix, (right - left) / 2, (bottom - top) / 2, -mUserDistance); } @@ -504,10 +505,10 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster private void initializeViews() { mSelectionManager = new SelectionManager(mActivity, false); mSelectionManager.setSelectionListener(this); - Config.AlbumPage config = Config.AlbumPage.get(mActivity); - mSlotView = new SlotView(mActivity, config.slotViewSpec); + mConfig = Config.AlbumPage.get(mActivity); + mSlotView = new SlotView(mActivity, mConfig.slotViewSpec); mAlbumView = new AlbumSlotRenderer(mActivity, mSlotView, - mSelectionManager, config.placeholderColor); + mSelectionManager, mConfig.placeholderColor); mSlotView.setSlotRenderer(mAlbumView); mRootPane.addComponent(mSlotView); mSlotView.setListener(new SlotView.SimpleListener() { diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java index 1dca84068..929205a4e 100644 --- a/src/com/android/gallery3d/app/AlbumSetPage.java +++ b/src/com/android/gallery3d/app/AlbumSetPage.java @@ -138,7 +138,7 @@ public class AlbumSetPage extends ActivityState implements int slotViewTop = mActionBar.getHeight() + mConfig.paddingTop; int slotViewBottom = bottom - top - mConfig.paddingBottom; - int slotViewRight = right - left; + int slotViewRight = right - left - mConfig.paddingRight; if (mShowDetails) { mDetailsHelper.layout(left, slotViewTop, right, bottom); @@ -146,7 +146,7 @@ public class AlbumSetPage extends ActivityState implements mAlbumSetView.setHighlightItemPath(null); } - mSlotView.layout(0, slotViewTop, slotViewRight, slotViewBottom); + mSlotView.layout(mConfig.paddingLeft, slotViewTop, slotViewRight, slotViewBottom); } @Override diff --git a/src/com/android/gallery3d/app/Config.java b/src/com/android/gallery3d/app/Config.java index 7183acc33..3625dafe4 100644 --- a/src/com/android/gallery3d/app/Config.java +++ b/src/com/android/gallery3d/app/Config.java @@ -31,6 +31,8 @@ final class Config { public AlbumSetSlotRenderer.LabelSpec labelSpec; public int paddingTop; public int paddingBottom; + public int paddingLeft; + public int paddingRight; public int placeholderColor; public static synchronized AlbumSetPage get(Context context) { @@ -48,11 +50,15 @@ final class Config { slotViewSpec = new SlotView.Spec(); slotViewSpec.rowsLand = r.getInteger(R.integer.albumset_rows_land); slotViewSpec.rowsPort = r.getInteger(R.integer.albumset_rows_port); + slotViewSpec.colsLand = r.getInteger(R.integer.albumset_cols_land); + slotViewSpec.colsPort = r.getInteger(R.integer.albumset_cols_port); slotViewSpec.slotGap = r.getDimensionPixelSize(R.dimen.albumset_slot_gap); slotViewSpec.slotHeightAdditional = 0; paddingTop = r.getDimensionPixelSize(R.dimen.albumset_padding_top); paddingBottom = r.getDimensionPixelSize(R.dimen.albumset_padding_bottom); + paddingLeft = r.getDimensionPixelSize(R.dimen.albumset_padding_left); + paddingRight = r.getDimensionPixelSize(R.dimen.albumset_padding_right); labelSpec = new AlbumSetSlotRenderer.LabelSpec(); labelSpec.labelBackgroundHeight = r.getDimensionPixelSize( @@ -82,6 +88,10 @@ final class Config { private static AlbumPage sInstance; public SlotView.Spec slotViewSpec; + public int paddingTop; + public int paddingBottom; + public int paddingLeft; + public int paddingRight; public int placeholderColor; public static synchronized AlbumPage get(Context context) { @@ -99,7 +109,14 @@ final class Config { slotViewSpec = new SlotView.Spec(); slotViewSpec.rowsLand = r.getInteger(R.integer.album_rows_land); slotViewSpec.rowsPort = r.getInteger(R.integer.album_rows_port); + slotViewSpec.colsLand = r.getInteger(R.integer.album_cols_land); + slotViewSpec.colsPort = r.getInteger(R.integer.album_cols_port); slotViewSpec.slotGap = r.getDimensionPixelSize(R.dimen.album_slot_gap); + + paddingTop = r.getDimensionPixelSize(R.dimen.album_padding_top); + paddingBottom = r.getDimensionPixelSize(R.dimen.album_padding_bottom); + paddingLeft = r.getDimensionPixelSize(R.dimen.album_padding_left); + paddingRight = r.getDimensionPixelSize(R.dimen.album_padding_right); } } diff --git a/src/com/android/gallery3d/ui/Paper.java b/src/com/android/gallery3d/ui/Paper.java index b36f5c3a2..6ed5013a2 100644 --- a/src/com/android/gallery3d/ui/Paper.java +++ b/src/com/android/gallery3d/ui/Paper.java @@ -28,53 +28,76 @@ class Paper { @SuppressWarnings("unused") private static final String TAG = "Paper"; private static final int ROTATE_FACTOR = 4; - private EdgeAnimation mAnimationLeft = new EdgeAnimation(); - private EdgeAnimation mAnimationRight = new EdgeAnimation(); + private EdgeAnimation mAnimationBegin = new EdgeAnimation(); + private EdgeAnimation mAnimationEnd = new EdgeAnimation(); private int mWidth; + private int mHeight; private float[] mMatrix = new float[16]; + private final boolean mIsWide; + + public Paper(boolean wide) { + mIsWide = wide; + } + public void overScroll(float distance) { distance /= mWidth; // make it relative to width if (distance < 0) { - mAnimationLeft.onPull(-distance); + mAnimationBegin.onPull(-distance); } else { - mAnimationRight.onPull(distance); + mAnimationEnd.onPull(distance); } } public void edgeReached(float velocity) { velocity /= mWidth; // make it relative to width if (velocity < 0) { - mAnimationRight.onAbsorb(-velocity); + mAnimationEnd.onAbsorb(-velocity); } else { - mAnimationLeft.onAbsorb(velocity); + mAnimationBegin.onAbsorb(velocity); } } public void onRelease() { - mAnimationLeft.onRelease(); - mAnimationRight.onRelease(); + mAnimationBegin.onRelease(); + mAnimationEnd.onRelease(); } public boolean advanceAnimation() { // Note that we use "|" because we want both animations get updated. - return mAnimationLeft.update() | mAnimationRight.update(); + return mAnimationBegin.update() | mAnimationEnd.update(); } public void setSize(int width, int height) { mWidth = width; + mHeight = height; } - public float[] getTransform(Rect rect, float scrollX) { - float left = mAnimationLeft.getValue(); - float right = mAnimationRight.getValue(); - float screenX = rect.centerX() - scrollX; - // We linearly interpolate the value [left, right] for the screenX - // range int [-1/4, 5/4]*mWidth. So if part of the thumbnail is outside + public float[] getTransform(Rect rect, float scroll) { + Log.d(TAG, rect.toString()); + float start = mAnimationBegin.getValue(); + float end = mAnimationEnd.getValue(); + int center = 0; + int screenWidth = mWidth; + int rotateX = 0; + int rotateY = 0; + final boolean wide = mIsWide; + if (wide) { + center = rect.centerX(); + rotateY = 1; + } else { + center = rect.centerY(); + rotateX = 1; + screenWidth = mHeight; + } + float screen = center - scroll; + // We linearly interpolate the value [start, end] for the screen + // range int [-1/4, 5/4]*screenWidth. So if part of the thumbnail is outside // the screen, we still get some transform. - float x = screenX + mWidth / 4; - int range = 3 * mWidth / 2; - float t = ((range - x) * left - x * right) / range; + float x = screen + screenWidth / 4; + int range = 3 * screenWidth / 2; + float t = ((range - x) * start - x * end) / range; + // compress t to the range (-1, 1) by the function // f(t) = (1 / (1 + e^-t) - 0.5) * 2 // then multiply by 90 to make the range (-45, 45) @@ -82,8 +105,9 @@ class Paper { (1 / (1 + (float) Math.exp(-t * ROTATE_FACTOR)) - 0.5f) * 2 * -45; Matrix.setIdentityM(mMatrix, 0); Matrix.translateM(mMatrix, 0, mMatrix, 0, rect.centerX(), rect.centerY(), 0); - Matrix.rotateM(mMatrix, 0, degrees, 0, 1, 0); + Matrix.rotateM(mMatrix, 0, degrees, rotateX, rotateY, 0); Matrix.translateM(mMatrix, 0, mMatrix, 0, -rect.width() / 2, -rect.height() / 2, 0); + return mMatrix; } } diff --git a/src/com/android/gallery3d/ui/SlotView.java b/src/com/android/gallery3d/ui/SlotView.java index eaf23f553..c9a1ff303 100644 --- a/src/com/android/gallery3d/ui/SlotView.java +++ b/src/com/android/gallery3d/ui/SlotView.java @@ -24,6 +24,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.animation.DecelerateInterpolator; +import com.android.gallery3d.R; import com.android.gallery3d.anim.Animation; import com.android.gallery3d.app.AbstractGalleryActivity; import com.android.gallery3d.common.Utils; @@ -35,7 +36,6 @@ public class SlotView extends GLView { @SuppressWarnings("unused") private static final String TAG = "SlotView"; - private static final boolean WIDE = true; private static final int INDEX_NONE = -1; public static final int RENDER_MORE_PASS = 1; @@ -66,7 +66,7 @@ public class SlotView extends GLView { private final GestureDetector mGestureDetector; private final ScrollerHelper mScroller; - private final Paper mPaper = new Paper(); + private final Paper mPaper; private Listener mListener; private UserInteractionListener mUIListener; @@ -95,10 +95,14 @@ public class SlotView extends GLView { // Flag to check whether it is come from Photo Page. private boolean isFromPhotoPage = false; + private final boolean mIsWide; + public SlotView(AbstractGalleryActivity activity, Spec spec) { + mIsWide = activity.getResources().getBoolean(R.bool.config_scroll_horizontal); mGestureDetector = new GestureDetector(activity, new MyGestureListener()); mScroller = new ScrollerHelper(activity); mHandler = new SynchronizedHandler(activity.getGLRoot()); + mPaper = new Paper(mIsWide); setSlotSpec(spec); } @@ -116,7 +120,7 @@ public class SlotView extends GLView { return; } Rect rect = mLayout.getSlotRect(index, mTempRect); - int position = WIDE + int position = mIsWide ? (rect.left + rect.right - getWidth()) / 2 : (rect.top + rect.bottom - getHeight()) / 2; setScrollPosition(position); @@ -124,11 +128,11 @@ public class SlotView extends GLView { public void makeSlotVisible(int index) { Rect rect = mLayout.getSlotRect(index, mTempRect); - int visibleBegin = WIDE ? mScrollX : mScrollY; - int visibleLength = WIDE ? getWidth() : getHeight(); + int visibleBegin = mIsWide ? mScrollX : mScrollY; + int visibleLength = mIsWide ? getWidth() : getHeight(); int visibleEnd = visibleBegin + visibleLength; - int slotBegin = WIDE ? rect.left : rect.top; - int slotEnd = WIDE ? rect.right : rect.bottom; + int slotBegin = mIsWide ? rect.left : rect.top; + int slotEnd = mIsWide ? rect.right : rect.bottom; int position = visibleBegin; if (visibleLength < slotEnd - slotBegin) { @@ -199,8 +203,8 @@ public class SlotView extends GLView { } private void updateScrollPosition(int position, boolean force) { - if (!force && (WIDE ? position == mScrollX : position == mScrollY)) return; - if (WIDE) { + if (!force && (mIsWide ? position == mScrollX : position == mScrollY)) return; + if (mIsWide) { mScrollX = position; } else { mScrollY = position; @@ -335,7 +339,7 @@ public class SlotView extends GLView { canvas.save(GLCanvas.SAVE_FLAG_ALPHA | GLCanvas.SAVE_FLAG_MATRIX); Rect rect = mLayout.getSlotRect(index, mTempRect); if (paperActive) { - canvas.multiplyMatrix(mPaper.getTransform(rect, mScrollX), 0); + canvas.multiplyMatrix(mPaper.getTransform(rect, (mIsWide ? mScrollX : mScrollY)), 0); } else { canvas.translate(rect.left, rect.top, 0); } @@ -409,6 +413,8 @@ public class SlotView extends GLView { public int rowsLand = -1; public int rowsPort = -1; + public int colsLand = -1; + public int colsPort = -1; public int slotGap = -1; } @@ -454,7 +460,7 @@ public class SlotView extends GLView { public Rect getSlotRect(int index, Rect rect) { int col, row; - if (WIDE) { + if (mIsWide) { if (View.LAYOUT_DIRECTION_RTL == TextUtils .getLayoutDirectionFromLocale(Locale.getDefault())) { // If RTL, recalculate the columns and rows. @@ -526,10 +532,17 @@ public class SlotView extends GLView { 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 - mSpec.slotHeightAdditional; + if (mIsWide) { + int rows = (mWidth > mHeight) ? mSpec.rowsLand : mSpec.rowsPort; + mSlotGap = mSpec.slotGap; + mSlotHeight = Math.max(1, (mHeight - (rows - 1) * mSlotGap) / rows); + mSlotWidth = mSlotHeight - mSpec.slotHeightAdditional; + } else { + int cols = (mWidth > mHeight) ? mSpec.colsLand : mSpec.colsPort; + mSlotGap = mSpec.slotGap; + mSlotHeight = Math.max(1, (mWidth - (cols - 1) * mSlotGap) / cols); + mSlotWidth = mSlotHeight - mSpec.slotHeightAdditional; + } } if (mRenderer != null) { @@ -537,7 +550,7 @@ public class SlotView extends GLView { } int[] padding = new int[2]; - if (WIDE) { + if (mIsWide) { initLayoutParameters(mWidth, mHeight, mSlotWidth, mSlotHeight, padding); mVerticalPadding.startAnimateTo(padding[0]); mHorizontalPadding.startAnimateTo(padding[1]); @@ -558,7 +571,7 @@ public class SlotView extends GLView { private void updateVisibleSlotRange() { int position = mScrollPosition; - if (WIDE) { + if (mIsWide) { if (View.LAYOUT_DIRECTION_RTL == TextUtils .getLayoutDirectionFromLocale(Locale.getDefault())) { // If RTL, recalculate the position. @@ -610,8 +623,8 @@ public class SlotView extends GLView { } public int getSlotIndexByPosition(float x, float y) { - int absoluteX = Math.round(x) + (WIDE ? mScrollPosition : 0); - int absoluteY = Math.round(y) + (WIDE ? 0 : mScrollPosition); + int absoluteX = Math.round(x) + (mIsWide ? mScrollPosition : 0); + int absoluteY = Math.round(y) + (mIsWide ? 0 : mScrollPosition); if (View.LAYOUT_DIRECTION_RTL == TextUtils .getLayoutDirectionFromLocale(Locale.getDefault())) { // If RTL, recalculate the absoluteX. @@ -628,11 +641,11 @@ public class SlotView extends GLView { int columnIdx = absoluteX / (mSlotWidth + mSlotGap); int rowIdx = absoluteY / (mSlotHeight + mSlotGap); - if (!WIDE && columnIdx >= mUnitCount) { + if (!mIsWide && columnIdx >= mUnitCount) { return INDEX_NONE; } - if (WIDE && rowIdx >= mUnitCount) { + if (mIsWide && rowIdx >= mUnitCount) { return INDEX_NONE; } @@ -644,7 +657,7 @@ public class SlotView extends GLView { return INDEX_NONE; } - int index = WIDE + int index = mIsWide ? (columnIdx * mUnitCount + rowIdx) : (rowIdx * mUnitCount + columnIdx); @@ -652,7 +665,7 @@ public class SlotView extends GLView { } public int getScrollLimit() { - int limit = WIDE ? mContentLength - mWidth : mContentLength - mHeight; + int limit = mIsWide ? mContentLength - mWidth : mContentLength - mHeight; return limit <= 0 ? 0 : limit; } @@ -700,7 +713,7 @@ public class SlotView extends GLView { cancelDown(false); int scrollLimit = mLayout.getScrollLimit(); if (scrollLimit == 0) return false; - float velocity = WIDE ? velocityX : velocityY; + float velocity = mIsWide ? velocityX : velocityY; mScroller.fling((int) -velocity, 0, scrollLimit); if (mUIListener != null) mUIListener.onUserInteractionBegin(); invalidate(); @@ -711,7 +724,7 @@ public class SlotView extends GLView { public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { cancelDown(false); - float distance = WIDE ? distanceX : distanceY; + float distance = mIsWide ? distanceX : distanceY; int overDistance = mScroller.startScroll( Math.round(distance), 0, mLayout.getScrollLimit()); if (mOverscrollEffect == OVERSCROLL_3D && overDistance != 0) { @@ -758,7 +771,7 @@ public class SlotView extends GLView { mStartIndex = INDEX_NONE; } // Reset the scroll position to avoid scrolling over the updated limit. - setScrollPosition(WIDE ? mScrollX : mScrollY); + setScrollPosition(mIsWide ? mScrollX : mScrollY); return changed; } |