use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.
the class Launcher method addAppWidgetFromDrop.
/**
* Process a widget drop.
*/
private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
AppWidgetHostView hostView = info.boundWidget;
final int appWidgetId;
WidgetAddFlowHandler addFlowHandler = info.getHandler();
if (hostView != null) {
// In the case where we've prebound the widget, we remove it from the DragLayer
if (LOGD) {
Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
}
getDragLayer().removeView(hostView);
appWidgetId = hostView.getAppWidgetId();
addAppWidgetFromDropImpl(appWidgetId, info, hostView, addFlowHandler);
// Clear the boundWidget so that it doesn't get destroyed.
info.boundWidget = null;
} else {
// the widget, or we need to start an activity to configure the widget, or both.
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) {
appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider(info.componentName);
} else {
appWidgetId = getAppWidgetHost().allocateAppWidgetId();
}
Bundle options = info.bindOptions;
boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
if (success) {
addAppWidgetFromDropImpl(appWidgetId, info, null, addFlowHandler);
} else {
addFlowHandler.startBindFlow(this, appWidgetId, info, REQUEST_BIND_APPWIDGET);
}
}
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.
the class ButtonDropTarget method getIconRect.
public Rect getIconRect(DragObject dragObject) {
int viewWidth = dragObject.dragView.getMeasuredWidth();
int viewHeight = dragObject.dragView.getMeasuredHeight();
int drawableWidth = mDrawable.getIntrinsicWidth();
int drawableHeight = mDrawable.getIntrinsicHeight();
DragLayer dragLayer = mLauncher.getDragLayer();
// Find the rect to animate to (the view is center aligned)
Rect to = new Rect();
dragLayer.getViewRectRelativeToSelf(this, to);
final int width = drawableWidth;
final int height = drawableHeight;
final int left;
final int right;
if (Utilities.isRtl(getResources())) {
right = to.right - getPaddingRight();
left = right - width;
} else {
left = to.left + getPaddingLeft();
right = left + width;
}
final int top = to.top + (getMeasuredHeight() - height) / 2;
final int bottom = top + height;
to.set(left, top, right, bottom);
// Center the destination rect about the trash icon
final int xOffset = -(viewWidth - width) / 2;
final int yOffset = -(viewHeight - height) / 2;
to.offset(xOffset, yOffset);
return to;
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.
the class ButtonDropTarget method onDrop.
/**
* On drop animate the dropView to the icon.
*/
@Override
public void onDrop(final DragObject d, final DragOptions options) {
if (options.isFlingToDelete) {
// FlingAnimation handles the animation and then calls completeDrop().
return;
}
final DragLayer dragLayer = mLauncher.getDragLayer();
final Rect from = new Rect();
dragLayer.getViewRectRelativeToSelf(d.dragView, from);
final Rect to = getIconRect(d);
final float scale = (float) to.width() / from.width();
mDropTargetBar.deferOnDragEnd();
Runnable onAnimationEndRunnable = () -> {
completeDrop(d);
mDropTargetBar.onDragEnd();
mLauncher.getStateManager().goToState(NORMAL);
};
dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, DRAG_VIEW_DROP_DURATION, Interpolators.DEACCEL_2, Interpolators.LINEAR, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.
the class FocusHelper method handleIconKeyEvent.
/**
* Handles key events in a workspace containing icons.
*/
static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) {
boolean consume = FocusLogic.shouldConsume(keyCode);
if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
return consume;
}
Launcher launcher = Launcher.getLauncher(v.getContext());
DeviceProfile profile = launcher.getDeviceProfile();
if (DEBUG) {
Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s", KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout()));
}
// Initialize the variables.
ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
CellLayout iconLayout = (CellLayout) parent.getParent();
final Workspace workspace = (Workspace) iconLayout.getParent();
final ViewGroup dragLayer = (ViewGroup) workspace.getParent();
final ViewGroup tabs = (ViewGroup) dragLayer.findViewById(R.id.drop_target_bar);
final Hotseat hotseat = (Hotseat) dragLayer.findViewById(R.id.hotseat);
final ItemInfo itemInfo = (ItemInfo) v.getTag();
final int iconIndex = parent.indexOfChild(v);
final int pageIndex = workspace.indexOfChild(iconLayout);
final int pageCount = workspace.getChildCount();
CellLayout hotseatLayout = (CellLayout) hotseat.getChildAt(0);
ShortcutAndWidgetContainer hotseatParent = hotseatLayout.getShortcutsAndWidgets();
int[][] matrix;
// with the hotseat.
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) {
matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && profile.isVerticalBarLayout()) {
matrix = FocusLogic.createSparseMatrixWithHotseat(iconLayout, hotseatLayout, profile);
} else {
matrix = FocusLogic.createSparseMatrix(iconLayout);
}
// Process the focus.
int newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, iconIndex, pageIndex, pageCount, Utilities.isRtl(v.getResources()));
boolean isRtl = Utilities.isRtl(v.getResources());
View newIcon = null;
CellLayout workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex);
switch(newIconIndex) {
case FocusLogic.NOOP:
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
newIcon = tabs;
}
break;
case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
int newPageIndex = pageIndex - 1;
if (newIconIndex == FocusLogic.NEXT_PAGE_RIGHT_COLUMN) {
newPageIndex = pageIndex + 1;
}
int row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY;
parent = getCellLayoutChildrenForIndex(workspace, newPageIndex);
if (parent != null) {
iconLayout = (CellLayout) parent.getParent();
matrix = FocusLogic.createSparseMatrixWithPivotColumn(iconLayout, iconLayout.getCountX(), row);
newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, FocusLogic.PIVOT, newPageIndex, pageCount, Utilities.isRtl(v.getResources()));
if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
} else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
} else {
newIcon = parent.getChildAt(newIconIndex);
}
}
break;
case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
workspaceLayout = (CellLayout) workspace.getChildAt(pageIndex - 1);
newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
if (newIcon == null) {
// Check the hotseat if no focusable item was found on the workspace.
newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
workspace.snapToPage(pageIndex - 1);
}
break;
case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
break;
case FocusLogic.NEXT_PAGE_FIRST_ITEM:
newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
break;
case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN:
newPageIndex = pageIndex + 1;
if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN) {
newPageIndex = pageIndex - 1;
}
row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY;
parent = getCellLayoutChildrenForIndex(workspace, newPageIndex);
if (parent != null) {
iconLayout = (CellLayout) parent.getParent();
matrix = FocusLogic.createSparseMatrixWithPivotColumn(iconLayout, -1, row);
newIconIndex = FocusLogic.handleKeyEvent(keyCode, matrix, FocusLogic.PIVOT, newPageIndex, pageCount, Utilities.isRtl(v.getResources()));
if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
newIcon = handleNextPageFirstItem(workspace, hotseatLayout, pageIndex, isRtl);
} else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
newIcon = handlePreviousPageLastItem(workspace, hotseatLayout, pageIndex, isRtl);
} else {
newIcon = parent.getChildAt(newIconIndex);
}
}
break;
case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
newIcon = getFirstFocusableIconInReadingOrder(workspaceLayout, isRtl);
if (newIcon == null) {
// Check the hotseat if no focusable item was found on the workspace.
newIcon = getFirstFocusableIconInReadingOrder(hotseatLayout, isRtl);
}
break;
case FocusLogic.CURRENT_PAGE_LAST_ITEM:
newIcon = getFirstFocusableIconInReverseReadingOrder(workspaceLayout, isRtl);
if (newIcon == null) {
// Check the hotseat if no focusable item was found on the workspace.
newIcon = getFirstFocusableIconInReverseReadingOrder(hotseatLayout, isRtl);
}
break;
default:
// current page, some item.
if (0 <= newIconIndex && newIconIndex < parent.getChildCount()) {
newIcon = parent.getChildAt(newIconIndex);
} else if (parent.getChildCount() <= newIconIndex && newIconIndex < parent.getChildCount() + hotseatParent.getChildCount()) {
newIcon = hotseatParent.getChildAt(newIconIndex - parent.getChildCount());
}
break;
}
if (newIcon != null) {
newIcon.requestFocus();
playSoundEffect(keyCode, v);
}
return consume;
}
use of com.android.launcher3.dragndrop.DragLayer in project android_packages_apps_Trebuchet by LineageOS.
the class AppWidgetResizeFrame method showForWidget.
public static void showForWidget(LauncherAppWidgetHostView widget, CellLayout cellLayout) {
Launcher launcher = Launcher.getLauncher(cellLayout.getContext());
AbstractFloatingView.closeAllOpenViews(launcher);
DragLayer dl = launcher.getDragLayer();
AppWidgetResizeFrame frame = (AppWidgetResizeFrame) launcher.getLayoutInflater().inflate(R.layout.app_widget_resize_frame, dl, false);
frame.setupForWidget(widget, cellLayout, dl);
((DragLayer.LayoutParams) frame.getLayoutParams()).customPosition = true;
dl.addView(frame);
frame.mIsOpen = true;
frame.snapToWidget(false);
}
Aggregations