1 package ro
.ieval
.unical
;
2 import java
.io
.BufferedReader
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStreamReader
;
5 import java
.io
.PrintStream
;
6 import java
.io
.PrintWriter
;
7 import java
.net
.MalformedURLException
;
9 import java
.net
.URLConnection
;
10 import java
.util
.Date
;
12 import javax
.net
.ssl
.HttpsURLConnection
;
14 import ro
.ieval
.unical
.R
;
15 import com
.google
.gson
.Gson
;
17 import android
.graphics
.Color
;
18 import android
.os
.Bundle
;
19 import android
.os
.Handler
;
20 import android
.util
.Base64
;
21 import android
.widget
.EditText
;
22 import android
.widget
.TextView
;
25 public class mainActivity
extends android
.app
.Activity
{
26 Event
[] getEventList() {
31 hostUrlJson
=new URL(Constants
.searchUrl
);
32 HttpsURLConnection calConnection
= (HttpsURLConnection
) hostUrlJson
.openConnection();
33 calConnection
.setDoOutput(true);
34 calConnection
.setUseCaches(false);
35 calConnection
.setRequestProperty("Authorization", "Basic "+Base64
.encodeToString( (Constants
.user
+':'+Constants
.password
).getBytes(), Base64
.NO_WRAP
));
36 //calConnection.setRequestMethod("POST");
37 //calConnection.setDoInput(true);
38 //calConnection.connect();
40 final PrintWriter ps
=new PrintWriter(calConnection
.getOutputStream());
44 in
= new InputStreamReader(calConnection
.getInputStream());
46 events
=gson
.fromJson(in
,Event
[].class);
50 } catch (MalformedURLException e
) {
51 // TODO Auto-generated catch block
52 System
.err
.println("catch1");
54 } catch (IOException e
) {
55 // TODO Auto-generated catch block
56 System
.err
.println("catch2");
59 throw new AssertionError();
63 protected void onCreate(Bundle savedInstanceState
) {
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
);
72 final Handler h
=new Handler();
73 new Thread(new Runnable() {
75 final Event events
[]=getEventList();
76 h
.post(new Runnable() {
79 eventTitle
.setText(events
[0].title
);
80 date
.setText((new Date(events
[0].date
)).toString());
81 description
.setText(events
[0].description
);
82 //DatabaseInteract db=new DatabaseInteract(null);
83 //db.insertEvent(events[0]);