]> iEval git - unical.git/commitdiff
Date and time picker. Work in progress
authorPetru Trimbitas <l3asketballplayer@yahoo.com>
Tue, 11 Jun 2013 16:30:32 +0000 (19:30 +0300)
committerPetru Trimbitas <l3asketballplayer@yahoo.com>
Tue, 11 Jun 2013 16:30:32 +0000 (19:30 +0300)
res/layout/add_event_basic_tab.xml
res/values/strings.xml
src/ro/ieval/unical/AddEventActivity.java
src/ro/ieval/unical/DatePickerFragment.java [new file with mode: 0644]
src/ro/ieval/unical/TimePickerFragment.java [new file with mode: 0644]

index 6eb886e5617e1aa4ba6a6755853607c54dcee52b..29bb6897d5ed617d5b87e0c79253d36798881a66 100644 (file)
         <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>
index 7f54470c70cb5cb9e2111de51c779c298ec13a35..711ebb90a61ef356a54b9c28d59935eae411dfaa 100644 (file)
     <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>
index 42aa2f2ca4da591fbfb88d073d4edf7c9c055554..5606b65fca91679c93bfc561e585160ea5d18c05 100644 (file)
@@ -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 (file)
index 0000000..576875f
--- /dev/null
@@ -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 (file)
index 0000000..fa5ad8a
--- /dev/null
@@ -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
This page took 0.031109 seconds and 4 git commands to generate.