[DESCRIPTION]
KK以及L版本上,在图库中编辑完图片后,保存时默认是覆盖原图的,如果不想覆盖原图,可以参考以下方法修改。
[SOLUTION]
KK版本:
请找到如下文件并进行如下尝试:
alps/packages/apps/Gallery2/src/com/android/gallery3d/filtershow/FilterShowActivity.java
Original:
public void saveImage() {
if (mImageShow.hasModifications()) {
/// M: added for ConShots (never replace original conshot image with edited one) @{
Intent intent = getIntent();
if ((intent != null) && (intent.getBooleanExtra(NEED_SAVE_AS, false))) {
File dest = SaveImage.getNewFile(this, getSelectedImageUri());
SaveImage.saveImageAsACopy(this, dest);
return;
}
/// @}
// Get the name of the album, to which the image will be saved
File saveDir = SaveImage.getFinalSaveDirectory(this, mSelectedImageUri);
int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
showSavingProgress(albumName);
mImageShow.saveImage(this, null);
} else {
done();
}
}
Modified:
public void saveImage() {
if (mImageShow.hasModifications()) {
File saveDir = SaveImage.getFinalSaveDirectory(this, mSelectedImageUri);
int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
showSavingProgress(albumName);
File dest = SaveImage.getNewFile(this, getSelectedImageUri());
SaveImage.saveImageAsACopy(this, dest);
return;
} else {
done();
}
}
L版本:
请找到如下文件并进行如下尝试:
alps/packages/apps/Gallery2/src/com/android/gallery3d/filtershow/FilterShowActivity.java
Original:
public void saveImage() {
if (mImageShow.hasModifications()) {
/// M: [BUG.ADD] disable backpress when saving image @{
showSavingProgress(mAlbumNameForSaving);
/// @}
/// M: [BUG.MARK] disable backpress when saving image @{
/*
// Get the name of the album, to which the image will be saved
File saveDir = SaveImage.getFinalSaveDirectory(this, mSelectedImageUri);
int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
*/
/// @}
/// M: [BUG.ADD] @{
Intent intent = getIntent();
if ((intent != null) && (intent.getBooleanExtra(NEED_SAVE_AS, false))) {
// show saving progress for continus shot pictures. @{
File dest = SaveImage.getNewFile(this, getSelectedImageUri());
SaveImage.saveImageAsACopy(this, dest);
return;
}
/// @}
/// M: [FEATURE.ADD] clear refocus Exif/db when edit photo @{
checkIfNeedToClearRefocusFlag();
/// @}
/// M: [BUG.MARK] disable backpress when saving image @{
// showSavingProgress(albumName);
/// @}
mImageShow.saveImage(this, null);
} else {
done();
}
}
Modified:
public void saveImage() {
if (mImageShow.hasModifications()) {
File saveDir = SaveImage.getFinalSaveDirectory(this, mSelectedImageUri);
int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
showSavingProgress(albumName);
File dest = SaveImage.getNewFile(this, getSelectedImageUri());
SaveImage.saveImageAsACopy(this, dest);
return;
} else {
done();
}
}
N版本:
在L版本修改的基础上,在/ packages/ apps/ Gallery2/ src/ com/ android/ gallery3d/ filtershow/ tools/ SaveImage.java中添加如下方法:
public static void saveImageAsACopy(final FilterShowActivity filterShowActivity,File destination)
{
Uri selectedImageUri = filterShowActivity.getSelectedImageUri();
Uri sourceImageUri = MasterImage.getImage().getUri();
Intent processIntent = ProcessingService.getSaveIntent(filterShowActivity,
MasterImage.getImage().getPreset(), destination,
selectedImageUri, sourceImageUri, true, 90, 1f, true);
filterShowActivity.startService(processIntent);
if (!filterShowActivity.isSimpleEditAction()) {
String toastMessage = filterShowActivity.getResources().getString(
R.string.save_and_processing);
Toast.makeText(filterShowActivity,
toastMessage,
Toast.LENGTH_SHORT).show();
}
}
PS:以上修改,点击保存按钮后,回到PhotoPage界面,显示的是原图,如果想显示编辑后的图片,请修改如下Code:
KK版本:
1. PhotoPage.java
Original:
private void launchPhotoEditor() {
MediaItem current = mModel.getMediaItem(0);
if (current == null || (current.getSupportedOperations()
& MediaObject.SUPPORT_EDIT) == 0) {
return;
}
Intent intent = new Intent(ACTION_NEXTGEN_EDIT);
/// M: [BUG.MODIFY] create new task when launch photo editor from camera
// gallery and photo editor use same task stack @{
//intent.setDataAndType(current.getContentUri(), current.getMimeType())
// .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
/// @}
......
}
Modified:
private void launchPhotoEditor() {
MediaItem current = mModel.getMediaItem(0);
if (current == null || (current.getSupportedOperations()
& MediaObject.SUPPORT_EDIT) == 0) {
return;
}
Intent intent = new Intent(ACTION_NEXTGEN_EDIT);
/// M: [BUG.MODIFY] create new task when launch photo editor from camera
// gallery and photo editor use same task stack @{
intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
/*intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);*/
/// @}
......
}
2. SaveImage.java的如下函数,稍做修改:
如果 if(mPreviewImage != null) 这个分支被注释掉的话,请忽略此步;
否则,请按照如下方式修改:
Original:
public Uri processAndSaveImage(ImagePreset preset, boolean flatten,
int quality, float sizeFactor, boolean exit) {
......
Uri savedUri = mSelectedImageUri;
if (mPreviewImage != null) {
if (flatten) {
Object xmp = getPanoramaXMPData(newSourceUri, preset);
ExifInterface exif = getExifData(newSourceUri);
long time = System.currentTimeMillis();
updateExifData(exif, time);
if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) {
putPanoramaXMPData(mDestinationFile, xmp);
ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time);
Object result = mContext.getContentResolver().insert(
Images.Media.EXTERNAL_CONTENT_URI, values);
}
} else {
......
}
}
......
return uri;
}
Modified:
public Uri processAndSaveImage(ImagePreset preset, boolean flatten,
int quality, float sizeFactor, boolean exit) {
......
Uri savedUri = mSelectedImageUri;
if (mPreviewImage != null) {
if (flatten) {
Object xmp = getPanoramaXMPData(newSourceUri, preset);
ExifInterface exif = getExifData(newSourceUri);
long time = System.currentTimeMillis();
updateExifData(exif, time);
if (putExifData(mDestinationFile, exif, mPreviewImage, quality)) {
putPanoramaXMPData(mDestinationFile, xmp);
// delete by mtk start
/*ContentValues values = getContentValues(mContext, mSelectedImageUri, mDestinationFile, time);
Object result = mContext.getContentResolver().insert(
Images.Media.EXTERNAL_CONTENT_URI, values);*/
// delete by mtk end
}
// add by mtk start
savedUri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri,
mDestinationFile, time, !flatten);
// add by mtk end
} else {
......
}
}
......
//return uri;//delete by mtk
return savedUri; //add by mtk
}
L版本:
只修改PhotoPage.java即可。
Original:
private void launchPhotoEditor() {
......
MediaItem current = mModel.getMediaItem(0);
if (current == null || (current.getSupportedOperations()
& MediaObject.SUPPORT_EDIT) == 0) {
return;
}
Intent intent = new Intent(ACTION_NEXTGEN_EDIT);
/// M: [BUG.MODIFY] create new task when launch photo editor from camera
// gallery and photo editor use same task stack @{
/*intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);*/
intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
/// @}
......
}
Modified:
private void launchPhotoEditor() {
......
MediaItem current = mModel.getMediaItem(0);
if (current == null || (current.getSupportedOperations()
& MediaObject.SUPPORT_EDIT) == 0) {
return;
}
Intent intent = new Intent(ACTION_NEXTGEN_EDIT);
/// M: [BUG.MODIFY] create new task when launch photo editor from camera
// gallery and photo editor use same task stack @{
intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
/* intent.setDataAndType(current.getContentUri(), current.getMimeType())
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);*/
/// @}
......
}
M版本:
在L版本的修改基础上
1)将/packages/apps/Gallery2/src/com/android/gallery3d/app/PhotoPage.java中。
Original:
private void launchPhotoEditor()
{
....
((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null).addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK), REQUEST_EDIT);
overrideTransitionToEditor();
}
Modified:
private void launchPhotoEditor()
{
....
((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null),
REQUEST_EDIT);
overrideTransitionToEditor();
}
2)在/packages/apps/Gallery2/AndroidManifest.xml中
Original:
<activity android:name="com.android.gallery3d.filtershow.FilterShowActivity" android:label="@string/title_activity_filter_show" android:theme="@style/Theme.FilterShow" android:taskAffinity="com.android.gallery3d.filtershow.FilterShowActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:process=":filtershow" android:resizeableActivity="false">
Modified:
<activity
android:name="com.android.gallery3d.filtershow.FilterShowActivity"
android:label="@string/title_activity_filter_show"
android:theme="@style/Theme.FilterShow"
android:taskAffinity="com.android.gallery3d.filtershow.FilterShowActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:resizeableActivity="false">
注意:
合入上面修改后,FilterShow与Gallery在process中,也就是说,如果FilterShow发生异常,整个Gallery有可能会crash掉,是否要这样修改,请仔细权衡后再合入。
以上修改方法 本人在N版本上修改后报错:
01-05 10:45:49.606 3246 3246 E AndroidRuntime: FATAL EXCEPTION: main
01-05 10:45:49.606 3246 3246 E AndroidRuntime: Process: com.android.gallery3d, PID: 3246
01-05 10:45:49.606 3246 3246 E AndroidRuntime: java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.android.gallery3d.filtershow.pipeline.ProcessingService$LocalBinder
01-05 10:45:49.606 3246 3246 E AndroidRuntime: at com.android.gallery3d.filtershow.FilterShowActivity$1.onServiceConnected(FilterShowActivity.java:229)
需修改AndroidManifest.xml中如下service:
<service
android:name=".filtershow.pipeline.ProcessingService"
android:exported="false" />
<!-- android:process=":filtershow" -->
另外:由于添加了编辑图片后保存的功能需求,如FAQ11908这样修改。去掉了打开FitershowActivity 的Intent的Flag----Intent.FLAG_ACTIVITY_NEW_TASK。
而N版本上这边编辑图片的Activity又不支持分屏。
没有新建task导致编辑界面可以进入分屏模式,而此时编辑图片界面会出错。====> 那就没有别的办法了。因为如果新建task的话,PhotoPage这边无法获取到编辑这边返回的结果。这样导致编辑保存后,原图新图都保存了,但是返回到PhotoPage后,显示的是原图,而并非新图。