Search in sources :

Example 6 with Widget

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

Example 7 with Widget

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

the class DecoderRing method main.

public static void main(String[] args) throws Exception {
    File source = null;
    Class type = Key.class;
    int skip = 0;
    for (int i = 0; i < args.length; i++) {
        if ("-k".equals(args[i])) {
            type = Key.class;
        } else if ("-f".equals(args[i])) {
            type = Favorite.class;
        } else if ("-j".equals(args[i])) {
            type = Journal.class;
        } else if ("-i".equals(args[i])) {
            type = Resource.class;
        } else if ("-s".equals(args[i])) {
            type = Screen.class;
        } else if ("-w".equals(args[i])) {
            type = Widget.class;
        } else if ("-S".equals(args[i])) {
            if ((i + 1) < args.length) {
                skip = Integer.valueOf(args[++i]);
            } else {
                usage(args);
            }
        } else if (args[i] != null && !args[i].startsWith("-")) {
            source = new File(args[i]);
        } else {
            System.err.println("Unsupported flag: " + args[i]);
            usage(args);
        }
    }
    // read in the bytes
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    BufferedInputStream input = null;
    if (source == null) {
        input = new BufferedInputStream(System.in);
    } else {
        try {
            input = new BufferedInputStream(new FileInputStream(source));
        } catch (FileNotFoundException e) {
            System.err.println("failed to open file: " + source + ", " + e);
            System.exit(1);
        }
    }
    byte[] buffer = new byte[1024];
    try {
        while (input.available() > 0) {
            int n = input.read(buffer);
            int offset = 0;
            if (skip > 0) {
                offset = Math.min(skip, n);
                n -= offset;
                skip -= offset;
            }
            if (n > 0) {
                byteStream.write(buffer, offset, n);
            }
        }
    } catch (IOException e) {
        System.err.println("failed to read input: " + e);
        System.exit(1);
    }
    System.err.println("read this many bytes: " + byteStream.size());
    MessageNano proto = null;
    if (type == Key.class) {
        Key key = new Key();
        try {
            key = Key.parseFrom(byteStream.toByteArray());
        } catch (InvalidProtocolBufferNanoException e) {
            System.err.println("failed to parse proto: " + e);
            System.exit(1);
        }
        // keys are self-checked
        if (key.checksum != checkKey(key)) {
            System.err.println("key ckecksum failed");
            System.exit(1);
        }
        proto = key;
    } else {
        // other types are wrapped in a checksum message
        CheckedMessage wrapper = new CheckedMessage();
        try {
            MessageNano.mergeFrom(wrapper, byteStream.toByteArray());
        } catch (InvalidProtocolBufferNanoException e) {
            System.err.println("failed to parse wrapper: " + e);
            System.exit(1);
        }
        CRC32 checksum = new CRC32();
        checksum.update(wrapper.payload);
        if (wrapper.checksum != checksum.getValue()) {
            System.err.println("wrapper ckecksum failed");
            System.exit(1);
        }
        // decode the actual message
        proto = (MessageNano) type.newInstance();
        try {
            MessageNano.mergeFrom(proto, wrapper.payload);
        } catch (InvalidProtocolBufferNanoException e) {
            System.err.println("failed to parse proto: " + e);
            System.exit(1);
        }
    }
    // Generic string output
    System.out.println(proto.toString());
    // save off the icon bits in a file for inspection
    if (proto instanceof Resource) {
        Resource icon = (Resource) proto;
        final String path = "icon.webp";
        FileOutputStream iconFile = new FileOutputStream(path);
        iconFile.write(icon.data);
        iconFile.close();
        System.err.println("wrote " + path);
    }
    // save off the widget icon and preview bits in files for inspection
    if (proto instanceof Widget) {
        Widget widget = (Widget) proto;
        if (widget.icon != null) {
            final String path = "widget_icon.webp";
            FileOutputStream iconFile = new FileOutputStream(path);
            iconFile.write(widget.icon.data);
            iconFile.close();
            System.err.println("wrote " + path);
        }
        if (widget.preview != null) {
            final String path = "widget_preview.webp";
            FileOutputStream iconFile = new FileOutputStream(path);
            iconFile.write(widget.preview.data);
            iconFile.close();
            System.err.println("wrote " + path);
        }
    }
    // success
    System.exit(0);
}
Also used : Favorite(com.android.launcher3.backup.BackupProtos.Favorite) CRC32(java.util.zip.CRC32) MessageNano(com.google.protobuf.nano.MessageNano) Resource(com.android.launcher3.backup.BackupProtos.Resource) Widget(com.android.launcher3.backup.BackupProtos.Widget) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) InvalidProtocolBufferNanoException(com.google.protobuf.nano.InvalidProtocolBufferNanoException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) CheckedMessage(com.android.launcher3.backup.BackupProtos.CheckedMessage) File(java.io.File) Key(com.android.launcher3.backup.BackupProtos.Key)

Example 8 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 9 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