* commit '34a5e96b210af65c61f17052445fc7eb17b43ab9': Extend the TimePickerDialog test to cover 12- and 24-hour clocks.
This commit is contained in:
@@ -32,9 +32,14 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/date_widgets_example_pickDate_text"/>
|
||||
|
||||
<Button android:id="@+id/pickTime"
|
||||
<Button android:id="@+id/pickTime12"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/date_widgets_example_pickTime_text"/>
|
||||
android:text="@string/date_widgets_example_pickTime12_text"/>
|
||||
|
||||
<Button android:id="@+id/pickTime24"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/date_widgets_example_pickTime24_text"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -1342,7 +1342,8 @@
|
||||
<string name="text_switcher_1_next_text">Next</string>
|
||||
|
||||
<string name="date_widgets_example_dateDisplay_text"></string>
|
||||
<string name="date_widgets_example_pickTime_text">change the time</string>
|
||||
<string name="date_widgets_example_pickTime12_text">change the time (12 hour)</string>
|
||||
<string name="date_widgets_example_pickTime24_text">change the time (24 hour)</string>
|
||||
<string name="date_widgets_example_pickDate_text">change the date</string>
|
||||
|
||||
<string name="buttons_1_normal">Normal</string>
|
||||
|
||||
@@ -51,8 +51,9 @@ public class DateWidgets1 extends Activity {
|
||||
private int mHour;
|
||||
private int mMinute;
|
||||
|
||||
static final int TIME_DIALOG_ID = 0;
|
||||
static final int DATE_DIALOG_ID = 1;
|
||||
static final int TIME_12_DIALOG_ID = 0;
|
||||
static final int TIME_24_DIALOG_ID = 1;
|
||||
static final int DATE_DIALOG_ID = 2;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -62,21 +63,9 @@ public class DateWidgets1 extends Activity {
|
||||
|
||||
mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
|
||||
|
||||
Button pickDate = (Button) findViewById(R.id.pickDate);
|
||||
pickDate.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
showDialog(DATE_DIALOG_ID);
|
||||
}
|
||||
});
|
||||
|
||||
Button pickTime = (Button) findViewById(R.id.pickTime);
|
||||
pickTime.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
showDialog(TIME_DIALOG_ID);
|
||||
}
|
||||
});
|
||||
setDialogOnClickListener(R.id.pickDate, DATE_DIALOG_ID);
|
||||
setDialogOnClickListener(R.id.pickTime12, TIME_12_DIALOG_ID);
|
||||
setDialogOnClickListener(R.id.pickTime24, TIME_24_DIALOG_ID);
|
||||
|
||||
final Calendar c = Calendar.getInstance();
|
||||
mYear = c.get(Calendar.YEAR);
|
||||
@@ -88,12 +77,22 @@ public class DateWidgets1 extends Activity {
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
private void setDialogOnClickListener(int buttonId, final int dialogId) {
|
||||
Button b = (Button) findViewById(buttonId);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
showDialog(dialogId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
switch (id) {
|
||||
case TIME_DIALOG_ID:
|
||||
case TIME_12_DIALOG_ID:
|
||||
case TIME_24_DIALOG_ID:
|
||||
return new TimePickerDialog(this,
|
||||
mTimeSetListener, mHour, mMinute, false);
|
||||
mTimeSetListener, mHour, mMinute, id == TIME_24_DIALOG_ID);
|
||||
case DATE_DIALOG_ID:
|
||||
return new DatePickerDialog(this,
|
||||
mDateSetListener,
|
||||
@@ -105,7 +104,8 @@ public class DateWidgets1 extends Activity {
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, Dialog dialog) {
|
||||
switch (id) {
|
||||
case TIME_DIALOG_ID:
|
||||
case TIME_12_DIALOG_ID:
|
||||
case TIME_24_DIALOG_ID:
|
||||
((TimePickerDialog) dialog).updateTime(mHour, mMinute);
|
||||
break;
|
||||
case DATE_DIALOG_ID:
|
||||
|
||||
Reference in New Issue
Block a user