use of com.android.launcher3.widget.NavigableAppWidgetHostView in project android_packages_apps_Launcher3 by crdroidandroid.
the class LauncherPreviewRenderer method inflateAndAddWidgets.
private void inflateAndAddWidgets(LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
AppWidgetHostView view;
if (FeatureFlags.WIDGETS_IN_LAUNCHER_PREVIEW.get()) {
view = mAppWidgetHost.createView(mContext, info.appWidgetId, providerInfo);
} else {
view = new NavigableAppWidgetHostView(this) {
@Override
protected boolean shouldAllowDirectClick() {
return false;
}
};
view.setAppWidget(-1, providerInfo);
view.updateAppWidget(null);
}
view.setTag(info);
if (mWallpaperColorResources != null) {
view.setColorResources(mWallpaperColorResources);
}
addInScreenFromBind(view, info);
}
use of com.android.launcher3.widget.NavigableAppWidgetHostView in project android_packages_apps_Launcher3 by crdroidandroid.
the class ShortcutAndWidgetContainer method layoutChild.
/**
* Core logic to layout a child for this ViewGroup.
*/
public void layoutChild(View child) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
if (child instanceof NavigableAppWidgetHostView) {
NavigableAppWidgetHostView nahv = (NavigableAppWidgetHostView) child;
// Scale and center the widget to fit within its cells.
DeviceProfile profile = mActivity.getDeviceProfile();
float scaleX = profile.appWidgetScale.x;
float scaleY = profile.appWidgetScale.y;
nahv.setScaleToFit(Math.min(scaleX, scaleY));
nahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f, -(lp.height - (lp.height * scaleY)) / 2.0f);
}
int childLeft = lp.x;
int childTop = lp.y;
child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
if (lp.dropped) {
lp.dropped = false;
final int[] cellXY = mTmpCellXY;
getLocationOnScreen(cellXY);
mWallpaperManager.sendWallpaperCommand(getWindowToken(), WallpaperManager.COMMAND_DROP, cellXY[0] + childLeft + lp.width / 2, cellXY[1] + childTop + lp.height / 2, 0, null);
}
}
use of com.android.launcher3.widget.NavigableAppWidgetHostView in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetCell method setAppWidgetHostViewPreview.
private void setAppWidgetHostViewPreview(NavigableAppWidgetHostView appWidgetHostViewPreview, LauncherAppWidgetProviderInfo providerInfo, @Nullable RemoteViews remoteViews) {
appWidgetHostViewPreview.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
appWidgetHostViewPreview.setAppWidget(/* appWidgetId= */
-1, providerInfo);
Rect padding;
DeviceProfile deviceProfile = mActivity.getDeviceProfile();
if (deviceProfile.shouldInsetWidgets()) {
padding = new Rect();
appWidgetHostViewPreview.getWidgetInset(deviceProfile, padding);
} else {
padding = deviceProfile.inv.defaultWidgetPadding;
}
appWidgetHostViewPreview.setPadding(padding.left, padding.top, padding.right, padding.bottom);
appWidgetHostViewPreview.updateAppWidget(remoteViews);
}
use of com.android.launcher3.widget.NavigableAppWidgetHostView in project android_packages_apps_Launcher3 by crdroidandroid.
the class AddItemActivity method onLongClick.
@Override
public boolean onLongClick(View view) {
// Find the position of the preview relative to the touch location.
WidgetImageView img = mWidgetCell.getWidgetView();
NavigableAppWidgetHostView appWidgetHostView = mWidgetCell.getAppWidgetHostViewPreview();
// we abort the drag.
if (img.getDrawable() == null && appWidgetHostView == null) {
return false;
}
final Rect bounds;
// Start home and pass the draw request params
final PinItemDragListener listener;
if (appWidgetHostView != null) {
bounds = new Rect();
appWidgetHostView.getSourceVisualDragBounds(bounds);
bounds.offset(appWidgetHostView.getLeft() - (int) mLastTouchPos.x, appWidgetHostView.getTop() - (int) mLastTouchPos.y);
listener = new PinItemDragListener(mRequest, bounds, appWidgetHostView.getMeasuredWidth(), appWidgetHostView.getMeasuredWidth());
} else {
bounds = img.getBitmapBounds();
bounds.offset(img.getLeft() - (int) mLastTouchPos.x, img.getTop() - (int) mLastTouchPos.y);
listener = new PinItemDragListener(mRequest, bounds, img.getDrawable().getIntrinsicWidth(), img.getWidth());
}
// Start a system drag and drop. We use a transparent bitmap as preview for system drag
// as the preview is handled internally by launcher.
ClipDescription description = new ClipDescription("", new String[] { listener.getMimeType() });
ClipData data = new ClipData(description, new ClipData.Item(""));
view.startDragAndDrop(data, new DragShadowBuilder(view) {
@Override
public void onDrawShadow(Canvas canvas) {
}
@Override
public void onProvideShadowMetrics(Point outShadowSize, Point outShadowTouchPoint) {
outShadowSize.set(SHADOW_SIZE, SHADOW_SIZE);
outShadowTouchPoint.set(SHADOW_SIZE / 2, SHADOW_SIZE / 2);
}
}, null, View.DRAG_FLAG_GLOBAL);
Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).setPackage(getPackageName()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Launcher.ACTIVITY_TRACKER.registerCallback(listener);
startActivity(homeIntent, ActivityOptions.makeCustomAnimation(this, 0, android.R.anim.fade_out).toBundle());
logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_DRAGGED);
mFinishOnPause = true;
return false;
}
Aggregations