]> iEval git - unical.git/commitdiff
Add function to add event into local database
authorPetru Trimbitas <l3asketballplayer@yahoo.com>
Thu, 23 May 2013 15:55:16 +0000 (18:55 +0300)
committerPetru Trimbitas <l3asketballplayer@yahoo.com>
Thu, 23 May 2013 15:55:16 +0000 (18:55 +0300)
.classpath
project.properties
src/ro/ieval/unical/DatabaseInteract.java
src/ro/ieval/unical/Event.java
src/ro/ieval/unical/MySQLiteHelper.java
src/ro/ieval/unical/mainActivity.java

index a4763d1eeceda200d34208db1c129af010a168c6..bb0c7597707ce5a30801725ed67a55637c55e4eb 100644 (file)
@@ -4,5 +4,6 @@
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
index 21e5f605d0beffcc47c41c3fa9dab925f8a10123..a3ee5ab64f5e1901414e83e26717725e035b2aae 100644 (file)
@@ -12,4 +12,3 @@
 
 # Project target.
 target=android-17
-android.library.reference.1=../gridlayout_v7
index a4d2580026880edac0a26896f6e3d77727b0345b..dd2dde10d17643e6365b78c8c964de7b8959a73f 100644 (file)
@@ -1,5 +1,6 @@
 package ro.ieval.unical;
 
+import android.content.ContentValues;
 import android.content.Context;
 import android.database.SQLException;
 import android.database.sqlite.SQLiteDatabase;
@@ -7,6 +8,12 @@ import android.database.sqlite.SQLiteDatabase;
 public class DatabaseInteract {
        private SQLiteDatabase database;
        private MySQLiteHelper dbHelper;
+       private String[] allColumns = {
+                       MySQLiteHelper.ID, MySQLiteHelper.title, 
+                       MySQLiteHelper.description, MySQLiteHelper.date,
+                       MySQLiteHelper.duration, MySQLiteHelper.repeat,
+                       MySQLiteHelper.repeatIn, MySQLiteHelper.location
+       };
        
        public DatabaseInteract(Context context) {
                dbHelper = new MySQLiteHelper(context);
@@ -20,7 +27,18 @@ public class DatabaseInteract {
                dbHelper.close();
        }
        
-       //Add event
+       //Insert event
+       public void insertEvent(Event e) {
+               ContentValues values = new ContentValues();
+               values.put(allColumns[1],e.title);
+               values.put(allColumns[2],e.description);
+               values.put(allColumns[3],e.date);
+               values.put(allColumns[4],e.duration);
+               values.put(allColumns[5], e.repeat);
+               values.put(allColumns[6], e.repeatInterval);
+               values.put(allColumns[7], e.location);
+               database.insert(MySQLiteHelper.Name, null, values);
+       }
        //Delete event
        //Search event
 }
index 8d999476249ca761c80e2611dcb8d931492e09e5..d50820191a4794d13b66d719883a9f60ddc32f84 100644 (file)
@@ -1,6 +1,6 @@
 package ro.ieval.unical;
 public class Event {
-       public int date,time;
+       public int date,duration;
        public boolean repeat;
        public int repeatInterval;
        public String location;
index 889ebdaeb7b4faf62518c9219a0913d466818063..dc3595157db2a37f9040b810d286a2f90b290b54 100644 (file)
@@ -12,10 +12,10 @@ public class MySQLiteHelper extends SQLiteOpenHelper {
        public static final String Name="Events";
        
        public static final String ID = "_id";
-       public static final String name = "Name";
+       public static final String title = "Title";
        public static final String description = "Description";
        public static final String date = "Date";
-       public static final String time = "Time";
+       public static final String duration = "Duration";
        public static final String repeat = "repeat";
        public static final String repeatIn = "repeatInterval";
        public static final String location = "Location";
@@ -24,10 +24,10 @@ public class MySQLiteHelper extends SQLiteOpenHelper {
        
        private static final String Database_create = "create table " + Name + "(" + 
                        ID + " integer primary key autoincrement, " +
-                       name + " text not null, " + 
+                       title + " text not null, " + 
                        description + " text, " + 
                        date + " integer, " + 
-                       time + " integer, " +
+                       duration + " integer, " +
                        repeat + " integer, "+
                        repeatIn + " integer, " +
                        location + " text);"
index eba46042e83accc88ecc59570fca4efb9f2e5a49..5edc18ba6c3ab4a619d6207d6733f76655dfffbc 100644 (file)
@@ -2,11 +2,15 @@ package ro.ieval.unical;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Date;
 
+import javax.net.ssl.HttpsURLConnection;
+
 import ro.ieval.unical.R;
 import com.google.gson.Gson;
 
@@ -25,12 +29,23 @@ public class mainActivity extends android.app.Activity {
                InputStreamReader in;
                try {
                        hostUrlJson=new URL(Constants.searchUrl);
-                       URLConnection calConnection = hostUrlJson.openConnection();
-                       calConnection.setRequestProperty("Authorization", "Basic "+Base64.encodeToString( (Constants.user+':'+Constants.password).getBytes(), Base64.NO_WRAP));
+                       HttpsURLConnection calConnection = (HttpsURLConnection) hostUrlJson.openConnection();
+                       calConnection.setDoOutput(true);
+                       calConnection.setUseCaches(false);
+                       //calConnection.setRequestProperty("Authorization", "Basic "+Base64.encodeToString( (Constants.user+':'+Constants.password).getBytes(), Base64.NO_WRAP));
+                       //calConnection.setRequestMethod("POST");
+                       //calConnection.setDoInput(true);
+                       //calConnection.connect();
+
+                       final PrintWriter ps=new PrintWriter(calConnection.getOutputStream());
+                       ps.print("{}");
+                       ps.close();
+
                        in = new InputStreamReader(calConnection.getInputStream());
                        Gson gson=new Gson();
                        events=gson.fromJson(in,Event[].class);
                        in.close();
+
                        return events;
                } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
@@ -53,7 +68,7 @@ public class mainActivity extends android.app.Activity {
                final TextView date=(TextView) findViewById(R.id.date);
                final TextView description=(TextView) findViewById(R.id.description);
                super.onCreate(savedInstanceState);
-               System.err.println("MuieLaComisie");
+
                final Handler h=new Handler();
                new Thread(new Runnable() {
                        public void run() {
@@ -64,6 +79,8 @@ public class mainActivity extends android.app.Activity {
                                                eventTitle.setText(events[0].title);
                                                date.setText((new Date(events[0].date)).toString());
                                                description.setText(events[0].description);
+                                               //DatabaseInteract db=new DatabaseInteract(null);
+                                               //db.insertEvent(events[0]);
                                        }
                                });
                        }
This page took 0.034058 seconds and 4 git commands to generate.