use of cn.finalteam.galleryfinal.model.PhotoTempModel in project GalleryFinal by pengjianbo.
the class PhotoEditActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (GalleryFinal.getFunctionConfig() == null || GalleryFinal.getGalleryTheme() == null) {
resultFailureDelayed(getString(R.string.please_reopen_gf), true);
} else {
setContentView(R.layout.gf_activity_photo_edit);
mDefaultDrawable = getResources().getDrawable(R.drawable.ic_gf_default_photo);
mSelectPhotoList = (ArrayList<PhotoInfo>) getIntent().getSerializableExtra(SELECT_MAP);
mTakePhotoAction = this.getIntent().getBooleanExtra(TAKE_PHOTO_ACTION, false);
mCropPhotoAction = this.getIntent().getBooleanExtra(CROP_PHOTO_ACTION, false);
mEditPhotoAction = this.getIntent().getBooleanExtra(EDIT_PHOTO_ACTION, false);
if (mSelectPhotoList == null) {
mSelectPhotoList = new ArrayList<>();
}
mPhotoTempMap = new LinkedHashMap<>();
mPhotoList = new ArrayList<>(mSelectPhotoList);
mEditPhotoCacheFile = GalleryFinal.getCoreConfig().getEditPhotoCacheFolder();
if (mPhotoList == null) {
mPhotoList = new ArrayList<>();
}
for (PhotoInfo info : mPhotoList) {
mPhotoTempMap.put(info.getPhotoId(), new PhotoTempModel(info.getPhotoPath()));
}
findViews();
setListener();
setTheme();
mPhotoEditListAdapter = new PhotoEditListAdapter(this, mPhotoList, mScreenWidth);
mLvGallery.setAdapter(mPhotoEditListAdapter);
try {
File nomediaFile = new File(mEditPhotoCacheFile, ".nomedia");
if (!nomediaFile.exists()) {
nomediaFile.createNewFile();
}
} catch (IOException e) {
e.printStackTrace();
}
if (GalleryFinal.getFunctionConfig().isCamera()) {
mIvTakePhoto.setVisibility(View.VISIBLE);
}
if (GalleryFinal.getFunctionConfig().isCrop()) {
mIvCrop.setVisibility(View.VISIBLE);
}
if (GalleryFinal.getFunctionConfig().isRotate()) {
mIvRotate.setVisibility(View.VISIBLE);
}
if (!GalleryFinal.getFunctionConfig().isMutiSelect()) {
mLlGallery.setVisibility(View.GONE);
}
initCrop(mIvCropPhoto, GalleryFinal.getFunctionConfig().isCropSquare(), GalleryFinal.getFunctionConfig().getCropWidth(), GalleryFinal.getFunctionConfig().getCropHeight());
if (mPhotoList.size() > 0 && !mTakePhotoAction) {
loadImage(mPhotoList.get(0));
}
if (mTakePhotoAction) {
//打开相机
takePhotoAction();
}
if (mCropPhotoAction) {
mIvCrop.performClick();
if (!GalleryFinal.getFunctionConfig().isRotate() && !GalleryFinal.getFunctionConfig().isCamera()) {
mIvCrop.setVisibility(View.GONE);
}
} else {
//判断是否强制裁剪
hasForceCrop();
}
if (GalleryFinal.getFunctionConfig().isEnablePreview()) {
mIvPreView.setVisibility(View.VISIBLE);
}
}
}
use of cn.finalteam.galleryfinal.model.PhotoTempModel in project GalleryFinal by pengjianbo.
the class PhotoEditActivity method takeResult.
@Override
protected void takeResult(PhotoInfo info) {
if (!GalleryFinal.getFunctionConfig().isMutiSelect()) {
mPhotoList.clear();
mSelectPhotoList.clear();
}
mPhotoList.add(0, info);
mSelectPhotoList.add(info);
mPhotoTempMap.put(info.getPhotoId(), new PhotoTempModel(info.getPhotoPath()));
if (!GalleryFinal.getFunctionConfig().isEditPhoto() && mTakePhotoAction) {
resultAction();
} else {
if (GalleryFinal.getFunctionConfig().isEnablePreview()) {
mIvPreView.setVisibility(View.VISIBLE);
}
mPhotoEditListAdapter.notifyDataSetChanged();
PhotoSelectActivity activity = (PhotoSelectActivity) ActivityManager.getActivityManager().getActivity(PhotoSelectActivity.class.getName());
if (activity != null) {
activity.takeRefreshGallery(info, true);
}
loadImage(info);
hasForceCrop();
}
}
use of cn.finalteam.galleryfinal.model.PhotoTempModel 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();
}
}
}
Aggregations