Search in sources :

Example 1 with Video

use of us.koller.cameraroll.data.models.Video in project Camera-Roll-Android-App by kollerlukas.

the class ItemAdapter method instantiateItem.

@NonNull
@Override
public Object instantiateItem(@NonNull final ViewGroup container, int position) {
    AlbumItem albumItem = album.getAlbumItems().get(position);
    ViewHolder viewHolder;
    if (albumItem instanceof Video) {
        viewHolder = new VideoViewHolder(albumItem, position);
    } else if (albumItem instanceof Gif) {
        viewHolder = new GifViewHolder(albumItem, position);
    } else if (albumItem instanceof RAWImage) {
        viewHolder = new RAWImageViewHolder(albumItem, position);
    } else {
        viewHolder = new PhotoViewHolder(albumItem, position);
    }
    viewHolders.add(viewHolder);
    View v = viewHolder.getView(container);
    container.addView(v);
    if (callback != null) {
        boolean b = callback.onInstantiateItem(viewHolder);
        if (!b) {
            callback = null;
        }
    }
    return v;
}
Also used : RAWImage(us.koller.cameraroll.data.models.RAWImage) PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) ViewHolder(us.koller.cameraroll.adapter.item.viewHolder.ViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder) Gif(us.koller.cameraroll.data.models.Gif) Video(us.koller.cameraroll.data.models.Video) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) RAWImageViewHolder(us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder) PhotoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder) VideoViewHolder(us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder) GifViewHolder(us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder) View(android.view.View) NonNull(android.support.annotation.NonNull)

Example 2 with Video

use of us.koller.cameraroll.data.models.Video in project Camera-Roll-Android-App by kollerlukas.

the class MediaStoreRetriever method loadAlbums.

@Override
void loadAlbums(final Activity context, boolean hiddenFolders) {
    final long startTime = System.currentTimeMillis();
    final ArrayList<Album> albums = new ArrayList<>();
    // Return only video and image metadata.
    String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
    Uri queryUri = MediaStore.Files.getContentUri("external");
    CursorLoader cursorLoader = new CursorLoader(context, queryUri, projection, selection, // Selection args (none).
    null, MediaStore.Files.FileColumns.DATE_ADDED);
    final Cursor cursor = cursorLoader.loadInBackground();
    if (cursor == null) {
        return;
    }
    // search hiddenFolders
    if (hiddenFolders) {
        ArrayList<Album> hiddenAlbums = checkHiddenFolders(context);
        albums.addAll(hiddenAlbums);
    }
    AsyncTask.execute(new Runnable() {

        @Override
        public void run() {
            if (cursor.moveToFirst()) {
                String path;
                long dateTaken, id;
                int pathColumn = cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
                int idColumn = cursor.getColumnIndex(BaseColumns._ID);
                do {
                    path = cursor.getString(pathColumn);
                    AlbumItem albumItem = AlbumItem.getInstance(context, path);
                    if (albumItem != null) {
                        // set dateTaken
                        int dateTakenColumn = cursor.getColumnIndex(!(albumItem instanceof Video) ? MediaStore.Images.ImageColumns.DATE_TAKEN : MediaStore.Video.VideoColumns.DATE_TAKEN);
                        dateTaken = cursor.getLong(dateTakenColumn);
                        albumItem.setDate(dateTaken);
                        id = cursor.getLong(idColumn);
                        Uri uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), id);
                        albumItem.setUri(uri);
                        // search bucket
                        boolean foundBucket = false;
                        for (int i = 0; i < albums.size(); i++) {
                            if (albums.get(i).getPath().equals(FileOperation.Util.getParentPath(path))) {
                                albums.get(i).getAlbumItems().add(0, albumItem);
                                foundBucket = true;
                                break;
                            }
                        }
                        if (!foundBucket) {
                            // no bucket found
                            String bucketPath = FileOperation.Util.getParentPath(path);
                            if (bucketPath != null) {
                                albums.add(new Album().setPath(bucketPath));
                                albums.get(albums.size() - 1).getAlbumItems().add(0, albumItem);
                            }
                        }
                    }
                } while (cursor.moveToNext());
            }
            cursor.close();
            // done loading media with content resolver
            MediaProvider.OnMediaLoadedCallback callback = getCallback();
            if (callback != null) {
                callback.onMediaLoaded(albums);
            }
            Log.d("MediaStoreRetriever", "onMediaLoaded(): " + String.valueOf(System.currentTimeMillis() - startTime) + " ms");
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Cursor(android.database.Cursor) Uri(android.net.Uri) CursorLoader(android.support.v4.content.CursorLoader) Video(us.koller.cameraroll.data.models.Video)

Example 3 with Video

use of us.koller.cameraroll.data.models.Video in project Camera-Roll-Android-App by kollerlukas.

the class IntentReceiver method view.

private void view(Intent intent) {
    Uri uri = intent.getData();
    if (uri == null) {
        Toast.makeText(this, getString(R.string.error) + ": Uri = null", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, MainActivity.class));
        this.finish();
        return;
    }
    Album album = new Album().setPath("");
    AlbumItem albumItem;
    String mimeType = intent.getType();
    if (mimeType != null) {
        albumItem = AlbumItem.getInstance(this, uri, mimeType);
    } else {
        albumItem = AlbumItem.getInstance(this, uri);
    }
    if (albumItem == null) {
        Toast.makeText(this, getString(R.string.error), Toast.LENGTH_SHORT).show();
        this.finish();
        return;
    }
    album.getAlbumItems().add(albumItem);
    if (albumItem instanceof Video) {
        Intent view_video = new Intent(this, VideoPlayerActivity.class).setData(uri);
        startActivity(view_video);
    } else {
        Intent view_photo = new Intent(this, ItemActivity.class).setData(uri).putExtra(ItemActivity.ALBUM_ITEM, albumItem).putExtra(ItemActivity.VIEW_ONLY, true).putExtra(ItemActivity.ALBUM, album).putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem)).addFlags(intent.getFlags());
        startActivity(view_photo);
    }
    this.finish();
}
Also used : Video(us.koller.cameraroll.data.models.Video) Album(us.koller.cameraroll.data.models.Album) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) Intent(android.content.Intent) MainActivity(us.koller.cameraroll.ui.MainActivity) Uri(android.net.Uri) VideoPlayerActivity(us.koller.cameraroll.ui.VideoPlayerActivity)

Example 4 with Video

use of us.koller.cameraroll.data.models.Video in project Camera-Roll-Android-App by kollerlukas.

the class ItemActivity method videoOnClick.

public static void videoOnClick(Context context, AlbumItem albumItem) {
    if (!(albumItem instanceof Video)) {
        return;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(albumItem.getUri(context), "video/*");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, "No App found to play your video", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Video(us.koller.cameraroll.data.models.Video) Intent(android.content.Intent)

Aggregations

Video (us.koller.cameraroll.data.models.Video)4 AlbumItem (us.koller.cameraroll.data.models.AlbumItem)3 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Album (us.koller.cameraroll.data.models.Album)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1 CursorLoader (android.support.v4.content.CursorLoader)1 View (android.view.View)1 ArrayList (java.util.ArrayList)1 GifViewHolder (us.koller.cameraroll.adapter.item.viewHolder.GifViewHolder)1 PhotoViewHolder (us.koller.cameraroll.adapter.item.viewHolder.PhotoViewHolder)1 RAWImageViewHolder (us.koller.cameraroll.adapter.item.viewHolder.RAWImageViewHolder)1 VideoViewHolder (us.koller.cameraroll.adapter.item.viewHolder.VideoViewHolder)1 ViewHolder (us.koller.cameraroll.adapter.item.viewHolder.ViewHolder)1 Gif (us.koller.cameraroll.data.models.Gif)1 RAWImage (us.koller.cameraroll.data.models.RAWImage)1 MainActivity (us.koller.cameraroll.ui.MainActivity)1 VideoPlayerActivity (us.koller.cameraroll.ui.VideoPlayerActivity)1