Merge "Import translations. DO NOT MERGE" into ub-launcher3-calgary
am: c9efe2ba9c -s ours
Change-Id: I1fbfd1be22e96d99d05a76e480fc6dca290bc519
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 77f6612..ee21313 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -54,6 +54,7 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.util.CellAndSpan;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.ParcelableSparseArray;
@@ -1047,15 +1048,16 @@
return false;
}
- void visualizeDropLocation(View v, Bitmap dragOutline, int cellX, int cellY, int spanX,
- int spanY, boolean resize, DropTarget.DragObject dragObject) {
+ void visualizeDropLocation(View v, DragPreviewProvider outlineProvider, int cellX, int cellY,
+ int spanX, int spanY, boolean resize, DropTarget.DragObject dragObject) {
final int oldDragCellX = mDragCell[0];
final int oldDragCellY = mDragCell[1];
- if (dragOutline == null && v == null) {
+ if (outlineProvider == null || outlineProvider.gerenatedDragOutline == null) {
return;
}
+ Bitmap dragOutline = outlineProvider.gerenatedDragOutline;
if (cellX != oldDragCellX || cellY != oldDragCellY) {
Point dragOffset = dragObject.dragView.getDragVisualizeOffset();
Rect dragRegion = dragObject.dragView.getDragRegion();
diff --git a/src/com/android/launcher3/HolographicOutlineHelper.java b/src/com/android/launcher3/HolographicOutlineHelper.java
index 427acea..6822311 100644
--- a/src/com/android/launcher3/HolographicOutlineHelper.java
+++ b/src/com/android/launcher3/HolographicOutlineHelper.java
@@ -84,7 +84,7 @@
applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, color, outlineColor, true);
}
- void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
+ public void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
int outlineColor, boolean clipAlpha) {
// We start by removing most of the alpha channel so as to ignore shadows, and
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 886c5f0..334db4a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2809,7 +2809,7 @@
mDragLayer.onAccessibilityStateChanged(enabled);
}
- public void onDragStarted(View view) {
+ public void onDragStarted() {
if (isOnCustomContent()) {
// Custom content screen doesn't participate in drag and drop. If on custom
// content screen, move to default.
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 2758a7c..bea55d2 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1800,6 +1800,7 @@
case MotionEvent.ACTION_CANCEL:
if (mTouchState == TOUCH_STATE_SCROLLING) {
snapToDestination();
+ onScrollInteractionEnd();
}
resetTouchState();
break;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 6f61688..4c2d4bb 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -69,12 +69,12 @@
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
-import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.dragndrop.DragScroller;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dragndrop.SpringLoadedDragController;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutsContainerListener;
@@ -247,8 +247,7 @@
/** Is the user is dragging an item near the edge of a page? */
private boolean mInScrollArea = false;
- private HolographicOutlineHelper mOutlineHelper;
- @Thunk Bitmap mDragOutline = null;
+ private DragPreviewProvider mOutlineProvider = null;
public static final int DRAG_BITMAP_PADDING = DragPreviewProvider.DRAG_BITMAP_PADDING;
private boolean mWorkspaceFadeInAdjacentScreens;
@@ -343,8 +342,6 @@
public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mOutlineHelper = HolographicOutlineHelper.obtain(context);
-
mLauncher = (Launcher) context;
mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
final Resources res = getResources();
@@ -417,7 +414,13 @@
enfoceDragParity("onDragStart", 0, 0);
}
+ if (mOutlineProvider != null) {
+ // The outline is used to visualize where the item will land if dropped
+ mOutlineProvider.generateDragOutline(mCanvas);
+ }
+
updateChildrenLayersEnabled(false);
+ mLauncher.onDragStarted();
mLauncher.lockScreenOrientation();
mLauncher.onInteractionBegin();
// Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
@@ -426,6 +429,27 @@
if (mAddNewPageOnDrag) {
mDeferRemoveExtraEmptyScreen = false;
addExtraEmptyScreenOnDrag();
+
+ if (source != this && info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
+ // When dragging a widget from different source, move to a page which has
+ // enough space to place this widget (after rearranging/resizing). We special case
+ // widgets as they cannot be placed inside a folder.
+ // Start at the current page and search right (on LTR) until finding a page with
+ // enough space. Since an empty screen is the furthest right, a page must be found.
+ int currentPage = getPageNearestToCenterOfScreen();
+ for (int pageIndex = currentPage; pageIndex < getPageCount(); pageIndex++) {
+ CellLayout page = (CellLayout) getPageAt(pageIndex);
+ if (page.hasReorderSolution(info)) {
+ setCurrentPage(pageIndex);
+ break;
+ }
+ }
+ }
+ }
+
+ if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
+ // Always enter the spring loaded mode
+ mLauncher.enterSpringLoadedDragMode();
}
}
@@ -1999,23 +2023,8 @@
position[0], position[1], 0, null);
}
- public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) {
- // Find a page that has enough space to place this widget (after rearranging/resizing).
- // Start at the current page and search right (on LTR) until finding a page with enough
- // space. Since an empty screen is the furthest right, a page must be found.
- int currentPageInOverview = getPageNearestToCenterOfScreen();
- for (int pageIndex = currentPageInOverview; pageIndex < getPageCount(); pageIndex++) {
- CellLayout page = (CellLayout) getPageAt(pageIndex);
- if (page.hasReorderSolution(info)) {
- setCurrentPage(pageIndex);
- break;
- }
- }
-
- int[] size = estimateItemSize(info, false);
-
- // The outline is used to visualize where the item will land if dropped
- mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, size[0], size[1], clipAlpha);
+ public void prepareDragWithProvider(DragPreviewProvider outlineProvider) {
+ mOutlineProvider = outlineProvider;
}
public void exitWidgetResizeMode() {
@@ -2271,34 +2280,6 @@
return null;
}
- /**
- * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
- * Responsibility for the bitmap is transferred to the caller.
- */
- private Bitmap createDragOutline(Bitmap orig, int padding, int w, int h,
- boolean clipAlpha) {
- final int outlineColor = getResources().getColor(R.color.outline_color);
- final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
- mCanvas.setBitmap(b);
-
- Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight());
- float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(),
- (h - padding) / (float) orig.getHeight());
- int scaledWidth = (int) (scaleFactor * orig.getWidth());
- int scaledHeight = (int) (scaleFactor * orig.getHeight());
- Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
-
- // center the image
- dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
-
- mCanvas.drawBitmap(orig, src, dst, null);
- mOutlineHelper.applyExpensiveOutlineWithBlur(b, mCanvas, outlineColor, outlineColor,
- clipAlpha);
- mCanvas.setBitmap(null);
-
- return b;
- }
-
public void startDrag(CellLayout.CellInfo cellInfo) {
startDrag(cellInfo, false);
}
@@ -2337,11 +2318,8 @@
ItemInfo dragObject, DragPreviewProvider previewProvider) {
child.clearFocus();
child.setPressed(false);
+ mOutlineProvider = previewProvider;
- // The outline is used to visualize where the item will land if dropped
- mDragOutline = previewProvider.createDragOutline(mCanvas);
-
- mLauncher.onDragStarted(child);
// The drag bitmap follows the touch point around on the screen
final Bitmap b = previewProvider.createDragBitmap(mCanvas);
int halfPadding = previewProvider.previewPadding / 2;
@@ -2384,12 +2362,7 @@
dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset,
dragRect, scale, accessible);
dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());
-
b.recycle();
-
- if (!FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) {
- mLauncher.enterSpringLoadedDragMode();
- }
return dv;
}
@@ -3180,7 +3153,7 @@
item.spanY, child, mTargetCell);
if (!nearestDropOccupied) {
- mDragTargetLayout.visualizeDropLocation(child, mDragOutline,
+ mDragTargetLayout.visualizeDropLocation(child, mOutlineProvider,
mTargetCell[0], mTargetCell[1], item.spanX, item.spanY, false, d);
} else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER)
&& !mReorderAlarm.alarmPending() && (mLastReorderX != reorderX ||
@@ -3325,7 +3298,7 @@
}
boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY;
- mDragTargetLayout.visualizeDropLocation(child, mDragOutline,
+ mDragTargetLayout.visualizeDropLocation(child, mOutlineProvider,
mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, dragObject);
}
}
@@ -3716,7 +3689,7 @@
&& mDragInfo.cell != null) {
mDragInfo.cell.setVisibility(VISIBLE);
}
- mDragOutline = null;
+ mOutlineProvider = null;
mDragInfo = null;
if (!isFlingToDelete) {
diff --git a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
index ff70279..0baa8f3 100644
--- a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java
@@ -25,6 +25,7 @@
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
+import com.android.launcher3.shortcuts.DeepShortcutView;
import java.util.ArrayList;
@@ -46,7 +47,10 @@
@Override
public boolean performAction(View host, ItemInfo item, int action) {
if (action == ADD_TO_WORKSPACE) {
- final ShortcutInfo info = (ShortcutInfo) item;
+ if (!(host.getParent() instanceof DeepShortcutView)) {
+ return false;
+ }
+ final ShortcutInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo();
final int[] coordinates = new int[2];
final long screenId = findSpaceOnWorkspace(item, coordinates);
Runnable onComplete = new Runnable() {
diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java
index b90c2fd..e078d9b 100644
--- a/src/com/android/launcher3/graphics/DragPreviewProvider.java
+++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java
@@ -29,6 +29,7 @@
import com.android.launcher3.PreloadIconDrawable;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
+import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.folder.FolderIcon;
/**
@@ -45,6 +46,8 @@
// The padding added to the drag view during the preview generation.
public final int previewPadding;
+ public Bitmap gerenatedDragOutline;
+
public DragPreviewProvider(View view) {
mView = view;
@@ -118,6 +121,14 @@
return b;
}
+ public final void generateDragOutline(Canvas canvas) {
+ if (ProviderConfig.IS_DOGFOOD_BUILD && gerenatedDragOutline != null) {
+ throw new RuntimeException("Drag outline generated twice");
+ }
+
+ gerenatedDragOutline = createDragOutline(canvas);
+ }
+
/**
* Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
* Responsibility for the bitmap is transferred to the caller.
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java
index 37b6d04..e7fc415 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java
@@ -21,16 +21,19 @@
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import com.android.launcher3.IconCache;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LogAccelerateInterpolator;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
+import com.android.launcher3.shortcuts.DeepShortcutsContainer.UnbadgedShortcutInfo;
import com.android.launcher3.util.PillRevealOutlineProvider;
import com.android.launcher3.util.PillWidthRevealOutlineProvider;
@@ -48,6 +51,8 @@
private View mIconView;
private float mOpenAnimationProgress;
+ private UnbadgedShortcutInfo mInfo;
+
public DeepShortcutView(Context context) {
this(context, null, 0);
}
@@ -87,10 +92,36 @@
mPillRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
- public void applyShortcutInfo(ShortcutInfo info) {
+ /** package private **/
+ void applyShortcutInfo(UnbadgedShortcutInfo info, DeepShortcutsContainer container) {
+ mInfo = info;
IconCache cache = LauncherAppState.getInstance().getIconCache();
mBubbleText.applyFromShortcutInfo(info, cache);
mIconView.setBackground(mBubbleText.getIcon());
+
+ // Use the long label as long as it exists and fits.
+ CharSequence longLabel = info.mDetail.getLongLabel();
+ int availableWidth = mBubbleText.getWidth() - mBubbleText.getTotalPaddingLeft()
+ - mBubbleText.getTotalPaddingRight();
+ boolean usingLongLabel = !TextUtils.isEmpty(longLabel)
+ && mBubbleText.getPaint().measureText(longLabel.toString()) <= availableWidth;
+ mBubbleText.setText(usingLongLabel ? longLabel : info.mDetail.getShortLabel());
+
+ // TODO: Add the click handler to this view directly and not the child view.
+ mBubbleText.setOnClickListener(Launcher.getLauncher(getContext()));
+ mBubbleText.setOnLongClickListener(container);
+ mBubbleText.setOnTouchListener(container);
+ }
+
+ /**
+ * Returns the shortcut info that is suitable to be added on the homescreen
+ */
+ public ShortcutInfo getFinalInfo() {
+ ShortcutInfo badged = new ShortcutInfo(mInfo);
+ // Queue an update task on the worker thread. This ensures that the badged
+ // shortcut eventually gets its icon updated.
+ Launcher.getLauncher(getContext()).getModel().updateShortcutInfo(mInfo.mDetail, badged);
+ return badged;
}
public View getIconView() {
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
index cfeccfc..4d10506 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
@@ -183,12 +183,8 @@
}
for (int i = 0; i < shortcuts.size(); i++) {
final ShortcutInfoCompat shortcut = shortcuts.get(i);
- final ShortcutInfo launcherShortcutInfo =
- new UnbadgedShortcutInfo(shortcut, mLauncher);
- CharSequence shortLabel = shortcut.getShortLabel();
- CharSequence longLabel = shortcut.getLongLabel();
- uiHandler.post(new UpdateShortcutChild(i, launcherShortcutInfo,
- shortLabel, longLabel));
+ uiHandler.post(new UpdateShortcutChild(
+ i, new UnbadgedShortcutInfo(shortcut, mLauncher)));
}
}
});
@@ -197,32 +193,17 @@
/** Updates the child of this container at the given index based on the given shortcut info. */
private class UpdateShortcutChild implements Runnable {
private int mShortcutChildIndex;
- private ShortcutInfo mShortcutChildInfo;
- private CharSequence mShortLabel;
- private CharSequence mLongLabel;
+ private UnbadgedShortcutInfo mShortcutChildInfo;
- public UpdateShortcutChild(int shortcutChildIndex, ShortcutInfo shortcutChildInfo,
- CharSequence shortLabel, CharSequence longLabel) {
+ public UpdateShortcutChild(int shortcutChildIndex, UnbadgedShortcutInfo shortcutChildInfo) {
mShortcutChildIndex = shortcutChildIndex;
mShortcutChildInfo = shortcutChildInfo;
- mShortLabel = shortLabel;
- mLongLabel = longLabel;
}
@Override
public void run() {
- DeepShortcutView shortcutViewContainer = getShortcutAt(mShortcutChildIndex);
- shortcutViewContainer.applyShortcutInfo(mShortcutChildInfo);
- BubbleTextView shortcutView = getShortcutAt(mShortcutChildIndex).getBubbleText();
- // Use the long label as long as it exists and fits.
- int availableWidth = shortcutView.getWidth() - shortcutView.getTotalPaddingLeft()
- - shortcutView.getTotalPaddingRight();
- boolean usingLongLabel = !TextUtils.isEmpty(mLongLabel)
- && shortcutView.getPaint().measureText(mLongLabel.toString()) <= availableWidth;
- shortcutView.setText(usingLongLabel ? mLongLabel : mShortLabel);
- shortcutView.setOnClickListener(mLauncher);
- shortcutView.setOnLongClickListener(DeepShortcutsContainer.this);
- shortcutView.setOnTouchListener(DeepShortcutsContainer.this);
+ getShortcutAt(mShortcutChildIndex)
+ .applyShortcutInfo(mShortcutChildInfo, DeepShortcutsContainer.this);
}
}
@@ -525,14 +506,7 @@
// Return if global dragging is not enabled
if (!mLauncher.isDraggingEnabled()) return false;
- UnbadgedShortcutInfo unbadgedInfo = (UnbadgedShortcutInfo) v.getTag();
- ShortcutInfo badged = new ShortcutInfo(unbadgedInfo);
- // Queue an update task on the worker thread. This ensures that the badged
- // shortcut eventually gets its icon updated.
- mLauncher.getModel().updateShortcutInfo(unbadgedInfo.mDetail, badged);
-
// Long clicked on a shortcut.
-
mDeferContainerRemoval = true;
DeepShortcutView sv = (DeepShortcutView) v.getParent();
sv.setWillDrawIcon(false);
@@ -542,7 +516,7 @@
mIconShift.y = mIconLastTouchPos.y - mLauncher.getDeviceProfile().iconSizePx;
DragView dv = mLauncher.getWorkspace().beginDragShared(
- sv.getBubbleText(), this, false, badged,
+ sv.getBubbleText(), this, false, sv.getFinalInfo(),
new ShortcutDragPreviewProvider(sv.getIconView(), mIconShift));
dv.animateShift(-mIconShift.x, -mIconShift.y);
@@ -754,8 +728,8 @@
/**
* Extension of {@link ShortcutInfo} which does not badge the icons.
*/
- private static class UnbadgedShortcutInfo extends ShortcutInfo {
- private final ShortcutInfoCompat mDetail;
+ static class UnbadgedShortcutInfo extends ShortcutInfo {
+ public final ShortcutInfoCompat mDetail;
public UnbadgedShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
super(shortcutInfo, context);
diff --git a/src/com/android/launcher3/util/MultiStateAlphaController.java b/src/com/android/launcher3/util/MultiStateAlphaController.java
index 2a49361..956fc9e 100644
--- a/src/com/android/launcher3/util/MultiStateAlphaController.java
+++ b/src/com/android/launcher3/util/MultiStateAlphaController.java
@@ -17,6 +17,7 @@
package com.android.launcher3.util;
import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
@@ -33,6 +34,7 @@
private final View mTargetView;
private final float[] mAlphas;
private final AccessibilityManager mAm;
+ private int mZeroAlphaListenerCount = 0;
public MultiStateAlphaController(View view, int stateCount) {
mTargetView = view;
@@ -44,12 +46,20 @@
public void setAlphaAtIndex(float alpha, int index) {
mAlphas[index] = alpha;
+ updateAlpha();
+ }
+
+ private void updateAlpha() {
+ // Only update the alpha if no zero-alpha animation is running.
+ if (mZeroAlphaListenerCount > 0) {
+ return;
+ }
float finalAlpha = 1;
for (float a : mAlphas) {
finalAlpha = finalAlpha * a;
}
mTargetView.setAlpha(finalAlpha);
- mTargetView.setVisibility(alpha > 0 ? View.VISIBLE
+ mTargetView.setVisibility(finalAlpha > 0 ? View.VISIBLE
: (mAm.isEnabled() ? View.GONE : View.INVISIBLE));
}
@@ -58,9 +68,11 @@
* to {@param finalAlpha}. Alphas at other index are not affected.
*/
public Animator animateAlphaAtIndex(float finalAlpha, final int index) {
+ final ValueAnimator anim;
+
if (Float.compare(finalAlpha, mAlphas[index]) == 0) {
// Return a dummy animator to avoid null checks.
- return ValueAnimator.ofFloat(0, 0);
+ anim = ValueAnimator.ofFloat(0, 0);
} else {
ValueAnimator animator = ValueAnimator.ofFloat(mAlphas[index], finalAlpha);
animator.addUpdateListener(new AnimatorUpdateListener() {
@@ -70,7 +82,38 @@
setAlphaAtIndex(value, index);
}
});
- return animator;
+ anim = animator;
+ }
+
+ if (Float.compare(finalAlpha, 0f) == 0) {
+ // In case when any channel is animating to 0, and the current alpha is also 0, do not
+ // update alpha of the target view while the animation is running.
+ // We special case '0' because if any channel is set to 0, values of other
+ // channels do not matter.
+ anim.addListener(new ZeroAlphaAnimatorListener());
+ }
+ return anim;
+ }
+
+ private class ZeroAlphaAnimatorListener extends AnimatorListenerAdapter {
+
+ private boolean mStartedAtZero = false;
+
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mStartedAtZero = Float.compare(mTargetView.getAlpha(), 0f) == 0;
+ if (mStartedAtZero) {
+ mZeroAlphaListenerCount++;
+ mTargetView.setAlpha(0);
+ }
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (mStartedAtZero) {
+ mZeroAlphaListenerCount--;
+ updateAlpha();
+ }
}
}
}
diff --git a/src/com/android/launcher3/widget/PendingItemPreviewProvider.java b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
new file mode 100644
index 0000000..8739390
--- /dev/null
+++ b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.widget;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.view.View;
+
+import com.android.launcher3.HolographicOutlineHelper;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.PendingAddItemInfo;
+import com.android.launcher3.R;
+import com.android.launcher3.Workspace;
+import com.android.launcher3.graphics.DragPreviewProvider;
+
+/**
+ * Extension of {@link DragPreviewProvider} with logic specific to pending widgets/shortcuts
+ * dragged from the widget tray.
+ */
+public class PendingItemPreviewProvider extends DragPreviewProvider {
+
+ private final PendingAddItemInfo mAddInfo;
+ private final Bitmap mPreviewBitmap;
+
+ public PendingItemPreviewProvider(View view, PendingAddItemInfo addInfo, Bitmap preview) {
+ super(view);
+ mAddInfo = addInfo;
+ mPreviewBitmap = preview;
+ }
+
+ @Override
+ public Bitmap createDragOutline(Canvas canvas) {
+ Workspace workspace = Launcher.getLauncher(mView.getContext()).getWorkspace();
+ int[] size = workspace.estimateItemSize(mAddInfo, false);
+
+ int w = size[0];
+ int h = size[1];
+ final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
+ canvas.setBitmap(b);
+
+ Rect src = new Rect(0, 0, mPreviewBitmap.getWidth(), mPreviewBitmap.getHeight());
+ float scaleFactor = Math.min((w - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getWidth(),
+ (h - DRAG_BITMAP_PADDING) / (float) mPreviewBitmap.getHeight());
+ int scaledWidth = (int) (scaleFactor * mPreviewBitmap.getWidth());
+ int scaledHeight = (int) (scaleFactor * mPreviewBitmap.getHeight());
+ Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
+
+ // center the image
+ dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
+
+ canvas.drawBitmap(mPreviewBitmap, src, dst, null);
+
+ // Don't clip alpha values for the drag outline if we're using the default widget preview
+ boolean clipAlpha = !(mAddInfo instanceof PendingAddWidgetInfo &&
+ (((PendingAddWidgetInfo) mAddInfo).previewImage == 0));
+ final int outlineColor = mView.getResources().getColor(R.color.outline_color);
+ HolographicOutlineHelper.obtain(mView.getContext())
+ .applyExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor, clipAlpha);
+ canvas.setBitmap(null);
+
+ return b;
+ }
+}
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 34bee1b..352cea4 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -205,7 +205,7 @@
// Compose the drag image
Bitmap preview;
- float scale = 1f;
+ final float scale;
final Rect bounds = image.getBitmapBounds();
if (createItemInfo instanceof PendingAddWidgetInfo) {
@@ -242,19 +242,14 @@
scale = ((float) mLauncher.getDeviceProfile().iconSizePx) / preview.getWidth();
}
- // Don't clip alpha values for the drag outline if we're using the default widget preview
- boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo &&
- (((PendingAddWidgetInfo) createItemInfo).previewImage == 0));
+ // Since we are not going through the workspace for starting the drag, set drag related
+ // information on the workspace before starting the drag.
+ mLauncher.getWorkspace().prepareDragWithProvider(
+ new PendingItemPreviewProvider(v, createItemInfo, preview));
// Start the drag
- mLauncher.lockScreenOrientation();
mDragController.startDrag(image, preview, this, createItemInfo,
bounds, DragController.DRAG_ACTION_COPY, scale);
- // This call expects the extra empty screen to already be created, which is why we call it
- // after mDragController.startDrag().
- mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, preview, clipAlpha);
-
- preview.recycle();
return true;
}