Move GSON from libs/ to src/ and fix the search call
[unical.git] / src / ro / ieval / unical / mainActivity.java
CommitLineData
bdd8f09c
PT
1package ro.ieval.unical;
2import java.io.BufferedReader;
3import java.io.IOException;
4import java.io.InputStreamReader;
819197b2
PT
5import java.io.PrintStream;
6import java.io.PrintWriter;
bdd8f09c
PT
7import java.net.MalformedURLException;
8import java.net.URL;
9import java.net.URLConnection;
10import java.util.Date;
11
819197b2
PT
12import javax.net.ssl.HttpsURLConnection;
13
bdd8f09c
PT
14import ro.ieval.unical.R;
15import com.google.gson.Gson;
16
17import android.graphics.Color;
18import android.os.Bundle;
19import android.os.Handler;
20import android.util.Base64;
21import android.widget.EditText;
22import android.widget.TextView;
23
24
25public class mainActivity extends android.app.Activity {
26 Event[] getEventList() {
27 Event events[];
28 URL hostUrlJson;
29 InputStreamReader in;
30 try {
31 hostUrlJson=new URL(Constants.searchUrl);
819197b2
PT
32 HttpsURLConnection calConnection = (HttpsURLConnection) hostUrlJson.openConnection();
33 calConnection.setDoOutput(true);
34 calConnection.setUseCaches(false);
cfd903b6 35 calConnection.setRequestProperty("Authorization", "Basic "+Base64.encodeToString( (Constants.user+':'+Constants.password).getBytes(), Base64.NO_WRAP));
819197b2
PT
36 //calConnection.setRequestMethod("POST");
37 //calConnection.setDoInput(true);
38 //calConnection.connect();
39
40 final PrintWriter ps=new PrintWriter(calConnection.getOutputStream());
41 ps.print("{}");
42 ps.close();
43
bdd8f09c
PT
44 in = new InputStreamReader(calConnection.getInputStream());
45 Gson gson=new Gson();
46 events=gson.fromJson(in,Event[].class);
47 in.close();
819197b2 48
bdd8f09c
PT
49 return events;
50 } catch (MalformedURLException e) {
51 // TODO Auto-generated catch block
52 System.err.println("catch1");
53 e.printStackTrace();
54 } catch (IOException e) {
55 // TODO Auto-generated catch block
56 System.err.println("catch2");
57 e.printStackTrace();
58 }
59 throw new AssertionError();
60 }
61
62 @Override
63 protected void onCreate(Bundle savedInstanceState) {
64 // All Begins here :)
65 // And here it began the olympic app that does olympic thing
66 setContentView(R.layout.eventview);
67 final TextView eventTitle= (TextView) findViewById(R.id.eventTitle);
68 final TextView date=(TextView) findViewById(R.id.date);
69 final TextView description=(TextView) findViewById(R.id.description);
70 super.onCreate(savedInstanceState);
819197b2 71
bdd8f09c
PT
72 final Handler h=new Handler();
73 new Thread(new Runnable() {
74 public void run() {
75 final Event events[]=getEventList();
76 h.post(new Runnable() {
77 public void run() {
78 // aici incepe
79 eventTitle.setText(events[0].title);
80 date.setText((new Date(events[0].date)).toString());
81 description.setText(events[0].description);
819197b2
PT
82 //DatabaseInteract db=new DatabaseInteract(null);
83 //db.insertEvent(events[0]);
bdd8f09c
PT
84 }
85 });
86 }
87 }).start();
88 }
89}
This page took 0.016523 seconds and 4 git commands to generate.