FileDocCategorySizeDatePackage
ClockPicker.javaAPI DocAndroid 1.5 API3595Wed May 06 22:42:42 BST 2009com.android.alarmclock

ClockPicker

public class ClockPicker extends android.app.Activity implements AdapterView.OnItemSelectedListener, AdapterView.OnItemClickListener
Clock face picker for the Alarm Clock application.

Fields Summary
private android.view.LayoutInflater
mFactory
private android.widget.Gallery
mGallery
private android.content.SharedPreferences
mPrefs
private android.view.View
mClock
private android.view.ViewGroup
mClockLayout
private int
mPosition
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle icicle)

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

        mFactory = LayoutInflater.from(this);
        setContentView(R.layout.clockpicker);

        mGallery = (Gallery) findViewById(R.id.gallery);
        mGallery.setAdapter(new ClockAdapter());
        mGallery.setOnItemSelectedListener(this);
        mGallery.setOnItemClickListener(this);

        mPrefs = getSharedPreferences(AlarmClock.PREFERENCES, 0);
        int face = mPrefs.getInt(AlarmClock.PREF_CLOCK_FACE, 0);
        if (face < 0 || face >= AlarmClock.CLOCKS.length) face = 0;

        mClockLayout = (ViewGroup) findViewById(R.id.clock_layout);
        mClockLayout.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    selectClock(mPosition);
                }
        });

        mGallery.setSelection(face, false);
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View v, int position, long id)

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

        if (mClock != null) {
            mClockLayout.removeView(mClock);
        }
        mClock = mFactory.inflate(AlarmClock.CLOCKS[position], null);
        mClockLayout.addView(mClock, 0);
        mPosition = position;
    
public voidonNothingSelected(android.widget.AdapterView parent)

    
private synchronized voidselectClock(int position)

        SharedPreferences.Editor ed = mPrefs.edit();
        ed.putInt("face", position);
        ed.commit();

        setResult(RESULT_OK);
        finish();