summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2009-08-24 16:42:21 +0800
committerChih-Chung Chang <chihchung@google.com>2009-08-24 17:43:47 +0800
commitc830ac217a2ed42eee83e411ee9a04b2a3390392 (patch)
tree3e20cec41fe22361b0a2299326249984eb0d3d21
parentdc90a46a888b61a7e0ff79bdff71220e49fd039e (diff)
downloadLegacyCamera-c830ac217a2ed42eee83e411ee9a04b2a3390392.tar.gz
LegacyCamera-c830ac217a2ed42eee83e411ee9a04b2a3390392.tar.bz2
LegacyCamera-c830ac217a2ed42eee83e411ee9a04b2a3390392.zip
Fix 1559583: Unnecessary image is created when setting a wallpaper
-rw-r--r--src/com/android/camera/CropImage.java12
-rw-r--r--src/com/android/camera/Wallpaper.java149
2 files changed, 18 insertions, 143 deletions
diff --git a/src/com/android/camera/CropImage.java b/src/com/android/camera/CropImage.java
index d0c0395c..4c12655c 100644
--- a/src/com/android/camera/CropImage.java
+++ b/src/com/android/camera/CropImage.java
@@ -20,6 +20,7 @@ import com.android.camera.gallery.Cancelable;
import com.android.camera.gallery.IImage;
import com.android.camera.gallery.IImageList;
+import android.app.WallpaperManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -61,6 +62,7 @@ public class CropImage extends MonitoredActivity {
private Bitmap.CompressFormat mOutputFormat =
Bitmap.CompressFormat.JPEG; // only used with mSaveUri
private Uri mSaveUri = null;
+ private boolean mSetWallpaper = false;
private int mAspectX, mAspectY;
private boolean mDoFaceDetection = true;
private boolean mCircleCrop = false;
@@ -114,6 +116,8 @@ public class CropImage extends MonitoredActivity {
mOutputFormat = Bitmap.CompressFormat.valueOf(
outputFormatString);
}
+ } else {
+ mSetWallpaper = extras.getBoolean("setWallpaper");
}
mBitmap = (Bitmap) extras.getParcelable("data");
mAspectX = extras.getInt("aspectX");
@@ -330,6 +334,14 @@ public class CropImage extends MonitoredActivity {
Bundle extras = new Bundle();
setResult(RESULT_OK, new Intent(mSaveUri.toString())
.putExtras(extras));
+ } else if (mSetWallpaper) {
+ try {
+ WallpaperManager.getInstance(this).setBitmap(croppedImage);
+ setResult(RESULT_OK);
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to set wallpaper.", e);
+ setResult(RESULT_CANCELED);
+ }
} else {
Bundle extras = new Bundle();
extras.putString("rect", mCrop.getCropRect().toString());
diff --git a/src/com/android/camera/Wallpaper.java b/src/com/android/camera/Wallpaper.java
index 92b104a2..4b72dd74 100644
--- a/src/com/android/camera/Wallpaper.java
+++ b/src/com/android/camera/Wallpaper.java
@@ -17,127 +17,23 @@
package com.android.camera;
import android.app.Activity;
-import android.app.ProgressDialog;
-import android.app.WallpaperManager;
-import android.content.Context;
import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.provider.MediaStore;
-import android.util.Log;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
/**
* Wallpaper picker for the camera application. This just redirects to the
* standard pick action.
*/
public class Wallpaper extends Activity {
- private static final String LOG_TAG = "Camera";
- static final int PHOTO_PICKED = 1;
- static final int CROP_DONE = 2;
-
- static final int SHOW_PROGRESS = 0;
- static final int FINISH = 1;
-
- static final String DO_LAUNCH_ICICLE = "do_launch";
- static final String TEMP_FILE_PATH_ICICLE = "temp_file_path";
-
- private ProgressDialog mProgressDialog = null;
- private boolean mDoLaunch = true;
- private File mTempFile;
-
- private final Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case SHOW_PROGRESS: {
- CharSequence c = getText(R.string.wallpaper);
- mProgressDialog = ProgressDialog.show(Wallpaper.this,
- "", c, true, false);
- break;
- }
-
- case FINISH: {
- closeProgressDialog();
- setResult(RESULT_OK);
- finish();
- break;
- }
- }
- }
- };
-
- static class SetWallpaperThread extends Thread {
- private final Bitmap mBitmap;
- private final Handler mHandler;
- private final Context mContext;
- private final File mFile;
-
- public SetWallpaperThread(Bitmap bitmap, Handler handler,
- Context context, File file) {
- mBitmap = bitmap;
- mHandler = handler;
- mContext = context;
- mFile = file;
- }
-
- @Override
- public void run() {
- try {
- WallpaperManager.getInstance(mContext).setBitmap(mBitmap);
- } catch (IOException e) {
- Log.e(LOG_TAG, "Failed to set wallpaper.", e);
- } finally {
- mHandler.sendEmptyMessage(FINISH);
- mFile.delete();
- }
- }
- }
-
- private synchronized void closeProgressDialog() {
- if (mProgressDialog != null) {
- mProgressDialog.dismiss();
- mProgressDialog = null;
- }
- }
+ private static final String TAG = "Wallpaper";
+ private static final int PHOTO_PICKED = 1;
+ private static final int CROP_DONE = 2;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
- if (icicle != null) {
- mDoLaunch = icicle.getBoolean(DO_LAUNCH_ICICLE);
- mTempFile = new File(icicle.getString(TEMP_FILE_PATH_ICICLE));
- }
- }
-
- @Override
- protected void onSaveInstanceState(Bundle icicle) {
- icicle.putBoolean(DO_LAUNCH_ICICLE, mDoLaunch);
- icicle.putString(TEMP_FILE_PATH_ICICLE, mTempFile.getAbsolutePath());
- }
-
- @Override
- protected void onPause() {
- closeProgressDialog();
- super.onPause();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (!mDoLaunch) {
- return;
- }
Uri imageToUse = getIntent().getData();
if (imageToUse != null) {
Intent intent = new Intent();
@@ -156,13 +52,6 @@ public class Wallpaper extends Activity {
}
protected void formatIntent(Intent intent) {
- // TODO: A temporary file is NOT necessary
- // The CropImage intent should be able to set the wallpaper directly
- // without writing to a file, which we then need to read here to write
- // it again as the final wallpaper, this is silly
- mTempFile = getFileStreamPath("temp-wallpaper");
- mTempFile.getParentFile().mkdirs();
-
int width = getWallpaperDesiredMinimumWidth();
int height = getWallpaperDesiredMinimumHeight();
intent.putExtra("outputX", width);
@@ -171,40 +60,14 @@ public class Wallpaper extends Activity {
intent.putExtra("aspectY", height);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
- intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempFile));
- intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
- // TODO: we should have an extra called "setWallpaper" to ask CropImage
- // to set the cropped image as a wallpaper directly. This means the
- // SetWallpaperThread should be moved out of this class to CropImage
+ intent.putExtra("setWallpaper", true);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
- if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE)
- && (resultCode == RESULT_OK) && (data != null)) {
- try {
- InputStream s = new FileInputStream(mTempFile);
- try {
- Bitmap bitmap = BitmapFactory.decodeStream(s);
- if (bitmap == null) {
- Log.e(LOG_TAG, "Failed to set wallpaper. "
- + "Couldn't get bitmap for path "
- + mTempFile);
- } else {
- mHandler.sendEmptyMessage(SHOW_PROGRESS);
- new SetWallpaperThread(
- bitmap, mHandler, this, mTempFile).start();
- }
- mDoLaunch = false;
- } finally {
- Util.closeSilently(s);
- }
- } catch (FileNotFoundException ex) {
- Log.e(LOG_TAG, "file not found: " + mTempFile, ex);
- }
- } else {
- setResult(RESULT_CANCELED);
+ if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE)) {
+ setResult(resultCode);
finish();
}
}