summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2014-12-17 15:01:26 -0800
committerSteve Kondik <steve@cyngn.com>2015-03-28 14:56:24 -0700
commitd29332b5cc904c7c0fa10419e1ba3a73edf747a0 (patch)
tree21e8796dd942521f375eaf4f57ab24d315979a49 /src
parent51aa540d08dfd7ef45a9851dbdda20c62d8edc03 (diff)
downloadandroid_packages_apps_Gallery2-d29332b5cc904c7c0fa10419e1ba3a73edf747a0.tar.gz
android_packages_apps_Gallery2-d29332b5cc904c7c0fa10419e1ba3a73edf747a0.tar.bz2
android_packages_apps_Gallery2-d29332b5cc904c7c0fa10419e1ba3a73edf747a0.zip
Gallery2: Make grids scroll vertically by default
- Can optionally be switched back to horizontal via overlay. Change-Id: I666a2e7cfe95cba630171b6272eda9a786be4cb6
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/app/AlbumPage.java17
-rw-r--r--src/com/android/gallery3d/app/AlbumSetPage.java4
-rw-r--r--src/com/android/gallery3d/app/Config.java17
-rw-r--r--src/com/android/gallery3d/ui/Paper.java62
-rw-r--r--src/com/android/gallery3d/ui/SlotView.java65
5 files changed, 110 insertions, 55 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java
index 7824bf763..d0056fcfd 100644
--- a/src/com/android/gallery3d/app/AlbumPage.java
+++ b/src/com/android/gallery3d/app/AlbumPage.java
@@ -113,6 +113,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;
@@ -179,9 +180,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);
@@ -190,8 +191,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);
}
@@ -610,10 +611,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 b181b59fe..288472793 100644
--- a/src/com/android/gallery3d/app/AlbumSetPage.java
+++ b/src/com/android/gallery3d/app/AlbumSetPage.java
@@ -154,7 +154,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);
@@ -162,7 +162,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;
}