diff --git a/res/drawable/bg_drag_box.xml b/res/drawable/bg_drag_box.xml
deleted file mode 100644
index 49b3b86186..0000000000
--- a/res/drawable/bg_drag_box.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
diff --git a/res/layout/add_item_confirmation_activity.xml b/res/layout/add_item_confirmation_activity.xml
index 46d34447dd..da079da773 100644
--- a/res/layout/add_item_confirmation_activity.xml
+++ b/res/layout/add_item_confirmation_activity.xml
@@ -22,18 +22,28 @@
android:layout_height="match_parent">
-
+ android:background="?android:attr/colorPrimary"
+ android:layout_height="wrap_content">
+
+
+
+
mIdp.numColumns || widgetInfo.minSpanY > mIdp.numRows) {
// Cannot add widget
return false;
@@ -121,12 +111,9 @@ public class AddItemActivity extends BaseActivity {
mPendingWidgetInfo.spanY = Math.min(mIdp.numRows, widgetInfo.spanY);
mWidgetOptions = WidgetHostViewLoader.getDefaultOptionsForWidget(this, mPendingWidgetInfo);
- Bitmap preview = mApp.getWidgetCache().generateWidgetPreview(this, widgetInfo,
- mPendingWidgetInfo.spanX * mDeviceProfile.cellWidthPx, null, null);
- FastBitmapDrawable d = new FastBitmapDrawable(preview);
- d.setFilterBitmap(true);
- mTextView.setText(widgetInfo.getLabel(getPackageManager()));
- mTextView.setCompoundDrawables(null, d, null, null);
+ WidgetItem item = new WidgetItem(widgetInfo, getPackageManager(), mIdp);
+ mWidgetCell.applyFromCellItem(item, mApp.getWidgetCache());
+ mWidgetCell.ensurePreview();
return true;
}
@@ -151,7 +138,7 @@ public class AddItemActivity extends BaseActivity {
mPendingBindWidgetId = mAppWidgetHost.allocateAppWidgetId();
boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
- mPendingBindWidgetId, mRequest.getAppWidgetProviderInfo(), mWidgetOptions);
+ mPendingBindWidgetId, mRequest.getAppWidgetProviderInfo(this), mWidgetOptions);
if (success) {
acceptWidget(mPendingBindWidgetId);
return;
@@ -163,12 +150,12 @@ public class AddItemActivity extends BaseActivity {
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER,
mPendingWidgetInfo.componentName);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE,
- mRequest.getAppWidgetProviderInfo().getProfile());
+ mRequest.getAppWidgetProviderInfo(this).getProfile());
startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
}
private void acceptWidget(int widgetId) {
- InstallShortcutReceiver.queueWidget(mRequest.getAppWidgetProviderInfo(), widgetId, this);
+ InstallShortcutReceiver.queueWidget(mRequest.getAppWidgetProviderInfo(this), widgetId, this);
mWidgetOptions.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
mRequest.accept(mWidgetOptions);
finish();
diff --git a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
new file mode 100644
index 0000000000..d1f878a177
--- /dev/null
+++ b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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.dragndrop;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.LauncherApps;
+import android.content.pm.ShortcutInfo;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+
+import com.android.launcher3.IconCache;
+import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.compat.ShortcutConfigActivityInfo;
+
+/**
+ * Extension of ShortcutConfigActivityInfo to be used in the confirmation prompt for pin item
+ * request.
+ */
+@TargetApi(Build.VERSION_CODES.N_MR1)
+class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo {
+
+ // Class name used in the target component, such that it will never represent an
+ // actual existing class.
+ private static final String DUMMY_COMPONENT_CLASS = "pinned-shortcut";
+
+ private final ShortcutInfo mInfo;
+ private final Context mContext;
+
+ public PinShortcutRequestActivityInfo(ShortcutInfo info, Context context) {
+ super(new ComponentName(info.getPackage(), DUMMY_COMPONENT_CLASS), info.getUserHandle());
+ mInfo = info;
+ mContext = context;
+ }
+
+ @Override
+ public CharSequence getLabel() {
+ return mInfo.getShortLabel();
+ }
+
+ @Override
+ public Drawable getFullResIcon(IconCache cache) {
+ return mContext.getSystemService(LauncherApps.class)
+ .getShortcutIconDrawable(mInfo, LauncherAppState.getIDP(mContext).fillResIconDpi);
+ }
+
+ @Override
+ public boolean startConfigActivity(Activity activity, int requestCode) {
+ throw new RuntimeException("Not supported");
+ }
+
+ @Override
+ public boolean isPersistable() {
+ return false;
+ }
+}
diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java
index d07139d29f..87247f4177 100644
--- a/src/com/android/launcher3/widget/WidgetCell.java
+++ b/src/com/android/launcher3/widget/WidgetCell.java
@@ -23,6 +23,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
+import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -60,7 +61,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
private static final float PREVIEW_SCALE = 0.8f;
private int mPresetPreviewSize;
- int cellSize;
+ private int mCellSize;
private WidgetImageView mWidgetImage;
private TextView mWidgetName;
@@ -96,8 +97,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
private void setContainerWidth() {
DeviceProfile profile = mActivity.getDeviceProfile();
- cellSize = (int) (profile.cellWidthPx * WIDTH_SCALE);
- mPresetPreviewSize = (int) (cellSize * PREVIEW_SCALE);
+ mCellSize = (int) (profile.cellWidthPx * WIDTH_SCALE);
+ mPresetPreviewSize = (int) (mCellSize * PREVIEW_SCALE);
}
@Override
@@ -200,6 +201,12 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener {
return "";
}
+ @Override
+ public void setLayoutParams(ViewGroup.LayoutParams params) {
+ params.width = params.height = mCellSize;
+ super.setLayoutParams(params);
+ }
+
@Override
public CharSequence getAccessibilityClassName() {
return WidgetCell.class.getName();
diff --git a/src/com/android/launcher3/widget/WidgetsListAdapter.java b/src/com/android/launcher3/widget/WidgetsListAdapter.java
index 2d746d762f..60e6e2ac23 100644
--- a/src/com/android/launcher3/widget/WidgetsListAdapter.java
+++ b/src/com/android/launcher3/widget/WidgetsListAdapter.java
@@ -22,7 +22,6 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import com.android.launcher3.LauncherAppState;
@@ -124,11 +123,6 @@ public class WidgetsListAdapter extends Adapter {
// set up touch.
widget.setOnClickListener(mIconClickListener);
widget.setOnLongClickListener(mIconLongClickListener);
- LayoutParams lp = widget.getLayoutParams();
- lp.height = widget.cellSize;
- lp.width = widget.cellSize;
- widget.setLayoutParams(lp);
-
row.addView(widget);
}
} else if (diff < 0) {