FileDocCategorySizeDatePackage
WallpaperChooser.javaAPI DocAndroid 1.5 API7129Wed May 06 22:42:46 BST 2009com.android.launcher

WallpaperChooser

public class WallpaperChooser extends android.app.Activity implements android.view.View.OnClickListener, AdapterView.OnItemSelectedListener

Fields Summary
private static final Integer[]
THUMB_IDS
private static final Integer[]
IMAGE_IDS
private android.widget.Gallery
mGallery
private android.widget.ImageView
mImageView
private boolean
mIsWallpaperSet
private BitmapFactory.Options
mOptions
private android.graphics.Bitmap
mBitmap
private ArrayList
mThumbs
private ArrayList
mImages
Constructors Summary
Methods Summary
private voidfindWallpapers()

        mThumbs = new ArrayList<Integer>(THUMB_IDS.length + 4);
        Collections.addAll(mThumbs, THUMB_IDS);

        mImages = new ArrayList<Integer>(IMAGE_IDS.length + 4);
        Collections.addAll(mImages, IMAGE_IDS);

        final Resources resources = getResources();
        final String[] extras = resources.getStringArray(R.array.extra_wallpapers);
        final String packageName = getApplication().getPackageName();

        for (String extra : extras) {
            int res = resources.getIdentifier(extra, "drawable", packageName);
            if (res != 0) {
                final int thumbRes = resources.getIdentifier(extra + "_small",
                        "drawable", packageName);

                if (thumbRes != 0) {
                    mThumbs.add(thumbRes);
                    mImages.add(res);
                }
            }
        }
    
public voidonClick(android.view.View v)

        selectWallpaper(mGallery.getSelectedItemPosition());
    
public voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        findWallpapers();

        setContentView(R.layout.wallpaper_chooser);

        mOptions = new BitmapFactory.Options();
        mOptions.inDither = false;
        mOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;

        mGallery = (Gallery) findViewById(R.id.gallery);
        mGallery.setAdapter(new ImageAdapter(this));
        mGallery.setOnItemSelectedListener(this);
        mGallery.setCallbackDuringFling(false);

        Button b = (Button) findViewById(R.id.set);
        b.setOnClickListener(this);

        mImageView = (ImageView) findViewById(R.id.wallpaper);
    
public voidonItemSelected(android.widget.AdapterView parent, android.view.View v, int position, long id)

        final ImageView view = mImageView;
        Bitmap b = BitmapFactory.decodeResource(getResources(), mImages.get(position), mOptions);
        view.setImageBitmap(b);

        // Help the GC
        if (mBitmap != null) {
            mBitmap.recycle();
        }
        mBitmap = b;

        final Drawable drawable = view.getDrawable();
        drawable.setFilterBitmap(true);
        drawable.setDither(true);
    
public voidonNothingSelected(android.widget.AdapterView parent)

    
protected voidonResume()

        super.onResume();
        mIsWallpaperSet = false;
    
private voidselectWallpaper(int position)

        if (mIsWallpaperSet) {
            return;
        }

        mIsWallpaperSet = true;
        try {
            InputStream stream = getResources().openRawResource(mImages.get(position));
            setWallpaper(stream);
            setResult(RESULT_OK);
            finish();
        } catch (IOException e) {
            Log.e(Launcher.LOG_TAG, "Failed to set wallpaper: " + e);
        }