summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/widget
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/widget')
-rw-r--r--src/com/android/launcher3/widget/PendingAddShortcutInfo.java6
-rw-r--r--src/com/android/launcher3/widget/PendingAddWidgetInfo.java6
-rw-r--r--src/com/android/launcher3/widget/PendingItemPreviewProvider.java76
-rw-r--r--src/com/android/launcher3/widget/WidgetCell.java2
-rw-r--r--src/com/android/launcher3/widget/WidgetHostViewLoader.java4
-rw-r--r--src/com/android/launcher3/widget/WidgetsContainerView.java51
6 files changed, 105 insertions, 40 deletions
diff --git a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
index a56985083..486b18ef2 100644
--- a/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddShortcutInfo.java
@@ -35,10 +35,4 @@ public class PendingAddShortcutInfo extends PendingAddItemInfo {
componentName = new ComponentName(activityInfo.packageName, activityInfo.name);
itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
}
-
- @Override
- public String toString() {
- return String.format("PendingAddShortcutInfo package=%s, name=%s",
- activityInfo.packageName, activityInfo.name);
- }
}
diff --git a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
index de06ab664..f800ac44d 100644
--- a/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
+++ b/src/com/android/launcher3/widget/PendingAddWidgetInfo.java
@@ -59,10 +59,4 @@ public class PendingAddWidgetInfo extends PendingAddItemInfo {
public boolean isCustomWidget() {
return itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
}
-
- @Override
- public String toString() {
- return String.format("PendingAddWidgetInfo package=%s, name=%s",
- componentName.getPackageName(), componentName.getShortClassName());
- }
}
diff --git a/src/com/android/launcher3/widget/PendingItemPreviewProvider.java b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
new file mode 100644
index 000000000..eaa0bb3d5
--- /dev/null
+++ b/src/com/android/launcher3/widget/PendingItemPreviewProvider.java
@@ -0,0 +1,76 @@
+/*
+ * 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.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.ALPHA_8);
+ 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));
+ HolographicOutlineHelper.obtain(mView.getContext())
+ .applyExpensiveOutlineWithBlur(b, canvas, clipAlpha);
+ canvas.setBitmap(null);
+
+ return b;
+ }
+}
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index 97877fd35..293585dd6 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -135,6 +135,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
mWidgetName.setText(mItem.label);
mWidgetDims.setText(getContext().getString(R.string.widget_dims_format,
mItem.spanX, mItem.spanY));
+ mWidgetDims.setContentDescription(getContext().getString(
+ R.string.widget_accessible_dims_format, mItem.spanX, mItem.spanY));
mWidgetPreviewLoader = loader;
if (item.activityInfo != null) {
diff --git a/src/com/android/launcher3/widget/WidgetHostViewLoader.java b/src/com/android/launcher3/widget/WidgetHostViewLoader.java
index 297505be2..049871f98 100644
--- a/src/com/android/launcher3/widget/WidgetHostViewLoader.java
+++ b/src/com/android/launcher3/widget/WidgetHostViewLoader.java
@@ -11,6 +11,7 @@ import android.view.View;
import com.android.launcher3.AppWidgetResizeFrame;
import com.android.launcher3.DragSource;
+import com.android.launcher3.DropTarget;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
@@ -18,6 +19,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.util.Thunk;
public class WidgetHostViewLoader implements DragController.DragListener {
@@ -47,7 +49,7 @@ public class WidgetHostViewLoader implements DragController.DragListener {
}
@Override
- public void onDragStart(DragSource source, ItemInfo info, int dragAction) { }
+ public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { }
@Override
public void onDragEnd() {
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 538d4c988..89c44c859 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -33,6 +33,7 @@ import com.android.launcher3.CellLayout;
import com.android.launcher3.DeleteDropTarget;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
+import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.IconCache;
import com.android.launcher3.ItemInfo;
@@ -48,6 +49,7 @@ import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Thunk;
+import com.android.launcher3.util.TransformingTouchDelegate;
/**
* The widgets list view container.
@@ -63,11 +65,11 @@ public class WidgetsContainerView extends BaseContainerView
private IconCache mIconCache;
private final Rect mTmpBgPaddingRect = new Rect();
- private final Rect mTmpRect = new Rect();
/* Recycler view related member variables */
private WidgetsRecyclerView mRecyclerView;
private WidgetsListAdapter mAdapter;
+ private TransformingTouchDelegate mRecyclerViewTouchDelegate;
/* Touch handling related member variables. */
private Toast mWidgetInstructionToast;
@@ -95,29 +97,29 @@ public class WidgetsContainerView extends BaseContainerView
}
@Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+ getRevealView().getBackground().getPadding(mTmpBgPaddingRect);
+ mRecyclerViewTouchDelegate.setBounds(
+ mRecyclerView.getLeft() - mTmpBgPaddingRect.left,
+ mRecyclerView.getTop() - mTmpBgPaddingRect.top,
+ mRecyclerView.getRight() + mTmpBgPaddingRect.right,
+ mRecyclerView.getBottom() + mTmpBgPaddingRect.bottom);
+ }
+
+ @Override
protected void onFinishInflate() {
super.onFinishInflate();
mRecyclerView = (WidgetsRecyclerView) getContentView().findViewById(R.id.widgets_list_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ mRecyclerViewTouchDelegate = new TransformingTouchDelegate(mRecyclerView);
}
@Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- getRevealView().getBackground().getPadding(mTmpBgPaddingRect);
- if (Utilities.isRtl(getResources())) {
- getContentView().setPadding(0, mTmpBgPaddingRect.top, mTmpBgPaddingRect.right,
- mTmpBgPaddingRect.bottom);
- mTmpRect.set(mTmpBgPaddingRect.left, 0, 0, 0);
- mRecyclerView.updateBackgroundPadding(mTmpRect);
- } else {
- getContentView().setPadding(mTmpBgPaddingRect.left, mTmpBgPaddingRect.top, 0,
- mTmpBgPaddingRect.bottom);
- mTmpRect.set(0, 0, mTmpBgPaddingRect.right, 0);
- mRecyclerView.updateBackgroundPadding(mTmpRect);
- }
-
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ ((View) mRecyclerView.getParent()).setTouchDelegate(mRecyclerViewTouchDelegate);
}
//
@@ -207,7 +209,7 @@ public class WidgetsContainerView extends BaseContainerView
// Compose the drag image
Bitmap preview;
- float scale = 1f;
+ final float scale;
final Rect bounds = image.getBitmapBounds();
if (createItemInfo instanceof PendingAddWidgetInfo) {
@@ -244,19 +246,14 @@ public class WidgetsContainerView extends BaseContainerView
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();
+ bounds, scale, new DragOptions());
return true;
}