Search in sources :

Example 1 with Widget

use of com.android.launcher3.backup.BackupProtos.Widget in project Launcher3 by chislon.

the class LauncherModel method resolveWidgetsForMimeType.

/**
     * Returns a list of all the widgets that can handle configuration with a particular mimeType.
     */
List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
    final PackageManager packageManager = context.getPackageManager();
    final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities = new ArrayList<WidgetMimeTypeHandlerData>();
    final Intent supportsIntent = new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
    supportsIntent.setType(mimeType);
    // Create a set of widget configuration components that we can test against
    final List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(context).getInstalledProviders();
    final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget = new HashMap<ComponentName, AppWidgetProviderInfo>();
    for (AppWidgetProviderInfo info : widgets) {
        configurationComponentToWidget.put(info.configure, info);
    }
    // Run through each of the intents that can handle this type of clip data, and cross
    // reference them with the components that are actual configuration components
    final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo info : activities) {
        final ActivityInfo activityInfo = info.activityInfo;
        final ComponentName infoComponent = new ComponentName(activityInfo.packageName, activityInfo.name);
        if (configurationComponentToWidget.containsKey(infoComponent)) {
            supportedConfigurationActivities.add(new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info, configurationComponentToWidget.get(infoComponent)));
        }
    }
    return supportedConfigurationActivities;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WidgetMimeTypeHandlerData(com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WidgetMimeTypeHandlerData(com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData)

Example 2 with Widget

use of com.android.launcher3.backup.BackupProtos.Widget in project Launcher3 by chislon.

the class LauncherBackupHelper method backupWidgets.

/**
     * Write all the static widget resources we need to render placeholders
     * for a package that is not installed.
     *
     * @param in notes from last backup
     * @param data output stream for key/value pairs
     * @param out notes about this backup
     * @param keys keys to mark as clean in the notes for next backup
     * @throws IOException
     */
private void backupWidgets(Journal in, BackupDataOutput data, Journal out, ArrayList<Key> keys) throws IOException {
    // persist static widget info that hasn't been persisted yet
    final LauncherAppState appState = LauncherAppState.getInstanceNoCreate();
    if (appState == null) {
        // try again later
        dataChanged();
        if (DEBUG)
            Log.d(TAG, "Launcher is not initialized, delaying widget backup");
        return;
    }
    final ContentResolver cr = mContext.getContentResolver();
    final WidgetPreviewLoader previewLoader = new WidgetPreviewLoader(mContext);
    final PagedViewCellLayout widgetSpacingLayout = new PagedViewCellLayout(mContext);
    final IconCache iconCache = appState.getIconCache();
    final int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
    final DeviceProfile profile = appState.getDynamicGrid().getDeviceProfile();
    if (DEBUG)
        Log.d(TAG, "cellWidthPx: " + profile.cellWidthPx);
    // read the old ID set
    Set<String> savedIds = getSavedIdsByType(Key.WIDGET, in);
    if (DEBUG)
        Log.d(TAG, "widgets savedIds.size()=" + savedIds.size());
    int startRows = out.rows;
    if (DEBUG)
        Log.d(TAG, "starting here: " + startRows);
    String where = Favorites.ITEM_TYPE + "=" + Favorites.ITEM_TYPE_APPWIDGET;
    Cursor cursor = cr.query(Favorites.CONTENT_URI, FAVORITE_PROJECTION, where, null, null);
    Set<String> currentIds = new HashSet<String>(cursor.getCount());
    try {
        cursor.moveToPosition(-1);
        while (cursor.moveToNext()) {
            final long id = cursor.getLong(ID_INDEX);
            final String providerName = cursor.getString(APPWIDGET_PROVIDER_INDEX);
            final int spanX = cursor.getInt(SPANX_INDEX);
            final int spanY = cursor.getInt(SPANY_INDEX);
            final ComponentName provider = ComponentName.unflattenFromString(providerName);
            Key key = null;
            String backupKey = null;
            if (provider != null) {
                key = getKey(Key.WIDGET, providerName);
                backupKey = keyToBackupKey(key);
                currentIds.add(backupKey);
            } else {
                Log.w(TAG, "empty intent on appwidget: " + id);
            }
            if (savedIds.contains(backupKey)) {
                if (DEBUG)
                    Log.d(TAG, "already saved widget " + backupKey);
                // remember that we already backed this up previously
                keys.add(key);
            } else if (backupKey != null) {
                if (DEBUG)
                    Log.d(TAG, "I can count this high: " + out.rows);
                if ((out.rows - startRows) < MAX_WIDGETS_PER_PASS) {
                    if (DEBUG)
                        Log.d(TAG, "saving widget " + backupKey);
                    previewLoader.setPreviewSize(spanX * profile.cellWidthPx, spanY * profile.cellHeightPx, widgetSpacingLayout);
                    byte[] blob = packWidget(dpi, previewLoader, iconCache, provider);
                    keys.add(key);
                    writeRowToBackup(key, blob, out, data);
                } else {
                    if (DEBUG)
                        Log.d(TAG, "scheduling another run for widget " + backupKey);
                    // too many widgets for this pass, request another.
                    dataChanged();
                }
            }
        }
    } finally {
        cursor.close();
    }
    if (DEBUG)
        Log.d(TAG, "widget currentIds.size()=" + currentIds.size());
    // these IDs must have been deleted
    savedIds.removeAll(currentIds);
    out.rows += removeDeletedKeysFromBackup(savedIds, data);
}
Also used : Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver) ComponentName(android.content.ComponentName) Key(com.android.launcher3.backup.BackupProtos.Key) HashSet(java.util.HashSet)

Example 3 with Widget

use of com.android.launcher3.backup.BackupProtos.Widget in project Launcher3 by chislon.

the class AppsCustomizePagedView method onSyncWidgetPageItems.

private void onSyncWidgetPageItems(AsyncTaskPageData data) {
    if (mInTransition) {
        mDeferredSyncWidgetPageItems.add(data);
        return;
    }
    try {
        int page = data.page;
        PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
        ArrayList<Object> items = data.items;
        int count = items.size();
        for (int i = 0; i < count; ++i) {
            PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i);
            if (widget != null) {
                Bitmap preview = data.generatedImages.get(i);
                widget.applyPreview(new FastBitmapDrawable(preview), i);
            }
        }
        enableHwLayersOnVisiblePages();
        // Update all thread priorities
        Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
        while (iter.hasNext()) {
            AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
            int pageIndex = task.page;
            task.setThreadPriority(getThreadPriorityForPage(pageIndex));
        }
    } finally {
        data.cleanup(false);
    }
}
Also used : Bitmap(android.graphics.Bitmap) DragObject(com.android.launcher3.DropTarget.DragObject) Point(android.graphics.Point)

Example 4 with Widget

use of com.android.launcher3.backup.BackupProtos.Widget in project Launcher3 by chislon.

the class LauncherBackupHelper method unpackWidget.

/** Deserialize a widget from persistence, after verifying checksum wrapper. */
private Widget unpackWidget(byte[] buffer, int offset, int dataSize) throws InvalidProtocolBufferNanoException {
    Widget widget = new Widget();
    MessageNano.mergeFrom(widget, readCheckedBytes(buffer, offset, dataSize));
    return widget;
}
Also used : Widget(com.android.launcher3.backup.BackupProtos.Widget)

Example 5 with Widget

use of com.android.launcher3.backup.BackupProtos.Widget 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)

Aggregations

AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)4 Point (android.graphics.Point)4 DragObject (com.android.launcher3.DropTarget.DragObject)4 Bitmap (android.graphics.Bitmap)3 Widget (com.android.launcher3.backup.BackupProtos.Widget)3 ComponentName (android.content.ComponentName)2 ResolveInfo (android.content.pm.ResolveInfo)2 Key (com.android.launcher3.backup.BackupProtos.Key)2 Resource (com.android.launcher3.backup.BackupProtos.Resource)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 ContentResolver (android.content.ContentResolver)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 Cursor (android.database.Cursor)1 Drawable (android.graphics.drawable.Drawable)1 GridLayout (android.widget.GridLayout)1 WidgetMimeTypeHandlerData (com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData)1 CheckedMessage (com.android.launcher3.backup.BackupProtos.CheckedMessage)1 Favorite (com.android.launcher3.backup.BackupProtos.Favorite)1