]> iEval git - unical.git/blob - mainActivity.java
9b9960f8c8324d618605496c9e43c777238b9b0c
[unical.git] / mainActivity.java
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;
8 import java.net.URL;
9 import java.net.URLConnection;
10 import java.util.Date;
11
12 import javax.net.ssl.HttpsURLConnection;
13
14 import ro.ieval.unical.R;
15 import com.google.gson.Gson;
16
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;
23
24
25 public 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);
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();
39
40 final PrintWriter ps=new PrintWriter(calConnection.getOutputStream());
41 ps.print("{}");
42 ps.close();
43
44 in = new InputStreamReader(calConnection.getInputStream());
45 Gson gson=new Gson();
46 events=gson.fromJson(in,Event[].class);
47 in.close();
48
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);
71
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);
82 //DatabaseInteract db=new DatabaseInteract(null);
83 //db.insertEvent(events[0]);
84 }
85 });
86 }
87 }).start();
88 }
89 }
This page took 0.058729 seconds and 3 git commands to generate.