]> iEval git - unical.git/commitdiff
Now events are added to calendar. Edit also works now
authorPetru <l3asketballplayer@yahoo.com>
Thu, 15 Aug 2013 17:26:36 +0000 (20:26 +0300)
committerPetru <l3asketballplayer@yahoo.com>
Thu, 15 Aug 2013 17:26:36 +0000 (20:26 +0300)
res/layout/add_event.xml
src/ro/ieval/unical/AddEventActivity.java
src/ro/ieval/unical/Event.java

index 8ac6f0cba1e57d090e712349b0d4ee56aa4eb7d7..c14561c8094408161dab3f116148449f28730ddd 100644 (file)
                     android:ems="8"
                     android:visibility="gone" />
         </LinearLayout>
-        <EditText
-                android:id="@+id/description"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:ems="10"
-                android:hint="@string/description"
-                android:inputType="textMultiLine" >
-
-            <requestFocus />
-        </EditText>
     </LinearLayout>
 </LinearLayout>
         </ScrollView>
\ No newline at end of file
index 4c761d69c2f4730e69d605520ddcf56738cf4e1b..8d00641084f34e8beb7753563b1e50e821bb04d8 100644 (file)
@@ -4,6 +4,7 @@ import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.TimeZone;
 
 import android.app.ActionBar;
 import android.app.Activity;
@@ -76,11 +77,12 @@ public final class AddEventActivity extends Activity implements OnDateSetListene
 
        private TextView dateTimeTextView;
     public static final String EXTRA_EVENT = "event";
-    private Event event;
+    private static Event event=new Event();
 
     public static void editEvent(final Context c, final Event e) {
         final Intent i = new Intent(c,AddEventActivity.class);
         i.putExtra(AddEventActivity.EXTRA_EVENT,e);
+        event=e;
         c.startActivity(i);
     }
 
@@ -144,12 +146,14 @@ public final class AddEventActivity extends Activity implements OnDateSetListene
         cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, "unical");
         cv.put(CalendarContract.Calendars.VISIBLE, 1);
         cv.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
+        cv.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, TimeZone.getDefault().getID());
         calUri = calUri.buildUpon()
                 .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                 .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, "unical")
                 .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
                 .build();
 
+        this.getContentResolver().delete(calUri, CalendarContract.Calendars.ACCOUNT_NAME + " = 'unical'", new String[0]);
         this.getContentResolver().insert(calUri, cv);
         Event.calendarCreated=true;
     }
@@ -162,23 +166,25 @@ public final class AddEventActivity extends Activity implements OnDateSetListene
                                return true;
             case R.id.save:
 
-                Event ev=new Event();
-                ev.title=((EditText)findViewById(R.id.eventtitle)).getText().toString();
+                if(event.title!=null) event.delete(this);
+                event.title=((EditText)findViewById(R.id.eventtitle)).getText().toString();
                 String start=((TextView)findViewById(R.id.date_start)).getText().toString()+ " " +((TextView)findViewById(R.id.time_start)).getText().toString();
                 String end=((TextView)findViewById(R.id.date_end)).getText().toString()+ " "+((TextView)findViewById(R.id.time_end)).getText().toString();
 
                 try {
                     Date s=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(start);
                     Date e=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(end);
-                    ev.dtstart=s.getTime();
-                    ev.dtend=s.getTime();
+                    event.dtstart=s.getTime();
+                    event.dtend=s.getTime();
                 } catch (ParseException e) {
                     e.printStackTrace();
                 }
 
-                ev.description=((EditText) findViewById(R.id.description)).getText().toString();
+                event.description=((EditText) findViewById(R.id.description)).getText().toString();
 
-                if(!Event.calendarCreated) createCalendar();
+                if(!Event.calendarCreated)createCalendar();
+                event.calendarID=Event.getUnicalId(this);
+                event.insert(this);
 
                 Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG);
                 toast.show();
index f033533ecbb619b9e39e1668ec5a75da0d669f7c..a7fce60a038b1a62b1b0e5a44a73f8146389a34a 100644 (file)
@@ -1,6 +1,7 @@
 package ro.ieval.unical;
 
 import java.util.ArrayList;
+import java.util.TimeZone;
 
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -106,10 +107,24 @@ final class Event implements Parcelable{
                return  r.toArray(new Event[r.size()]);
        }
 
+    public static long getUnicalId(final Context context) {
+        for(final Calendar calendar : Calendar.getAllCalendars(context))
+            if(calendar.name.equals("unical")) return calendar._id;
+
+        return 0;
+    }
+
+
     public void insert(final Context context) {
-        final ContentResolver cr=context.getContentResolver();
-        //cr.insert(Uri.withAppendedPath(Events.CONTENT_URI));
-        //cr.notifyChange();
+       ContentValues cv = new ContentValues();
+        cv.put("calendar_id",calendarID);
+        cv.put("title",title);
+        cv.put("description",description);
+        cv.put("dtstart",dtstart);
+        cv.put("dtend",dtend);
+        cv.put("eventTimezone", TimeZone.getDefault().getID());
+
+        Uri url = context.getContentResolver().insert(Events.CONTENT_URI, cv);
     }
 
        public void delete(final Context context){
This page took 0.036451 seconds and 4 git commands to generate.