Search in sources :

Example 6 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by AOSPA.

the class AppWidgetResizeFrame method snapToWidget.

private void snapToWidget(boolean animate) {
    getSnappedRectRelativeToDragLayer(sTmpRect);
    int newWidth = sTmpRect.width();
    int newHeight = sTmpRect.height();
    int newX = sTmpRect.left;
    int newY = sTmpRect.top;
    // down accordingly to provide a proper touch target.
    if (newY < 0) {
        // In this case we shift the touch region down to start at the top of the DragLayer
        mTopTouchRegionAdjustment = -newY;
    } else {
        mTopTouchRegionAdjustment = 0;
    }
    if (newY + newHeight > mDragLayer.getHeight()) {
        // In this case we shift the touch region up to end at the bottom of the DragLayer
        mBottomTouchRegionAdjustment = -(newY + newHeight - mDragLayer.getHeight());
    } else {
        mBottomTouchRegionAdjustment = 0;
    }
    final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
    final CellLayout pairedCellLayout;
    if (mCellLayout.getParent() instanceof Workspace) {
        Workspace workspace = (Workspace) mCellLayout.getParent();
        pairedCellLayout = workspace.getScreenPair(mCellLayout);
    } else {
        pairedCellLayout = null;
    }
    if (!animate) {
        lp.width = newWidth;
        lp.height = newHeight;
        lp.x = newX;
        lp.y = newY;
        for (int i = 0; i < HANDLE_COUNT; i++) {
            mDragHandles[i].setAlpha(1f);
        }
        if (pairedCellLayout != null) {
            updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */
            1f, /* springLoadedProgress= */
            0f);
        }
        requestLayout();
    } else {
        ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp, PropertyValuesHolder.ofInt(LAYOUT_WIDTH, lp.width, newWidth), PropertyValuesHolder.ofInt(LAYOUT_HEIGHT, lp.height, newHeight), PropertyValuesHolder.ofInt(LAYOUT_X, lp.x, newX), PropertyValuesHolder.ofInt(LAYOUT_Y, lp.y, newY));
        mFirstFrameAnimatorHelper.addTo(oa).addUpdateListener(a -> requestLayout());
        AnimatorSet set = new AnimatorSet();
        set.play(oa);
        for (int i = 0; i < HANDLE_COUNT; i++) {
            set.play(mFirstFrameAnimatorHelper.addTo(ObjectAnimator.ofFloat(mDragHandles[i], ALPHA, 1f)));
        }
        if (pairedCellLayout != null) {
            updateInvalidResizeEffect(mCellLayout, pairedCellLayout, /* alpha= */
            1f, /* springLoadedProgress= */
            0f, /* animatorSet= */
            set);
        }
        set.setDuration(SNAP_DURATION);
        set.start();
    }
    setFocusableInTouchMode(true);
    requestFocus();
}
Also used : DragLayer(com.android.launcher3.dragndrop.DragLayer) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet)

Example 7 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetsListTableViewHolderBinder method recycleTableBeforeBinding.

/**
 * Adds and hides table rows and columns from {@code table} to ensure there is sufficient room
 * to display {@code widgetItemsTable}.
 *
 * <p>Instead of recreating all UI elements in {@code table}, this function recycles all
 * existing UI elements. Instead of deleting excessive elements, it hides them.
 */
private void recycleTableBeforeBinding(TableLayout table, List<ArrayList<WidgetItem>> widgetItemsTable) {
    // Hide extra table rows.
    for (int i = widgetItemsTable.size(); i < table.getChildCount(); i++) {
        table.getChildAt(i).setVisibility(View.GONE);
    }
    for (int i = 0; i < widgetItemsTable.size(); i++) {
        List<WidgetItem> widgetItems = widgetItemsTable.get(i);
        TableRow tableRow;
        if (i < table.getChildCount()) {
            tableRow = (TableRow) table.getChildAt(i);
        } else {
            tableRow = new TableRow(table.getContext());
            tableRow.setGravity(Gravity.TOP);
            table.addView(tableRow);
        }
        if (tableRow.getChildCount() > widgetItems.size()) {
            for (int j = widgetItems.size(); j < tableRow.getChildCount(); j++) {
                tableRow.getChildAt(j).setVisibility(View.GONE);
            }
        } else {
            for (int j = tableRow.getChildCount(); j < widgetItems.size(); j++) {
                WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, tableRow, false);
                // set up touch.
                View preview = widget.findViewById(R.id.widget_preview_container);
                preview.setOnClickListener(mIconClickListener);
                preview.setOnLongClickListener(mIconLongClickListener);
                widget.setAnimatePreview(false);
                tableRow.addView(widget);
            }
        }
    }
}
Also used : TableRow(android.widget.TableRow) WidgetItem(com.android.launcher3.model.WidgetItem) WidgetCell(com.android.launcher3.widget.WidgetCell) View(android.view.View)

Example 8 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Trebuchet by LineageOS.

the class Workspace method beginDragShared.

/**
 * Core functionality for beginning a drag operation for an item that will be dropped within
 * the workspace
 */
public DragView beginDragShared(View child, DraggableView draggableView, DragSource source, ItemInfo dragObject, DragPreviewProvider previewProvider, DragOptions dragOptions) {
    float iconScale = 1f;
    if (child instanceof BubbleTextView) {
        Drawable icon = ((BubbleTextView) child).getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
    }
    // Clear the pressed state if necessary
    child.clearFocus();
    child.setPressed(false);
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedBackground();
    }
    mOutlineProvider = previewProvider;
    if (draggableView == null && child instanceof DraggableView) {
        draggableView = (DraggableView) child;
    }
    // The drag bitmap follows the touch point around on the screen
    final Bitmap b = previewProvider.createDragBitmap();
    int halfPadding = previewProvider.previewPadding / 2;
    float scale = previewProvider.getScaleAndPosition(b, mTempXY);
    int dragLayerX = mTempXY[0];
    int dragLayerY = mTempXY[1];
    Point dragVisualizeOffset = null;
    Rect dragRect = new Rect();
    if (draggableView != null) {
        draggableView.getSourceVisualDragBounds(dragRect);
        dragLayerY += dragRect.top;
        dragVisualizeOffset = new Point(-halfPadding, halfPadding);
    }
    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }
    if (child instanceof BubbleTextView && !dragOptions.isAccessibleDrag) {
        PopupContainerWithArrow popupContainer = PopupContainerWithArrow.showForIcon((BubbleTextView) child);
        if (popupContainer != null) {
            dragOptions.preDragCondition = popupContainer.createPreDragCondition();
            mLauncher.getUserEventDispatcher().resetElapsedContainerMillis("dragging started");
        }
    }
    DragView dv = mDragController.startDrag(b, draggableView, dragLayerX, dragLayerY, source, dragObject, dragVisualizeOffset, dragRect, scale * iconScale, scale, dragOptions);
    dv.setIntrinsicIconScaleFactor(dragOptions.intrinsicIconScaleFactor);
    return dv;
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) PreloadIconDrawable(com.android.launcher3.graphics.PreloadIconDrawable) DragView(com.android.launcher3.dragndrop.DragView) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) Point(android.graphics.Point) DraggableView(com.android.launcher3.dragndrop.DraggableView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 9 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Trebuchet by LineageOS.

the class SecondaryDisplayLauncher method onIconClicked.

private void onIconClicked(View v) {
    // view has detached (it's possible for this to happen if the view is removed mid touch).
    if (v.getWindowToken() == null)
        return;
    Object tag = v.getTag();
    if (tag instanceof ItemInfo) {
        ItemInfo item = (ItemInfo) tag;
        Intent intent;
        if (item instanceof PromiseAppInfo) {
            PromiseAppInfo promiseAppInfo = (PromiseAppInfo) item;
            intent = promiseAppInfo.getMarketIntent(this);
        } else {
            intent = item.getIntent();
        }
        if (intent == null) {
            throw new IllegalArgumentException("Input must have a valid intent");
        }
        startActivitySafely(v, intent, item, CONTAINER_ALL_APPS);
    }
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) PromiseAppInfo(com.android.launcher3.model.data.PromiseAppInfo) Intent(android.content.Intent)

Example 10 with Touch

use of com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetsListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
    WidgetListRowEntry entry = mEntries.get(pos);
    List<WidgetItem> infoList = entry.widgets;
    ViewGroup row = holder.cellContainer;
    if (DEBUG) {
        Log.d(TAG, String.format("onBindViewHolder [pos=%d, widget#=%d, row.getChildCount=%d]", pos, infoList.size(), row.getChildCount()));
    }
    // Add more views.
    // if there are too many, hide them.
    int expectedChildCount = infoList.size() + Math.max(0, infoList.size() - 1);
    int childCount = row.getChildCount();
    if (expectedChildCount > childCount) {
        for (int i = childCount; i < expectedChildCount; i++) {
            if ((i & 1) == 1) {
                // Add a divider for odd index
                mLayoutInflater.inflate(R.layout.widget_list_divider, row);
            } else {
                // Add cell for even index
                WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(R.layout.widget_cell, row, false);
                // set up touch.
                widget.setOnClickListener(mIconClickListener);
                widget.setOnLongClickListener(mIconLongClickListener);
                row.addView(widget);
            }
        }
    } else if (expectedChildCount < childCount) {
        for (int i = expectedChildCount; i < childCount; i++) {
            row.getChildAt(i).setVisibility(View.GONE);
        }
    }
    // Bind the views in the application info section.
    holder.title.applyFromPackageItemInfo(entry.pkgItem);
    // Bind the view in the widget horizontal tray region.
    for (int i = 0; i < infoList.size(); i++) {
        WidgetCell widget = (WidgetCell) row.getChildAt(2 * i);
        widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
        widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
        widget.ensurePreview();
        widget.setVisibility(View.VISIBLE);
        if (i > 0) {
            row.getChildAt(2 * i - 1).setVisibility(View.VISIBLE);
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) WidgetItem(com.android.launcher3.model.WidgetItem)

Aggregations

Point (android.graphics.Point)32 Rect (android.graphics.Rect)28 Intent (android.content.Intent)20 View (android.view.View)17 DragLayer (com.android.launcher3.dragndrop.DragLayer)14 DropTarget (com.android.launcher3.DropTarget)13 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)13 ClipData (android.content.ClipData)12 ClipDescription (android.content.ClipDescription)12 Canvas (android.graphics.Canvas)12 DragView (com.android.launcher3.dragndrop.DragView)12 PendingAppWidgetHostView (com.android.launcher3.widget.PendingAppWidgetHostView)12 DraggableView (com.android.launcher3.dragndrop.DraggableView)10 DeviceProfile (com.android.launcher3.DeviceProfile)8 FolderIcon (com.android.launcher3.folder.FolderIcon)8 AnimatorSet (android.animation.AnimatorSet)7 ObjectAnimator (android.animation.ObjectAnimator)7 SuppressLint (android.annotation.SuppressLint)7 Drawable (android.graphics.drawable.Drawable)7 DragShadowBuilder (android.view.View.DragShadowBuilder)7