]>
Commit | Line | Data |
---|---|---|
bdd8f09c PT |
1 | package ro.ieval.unical; |
2 | import java.io.BufferedReader; | |
3 | import java.io.IOException; | |
4 | import java.io.InputStreamReader; | |
5 | import java.net.MalformedURLException; | |
6 | import java.net.URL; | |
7 | import java.net.URLConnection; | |
8 | import java.util.Date; | |
9 | ||
10 | import ro.ieval.unical.R; | |
11 | import com.google.gson.Gson; | |
12 | ||
13 | import android.graphics.Color; | |
14 | import android.os.Bundle; | |
15 | import android.os.Handler; | |
16 | import android.util.Base64; | |
17 | import android.widget.EditText; | |
18 | import android.widget.TextView; | |
19 | ||
20 | ||
21 | public class mainActivity extends android.app.Activity { | |
22 | Event[] getEventList() { | |
23 | Event events[]; | |
24 | URL hostUrlJson; | |
25 | InputStreamReader in; | |
26 | try { | |
27 | hostUrlJson=new URL(Constants.searchUrl); | |
28 | URLConnection calConnection = hostUrlJson.openConnection(); | |
29 | calConnection.setRequestProperty("Authorization", "Basic "+Base64.encodeToString( (Constants.user+':'+Constants.password).getBytes(), Base64.NO_WRAP)); | |
30 | in = new InputStreamReader(calConnection.getInputStream()); | |
31 | Gson gson=new Gson(); | |
32 | events=gson.fromJson(in,Event[].class); | |
33 | in.close(); | |
34 | return events; | |
35 | } catch (MalformedURLException e) { | |
36 | // TODO Auto-generated catch block | |
37 | System.err.println("catch1"); | |
38 | e.printStackTrace(); | |
39 | } catch (IOException e) { | |
40 | // TODO Auto-generated catch block | |
41 | System.err.println("catch2"); | |
42 | e.printStackTrace(); | |
43 | } | |
44 | throw new AssertionError(); | |
45 | } | |
46 | ||
47 | @Override | |
48 | protected void onCreate(Bundle savedInstanceState) { | |
49 | // All Begins here :) | |
50 | // And here it began the olympic app that does olympic thing | |
51 | setContentView(R.layout.eventview); | |
52 | final TextView eventTitle= (TextView) findViewById(R.id.eventTitle); | |
53 | final TextView date=(TextView) findViewById(R.id.date); | |
54 | final TextView description=(TextView) findViewById(R.id.description); | |
55 | super.onCreate(savedInstanceState); | |
56 | System.err.println("MuieLaComisie"); | |
57 | final Handler h=new Handler(); | |
58 | new Thread(new Runnable() { | |
59 | public void run() { | |
60 | final Event events[]=getEventList(); | |
61 | h.post(new Runnable() { | |
62 | public void run() { | |
63 | // aici incepe | |
64 | eventTitle.setText(events[0].title); | |
65 | date.setText((new Date(events[0].date)).toString()); | |
66 | description.setText(events[0].description); | |
67 | } | |
68 | }); | |
69 | } | |
70 | }).start(); | |
71 | } | |
72 | } |