Search in sources :

Example 96 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 97 with AppWidgetProviderInfo

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

the class LauncherTransitionable method bindAppWidget.

/**
 * Add the views for a widget to the workspace.
 *
 * Implementation of the method from LauncherModel.Callbacks.
 */
public void bindAppWidget(final LauncherAppWidgetInfo item) {
    Runnable r = new Runnable() {

        public void run() {
            bindAppWidget(item);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }
    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.screenId, 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) Point(android.graphics.Point)

Example 98 with AppWidgetProviderInfo

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

the class LauncherBackupHelper method packWidget.

/**
 * Serialize a widget for persistence, including a checksum wrapper.
 */
private byte[] packWidget(int dpi, WidgetPreviewLoader previewLoader, IconCache iconCache, ComponentName provider) {
    final AppWidgetProviderInfo info = findAppWidgetProviderInfo(provider);
    Widget widget = new Widget();
    widget.provider = provider.flattenToShortString();
    widget.label = info.label;
    widget.configure = info.configure != null;
    if (info.icon != 0) {
        widget.icon = new Resource();
        Drawable fullResIcon = iconCache.getFullResIcon(provider.getPackageName(), info.icon);
        Bitmap icon = Utilities.createIconBitmap(fullResIcon, mContext);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        if (icon.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
            widget.icon.data = os.toByteArray();
            widget.icon.dpi = dpi;
        }
    }
    if (info.previewImage != 0) {
        widget.preview = new Resource();
        Bitmap preview = previewLoader.generateWidgetPreview(info, null);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        if (preview.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
            widget.preview.data = os.toByteArray();
            widget.preview.dpi = dpi;
        }
    }
    return writeCheckedBytes(widget);
}
Also used : Bitmap(android.graphics.Bitmap) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Widget(com.android.launcher3.backup.BackupProtos.Widget) Resource(com.android.launcher3.backup.BackupProtos.Resource) Drawable(android.graphics.drawable.Drawable) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 99 with AppWidgetProviderInfo

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

the class LauncherBackupHelper method findAppWidgetProviderInfo.

private AppWidgetProviderInfo findAppWidgetProviderInfo(ComponentName component) {
    if (mWidgetMap == null) {
        List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(mContext).getInstalledProviders();
        mWidgetMap = new HashMap<ComponentName, AppWidgetProviderInfo>(widgets.size());
        for (AppWidgetProviderInfo info : widgets) {
            mWidgetMap.put(info.provider, info);
        }
    }
    return mWidgetMap.get(component);
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName)

Example 100 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)122 Bundle (android.os.Bundle)29 ComponentName (android.content.ComponentName)26 Point (android.graphics.Point)24 AppWidgetHostView (android.appwidget.AppWidgetHostView)21 WidgetBackupProvider (com.android.server.WidgetBackupProvider)15 ActivityInfo (android.content.pm.ActivityInfo)14 ResolveInfo (android.content.pm.ResolveInfo)14 ArrayList (java.util.ArrayList)13 Intent (android.content.Intent)12 IOException (java.io.IOException)12 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)12 PackageManager (android.content.pm.PackageManager)10 Test (org.junit.Test)10 Parcelable (android.os.Parcelable)8 Context (android.content.Context)7 Resources (android.content.res.Resources)7 View (android.view.View)7 IPackageManager (android.content.pm.IPackageManager)6 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6