From: Marius Gavrilescu Date: Wed, 12 Jun 2013 11:29:52 +0000 (+0300) Subject: Finish DateTime picking and clean up X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=3dd871efed8ef534c16c62a99a011f4f11e54f56;p=unical.git Finish DateTime picking and clean up --- diff --git a/project.properties b/project.properties index 5bba9ba..a3ee5ab 100644 --- a/project.properties +++ b/project.properties @@ -12,5 +12,3 @@ # Project target. target=android-17 -android.library.reference.1=..\\..\\..\\..\\eclipse\\facebook-android-sdk-3.0.1\\facebook -android.library.reference.2=../facebook-android-sdk-3.0.1/facebook diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 5606b65..436d2ca 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -1,15 +1,24 @@ package ro.ieval.unical; +import java.util.Calendar; +import java.util.GregorianCalendar; + import android.app.ActionBar; import android.app.Activity; -import android.app.DialogFragment; +import android.app.DatePickerDialog.OnDateSetListener; import android.app.Fragment; +import android.app.TimePickerDialog.OnTimeSetListener; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.DatePicker; +import android.widget.TextView; +import android.widget.TimePicker; + +public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{ + private TextView dateTimeTextView; -public final class AddEventActivity extends Activity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -63,14 +72,27 @@ public final class AddEventActivity extends Activity { } } - 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"); - } + public void showDateTimePickerDialog(final View v) { + dateTimeTextView=(TextView) v; + if(v.getId()==R.id.date_start || v.getId()==R.id.date_end) + new DatePickerFragment().show(getFragmentManager(), "datePicker"); + else + new TimePickerFragment().show(getFragmentManager(), "timePicker"); + } + + @Override + public void onTimeSet(final TimePicker picker, final int hour, final int minute) { + dateTimeTextView.setText(String.format("%2d:%2d",hour,minute)); + if(dateTimeTextView.getId() == R.id.time_start) + ((TextView)findViewById(R.id.time_end)).setText(String.format("%2d:%2d",hour,minute)); + } + + @Override + public void onDateSet(final DatePicker picker, final int year, final int monthOfYear, final int dayOfMonth) { + final Calendar calendar=new GregorianCalendar(year, monthOfYear, dayOfMonth); + dateTimeTextView.setText(String.format("%4d-%2d-%2d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); + calendar.add(Calendar.DAY_OF_MONTH, 1); + if(dateTimeTextView.getId() == R.id.date_start) + ((TextView)findViewById(R.id.date_end)).setText(String.format("%4d-%2d-%2d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); } } diff --git a/src/ro/ieval/unical/DatePickerFragment.java b/src/ro/ieval/unical/DatePickerFragment.java index 719fe37..956277d 100644 --- a/src/ro/ieval/unical/DatePickerFragment.java +++ b/src/ro/ieval/unical/DatePickerFragment.java @@ -1,43 +1,17 @@ package ro.ieval.unical; -import java.text.SimpleDateFormat; -import java.util.GregorianCalendar; +import java.util.Calendar; -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 { - +public class DatePickerFragment extends DialogFragment { @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)); - } + public Dialog onCreateDialog(final Bundle savedInstanceState) { + final Calendar c = Calendar.getInstance(); + return new DatePickerDialog(getActivity(), (OnDateSetListener) getActivity(), c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); } } \ No newline at end of file diff --git a/src/ro/ieval/unical/TimePickerFragment.java b/src/ro/ieval/unical/TimePickerFragment.java index fa5ad8a..2b84962 100644 --- a/src/ro/ieval/unical/TimePickerFragment.java +++ b/src/ro/ieval/unical/TimePickerFragment.java @@ -1,32 +1,20 @@ package ro.ieval.unical; -import java.util.GregorianCalendar; +import java.util.Calendar; import android.app.Dialog; import android.app.DialogFragment; import android.app.TimePickerDialog; +import android.app.TimePickerDialog.OnTimeSetListener; import android.os.Bundle; import android.text.format.DateFormat; -import android.widget.TimePicker; -public class TimePickerFragment extends DialogFragment - implements TimePickerDialog.OnTimeSetListener { +public class TimePickerFragment extends DialogFragment { @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())); + public Dialog onCreateDialog(final Bundle savedInstanceState) { + final Calendar c = Calendar.getInstance(); + return new TimePickerDialog(getActivity(), (OnTimeSetListener) getActivity(), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.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