Search in sources :

Example 66 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppsCustomizePagedView method loadWidgetPreviewsInBackground.

private void loadWidgetPreviewsInBackground(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
    // previews synchronously
    if (task != null) {
        // Ensure that this task starts running at the correct priority
        task.syncThreadPriority();
    }
    // Load each of the widget/shortcut previews
    ArrayList<Object> items = data.items;
    ArrayList<Bitmap> images = data.generatedImages;
    int count = items.size();
    for (int i = 0; i < count; ++i) {
        if (task != null) {
            // Ensure we haven't been cancelled yet
            if (task.isCancelled())
                break;
            // Before work on each item, ensure that this task is running at the correct
            // priority
            task.syncThreadPriority();
        }
        Object rawInfo = items.get(i);
        if (rawInfo instanceof AppWidgetProviderInfo) {
            AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
            int[] cellSpans = Launcher.getSpanForWidget(mLauncher, info);
            int maxWidth = Math.min(data.maxImageWidth, mWidgetSpacingLayout.estimateCellWidth(cellSpans[0]));
            int maxHeight = Math.min(data.maxImageHeight, mWidgetSpacingLayout.estimateCellHeight(cellSpans[1]));
            Bitmap b = getWidgetPreview(info.provider, info.previewImage, info.icon, cellSpans[0], cellSpans[1], maxWidth, maxHeight);
            images.add(b);
        } else if (rawInfo instanceof ResolveInfo) {
            // Fill in the shortcuts information
            ResolveInfo info = (ResolveInfo) rawInfo;
            images.add(getShortcutPreview(info, data.maxImageWidth, data.maxImageHeight));
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Bitmap(android.graphics.Bitmap) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(com.android.launcher2.DropTarget.DragObject) Paint(android.graphics.Paint)

Example 67 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_packages_apps_Launcher2 by CyanogenMod.

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 = mWidgetSpacingLayout.getContentWidth();
    final int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX);
    int contentHeight = mWidgetSpacingLayout.getContentHeight();
    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 - mNumAppsPages) * 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);
            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);
            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.LEFT), GridLayout.spec(ix, GridLayout.TOP));
        lp.width = cellWidth;
        lp.height = cellHeight;
        lp.setGravity(Gravity.TOP | Gravity.LEFT);
        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];
            }
            if (immediate) {
                AsyncTaskPageData data = new AsyncTaskPageData(page, items, maxPreviewWidth, maxPreviewHeight, null, null);
                loadWidgetPreviewsInBackground(null, data);
                onSyncWidgetPageItems(data);
            } else {
                if (mInTransition) {
                    mDeferredPrepareLoadWidgetPreviewsTasks.add(this);
                } else {
                    prepareLoadWidgetPreviewsTask(page, items, maxPreviewWidth, maxPreviewHeight, mWidgetCountX);
                }
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) ResolveInfo(android.content.pm.ResolveInfo) GridLayout(android.widget.GridLayout) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(com.android.launcher2.DropTarget.DragObject) ComponentName(android.content.ComponentName)

Example 68 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Fairphone by Kwamecorp.

the class AppsCustomizePagedView method dumpAppWidgetProviderInfoList.

private void dumpAppWidgetProviderInfoList(String tag, String label, ArrayList<Object> list) {
    Log.d(tag, label + " size=" + list.size());
    for (Object i : list) {
        if (i instanceof AppWidgetProviderInfo) {
            AppWidgetProviderInfo info = (AppWidgetProviderInfo) i;
            Log.d(tag, "   label=\"" + info.label + "\" previewImage=" + info.previewImage + " resizeMode=" + info.resizeMode + " configure=" + info.configure + " initialLayout=" + info.initialLayout + " minWidth=" + info.minWidth + " minHeight=" + info.minHeight);
        } else if (i instanceof ResolveInfo) {
            ResolveInfo info = (ResolveInfo) i;
            Log.d(tag, "   label=\"" + info.loadLabel(mPackageManager) + "\" icon=" + info.icon);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(org.fairphone.launcher.DropTarget.DragObject)

Example 69 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Fairphone by Kwamecorp.

the class LauncherTransitionable method bindAppWidget.

/**
	 * Add the views for a widget to the workspace.
	 * 
	 * Implementation of the method from LauncherModel.Callbacks.
	 */
public void bindAppWidget(LauncherAppWidgetInfo item) {
    setLoadOnResume();
    final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
    if (DEBUG_WIDGETS) {
        Log.d(TAG, "bindAppWidget: " + item);
    }
    final Workspace workspace = mWorkspace;
    final int appWidgetId = item.appWidgetId;
    final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (DEBUG_WIDGETS) {
        Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
    }
    item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    item.hostView.setTag(item);
    item.onBindAppWidget(this);
    workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX, item.cellY, item.spanX, item.spanY, false);
    addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
    workspace.requestLayout();
    if (DEBUG_WIDGETS) {
        Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms");
    }
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) SuppressLint(android.annotation.SuppressLint)

Example 70 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Fairphone by Kwamecorp.

the class Workspace method onDrop.

public void onDrop(final DragObject d) {
    mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, mDragViewVisualCenter);
    CellLayout dropTargetLayout = mDropToLayout;
    // We want the point to be mapped to the dragTarget.
    if (dropTargetLayout != null) {
        if (mLauncher.isHotseatLayout(dropTargetLayout)) {
            mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
        } else {
            mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null);
        }
    }
    int snapScreen = -1;
    boolean resizeOnDrop = false;
    if (d.dragSource != this) {
        final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1] };
        onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d);
    } else if (mDragInfo != null) {
        final View cell = mDragInfo.cell;
        Runnable resizeRunnable = null;
        if (dropTargetLayout != null) {
            // Move internally
            boolean hasMovedLayouts = (getParentCellLayoutForView(cell) != dropTargetLayout);
            boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
            long container = hasMovedIntoHotseat ? LauncherSettings.Favorites.CONTAINER_HOTSEAT : LauncherSettings.Favorites.CONTAINER_DESKTOP;
            int screen = (mTargetCell[0] < 0) ? mDragInfo.screen : indexOfChild(dropTargetLayout);
            int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
            int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
            // First we find the cell nearest to point at which the item is
            // dropped, without any consideration to whether there is an item there.
            mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell);
            float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
            // cell also contains a shortcut, then create a folder with the two shortcuts.
            if (!mInScrollArea && createUserFolderIfNecessary(cell, container, dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) {
                return;
            }
            if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, distance, d, false)) {
                return;
            }
            // Aside from the special case where we're dropping a shortcut onto a shortcut,
            // we need to find the nearest cell location that is vacant
            ItemInfo item = (ItemInfo) d.dragInfo;
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }
            int[] resultSpan = new int[2];
            mTargetCell = dropTargetLayout.createArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, mTargetCell, resultSpan, CellLayout.MODE_ON_DROP);
            boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
            // if the widget resizes on drop
            if (foundCell && (cell instanceof AppWidgetHostView) && (resultSpan[0] != item.spanX || resultSpan[1] != item.spanY)) {
                resizeOnDrop = true;
                item.spanX = resultSpan[0];
                item.spanY = resultSpan[1];
                AppWidgetHostView awhv = (AppWidgetHostView) cell;
                AppWidgetResizeFrame.updateWidgetSizeRanges(awhv, mLauncher, resultSpan[0], resultSpan[1]);
            }
            if (mCurrentPage != screen && !hasMovedIntoHotseat) {
                snapScreen = screen;
                snapToPage(screen);
            }
            if (foundCell) {
                final ItemInfo info = (ItemInfo) cell.getTag();
                if (hasMovedLayouts) {
                    // Reparent the view
                    getParentCellLayoutForView(cell).removeView(cell);
                    addInScreen(cell, container, screen, mTargetCell[0], mTargetCell[1], info.spanX, info.spanY);
                }
                // update the item's position after drop
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                lp.cellX = lp.tmpCellX = mTargetCell[0];
                lp.cellY = lp.tmpCellY = mTargetCell[1];
                lp.cellHSpan = item.spanX;
                lp.cellVSpan = item.spanY;
                lp.isLockedToGrid = true;
                cell.setId(LauncherModel.getCellLayoutChildId(container, mDragInfo.screen, mTargetCell[0], mTargetCell[1], mDragInfo.spanX, mDragInfo.spanY));
                if (container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && cell instanceof LauncherAppWidgetHostView) {
                    final CellLayout cellLayout = dropTargetLayout;
                    // We post this call so that the widget has a chance to be placed
                    // in its final location
                    final LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) cell;
                    AppWidgetProviderInfo pinfo = hostView.getAppWidgetInfo();
                    if (pinfo != null && pinfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE) {
                        final Runnable addResizeFrame = new Runnable() {

                            public void run() {
                                DragLayer dragLayer = mLauncher.getDragLayer();
                                dragLayer.addResizeFrame(info, hostView, cellLayout);
                            }
                        };
                        resizeRunnable = (new Runnable() {

                            public void run() {
                                if (!isPageMoving()) {
                                    addResizeFrame.run();
                                } else {
                                    mDelayedResizeRunnable = addResizeFrame;
                                }
                            }
                        });
                    }
                }
                LauncherModel.moveItemInDatabase(mLauncher, info, container, screen, lp.cellX, lp.cellY);
            } else {
                // If we can't find a drop location, we return the item to its original position
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                mTargetCell[0] = lp.cellX;
                mTargetCell[1] = lp.cellY;
                CellLayout layout = (CellLayout) cell.getParent().getParent();
                layout.markCellsAsOccupiedForView(cell);
            }
        }
        final CellLayout parent = (CellLayout) cell.getParent().getParent();
        final Runnable finalResizeRunnable = resizeRunnable;
        // Prepare it to be animated into its new position
        // This must be called after the view has been re-parented
        final Runnable onCompleteRunnable = new Runnable() {

            @Override
            public void run() {
                mAnimatingViewIntoPlace = false;
                updateChildrenLayersEnabled(false);
                if (finalResizeRunnable != null) {
                    finalResizeRunnable.run();
                }
            }
        };
        mAnimatingViewIntoPlace = true;
        if (d.dragView.hasDrawn()) {
            final ItemInfo info = (ItemInfo) cell.getTag();
            if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
                int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE : ANIMATE_INTO_POSITION_AND_DISAPPEAR;
                animateWidgetDrop(info, parent, d.dragView, onCompleteRunnable, animationType, cell, false);
            } else {
                int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION;
                mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, onCompleteRunnable, this);
            }
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            cell.setVisibility(VISIBLE);
        }
        parent.onDropChild(cell);
    }
}
Also used : ImageView(android.widget.ImageView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) AppWidgetHostView(android.appwidget.AppWidgetHostView) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Aggregations

AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)91 Point (android.graphics.Point)24 ComponentName (android.content.ComponentName)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)18 Bundle (android.os.Bundle)18 WidgetBackupProvider (com.android.server.WidgetBackupProvider)15 ActivityInfo (android.content.pm.ActivityInfo)14 ResolveInfo (android.content.pm.ResolveInfo)14 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)12 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)12 Intent (android.content.Intent)10 PackageManager (android.content.pm.PackageManager)9 Resources (android.content.res.Resources)7 View (android.view.View)7 Context (android.content.Context)6 IPackageManager (android.content.pm.IPackageManager)6 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 TypedArray (android.content.res.TypedArray)6 XmlResourceParser (android.content.res.XmlResourceParser)6