Search in sources :

Example 1 with Entry

use of com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry in project android_packages_apps_Gallery2 by LineageOS.

the class GalleryWidgetMigrator method updatePath.

private static void updatePath(File root, HashMap<Integer, Entry> entries, WidgetDatabaseHelper dbHelper, String oldExtStorage) {
    File[] files = root.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.isDirectory() && !entries.isEmpty()) {
                String path = file.getAbsolutePath();
                String oldPath = oldExtStorage + path.substring(RELATIVE_PATH_START);
                int oldBucketId = GalleryUtils.getBucketId(oldPath);
                Entry entry = entries.remove(oldBucketId);
                if (entry != null) {
                    int newBucketId = GalleryUtils.getBucketId(path);
                    String newAlbumPath = Path.fromString(entry.albumPath).getParent().getChild(newBucketId).toString();
                    Log.d(TAG, "migrate from " + entry.albumPath + " to " + newAlbumPath);
                    entry.albumPath = newAlbumPath;
                    // update entry's relative path
                    entry.relativePath = path.substring(RELATIVE_PATH_START);
                    dbHelper.updateEntry(entry);
                }
                // recursion
                updatePath(file, entries, dbHelper, oldExtStorage);
            }
        }
    }
}
Also used : Entry(com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry) File(java.io.File)

Example 2 with Entry

use of com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry in project android_packages_apps_Gallery2 by LineageOS.

the class PhotoAppWidgetProvider method onUpdate.

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    if (ApiHelper.HAS_REMOTE_VIEWS_SERVICE) {
        // migrate gallery widgets from pre-JB releases to JB due to bucket ID change
        GalleryWidgetMigrator.migrateGalleryWidgets(context);
    }
    WidgetDatabaseHelper helper = new WidgetDatabaseHelper(context);
    try {
        for (int id : appWidgetIds) {
            Entry entry = helper.getEntry(id);
            if (entry != null) {
                RemoteViews views = buildWidget(context, id, entry);
                appWidgetManager.updateAppWidget(id, views);
            } else {
                Log.e(TAG, "cannot load widget: " + id);
            }
        }
    } finally {
        helper.close();
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
Also used : Entry(com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry) RemoteViews(android.widget.RemoteViews)

Example 3 with Entry

use of com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry in project android_packages_apps_Gallery2 by LineageOS.

the class GalleryWidgetMigrator method migrateGalleryWidgetsInternal.

private static void migrateGalleryWidgetsInternal(Context context) {
    GalleryApp galleryApp = (GalleryApp) context.getApplicationContext();
    DataManager manager = galleryApp.getDataManager();
    WidgetDatabaseHelper dbHelper = new WidgetDatabaseHelper(context);
    // only need to migrate local-album entries of type TYPE_ALBUM
    List<Entry> entries = dbHelper.getEntries(WidgetDatabaseHelper.TYPE_ALBUM);
    if (entries == null)
        return;
    // Check each entry's relativePath. If exists, update bucket id using relative
    // path combined with external storage path. Otherwise, iterate through old external
    // storage paths to find the relative path that matches the old bucket id, and then update
    // bucket id and relative path
    HashMap<Integer, Entry> localEntries = new HashMap<Integer, Entry>(entries.size());
    for (Entry entry : entries) {
        Path path = Path.fromString(entry.albumPath);
        MediaSet mediaSet = (MediaSet) manager.getMediaObject(path);
        if (mediaSet instanceof LocalAlbum) {
            if (entry.relativePath != null && entry.relativePath.length() > 0) {
                // update entry using relative path + external storage path
                updateEntryUsingRelativePath(entry, dbHelper);
            } else {
                int bucketId = Integer.parseInt(path.getSuffix());
                localEntries.put(bucketId, entry);
            }
        }
    }
    if (!localEntries.isEmpty())
        migrateLocalEntries(context, localEntries, dbHelper);
}
Also used : Path(com.android.gallery3d.data.Path) Entry(com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry) HashMap(java.util.HashMap) WidgetDatabaseHelper(com.android.gallery3d.gadget.WidgetDatabaseHelper) MediaSet(com.android.gallery3d.data.MediaSet) LocalAlbum(com.android.gallery3d.data.LocalAlbum) DataManager(com.android.gallery3d.data.DataManager) GalleryApp(com.android.gallery3d.app.GalleryApp)

Aggregations

Entry (com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry)3 RemoteViews (android.widget.RemoteViews)1 GalleryApp (com.android.gallery3d.app.GalleryApp)1 DataManager (com.android.gallery3d.data.DataManager)1 LocalAlbum (com.android.gallery3d.data.LocalAlbum)1 MediaSet (com.android.gallery3d.data.MediaSet)1 Path (com.android.gallery3d.data.Path)1 WidgetDatabaseHelper (com.android.gallery3d.gadget.WidgetDatabaseHelper)1 File (java.io.File)1 HashMap (java.util.HashMap)1