Search in sources :

Example 1 with MediaObject

use of com.android.gallery3d.data.MediaObject in project android_packages_apps_Gallery2 by LineageOS.

the class GalleryProvider method openFile.

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    long token = Binder.clearCallingIdentity();
    try {
        if (mode.contains("w")) {
            throw new FileNotFoundException("cannot open file for write");
        }
        Path path = Path.fromString(uri.getPath());
        MediaObject object = mDataManager.getMediaObject(path);
        if (object == null) {
            throw new FileNotFoundException(uri.toString());
        }
        if (PicasaSource.isPicasaImage(object)) {
            return PicasaSource.openFile(getContext(), object, mode);
        } else {
            throw new FileNotFoundException("unspported type: " + object);
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : Path(com.android.gallery3d.data.Path) FileNotFoundException(java.io.FileNotFoundException) MediaObject(com.android.gallery3d.data.MediaObject)

Example 2 with MediaObject

use of com.android.gallery3d.data.MediaObject in project android_packages_apps_Gallery2 by LineageOS.

the class GalleryProvider method queryPicasaItem.

private Cursor queryPicasaItem(MediaObject image, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (projection == null)
        projection = SUPPORTED_PICASA_COLUMNS;
    Object[] columnValues = new Object[projection.length];
    double latitude = PicasaSource.getLatitude(image);
    double longitude = PicasaSource.getLongitude(image);
    boolean isValidLatlong = GalleryUtils.isValidLocation(latitude, longitude);
    for (int i = 0, n = projection.length; i < n; ++i) {
        String column = projection[i];
        if (PicasaColumns.USER_ACCOUNT.equals(column)) {
            columnValues[i] = PicasaSource.getUserAccount(getContext(), image);
        } else if (PicasaColumns.PICASA_ID.equals(column)) {
            columnValues[i] = PicasaSource.getPicasaId(image);
        } else if (ImageColumns.DISPLAY_NAME.equals(column)) {
            columnValues[i] = PicasaSource.getImageTitle(image);
        } else if (ImageColumns.SIZE.equals(column)) {
            columnValues[i] = PicasaSource.getImageSize(image);
        } else if (ImageColumns.MIME_TYPE.equals(column)) {
            columnValues[i] = PicasaSource.getContentType(image);
        } else if (ImageColumns.DATE_TAKEN.equals(column)) {
            columnValues[i] = PicasaSource.getDateTaken(image);
        } else if (ImageColumns.LATITUDE.equals(column)) {
            columnValues[i] = isValidLatlong ? latitude : null;
        } else if (ImageColumns.LONGITUDE.equals(column)) {
            columnValues[i] = isValidLatlong ? longitude : null;
        } else if (ImageColumns.ORIENTATION.equals(column)) {
            columnValues[i] = PicasaSource.getRotation(image);
        } else {
            Log.w(TAG, "unsupported column: " + column);
        }
    }
    MatrixCursor cursor = new MatrixCursor(projection);
    cursor.addRow(columnValues);
    return cursor;
}
Also used : MediaObject(com.android.gallery3d.data.MediaObject) MatrixCursor(android.database.MatrixCursor)

Example 3 with MediaObject

use of com.android.gallery3d.data.MediaObject in project android_packages_apps_Gallery2 by LineageOS.

the class ActionModeHandler method computeCanShare.

private boolean computeCanShare(ArrayList<MediaObject> selected, int max) {
    int numSelected = selected.size();
    boolean ret = computeCanShare(numSelected, max);
    if (!ret)
        return false;
    numSelected = 0;
    for (MediaObject mediaObject : selected) {
        if (mediaObject instanceof MediaSet) {
            numSelected = numSelected + ((MediaSet) mediaObject).getTotalMediaItemCount();
        } else {
            numSelected = numSelected + 1;
        }
        ret = computeCanShare(numSelected, max);
        if (!ret)
            return false;
    }
    return true;
}
Also used : MediaSet(com.android.gallery3d.data.MediaSet) MediaObject(com.android.gallery3d.data.MediaObject)

Example 4 with MediaObject

use of com.android.gallery3d.data.MediaObject in project android_packages_apps_Gallery2 by LineageOS.

the class ActionModeHandler method computeMenuOptions.

// Menu options are determined by selection set itself.
// We cannot expand it because MenuExecuter executes it based on
// the selection set instead of the expanded result.
// e.g. LocalImage can be rotated but collections of them (LocalAlbum) can't.
private int computeMenuOptions(ArrayList<MediaObject> selected) {
    int operation = MediaObject.SUPPORT_ALL;
    int type = 0;
    for (MediaObject mediaObject : selected) {
        int support = mediaObject.getSupportedOperations();
        type |= mediaObject.getMediaType();
        operation &= support;
    }
    switch(selected.size()) {
        case 1:
            final String mimeType = MenuExecutor.getMimeType(type);
            if (!GalleryUtils.isEditorAvailable(mActivity, mimeType)) {
                operation &= ~MediaObject.SUPPORT_EDIT;
            }
            break;
        default:
            operation = computeMenuOptionsMultiple(operation, selected.size());
    }
    return operation;
}
Also used : MediaObject(com.android.gallery3d.data.MediaObject)

Example 5 with MediaObject

use of com.android.gallery3d.data.MediaObject in project android_packages_apps_Gallery2 by LineageOS.

the class GalleryProvider method query.

// TODO: consider concurrent access
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    long token = Binder.clearCallingIdentity();
    try {
        Path path = Path.fromString(uri.getPath());
        MediaObject object = mDataManager.getMediaObject(path);
        if (object == null) {
            Log.w(TAG, "cannot find: " + uri);
            return null;
        }
        if (PicasaSource.isPicasaImage(object)) {
            return queryPicasaItem(object, projection, selection, selectionArgs, sortOrder);
        } else {
            return null;
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : Path(com.android.gallery3d.data.Path) MediaObject(com.android.gallery3d.data.MediaObject)

Aggregations

MediaObject (com.android.gallery3d.data.MediaObject)7 Path (com.android.gallery3d.data.Path)3 Intent (android.content.Intent)1 MatrixCursor (android.database.MatrixCursor)1 DataManager (com.android.gallery3d.data.DataManager)1 MediaSet (com.android.gallery3d.data.MediaSet)1 Job (com.android.gallery3d.util.ThreadPool.Job)1 JobContext (com.android.gallery3d.util.ThreadPool.JobContext)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1