ClockPickerpublic class ClockPicker extends android.app.Activity implements AdapterView.OnItemSelectedListener, AdapterView.OnItemClickListenerClock 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 |
Methods Summary |
---|
public void | onCreate(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 void | onItemClick(android.widget.AdapterView parent, android.view.View v, int position, long id)
selectClock(position);
| public void | onItemSelected(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 void | onNothingSelected(android.widget.AdapterView parent)
| private synchronized void | selectClock(int position)
SharedPreferences.Editor ed = mPrefs.edit();
ed.putInt("face", position);
ed.commit();
setResult(RESULT_OK);
finish();
|
|