Merge "Centering drag outline when placing shortcut on screen" into jb-dev
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index d468762..a6a377e 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -46,6 +46,7 @@
<dimen name="hotseat_height_gap">-1dp</dimen>
<dimen name="workspace_overscroll_drawable_padding">0dp</dimen>
<dimen name="workspace_icon_text_size">12sp</dimen>
+ <dimen name="workspace_spring_loaded_page_spacing">15dp</dimen>
<dimen name="app_icon_drawable_padding">6dp</dimen>
<dimen name="app_icon_drawable_padding_land">2dp</dimen>
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index a3080a8..5d9cf81 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -75,6 +75,8 @@
private static final int MIN_SNAP_VELOCITY = 1500;
private static final int MIN_FLING_VELOCITY = 250;
+ static final int AUTOMATIC_PAGE_SPACING = -1;
+
protected int mFlingThresholdVelocity;
protected int mMinFlingVelocity;
protected int mMinSnapVelocity;
@@ -450,17 +452,23 @@
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+ final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+ int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthMode != MeasureSpec.EXACTLY) {
throw new IllegalStateException("Workspace can only be used in EXACTLY mode.");
}
+ // Return early if we aren't given a proper dimension
+ if (widthSize <= 0 || heightSize <= 0) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ return;
+ }
+
/* Allow the height to be set as WRAP_CONTENT. This allows the particular case
* of the All apps view on XLarge displays to not take up more space then it needs. Width
* is still not allowed to be set as WRAP_CONTENT since many parts of the code expect
* each page to have the same width.
*/
- final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int maxChildHeight = 0;
final int verticalPadding = getPaddingTop() + getPaddingBottom();
@@ -507,12 +515,17 @@
setMeasuredDimension(widthSize, heightSize);
+ // We can't call getChildOffset/getRelativeChildOffset until we set the measured dimensions.
+ // We also wait until we set the measured dimensions before flushing the cache as well, to
+ // ensure that the cache is filled with good values.
+ invalidateCachedOffsets();
+
if (childCount > 0) {
if (DEBUG) Log.d(TAG, "getRelativeChildOffset(): " + getMeasuredWidth() + ", "
+ getChildWidth(0));
// Calculate the variable page spacing if necessary
- if (mPageSpacing < 0) {
+ if (mPageSpacing == AUTOMATIC_PAGE_SPACING) {
// The gap between pages in the PagedView should be equal to the gap from the page
// to the edge of the screen (so it is not visible in the current screen). To
// account for unequal padding on each side of the paged view, we take the maximum
@@ -524,10 +537,6 @@
}
}
- // We can't call getChildOffset/getRelativeChildOffset until we set the measured dimensions.
- // We also wait until we set the measured dimensions before flushing the cache as well, to
- // ensure that the cache is filled with good values.
- invalidateCachedOffsets();
updateScrollingIndicatorPosition();
if (childCount > 0) {
@@ -747,6 +756,10 @@
}
}
+ protected boolean shouldDrawChild(View child) {
+ return child.getAlpha() > 0;
+ }
+
@Override
protected void dispatchDraw(Canvas canvas) {
int halfScreenSize = getMeasuredWidth() / 2;
@@ -783,7 +796,7 @@
// View.INVISIBLE, preventing re-drawing of their hardware layer
for (int i = getChildCount() - 1; i >= 0; i--) {
final View v = getPageAt(i);
- if (leftScreen <= i && i <= rightScreen && v.getAlpha() > 0) {
+ if (leftScreen <= i && i <= rightScreen && shouldDrawChild(v)) {
v.setVisibility(VISIBLE);
drawChild(canvas, v, drawingTime);
} else {
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 3910c45..d15d318 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -199,6 +199,7 @@
private Point mDisplaySize = new Point();
private boolean mIsStaticWallpaper;
private int mWallpaperTravelWidth;
+ private int mSpringLoadedPageSpacing;
// Variables relating to the creation of user folders by hovering shortcuts over shortcuts
private static final int FOLDER_CREATION_TIMEOUT = 0;
@@ -322,6 +323,8 @@
mSpringLoadedShrinkFactor =
res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f;
+ mSpringLoadedPageSpacing =
+ res.getDimensionPixelSize(R.dimen.workspace_spring_loaded_page_spacing);
// if the value is manually specified, use that instead
cellCountX = a.getInt(R.styleable.Workspace_cellCountX, cellCountX);
@@ -450,6 +453,13 @@
public void onChildViewRemoved(View parent, View child) {
}
+ protected boolean shouldDrawChild(View child) {
+ final CellLayout cl = (CellLayout) child;
+ return super.shouldDrawChild(child) &&
+ (cl.getShortcutsAndWidgets().getAlpha() > 0 ||
+ cl.getBackgroundAlpha() > 0);
+ }
+
/**
* @return The open folder on the current screen, or null if there is none
*/
@@ -1536,6 +1546,7 @@
if (state != State.NORMAL) {
finalScaleFactor = mSpringLoadedShrinkFactor - (stateIsSmall ? 0.1f : 0);
+ setPageSpacing(mSpringLoadedPageSpacing);
if (oldStateIsNormal && stateIsSmall) {
zoomIn = false;
setLayoutScale(finalScaleFactor);
@@ -1545,6 +1556,7 @@
setLayoutScale(finalScaleFactor);
}
} else {
+ setPageSpacing(PagedView.AUTOMATIC_PAGE_SPACING);
setLayoutScale(1.0f);
}