FileDocCategorySizeDatePackage
Wallpaper.javaAPI DocAndroid 1.5 API7120Wed May 06 22:42:42 BST 2009com.android.camera

Wallpaper

public 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
Constructors Summary
Methods Summary
private synchronized voidcloseProgressDialog()

        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    
protected voidformatIntent(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 voidonActivityResult(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 voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);
        if (icicle != null) {
            mDoLaunch = icicle.getBoolean(sDoLaunchIcicle);
            mTempFilePath = icicle.getString(sTempFilePathIcicle);
        }
    
protected voidonPause()

        closeProgressDialog();
        super.onPause();
    
protected voidonResume()

        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 voidonSaveInstanceState(android.os.Bundle icicle)

        icicle.putBoolean(sDoLaunchIcicle, mDoLaunch);
        icicle.putString(sTempFilePathIcicle, mTempFilePath);