use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.
the class PhotoEditActivity method rotatePhoto.
/**
* 图片旋转
*/
private void rotatePhoto() {
if (mPhotoList.size() > 0 && mPhotoList.get(mSelectIndex) != null && !mRotating) {
final PhotoInfo photoInfo = mPhotoList.get(mSelectIndex);
final String ext = FilenameUtils.getExtension(photoInfo.getPhotoPath());
if (StringUtils.isEmpty(ext) || !(ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg"))) {
toast(getString(R.string.edit_letoff_photo_format));
return;
}
mRotating = true;
if (photoInfo != null) {
final PhotoTempModel photoTempModel = mPhotoTempMap.get(photoInfo.getPhotoId());
final String path = photoTempModel.getSourcePath();
File file;
if (GalleryFinal.getFunctionConfig().isRotateReplaceSource()) {
//裁剪覆盖源文件
file = new File(path);
} else {
file = new File(mEditPhotoCacheFile, Utils.getFileName(path) + "_rotate." + ext);
}
final File rotateFile = file;
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
mTvEmptyView.setVisibility(View.VISIBLE);
mProgressDialog = ProgressDialog.show(PhotoEditActivity.this, "", getString(R.string.waiting), true, false);
}
@Override
protected Bitmap doInBackground(Void... params) {
int orientation;
if (GalleryFinal.getFunctionConfig().isRotateReplaceSource()) {
orientation = 90;
} else {
orientation = photoTempModel.getOrientation() + 90;
}
Bitmap bitmap = Utils.rotateBitmap(path, orientation, mScreenWidth, mScreenHeight);
if (bitmap != null) {
Bitmap.CompressFormat format;
if (ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg")) {
format = Bitmap.CompressFormat.JPEG;
} else {
format = Bitmap.CompressFormat.PNG;
}
Utils.saveBitmap(bitmap, format, rotateFile);
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (mProgressDialog != null) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
if (bitmap != null) {
bitmap.recycle();
mTvEmptyView.setVisibility(View.GONE);
if (!GalleryFinal.getFunctionConfig().isRotateReplaceSource()) {
int orientation = photoTempModel.getOrientation() + 90;
if (orientation == 360) {
orientation = 0;
}
photoTempModel.setOrientation(orientation);
}
Message message = mHanlder.obtainMessage();
message.what = UPDATE_PATH;
message.obj = rotateFile.getAbsolutePath();
mHanlder.sendMessage(message);
} else {
mTvEmptyView.setText(R.string.no_photo);
}
loadImage(photoInfo);
mRotating = false;
}
}.execute();
}
}
}
use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.
the class PhotoTools method getAllPhotoFolder.
/**
* 获取所有图片
* @param context
* @return
*/
public static List<PhotoFolderInfo> getAllPhotoFolder(Context context, List<PhotoInfo> selectPhotoMap) {
List<PhotoFolderInfo> allFolderList = new ArrayList<>();
final String[] projectionPhotos = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.ORIENTATION, MediaStore.Images.Thumbnails.DATA };
final ArrayList<PhotoFolderInfo> allPhotoFolderList = new ArrayList<>();
HashMap<Integer, PhotoFolderInfo> bucketMap = new HashMap<>();
Cursor cursor = null;
//所有图片
PhotoFolderInfo allPhotoFolderInfo = new PhotoFolderInfo();
allPhotoFolderInfo.setFolderId(0);
allPhotoFolderInfo.setFolderName(context.getResources().getString(R.string.all_photo));
allPhotoFolderInfo.setPhotoList(new ArrayList<PhotoInfo>());
allPhotoFolderList.add(0, allPhotoFolderInfo);
List<String> selectedList = GalleryFinal.getFunctionConfig().getSelectedList();
List<String> filterList = GalleryFinal.getFunctionConfig().getFilterList();
try {
cursor = MediaStore.Images.Media.query(context.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projectionPhotos, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
if (cursor != null) {
int bucketNameColumn = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
final int bucketIdColumn = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
while (cursor.moveToNext()) {
int bucketId = cursor.getInt(bucketIdColumn);
String bucketName = cursor.getString(bucketNameColumn);
final int dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
final int imageIdColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
//int thumbImageColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
final int imageId = cursor.getInt(imageIdColumn);
final String path = cursor.getString(dataColumn);
//final String thumb = cursor.getString(thumbImageColumn);
File file = new File(path);
if ((filterList == null || !filterList.contains(path)) && file.exists() && file.length() > 0) {
final PhotoInfo photoInfo = new PhotoInfo();
photoInfo.setPhotoId(imageId);
photoInfo.setPhotoPath(path);
//photoInfo.setThumbPath(thumb);
if (allPhotoFolderInfo.getCoverPhoto() == null) {
allPhotoFolderInfo.setCoverPhoto(photoInfo);
}
//添加到所有图片
allPhotoFolderInfo.getPhotoList().add(photoInfo);
//通过bucketId获取文件夹
PhotoFolderInfo photoFolderInfo = bucketMap.get(bucketId);
if (photoFolderInfo == null) {
photoFolderInfo = new PhotoFolderInfo();
photoFolderInfo.setPhotoList(new ArrayList<PhotoInfo>());
photoFolderInfo.setFolderId(bucketId);
photoFolderInfo.setFolderName(bucketName);
photoFolderInfo.setCoverPhoto(photoInfo);
bucketMap.put(bucketId, photoFolderInfo);
allPhotoFolderList.add(photoFolderInfo);
}
photoFolderInfo.getPhotoList().add(photoInfo);
if (selectedList != null && selectedList.size() > 0 && selectedList.contains(path)) {
selectPhotoMap.add(photoInfo);
}
}
}
}
} catch (Exception ex) {
ILogger.e(ex);
} finally {
if (cursor != null) {
cursor.close();
}
}
allFolderList.addAll(allPhotoFolderList);
if (selectedList != null) {
selectedList.clear();
}
return allFolderList;
}
use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.
the class PhotoSelectActivity method takeRefreshGallery.
/**
* 解决在5.0手机上刷新Gallery问题,从startActivityForResult回到Activity把数据添加到集合中然后理解跳转到下一个页面,
* adapter的getCount与list.size不一致,所以我这里用了延迟刷新数据
* @param photoInfo
*/
private void takeRefreshGallery(PhotoInfo photoInfo) {
mCurPhotoList.add(0, photoInfo);
mPhotoListAdapter.notifyDataSetChanged();
//添加到集合中
List<PhotoInfo> photoInfoList = mAllPhotoFolderList.get(0).getPhotoList();
if (photoInfoList == null) {
photoInfoList = new ArrayList<>();
}
photoInfoList.add(0, photoInfo);
mAllPhotoFolderList.get(0).setPhotoList(photoInfoList);
if (mFolderListAdapter.getSelectFolder() != null) {
PhotoFolderInfo photoFolderInfo = mFolderListAdapter.getSelectFolder();
List<PhotoInfo> list = photoFolderInfo.getPhotoList();
if (list == null) {
list = new ArrayList<>();
}
list.add(0, photoInfo);
if (list.size() == 1) {
photoFolderInfo.setCoverPhoto(photoInfo);
}
mFolderListAdapter.getSelectFolder().setPhotoList(list);
} else {
String folderA = new File(photoInfo.getPhotoPath()).getParent();
for (int i = 1; i < mAllPhotoFolderList.size(); i++) {
PhotoFolderInfo folderInfo = mAllPhotoFolderList.get(i);
String folderB = null;
if (!StringUtils.isEmpty(photoInfo.getPhotoPath())) {
folderB = new File(photoInfo.getPhotoPath()).getParent();
}
if (TextUtils.equals(folderA, folderB)) {
List<PhotoInfo> list = folderInfo.getPhotoList();
if (list == null) {
list = new ArrayList<>();
}
list.add(0, photoInfo);
folderInfo.setPhotoList(list);
if (list.size() == 1) {
folderInfo.setCoverPhoto(photoInfo);
}
}
}
}
mFolderListAdapter.notifyDataSetChanged();
}
use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.
the class PhotoSelectActivity method folderItemClick.
private void folderItemClick(int position) {
mLlFolderPanel.setVisibility(View.GONE);
mCurPhotoList.clear();
PhotoFolderInfo photoFolderInfo = mAllPhotoFolderList.get(position);
if (photoFolderInfo.getPhotoList() != null) {
mCurPhotoList.addAll(photoFolderInfo.getPhotoList());
}
mPhotoListAdapter.notifyDataSetChanged();
if (position == 0) {
mPhotoTargetFolder = null;
} else {
PhotoInfo photoInfo = photoFolderInfo.getCoverPhoto();
if (photoInfo != null && !StringUtils.isEmpty(photoInfo.getPhotoPath())) {
mPhotoTargetFolder = new File(photoInfo.getPhotoPath()).getParent();
} else {
mPhotoTargetFolder = null;
}
}
mTvSubTitle.setText(photoFolderInfo.getFolderName());
mFolderListAdapter.setSelectFolder(photoFolderInfo);
mFolderListAdapter.notifyDataSetChanged();
if (mCurPhotoList.size() == 0) {
mTvEmptyView.setText(R.string.no_photo);
}
}
Aggregations