From: Petru Trimbitas Date: Tue, 11 Jun 2013 16:30:32 +0000 (+0300) Subject: Date and time picker. Work in progress X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=e6ba41a802c53e6d1ae9667f43955d00b20bb233;p=unical.git Date and time picker. Work in progress --- diff --git a/res/layout/add_event_basic_tab.xml b/res/layout/add_event_basic_tab.xml index 6eb886e..29bb689 100644 --- a/res/layout/add_event_basic_tab.xml +++ b/res/layout/add_event_basic_tab.xml @@ -15,4 +15,74 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 7f54470..711ebb9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -31,6 +31,10 @@ Event Name Cancel New Event + Pick time + Pick date + Start: + End: Daily diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 42aa2f2..5606b65 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -1,11 +1,13 @@ package ro.ieval.unical; import android.app.ActionBar; import android.app.Activity; +import android.app.DialogFragment; import android.app.Fragment; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; public final class AddEventActivity extends Activity { @Override @@ -60,4 +62,15 @@ public final class AddEventActivity extends Activity { return false; } } + + public void showTimePickerDialog(View v) { + if(v.getId()==R.id.date_start || v.getId()==R.id.date_end) { + DialogFragment newFragment = new DatePickerFragment(); + newFragment.show(getFragmentManager(),"datePicker"); + } + else { + DialogFragment newFragment = new TimePickerFragment(); + newFragment.show(getFragmentManager(), "timePicker"); + } + } } diff --git a/src/ro/ieval/unical/DatePickerFragment.java b/src/ro/ieval/unical/DatePickerFragment.java new file mode 100644 index 0000000..576875f --- /dev/null +++ b/src/ro/ieval/unical/DatePickerFragment.java @@ -0,0 +1,43 @@ +package ro.ieval.unical; + +import java.text.SimpleDateFormat; +import java.util.GregorianCalendar; + +import android.app.Activity; +import android.app.DatePickerDialog; +import android.app.DatePickerDialog.OnDateSetListener; +import android.app.Dialog; +import android.app.DialogFragment; +import android.os.Bundle; +import android.view.View; +import android.webkit.WebView.FindListener; +import android.widget.DatePicker; +import android.widget.EditText; + +public class DatePickerFragment extends DialogFragment + implements OnDateSetListener { + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the current time as the default values for the picker + final GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance(); + int year = c.get(GregorianCalendar.YEAR); + int month = c.get(GregorianCalendar.MONTH); + int day = c.get(GregorianCalendar.DAY_OF_MONTH); + + // Create a new instance of TimePickerDialog and return it + return new DatePickerDialog(getActivity(), this, year, month, day); + } + @Override + public void onDateSet(DatePicker picker, int year, int month, int day) { + if(picker.getId()==R.id.date_start) { + EditText ds = (EditText) a.findViewById(R.id.date_start); + EditText de = (EditText) a.findViewById(R.id.date_end); + ds.setText(String.format("%d-%d-%d", year,month,day)); + de.setText(String.format("%d-%d-%d", year,month,day)); + }else { + EditText de = (EditText) a.findViewById(R.id.date_end); + de.setText(String.format("%d-%d-%d", year,month,day)); + } + } +} \ No newline at end of file diff --git a/src/ro/ieval/unical/TimePickerFragment.java b/src/ro/ieval/unical/TimePickerFragment.java new file mode 100644 index 0000000..fa5ad8a --- /dev/null +++ b/src/ro/ieval/unical/TimePickerFragment.java @@ -0,0 +1,32 @@ +package ro.ieval.unical; + +import java.util.GregorianCalendar; + +import android.app.Dialog; +import android.app.DialogFragment; +import android.app.TimePickerDialog; +import android.os.Bundle; +import android.text.format.DateFormat; +import android.widget.TimePicker; + +public class TimePickerFragment extends DialogFragment + implements TimePickerDialog.OnTimeSetListener { + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the current time as the default values for the picker + final GregorianCalendar c = (GregorianCalendar) GregorianCalendar.getInstance(); + int hour = c.get(GregorianCalendar.HOUR_OF_DAY); + int minute = c.get(GregorianCalendar.MINUTE); + + // Create a new instance of TimePickerDialog and return it + return new TimePickerDialog(getActivity(), this, hour, minute, + DateFormat.is24HourFormat(getActivity())); + } + + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + // Do something with the time chosen by the user + + } +} \ No newline at end of file