]> iEval git - unical.git/commitdiff
Finish DateTime picking and clean up
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 12 Jun 2013 11:29:52 +0000 (14:29 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 12 Jun 2013 11:29:52 +0000 (14:29 +0300)
project.properties
src/ro/ieval/unical/AddEventActivity.java
src/ro/ieval/unical/DatePickerFragment.java
src/ro/ieval/unical/TimePickerFragment.java

index 5bba9ba1e95df7967a29c62e2dfd1dfe55ddfe4e..a3ee5ab64f5e1901414e83e26717725e035b2aae 100644 (file)
@@ -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
index 5606b65fca91679c93bfc561e585160ea5d18c05..436d2cab7fb356dee8c1fc5c72c25bea5bcd06d2 100644 (file)
@@ -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)));
        }
 }
index 719fe372a491dd71e696315f0d63cf1a5e2f2f41..956277d718ee2fbe328204efd4186d1591f507a9 100644 (file)
@@ -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
index fa5ad8ab4a64c374cf976cf5f9ce14e577540380..2b84962ccea63f09437f38b87e69ca71a3f069df 100644 (file)
@@ -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
This page took 0.0269 seconds and 4 git commands to generate.