summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2/Workspace.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher2/Workspace.java')
-rw-r--r--src/com/android/launcher2/Workspace.java226
1 files changed, 109 insertions, 117 deletions
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 44b9f68da..d1d47f5f6 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -24,7 +24,6 @@ import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.WallpaperManager;
import android.appwidget.AppWidgetHostView;
-import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
@@ -33,10 +32,8 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
-import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Matrix;
-import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
@@ -45,7 +42,6 @@ import android.graphics.drawable.Drawable;
import android.os.IBinder;
import android.os.Parcelable;
import android.util.AttributeSet;
-import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.Display;
@@ -175,16 +171,12 @@ public class Workspace extends SmoothPagedView
private Bitmap mDragOutline = null;
private final Rect mTempRect = new Rect();
private final int[] mTempXY = new int[2];
+ private int[] mTempVisiblePagesRange = new int[2];
private float mOverscrollFade = 0;
private boolean mOverscrollTransformsSet;
public static final int DRAG_BITMAP_PADDING = 2;
private boolean mWorkspaceFadeInAdjacentScreens;
- // Camera and Matrix used to determine the final position of a neighboring CellLayout
- private final Matrix mMatrix = new Matrix();
- private final Camera mCamera = new Camera();
- private final float mTempFloat2[] = new float[2];
-
enum WallpaperVerticalOffset { TOP, MIDDLE, BOTTOM };
int mWallpaperWidth;
int mWallpaperHeight;
@@ -285,6 +277,7 @@ public class Workspace extends SmoothPagedView
// With workspace, data is available straight from the get-go
setDataIsReady();
+ mLauncher = (Launcher) context;
final Resources res = getResources();
mWorkspaceFadeInAdjacentScreens = res.getBoolean(R.bool.config_workspaceFadeAdjacentScreens);
mFadeInAdjacentScreens = false;
@@ -303,20 +296,20 @@ public class Workspace extends SmoothPagedView
// landscape
TypedArray actionBarSizeTypedArray =
context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
- DisplayMetrics displayMetrics = res.getDisplayMetrics();
final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f);
- final float systemBarHeight = res.getDimension(R.dimen.status_bar_height);
- final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp *
- displayMetrics.density;
+
+ Point minDims = new Point();
+ Point maxDims = new Point();
+ mLauncher.getWindowManager().getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
cellCountX = 1;
- while (CellLayout.widthInPortrait(res, cellCountX + 1) <= smallestScreenDim) {
+ while (CellLayout.widthInPortrait(res, cellCountX + 1) <= minDims.x) {
cellCountX++;
}
cellCountY = 1;
while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1)
- <= smallestScreenDim - systemBarHeight) {
+ <= minDims.y) {
cellCountY++;
}
}
@@ -338,7 +331,6 @@ public class Workspace extends SmoothPagedView
LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY);
setHapticFeedbackEnabled(false);
- mLauncher = (Launcher) context;
initWorkspace();
// Disable multitouch across the workspace/all apps/customize tray
@@ -378,19 +370,9 @@ public class Workspace extends SmoothPagedView
return r;
}
- public void buildPageHardwareLayers() {
- if (getWindowToken() != null) {
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- CellLayout cl = (CellLayout) getChildAt(i);
- cl.getShortcutsAndWidgets().buildLayer();
- }
- }
- }
-
public void onDragStart(DragSource source, Object info, int dragAction) {
mIsDragOccuring = true;
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
mLauncher.lockScreenOrientation();
setChildrenBackgroundAlphaMultipliers(1f);
// Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
@@ -400,7 +382,7 @@ public class Workspace extends SmoothPagedView
public void onDragEnd() {
mIsDragOccuring = false;
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
mLauncher.unlockScreenOrientation(false);
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
@@ -450,7 +432,6 @@ public class Workspace extends SmoothPagedView
CellLayout cl = ((CellLayout) child);
cl.setOnInterceptTouchListener(this);
cl.setClickable(true);
- cl.enableHardwareLayers();
cl.setContentDescription(getContext().getString(
R.string.workspace_description_format, getChildCount()));
}
@@ -733,16 +714,11 @@ public class Workspace extends SmoothPagedView
}
}
- @Override
- protected boolean isScrollingIndicatorEnabled() {
- return super.isScrollingIndicatorEnabled() && (mState != State.SPRING_LOADED);
- }
-
protected void onPageBeginMoving() {
super.onPageBeginMoving();
if (isHardwareAccelerated()) {
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
} else {
if (mNextPage != INVALID_PAGE) {
// we're snapping to a particular screen
@@ -776,7 +752,7 @@ public class Workspace extends SmoothPagedView
super.onPageEndMoving();
if (isHardwareAccelerated()) {
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
} else {
clearChildrenCache();
}
@@ -851,10 +827,12 @@ public class Workspace extends SmoothPagedView
}
protected void setWallpaperDimension() {
- DisplayMetrics displayMetrics = new DisplayMetrics();
- mLauncher.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
- final int maxDim = Math.max(displayMetrics.widthPixels, displayMetrics.heightPixels);
- final int minDim = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels);
+ Point minDims = new Point();
+ Point maxDims = new Point();
+ mLauncher.getWindowManager().getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
+
+ final int maxDim = Math.max(maxDims.x, maxDims.y);
+ final int minDim = Math.min(minDims.x, minDims.y);
// We need to ensure that there is enough extra space in the wallpaper for the intended
// parallax effects
@@ -1102,7 +1080,7 @@ public class Workspace extends SmoothPagedView
if (!isSmall() && !mIsSwitchingState) {
if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel();
if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel();
- mChildrenOutlineFadeInAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 1.0f);
+ mChildrenOutlineFadeInAnimation = LauncherAnimUtils.ofFloat(this, "childrenOutlineAlpha", 1.0f);
mChildrenOutlineFadeInAnimation.setDuration(CHILDREN_OUTLINE_FADE_IN_DURATION);
mChildrenOutlineFadeInAnimation.start();
}
@@ -1112,7 +1090,7 @@ public class Workspace extends SmoothPagedView
if (!isSmall() && !mIsSwitchingState) {
if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel();
if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel();
- mChildrenOutlineFadeOutAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 0.0f);
+ mChildrenOutlineFadeOutAnimation = LauncherAnimUtils.ofFloat(this, "childrenOutlineAlpha", 0.0f);
mChildrenOutlineFadeOutAnimation.setDuration(CHILDREN_OUTLINE_FADE_OUT_DURATION);
mChildrenOutlineFadeOutAnimation.setStartDelay(CHILDREN_OUTLINE_FADE_OUT_DELAY);
mChildrenOutlineFadeOutAnimation.start();
@@ -1157,7 +1135,7 @@ public class Workspace extends SmoothPagedView
float startAlpha = getBackgroundAlpha();
if (finalAlpha != startAlpha) {
if (animated) {
- mBackgroundFadeOutAnimation = ValueAnimator.ofFloat(startAlpha, finalAlpha);
+ mBackgroundFadeOutAnimation = LauncherAnimUtils.ofFloat(startAlpha, finalAlpha);
mBackgroundFadeOutAnimation.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
setBackgroundAlpha(((Float) animation.getAnimatedValue()).floatValue());
@@ -1183,31 +1161,6 @@ public class Workspace extends SmoothPagedView
return mBackgroundAlpha;
}
- /**
- * Due to 3D transformations, if two CellLayouts are theoretically touching each other,
- * on the xy plane, when one is rotated along the y-axis, the gap between them is perceived
- * as being larger. This method computes what offset the rotated view should be translated
- * in order to minimize this perceived gap.
- * @param degrees Angle of the view
- * @param width Width of the view
- * @param height Height of the view
- * @return Offset to be used in a View.setTranslationX() call
- */
- private float getOffsetXForRotation(float degrees, int width, int height) {
- mMatrix.reset();
- mCamera.save();
- mCamera.rotateY(Math.abs(degrees));
- mCamera.getMatrix(mMatrix);
- mCamera.restore();
-
- mMatrix.preTranslate(-width * 0.5f, -height * 0.5f);
- mMatrix.postTranslate(width * 0.5f, height * 0.5f);
- mTempFloat2[0] = width;
- mTempFloat2[1] = height;
- mMatrix.mapPoints(mTempFloat2);
- return (width - mTempFloat2[0]) * (degrees > 0.0f ? 1.0f : -1.0f);
- }
-
float backgroundAlphaInterpolator(float r) {
float pivotA = 0.1f;
float pivotB = 0.4f;
@@ -1267,6 +1220,7 @@ public class Workspace extends SmoothPagedView
super.screenScrolled(screenCenter);
updatePageAlphaValues(screenCenter);
+ enableHwLayersOnVisiblePages();
if (mOverScrollX < 0 || mOverScrollX > mMaxScrollX) {
int index = mOverScrollX < 0 ? 0 : getChildCount() - 1;
@@ -1415,18 +1369,66 @@ public class Workspace extends SmoothPagedView
}
}
- private void updateChildrenLayersEnabled() {
+
+ private void updateChildrenLayersEnabled(boolean force) {
boolean small = mState == State.SMALL || mIsSwitchingState;
- boolean enableChildrenLayers = small || mAnimatingViewIntoPlace || isPageMoving();
+ boolean enableChildrenLayers = force || small || mAnimatingViewIntoPlace || isPageMoving();
if (enableChildrenLayers != mChildrenLayersEnabled) {
mChildrenLayersEnabled = enableChildrenLayers;
- for (int i = 0; i < getPageCount(); i++) {
- ((ViewGroup)getChildAt(i)).setChildrenLayersEnabled(mChildrenLayersEnabled);
+ if (mChildrenLayersEnabled) {
+ enableHwLayersOnVisiblePages();
+ } else {
+ for (int i = 0; i < getPageCount(); i++) {
+ final CellLayout cl = (CellLayout) getChildAt(i);
+ cl.disableHardwareLayers();
+ }
}
}
}
+ private void enableHwLayersOnVisiblePages() {
+ if (mChildrenLayersEnabled) {
+ final int screenCount = getChildCount();
+ getVisiblePages(mTempVisiblePagesRange);
+ int leftScreen = mTempVisiblePagesRange[0];
+ int rightScreen = mTempVisiblePagesRange[1];
+ if (leftScreen == rightScreen) {
+ // make sure we're caching at least two pages always
+ if (rightScreen < screenCount - 1) {
+ rightScreen++;
+ } else if (leftScreen > 0) {
+ leftScreen--;
+ }
+ }
+ for (int i = 0; i < screenCount; i++) {
+ final CellLayout layout = (CellLayout) getChildAt(i);
+ if (!(leftScreen <= i && i <= rightScreen && shouldDrawChild(layout))) {
+ layout.disableHardwareLayers();
+ }
+ }
+ for (int i = 0; i < screenCount; i++) {
+ final CellLayout layout = (CellLayout) getChildAt(i);
+ if (leftScreen <= i && i <= rightScreen && shouldDrawChild(layout)) {
+ layout.enableHardwareLayers();
+ }
+ }
+ }
+ }
+
+ public void buildPageHardwareLayers() {
+ // force layers to be enabled just for the call to buildLayer
+ updateChildrenLayersEnabled(true);
+ if (getWindowToken() != null) {
+ final int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ CellLayout cl = (CellLayout) getChildAt(i);
+ cl.buildHardwareLayer();
+ }
+ }
+ updateChildrenLayersEnabled(false);
+ }
+
protected void onWallpaperTap(MotionEvent ev) {
final int[] position = mTempCell;
getLocationOnScreen(position);
@@ -1515,14 +1517,14 @@ public class Workspace extends SmoothPagedView
mDragOutline = createDragOutline(v, canvas, DRAG_BITMAP_PADDING);
}
- public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, Paint alphaClipPaint) {
+ public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) {
final Canvas canvas = new Canvas();
int[] size = estimateItemSize(info.spanX, info.spanY, info, false);
// The outline is used to visualize where the item will land if dropped
mDragOutline = createDragOutline(b, canvas, DRAG_BITMAP_PADDING, size[0],
- size[1], alphaClipPaint);
+ size[1], clipAlpha);
}
public void exitWidgetResizeMode() {
@@ -1560,7 +1562,7 @@ public class Workspace extends SmoothPagedView
// Initialize animation arrays for the first time if necessary
initAnimationArrays();
- AnimatorSet anim = animated ? new AnimatorSet() : null;
+ AnimatorSet anim = animated ? LauncherAnimUtils.createAnimatorSet() : null;
// Stop any scrolling, move to the current page right away
setCurrentPage(getNextPage());
@@ -1585,7 +1587,7 @@ public class Workspace extends SmoothPagedView
if (oldStateIsNormal && stateIsSmall) {
zoomIn = false;
setLayoutScale(finalScaleFactor);
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
} else {
finalBackgroundAlpha = 1.0f;
setLayoutScale(finalScaleFactor);
@@ -1676,7 +1678,7 @@ public class Workspace extends SmoothPagedView
}
if (mOldBackgroundAlphas[i] != 0 ||
mNewBackgroundAlphas[i] != 0) {
- ValueAnimator bgAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
+ ValueAnimator bgAnim = LauncherAnimUtils.ofFloat(0f, 1f).setDuration(duration);
bgAnim.setInterpolator(mZoomInInterpolator);
bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
public void onAnimationUpdate(float a, float b) {
@@ -1725,7 +1727,7 @@ public class Workspace extends SmoothPagedView
public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) {
mIsSwitchingState = false;
mWallpaperOffset.setOverrideHorizontalCatchupConstant(false);
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
// The code in getChangeStateAnimation to determine initialAlpha and finalAlpha will ensure
// ensure that only the current page is visible during (and subsequently, after) the
// transition animation. If fade adjacent pages is disabled, then re-enable the page
@@ -1835,7 +1837,7 @@ public class Workspace extends SmoothPagedView
* Responsibility for the bitmap is transferred to the caller.
*/
private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding, int w, int h,
- Paint alphaClipPaint) {
+ boolean clipAlpha) {
final int outlineColor = getResources().getColor(android.R.color.holo_blue_light);
final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canvas.setBitmap(b);
@@ -1852,7 +1854,7 @@ public class Workspace extends SmoothPagedView
canvas.drawBitmap(orig, src, dst, null);
mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor,
- alphaClipPaint);
+ clipAlpha);
canvas.setBitmap(null);
return b;
@@ -2163,7 +2165,7 @@ public class Workspace extends SmoothPagedView
// We want the point to be mapped to the dragTarget.
if (dropTargetLayout != null) {
if (mLauncher.isHotseatLayout(dropTargetLayout)) {
- mapPointFromSelfToSibling(mLauncher.getHotseat(), mDragViewVisualCenter);
+ mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
} else {
mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null);
}
@@ -2307,7 +2309,7 @@ public class Workspace extends SmoothPagedView
@Override
public void run() {
mAnimatingViewIntoPlace = false;
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
if (finalResizeRunnable != null) {
finalResizeRunnable.run();
}
@@ -2430,7 +2432,13 @@ public class Workspace extends SmoothPagedView
// Here we store the final page that will be dropped to, if the workspace in fact
// receives the drop
if (mInScrollArea) {
- mDropToLayout = mDragOverlappingLayout;
+ if (isPageMoving()) {
+ // If the user drops while the page is scrolling, we should use that page as the
+ // destination instead of the page that is being hovered over.
+ mDropToLayout = (CellLayout) getPageAt(getNextPage());
+ } else {
+ mDropToLayout = mDragOverlappingLayout;
+ }
} else {
mDropToLayout = mDragTargetLayout;
}
@@ -3330,7 +3338,7 @@ public class Workspace extends SmoothPagedView
// hardware layers on children are enabled on startup, but should be disabled until
// needed
- updateChildrenLayersEnabled();
+ updateChildrenLayersEnabled(false);
setWallpaperDimension();
}
@@ -3382,7 +3390,8 @@ public class Workspace extends SmoothPagedView
View v = cl.getShortcutsAndWidgets().getChildAt(i);
ItemInfo info = (ItemInfo) v.getTag();
// Null check required as the AllApps button doesn't have an item info
- if (info != null) {
+ if (info != null && info.requiresDbUpdate) {
+ info.requiresDbUpdate = false;
LauncherModel.modifyItemInDatabase(mLauncher, info, container, screen, info.cellX,
info.cellY, info.spanX, info.spanY);
}
@@ -3610,14 +3619,9 @@ public class Workspace extends SmoothPagedView
}
}
- void removeItems(final ArrayList<ApplicationInfo> apps) {
- final AppWidgetManager widgets = AppWidgetManager.getInstance(getContext());
-
+ void removeItems(final ArrayList<String> packages) {
final HashSet<String> packageNames = new HashSet<String>();
- final int appCount = apps.size();
- for (int i = 0; i < appCount; i++) {
- packageNames.add(apps.get(i).componentName.getPackageName());
- }
+ packageNames.addAll(packages);
ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
for (final CellLayout layoutParent: cellLayouts) {
@@ -3698,11 +3702,7 @@ public class Workspace extends SmoothPagedView
});
}
- // It is no longer the case the BubbleTextViews correspond 1:1 with the workspace items in
- // the database (and LauncherModel) since shortcuts are not added and animated in until
- // the user returns to launcher. As a result, we really should be cleaning up the Db
- // regardless of whether the item was added or not (unlike the logic above). This is only
- // relevant for direct workspace items.
+ // Clean up new-apps animation list
post(new Runnable() {
@Override
public void run() {
@@ -3712,26 +3712,18 @@ public class Workspace extends SmoothPagedView
Set<String> newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY,
null);
- for (String packageName: packageNames) {
- // Remove all items that have the same package, but were not removed above
- ArrayList<ShortcutInfo> infos =
- mLauncher.getModel().getShortcutInfosForPackage(packageName);
- for (ShortcutInfo info : infos) {
- LauncherModel.deleteItemFromDatabase(mLauncher, info);
- }
- // Remove all queued items that match the same package
- if (newApps != null) {
- synchronized (newApps) {
- Iterator<String> iter = newApps.iterator();
- while (iter.hasNext()) {
- try {
- Intent intent = Intent.parseUri(iter.next(), 0);
- String pn = ItemInfo.getPackageName(intent);
- if (packageNames.contains(pn)) {
- iter.remove();
- }
- } catch (URISyntaxException e) {}
- }
+ // Remove all queued items that match the same package
+ if (newApps != null) {
+ synchronized (newApps) {
+ Iterator<String> iter = newApps.iterator();
+ while (iter.hasNext()) {
+ try {
+ Intent intent = Intent.parseUri(iter.next(), 0);
+ String pn = ItemInfo.getPackageName(intent);
+ if (packageNames.contains(pn)) {
+ iter.remove();
+ }
+ } catch (URISyntaxException e) {}
}
}
}