Browse Source

【提交内容】:完善日期控件,支持时分

wangyj18 9 years ago
parent
commit
cac4fa912e
1 changed files with 31 additions and 11 deletions
  1. 31 11
      wade-mobile-func/src/com/wade/mobile/func/MobileUI.java

+ 31 - 11
wade-mobile-func/src/com/wade/mobile/func/MobileUI.java

@ -13,6 +13,7 @@ import android.app.AlertDialog;
13 13
import android.app.AlertDialog.Builder;
14 14
import android.app.DatePickerDialog;
15 15
import android.app.ProgressDialog;
16
import android.app.TimePickerDialog;
16 17
import android.content.DialogInterface;
17 18
import android.content.Intent;
18 19
import android.graphics.Color;
@ -21,6 +22,7 @@ import android.view.KeyEvent;
21 22
import android.webkit.WebView;
22 23
import android.widget.DatePicker;
23 24
import android.widget.LinearLayout;
25
import android.widget.TimePicker;
24 26

25 27
import com.ailk.common.data.IData;
26 28
import com.ailk.common.data.IDataset;
@ -495,7 +497,7 @@ public class MobileUI extends Plugin {
495 497
	}
496 498

497 499
	public void getDate(String date, final String format) {
498
		int year, month, day_of_month;
500
		int year, month, day_of_month, hour, minute;
499 501
		final Calendar cal = Calendar.getInstance();
500 502
		final SimpleDateFormat df = new SimpleDateFormat(format);
501 503
		if (date != null && !date.equals(NULL) && !date.equals("")) {
@ -511,10 +513,13 @@ public class MobileUI extends Plugin {
511 513
		year = cal.get(Calendar.YEAR);
512 514
		month = cal.get(Calendar.MONTH);
513 515
		day_of_month = cal.get(Calendar.DAY_OF_MONTH);
516
		hour = cal.get(Calendar.HOUR_OF_DAY);
517
		minute = cal.get(Calendar.MINUTE);
514 518

515
		if (format.endsWith("MM")) {
516
			final YMPickerDialog datePickerDialog = new YMPickerDialog(context,
517
					new DatePickerDialog.OnDateSetListener() {
519
		String fmt = format.toUpperCase();
520
		if(fmt.matches("YYYY.*MM.*DD.*")){
521
			final DatePickerDialog datePickerDialog = new DatePickerDialog(
522
					context, new DatePickerDialog.OnDateSetListener() {
518 523
						@Override
519 524
						public void onDateSet(DatePicker view, int year,
520 525
								int monthOfYear, int dayOfMonth) {
@ -525,12 +530,12 @@ public class MobileUI extends Plugin {
525 530

526 531
					}, year,// 传入年份
527 532
					month,// 传入月份
528
					day_of_month,// 传入天数
529
					df);
533
					day_of_month// 传入天数
534
			);
530 535
			datePickerDialog.show();
531
		} else {
532
			final DatePickerDialog datePickerDialog = new DatePickerDialog(
533
					context, new DatePickerDialog.OnDateSetListener() {
536
		} else if(fmt.matches("YYYY.*MM.*")){
537
			final YMPickerDialog datePickerDialog = new YMPickerDialog(context,
538
					new DatePickerDialog.OnDateSetListener() {
534 539
						@Override
535 540
						public void onDateSet(DatePicker view, int year,
536 541
								int monthOfYear, int dayOfMonth) {
@ -541,9 +546,24 @@ public class MobileUI extends Plugin {
541 546

542 547
					}, year,// 传入年份
543 548
					month,// 传入月份
544
					day_of_month// 传入天数
545
			);
549
					day_of_month,// 传入天数
550
					df);
546 551
			datePickerDialog.show();
552
		} else if(fmt.matches("HH.*MM.*")){
553
			final TimePickerDialog timePickerDialog = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener(){
554

555
				@Override
556
				public void onTimeSet(TimePicker paramTimePicker,
557
						int hour, int minute) {
558
					
559
					cal.set(Calendar.HOUR_OF_DAY, hour);
560
					cal.set(Calendar.MINUTE, minute);
561
					String date = df.format(cal.getTime());
562
					MobileUI.this.callback(date);
563
				}
564
				
565
			}, hour, minute, true);
566
			timePickerDialog.show();
547 567
		}
548 568
	}
549 569