FileDocCategorySizeDatePackage
Wallpaper.javaAPI DocAndroid 1.5 API4455Wed May 06 22:41:08 BST 2009com.example.android.home

Wallpaper

public class Wallpaper extends android.app.Activity implements AdapterView.OnItemSelectedListener, AdapterView.OnItemClickListener
Wallpaper picker for the Home application. User can choose from a gallery of stock photos.

Fields Summary
private static final String
LOG_TAG
private static final Integer[]
THUMB_IDS
private static final Integer[]
IMAGE_IDS
private android.widget.Gallery
mGallery
private boolean
mIsWallpaperSet
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle icicle)

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

        setContentView(R.layout.wallpaper);

        mGallery = (Gallery) findViewById(R.id.gallery);
        mGallery.setAdapter(new ImageAdapter(this));
        mGallery.setOnItemSelectedListener(this);
        mGallery.setOnItemClickListener(this);
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View v, int position, long id)

        selectWallpaper(position);
    
public voidonItemSelected(android.widget.AdapterView parent, android.view.View v, int position, long id)

        getWindow().setBackgroundDrawableResource(IMAGE_IDS[position]);
    
public voidonNothingSelected(android.widget.AdapterView parent)

    
protected voidonResume()

        super.onResume();
        mIsWallpaperSet = false;
    
public booleanonTouchEvent(android.view.MotionEvent event)

        selectWallpaper(mGallery.getSelectedItemPosition());
        return true;
    
private synchronized voidselectWallpaper(int position)

        if (mIsWallpaperSet) {
            return;
        }
        mIsWallpaperSet = true;
        try {
            InputStream stream = getResources().openRawResource(IMAGE_IDS[position]);
            setWallpaper(stream);
            setResult(RESULT_OK);
            finish();
        } catch (IOException e) {
            Log.e(LOG_TAG, "Failed to set wallpaper " + e);
        }