Search in sources :

Example 46 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project platform_packages_apps_launcher by android.

the class Launcher method bindAppWidgets.

private void bindAppWidgets(Launcher.DesktopBinder binder, LinkedList<LauncherAppWidgetInfo> appWidgets) {
    final Workspace workspace = mWorkspace;
    final boolean desktopLocked = mDesktopLocked;
    if (!appWidgets.isEmpty()) {
        final LauncherAppWidgetInfo item = appWidgets.removeFirst();
        final int appWidgetId = item.appWidgetId;
        final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
        item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
        if (LOGD) {
            d(LOG_TAG, String.format("about to setAppWidget for id=%d, info=%s", appWidgetId, appWidgetInfo));
        }
        item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
        item.hostView.setTag(item);
        workspace.addInScreen(item.hostView, item.screen, item.cellX, item.cellY, item.spanX, item.spanY, !desktopLocked);
        workspace.requestLayout();
    }
    if (appWidgets.isEmpty()) {
        if (PROFILE_ROTATE) {
            android.os.Debug.stopMethodTracing();
        }
    } else {
        binder.obtainMessage(DesktopBinder.MESSAGE_BIND_APPWIDGETS).sendToTarget();
    }
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 47 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo 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 48 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.

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(com.android.launcher3.DropTarget.DragObject)

Example 49 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.

the class AppsCustomizePagedView method preloadWidget.

private void preloadWidget(final PendingAddWidgetInfo info) {
    final AppWidgetProviderInfo pInfo = info.info;
    final Bundle options = getDefaultOptionsForWidget(mLauncher, info);
    if (pInfo.configure != null) {
        info.bindOptions = options;
        return;
    }
    mWidgetCleanupState = WIDGET_PRELOAD_PENDING;
    mBindWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
            // SDK level check.
            if (options == null) {
                if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName)) {
                    mWidgetCleanupState = WIDGET_BOUND;
                }
            } else {
                if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName, options)) {
                    mWidgetCleanupState = WIDGET_BOUND;
                }
            }
        }
    };
    post(mBindWidgetRunnable);
    mInflateWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            if (mWidgetCleanupState != WIDGET_BOUND) {
                return;
            }
            AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView(getContext(), mWidgetLoadingId, pInfo);
            info.boundWidget = hostView;
            mWidgetCleanupState = WIDGET_INFLATED;
            hostView.setVisibility(INVISIBLE);
            int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(info.spanX, info.spanY, info, false);
            // We want the first widget layout to be the correct size. This will be important
            // for width size reporting to the AppWidgetManager.
            DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0], unScaledSize[1]);
            lp.x = lp.y = 0;
            lp.customPosition = true;
            hostView.setLayoutParams(lp);
            mLauncher.getDragLayer().addView(hostView);
        }
    };
    post(mInflateWidgetRunnable);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) Bundle(android.os.Bundle) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 50 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.

the class AppsCustomizePagedView method onPackagesUpdated.

public void onPackagesUpdated(ArrayList<Object> widgetsAndShortcuts) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    // Get the list of widgets and shortcuts
    mWidgets.clear();
    for (Object o : widgetsAndShortcuts) {
        if (o instanceof AppWidgetProviderInfo) {
            AppWidgetProviderInfo widget = (AppWidgetProviderInfo) o;
            if (!app.shouldShowAppOrWidgetProvider(widget.provider)) {
                continue;
            }
            widget.label = widget.label.trim();
            if (widget.minWidth > 0 && widget.minHeight > 0) {
                // Ensure that all widgets we show can be added on a workspace of this size
                int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget);
                int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget);
                int minSpanX = Math.min(spanXY[0], minSpanXY[0]);
                int minSpanY = Math.min(spanXY[1], minSpanXY[1]);
                if (minSpanX <= (int) grid.numColumns && minSpanY <= (int) grid.numRows) {
                    mWidgets.add(widget);
                } else {
                    Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + widget.minWidth + ", " + widget.minHeight + ")");
                }
            } else {
                Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + widget.minWidth + ", " + widget.minHeight + ")");
            }
        } else {
            // just add shortcuts
            mWidgets.add(o);
        }
    }
    updatePageCountsAndInvalidateData();
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(com.android.launcher3.DropTarget.DragObject) Point(android.graphics.Point)

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