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;
}
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");
}
});
}
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();
}
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();
}
}
Aggregations