<requestFocus />
</EditText>
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/start_label"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <EditText
+ android:inputType="time"
+ android:id="@+id/time_start"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="showTimePickerDialog"
+ android:text="@string/pick_time"
+ android:layout_weight="1"
+ android:ems="10"
+ android:focusable="false"
+ />
+ <EditText
+ android:inputType="date"
+ android:id="@+id/date_start"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="showTimePickerDialog"
+ android:text="@string/pick_date"
+ android:layout_weight="1"
+ android:ems="10"
+ android:focusable="false"
+ />
+
+ </LinearLayout>
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/end_label"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <EditText
+ android:inputType="time"
+ android:id="@+id/time_end"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="showTimePickerDialog"
+ android:text="@string/pick_time"
+ android:layout_weight="1"
+ android:ems="10"
+ android:focusable="false"
+ />
+ <EditText
+ android:inputType="date"
+ android:id="@+id/date_end"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="showTimePickerDialog"
+ android:text="@string/pick_date"
+ android:layout_weight="1"
+ android:ems="10"
+ android:focusable="false"
+ />
+
+ </LinearLayout>
+
</LinearLayout>
<string name="eventname">Event Name</string>
<string name="cancel">Cancel</string>
<string name="new_event">New Event</string>
+ <string name="pick_time">Pick time</string>
+ <string name="pick_date">Pick date</string>
+ <string name="start_label">Start: </string>
+ <string name="end_label">End: </string>
<string-array name="Repeat">
<item>Daily</item>
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
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");
+ }
+ }
}
--- /dev/null
+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
--- /dev/null
+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