Search in sources :

Example 1 with GalleryApp

use of com.android.gallery3d.app.GalleryApp in project android_packages_apps_Gallery2 by LineageOS.

the class WidgetConfigure method setChoosenAlbum.

private void setChoosenAlbum(Intent data) {
    String albumPath = data.getStringExtra(AlbumPicker.KEY_ALBUM_PATH);
    WidgetDatabaseHelper helper = new WidgetDatabaseHelper(this);
    try {
        String relativePath = null;
        GalleryApp galleryApp = (GalleryApp) getApplicationContext();
        DataManager manager = galleryApp.getDataManager();
        Path path = Path.fromString(albumPath);
        MediaSet mediaSet = (MediaSet) manager.getMediaObject(path);
        if (mediaSet instanceof LocalAlbum) {
            int bucketId = Integer.parseInt(path.getSuffix());
            // If the chosen album is a local album, find relative path
            // Otherwise, leave the relative path field empty
            relativePath = LocalAlbum.getRelativePath(bucketId);
            Log.i(TAG, "Setting widget, album path: " + albumPath + ", relative path: " + relativePath);
        }
        helper.setWidget(mAppWidgetId, WidgetDatabaseHelper.TYPE_ALBUM, albumPath, relativePath);
        updateWidgetAndFinish(helper.getEntry(mAppWidgetId));
    } finally {
        helper.close();
    }
}
Also used : Path(com.android.gallery3d.data.Path) MediaSet(com.android.gallery3d.data.MediaSet) LocalAlbum(com.android.gallery3d.data.LocalAlbum) DataManager(com.android.gallery3d.data.DataManager) GalleryApp(com.android.gallery3d.app.GalleryApp)

Example 2 with GalleryApp

use of com.android.gallery3d.app.GalleryApp in project android_packages_apps_Gallery2 by LineageOS.

the class GalleryProvider method onCreate.

@Override
public boolean onCreate() {
    GalleryApp app = (GalleryApp) getContext().getApplicationContext();
    mDataManager = app.getDataManager();
    return true;
}
Also used : GalleryApp(com.android.gallery3d.app.GalleryApp)

Example 3 with GalleryApp

use of com.android.gallery3d.app.GalleryApp 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

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