# 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
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);
}
}
- 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)));
}
}
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
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