Java Code Examples for com.yanzhenjie.album.AlbumFile#setSize()
The following examples show how to use
com.yanzhenjie.album.AlbumFile#setSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PictureFileUtils.java From smart-farmer-android with Apache License 2.0 | 5 votes |
public static AlbumFile createAlbumFile(File file, boolean isVideo){ AlbumFile albumFile = new AlbumFile(); albumFile.setMediaType(isVideo ? AlbumFile.TYPE_VIDEO : AlbumFile.TYPE_IMAGE); albumFile.setPath(file.getAbsolutePath()); String name = file.getName(); albumFile.setName(name); int lastPoint = name.lastIndexOf("."); if (lastPoint != -1){ albumFile.setTitle(name.substring(0, lastPoint)); } else { albumFile.setTitle(name); } albumFile.setBucketName(file.getParent()); if (lastPoint != -1 && lastPoint != name.length() - 1){ albumFile.setMimeType(MimeTypeMap.getSingleton().getMimeTypeFromExtension(name.substring(lastPoint + 1))); } long date = System.currentTimeMillis(); albumFile.setAddDate(date); albumFile.setModifyDate(date); albumFile.setLatitude(0); albumFile.setLongitude(0); albumFile.setSize(file.length()); albumFile.setThumbPath(null); albumFile.setChecked(true); albumFile.setEnable(true); // if (!isVideo) { // int degree = PictureFileUtils.readPictureDegree(file.getAbsolutePath()); // rotateImage(degree, file); // } if (isVideo) { int[] size = readVideoInfo(file.getPath()); albumFile.setWidth(size[0]); albumFile.setHeight(size[1]); albumFile.setDuration(size[2]); } return albumFile; }
Example 2
Source File: PathConversion.java From Album with Apache License 2.0 | 4 votes |
@WorkerThread @NonNull public AlbumFile convert(String filePath) { File file = new File(filePath); AlbumFile albumFile = new AlbumFile(); albumFile.setPath(filePath); File parentFile = file.getParentFile(); albumFile.setBucketName(parentFile.getName()); String mimeType = AlbumUtils.getMimeType(filePath); albumFile.setMimeType(mimeType); long nowTime = System.currentTimeMillis(); albumFile.setAddDate(nowTime); albumFile.setSize(file.length()); int mediaType = 0; if (!TextUtils.isEmpty(mimeType)) { if (mimeType.contains("video")) mediaType = AlbumFile.TYPE_VIDEO; if (mimeType.contains("image")) mediaType = AlbumFile.TYPE_IMAGE; } albumFile.setMediaType(mediaType); if (mSizeFilter != null && mSizeFilter.filter(file.length())) { albumFile.setDisable(true); } if (mMimeFilter != null && mMimeFilter.filter(mimeType)) { albumFile.setDisable(true); } if (mediaType == AlbumFile.TYPE_VIDEO) { MediaPlayer player = new MediaPlayer(); try { player.setDataSource(filePath); player.prepare(); albumFile.setDuration(player.getDuration()); } catch (Exception ignored) { } finally { player.release(); } if (mDurationFilter != null && mDurationFilter.filter(albumFile.getDuration())) { albumFile.setDisable(true); } } return albumFile; }
Example 3
Source File: MediaReader.java From Album with Apache License 2.0 | 4 votes |
/** * Scan for image files. */ @WorkerThread private void scanImageFile(Map<String, AlbumFolder> albumFolderMap, AlbumFolder allFileFolder) { ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGES, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { String path = cursor.getString(0); String bucketName = cursor.getString(1); String mimeType = cursor.getString(2); long addDate = cursor.getLong(3); float latitude = cursor.getFloat(4); float longitude = cursor.getFloat(5); long size = cursor.getLong(6); AlbumFile imageFile = new AlbumFile(); imageFile.setMediaType(AlbumFile.TYPE_IMAGE); imageFile.setPath(path); imageFile.setBucketName(bucketName); imageFile.setMimeType(mimeType); imageFile.setAddDate(addDate); imageFile.setLatitude(latitude); imageFile.setLongitude(longitude); imageFile.setSize(size); if (mSizeFilter != null && mSizeFilter.filter(size)) { if (!mFilterVisibility) continue; imageFile.setDisable(true); } if (mMimeFilter != null && mMimeFilter.filter(mimeType)) { if (!mFilterVisibility) continue; imageFile.setDisable(true); } allFileFolder.addAlbumFile(imageFile); AlbumFolder albumFolder = albumFolderMap.get(bucketName); if (albumFolder != null) albumFolder.addAlbumFile(imageFile); else { albumFolder = new AlbumFolder(); albumFolder.setName(bucketName); albumFolder.addAlbumFile(imageFile); albumFolderMap.put(bucketName, albumFolder); } } cursor.close(); } }
Example 4
Source File: MediaReader.java From Album with Apache License 2.0 | 4 votes |
/** * Scan for image files. */ @WorkerThread private void scanVideoFile(Map<String, AlbumFolder> albumFolderMap, AlbumFolder allFileFolder) { ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, VIDEOS, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { String path = cursor.getString(0); String bucketName = cursor.getString(1); String mimeType = cursor.getString(2); long addDate = cursor.getLong(3); float latitude = cursor.getFloat(4); float longitude = cursor.getFloat(5); long size = cursor.getLong(6); long duration = cursor.getLong(7); AlbumFile videoFile = new AlbumFile(); videoFile.setMediaType(AlbumFile.TYPE_VIDEO); videoFile.setPath(path); videoFile.setBucketName(bucketName); videoFile.setMimeType(mimeType); videoFile.setAddDate(addDate); videoFile.setLatitude(latitude); videoFile.setLongitude(longitude); videoFile.setSize(size); videoFile.setDuration(duration); if (mSizeFilter != null && mSizeFilter.filter(size)) { if (!mFilterVisibility) continue; videoFile.setDisable(true); } if (mMimeFilter != null && mMimeFilter.filter(mimeType)) { if (!mFilterVisibility) continue; videoFile.setDisable(true); } if (mDurationFilter != null && mDurationFilter.filter(duration)) { if (!mFilterVisibility) continue; videoFile.setDisable(true); } allFileFolder.addAlbumFile(videoFile); AlbumFolder albumFolder = albumFolderMap.get(bucketName); if (albumFolder != null) albumFolder.addAlbumFile(videoFile); else { albumFolder = new AlbumFolder(); albumFolder.setName(bucketName); albumFolder.addAlbumFile(videoFile); albumFolderMap.put(bucketName, albumFolder); } } cursor.close(); } }