mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-21 05:05:31 +00:00
# some ignores for bin in mobile
# some test code for deserialization
This commit is contained in:
@@ -11,3 +11,6 @@ sailing_debug0*
|
||||
/mobile/com.sap.sailing.racecommittee.app/.settings/org.eclipse.jdt.core.prefs
|
||||
/mobile/com.sap.sailing.racecommittee.app/bin/*
|
||||
/mobile/com.sap.sailing.racecommittee.app/gen/*
|
||||
/mobile/com.sap.sailing.racecommittee.glue/bin/com.sap.sailing.racecommittee.glue.jar
|
||||
/mobile/com.sap.sailing.racecommittee.glue/bin/jarlist.cache
|
||||
/java/com.sap.sailing.server.gateway.serialization.test/.settings/*.prefs
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
<uses-sdk
|
||||
android:minSdkVersion="13"
|
||||
android:targetSdkVersion="15" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
||||
Binary file not shown.
@@ -4,10 +4,9 @@
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/hello_world"
|
||||
tools:context=".EventSelectionActivity" />
|
||||
|
||||
|
||||
+102
-11
@@ -1,20 +1,111 @@
|
||||
package com.sap.sailing.racecommittee.app;
|
||||
|
||||
import android.os.Bundle;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.server.gateway.deserialization.CourseAreaJsonDeserializer;
|
||||
import com.sap.sailing.server.gateway.deserialization.EventJsonDeserializer;
|
||||
import com.sap.sailing.server.gateway.deserialization.JsonDeserializationException;
|
||||
import com.sap.sailing.server.gateway.deserialization.JsonDeserializer;
|
||||
import com.sap.sailing.server.gateway.deserialization.VenueJsonDeserializer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class EventSelectionActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_event_selection);
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_event_selection);
|
||||
|
||||
Downloader downloader = new Downloader(this);
|
||||
downloader.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.activity_event_selection, menu);
|
||||
return true;
|
||||
}
|
||||
public void show(String result) {
|
||||
TextView tv = (TextView) findViewById(R.id.textView1);
|
||||
|
||||
if (result != null) {
|
||||
|
||||
JsonDeserializer<Event> deserializer = new EventJsonDeserializer(
|
||||
new VenueJsonDeserializer(
|
||||
new CourseAreaJsonDeserializer()));
|
||||
|
||||
JSONParser p = new JSONParser();
|
||||
try {
|
||||
JSONArray o = (JSONArray) p.parse(result);
|
||||
for (Object e : o) {
|
||||
Event event = deserializer.deserialize((JSONObject)e);
|
||||
tv.setText(event.getName());
|
||||
}
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tv.setText("Fehler");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.activity_event_selection, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
private class Downloader extends AsyncTask<Object, Integer, String> {
|
||||
|
||||
private EventSelectionActivity activity;
|
||||
|
||||
public Downloader(EventSelectionActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(Object... params) {
|
||||
try {
|
||||
URL url = new URL("http://10.0.2.2:8888/sailingserver/rc/events");
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
urlConnection.setConnectTimeout(5000);
|
||||
try {
|
||||
BufferedReader r = new BufferedReader(
|
||||
new InputStreamReader(urlConnection.getInputStream()));
|
||||
StringBuilder total = new StringBuilder();
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
total.append(line);
|
||||
}
|
||||
return total.toString();
|
||||
} finally {
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
super.onPostExecute(result);
|
||||
activity.show(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user