Wallpaperpublic class Wallpaper extends android.app.Activity Wallpaper picker for the camera application. This just redirects to the standard pick action. |
Fields Summary |
---|
private static final String | LOG_TAG | static final int | PHOTO_PICKED | static final int | CROP_DONE | static final int | SHOW_PROGRESS | static final int | FINISH | static final String | sDoLaunchIcicle | static final String | sTempFilePathIcicle | private android.app.ProgressDialog | mProgressDialog | private boolean | mDoLaunch | private String | mTempFilePath | private android.os.Handler | mHandler |
Methods Summary |
---|
private synchronized void | closeProgressDialog()
if (mProgressDialog != null) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
| protected void | formatIntent(android.content.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
File f = getFileStreamPath("temp-wallpaper");
(new File(f.getParent())).mkdirs();
mTempFilePath = f.toString();
f.delete();
int width = getWallpaperDesiredMinimumWidth();
int height = getWallpaperDesiredMinimumHeight();
intent.putExtra("outputX", width);
intent.putExtra("outputY", height);
intent.putExtra("aspectX", width);
intent.putExtra("aspectY", height);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse("file:/" + mTempFilePath));
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
| protected void | onActivityResult(int requestCode, int resultCode, android.content.Intent data)
if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE) && (resultCode == RESULT_OK)
&& (data != null)) {
try {
File tempFile = new File(mTempFilePath);
InputStream s = new FileInputStream(tempFile);
Bitmap bitmap = BitmapFactory.decodeStream(s);
if (bitmap == null) {
Log.e(LOG_TAG, "Failed to set wallpaper. Couldn't get bitmap for path " + mTempFilePath);
} else {
if (android.util.Config.LOGV)
Log.v(LOG_TAG, "bitmap size is " + bitmap.getWidth() + " / " + bitmap.getHeight());
mHandler.sendEmptyMessage(SHOW_PROGRESS);
new SetWallpaperThread(bitmap, mHandler, this, tempFile).start();
}
mDoLaunch = false;
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
} else {
setResult(RESULT_CANCELED);
finish();
}
| protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
if (icicle != null) {
mDoLaunch = icicle.getBoolean(sDoLaunchIcicle);
mTempFilePath = icicle.getString(sTempFilePathIcicle);
}
| protected void | onPause()
closeProgressDialog();
super.onPause();
| protected void | onResume()
super.onResume();
if (!mDoLaunch) {
return;
}
Uri imageToUse = getIntent().getData();
if (imageToUse != null) {
Intent intent = new Intent();
intent.setClassName("com.android.camera", "com.android.camera.CropImage");
intent.setData(imageToUse);
formatIntent(intent);
startActivityForResult(intent, CROP_DONE);
} else {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
formatIntent(intent);
startActivityForResult(intent, PHOTO_PICKED);
}
| protected void | onSaveInstanceState(android.os.Bundle icicle)
icicle.putBoolean(sDoLaunchIcicle, mDoLaunch);
icicle.putString(sTempFilePathIcicle, mTempFilePath);
|
|