Search in sources :

Example 1 with PendingAddShortcutInfo

use of com.android.launcher3.widget.PendingAddShortcutInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class FolderIcon method onDragEnter.

public void onDragEnter(ItemInfo dragInfo) {
    if (mFolder.isDestroyed() || !willAcceptItem(dragInfo))
        return;
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) getLayoutParams();
    CellLayout cl = (CellLayout) getParent().getParent();
    mBackground.animateToAccept(cl, lp.cellX, lp.cellY);
    mOpenAlarm.setOnAlarmListener(mOnOpenListener);
    if (SPRING_LOADING_ENABLED && ((dragInfo instanceof AppInfo) || (dragInfo instanceof WorkspaceItemInfo) || (dragInfo instanceof PendingAddShortcutInfo))) {
        mOpenAlarm.setAlarm(ON_OPEN_DELAY);
    }
}
Also used : CellLayout(com.android.launcher3.CellLayout) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) AppInfo(com.android.launcher3.model.data.AppInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 2 with PendingAddShortcutInfo

use of com.android.launcher3.widget.PendingAddShortcutInfo in project Launcher3 by chislon.

the class AppsCustomizePagedView method syncWidgetPageItems.

public void syncWidgetPageItems(final int page, final boolean immediate) {
    int numItemsPerPage = mWidgetCountX * mWidgetCountY;
    // Calculate the dimensions of each cell we are giving to each widget
    final ArrayList<Object> items = new ArrayList<Object>();
    int contentWidth = mContentWidth;
    final int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX);
    int contentHeight = mContentHeight;
    final int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY);
    // Prepare the set of widgets to load previews for in the background
    int offset = page * numItemsPerPage;
    for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) {
        items.add(mWidgets.get(i));
    }
    // Prepopulate the pages with the other widget info, and fill in the previews later
    final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
    layout.setColumnCount(layout.getCellCountX());
    for (int i = 0; i < items.size(); ++i) {
        Object rawInfo = items.get(i);
        PendingAddItemInfo createItemInfo = null;
        PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate(R.layout.apps_customize_widget, layout, false);
        if (rawInfo instanceof AppWidgetProviderInfo) {
            // Fill in the widget information
            AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
            createItemInfo = new PendingAddWidgetInfo(info, null, null);
            // Determine the widget spans and min resize spans.
            int[] spanXY = Launcher.getSpanForWidget(mLauncher, info);
            createItemInfo.spanX = spanXY[0];
            createItemInfo.spanY = spanXY[1];
            int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, info);
            createItemInfo.minSpanX = minSpanXY[0];
            createItemInfo.minSpanY = minSpanXY[1];
            widget.applyFromAppWidgetProviderInfo(info, -1, spanXY, mWidgetPreviewLoader);
            widget.setTag(createItemInfo);
            widget.setShortPressListener(this);
        } else if (rawInfo instanceof ResolveInfo) {
            // Fill in the shortcuts information
            ResolveInfo info = (ResolveInfo) rawInfo;
            createItemInfo = new PendingAddShortcutInfo(info.activityInfo);
            createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
            createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, info.activityInfo.name);
            widget.applyFromResolveInfo(mPackageManager, info, mWidgetPreviewLoader);
            widget.setTag(createItemInfo);
        }
        widget.setOnClickListener(this);
        widget.setOnLongClickListener(this);
        widget.setOnTouchListener(this);
        widget.setOnKeyListener(this);
        // Layout each widget
        int ix = i % mWidgetCountX;
        int iy = i / mWidgetCountX;
        GridLayout.LayoutParams lp = new GridLayout.LayoutParams(GridLayout.spec(iy, GridLayout.START), GridLayout.spec(ix, GridLayout.TOP));
        lp.width = cellWidth;
        lp.height = cellHeight;
        lp.setGravity(Gravity.TOP | Gravity.START);
        if (ix > 0)
            lp.leftMargin = mWidgetWidthGap;
        if (iy > 0)
            lp.topMargin = mWidgetHeightGap;
        layout.addView(widget, lp);
    }
    // wait until a call on onLayout to start loading, because
    // PagedViewWidget.getPreviewSize() will return 0 if it hasn't been laid out
    // TODO: can we do a measure/layout immediately?
    layout.setOnLayoutListener(new Runnable() {

        public void run() {
            // Load the widget previews
            int maxPreviewWidth = cellWidth;
            int maxPreviewHeight = cellHeight;
            if (layout.getChildCount() > 0) {
                PagedViewWidget w = (PagedViewWidget) layout.getChildAt(0);
                int[] maxSize = w.getPreviewSize();
                maxPreviewWidth = maxSize[0];
                maxPreviewHeight = maxSize[1];
            }
            mWidgetPreviewLoader.setPreviewSize(maxPreviewWidth, maxPreviewHeight, mWidgetSpacingLayout);
            if (immediate) {
                AsyncTaskPageData data = new AsyncTaskPageData(page, items, maxPreviewWidth, maxPreviewHeight, null, null, mWidgetPreviewLoader);
                loadWidgetPreviewsInBackground(null, data);
                onSyncWidgetPageItems(data);
            } else {
                if (mInTransition) {
                    mDeferredPrepareLoadWidgetPreviewsTasks.add(this);
                } else {
                    prepareLoadWidgetPreviewsTask(page, items, maxPreviewWidth, maxPreviewHeight, mWidgetCountX);
                }
            }
            layout.setOnLayoutListener(null);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Point(android.graphics.Point) ResolveInfo(android.content.pm.ResolveInfo) GridLayout(android.widget.GridLayout) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(com.android.launcher3.DropTarget.DragObject) ComponentName(android.content.ComponentName)

Example 3 with PendingAddShortcutInfo

use of com.android.launcher3.widget.PendingAddShortcutInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class PinItemDragListener method createDragHelper.

@Override
protected PendingItemDragHelper createDragHelper() {
    final PendingAddItemInfo item;
    if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
        item = new PendingAddShortcutInfo(new PinShortcutRequestActivityInfo(mRequest, mLauncher));
    } else {
        // mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET
        LauncherAppWidgetProviderInfo providerInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher));
        final PinWidgetFlowHandler flowHandler = new PinWidgetFlowHandler(providerInfo, mRequest);
        item = new PendingAddWidgetInfo(providerInfo, CONTAINER_PIN_WIDGETS) {

            @Override
            public WidgetAddFlowHandler getHandler() {
                return flowHandler;
            }
        };
    }
    View view = new View(mLauncher);
    view.setTag(item);
    PendingItemDragHelper dragHelper = new PendingItemDragHelper(view);
    if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_APPWIDGET) {
        dragHelper.setRemoteViewsPreview(getPreview(mRequest));
    }
    return dragHelper;
}
Also used : LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) PendingAddItemInfo(com.android.launcher3.PendingAddItemInfo) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PendingItemDragHelper(com.android.launcher3.widget.PendingItemDragHelper) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) WidgetAddFlowHandler(com.android.launcher3.widget.WidgetAddFlowHandler) View(android.view.View)

Example 4 with PendingAddShortcutInfo

use of com.android.launcher3.widget.PendingAddShortcutInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class Folder method onDrop.

@Override
public void onDrop(DragObject d, DragOptions options) {
    // the target location again such that the icon is placed of the final page.
    if (!mContent.rankOnCurrentPage(mEmptyCellRank)) {
        // Reorder again.
        mTargetRank = getTargetRank(d, null);
        // Rearrange items immediately.
        mReorderAlarmListener.onAlarm(mReorderAlarm);
        mOnScrollHintAlarm.cancelAlarm();
        mScrollPauseAlarm.cancelAlarm();
    }
    mContent.completePendingPageChanges();
    Launcher launcher = mLauncherDelegate.getLauncher();
    if (launcher == null) {
        return;
    }
    PendingAddShortcutInfo pasi = d.dragInfo instanceof PendingAddShortcutInfo ? (PendingAddShortcutInfo) d.dragInfo : null;
    WorkspaceItemInfo pasiSi = pasi != null ? pasi.activityInfo.createWorkspaceItemInfo() : null;
    if (pasi != null && pasiSi == null) {
        // There is no WorkspaceItemInfo, so we have to go through a configuration activity.
        pasi.container = mInfo.id;
        pasi.rank = mEmptyCellRank;
        launcher.addPendingItem(pasi, pasi.container, pasi.screenId, null, pasi.spanX, pasi.spanY);
        d.deferDragViewCleanupPostAnimation = false;
        mRearrangeOnClose = true;
    } else {
        final WorkspaceItemInfo si;
        if (pasiSi != null) {
            si = pasiSi;
        } else if (d.dragInfo instanceof AppInfo) {
            // Came from all apps -- make a copy.
            si = ((AppInfo) d.dragInfo).makeWorkspaceItem();
        } else {
            // WorkspaceItemInfo
            si = (WorkspaceItemInfo) d.dragInfo;
        }
        View currentDragView;
        if (mIsExternalDrag) {
            currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);
            // Actually move the item in the database if it was an external drag. Call this
            // before creating the view, so that WorkspaceItemInfo is updated appropriately.
            mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
            mIsExternalDrag = false;
        } else {
            currentDragView = mCurrentDragView;
            mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
        }
        if (d.dragView.hasDrawn()) {
            // Temporarily reset the scale such that the animation target gets calculated
            // correctly.
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            launcher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, null);
            setScaleX(scaleX);
            setScaleY(scaleY);
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            currentDragView.setVisibility(VISIBLE);
        }
        mItemsInvalidated = true;
        rearrangeChildren();
        // Temporarily suppress the listener, as we did all the work already here.
        try (SuppressInfoChanges s = new SuppressInfoChanges()) {
            mInfo.add(si, mEmptyCellRank, false);
        }
        // #onDropCompleted.
        if (d.dragSource != this) {
            updateItemLocationsInDatabaseBatch(false);
        }
    }
    // Clear the drag info, as it is no longer being dragged.
    mDragInProgress = false;
    if (mContent.getPageCount() > 1) {
        // The animation has already been shown while opening the folder.
        mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncherDelegate.getModelWriter());
    }
    launcher.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
    if (d.stateAnnouncer != null) {
        d.stateAnnouncer.completeAction(R.string.item_moved);
    }
    mStatsLogManager.logger().withItemInfo(d.dragInfo).withInstanceId(d.logInstanceId).log(LAUNCHER_ITEM_DROP_COMPLETED);
}
Also used : PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) Launcher(com.android.launcher3.Launcher) ClipPathView(com.android.launcher3.views.ClipPathView) BubbleTextView(com.android.launcher3.BubbleTextView) View(android.view.View) TextView(android.widget.TextView) AppWidgetHostView(android.appwidget.AppWidgetHostView) PagedView(com.android.launcher3.PagedView) AbstractFloatingView(com.android.launcher3.AbstractFloatingView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AppInfo(com.android.launcher3.model.data.AppInfo)

Example 5 with PendingAddShortcutInfo

use of com.android.launcher3.widget.PendingAddShortcutInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class AddItemActivity method setupShortcut.

private void setupShortcut() {
    PinShortcutRequestActivityInfo shortcutInfo = new PinShortcutRequestActivityInfo(mRequest, this);
    mWidgetCell.getWidgetView().setTag(new PendingAddShortcutInfo(shortcutInfo));
    applyWidgetItemAsync(() -> new WidgetItem(shortcutInfo, mApp.getIconCache(), getPackageManager()));
}
Also used : PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) WidgetItem(com.android.launcher3.model.WidgetItem)

Aggregations

PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)7 Point (android.graphics.Point)5 View (android.view.View)3 AppInfo (com.android.launcher3.model.data.AppInfo)3 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)3 SuppressLint (android.annotation.SuppressLint)2 AppWidgetHostView (android.appwidget.AppWidgetHostView)2 Rect (android.graphics.Rect)2 Drawable (android.graphics.drawable.Drawable)2 Launcher (com.android.launcher3.Launcher)2 DraggableView (com.android.launcher3.dragndrop.DraggableView)2 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)2 PendingAddWidgetInfo (com.android.launcher3.widget.PendingAddWidgetInfo)2 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 ComponentName (android.content.ComponentName)1 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)1 LauncherApps (android.content.pm.LauncherApps)1 ResolveInfo (android.content.pm.ResolveInfo)1 Resources (android.content.res.Resources)1 Paint (android.graphics.Paint)1