mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-30 15:57:11 +00:00
# app sends events to server
This commit is contained in:
1 parent
9fc6643b14
commit
62f891872f
13 files changed
+139
-112
No files matched your search
@@ -8,6 +8,10 @@
|
||||
android:targetSdkVersion="17"
|
||||
android:maxSdkVersion="17" />
|
||||
|
||||
<permission
|
||||
android:name="com.sap.sailing.racecommittee.app.MAPS_RECEIVE"
|
||||
android:protectionLevel="signature" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
@@ -15,6 +19,11 @@
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
|
||||
<uses-permission android:name="com.sap.sailing.racecommittee.app.MAPS_RECEIVE" />
|
||||
|
||||
<uses-feature
|
||||
android:glEsVersion="0x00020000"
|
||||
android:required="true" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/sap_sailing_app_icon"
|
||||
@@ -34,9 +43,24 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.RacingActivity">
|
||||
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name="com.sap.sailing.racecommittee.app.services.RaceStateService"
|
||||
android:enabled="true"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.sap.sailing.racecommittee.app.action.registerRace" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name=".services.sending.EventSendingService"
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="com.sap.sailing.racecommittee.app.action.sendSavedIntents" />
|
||||
<action android:name="com.sap.sailing.racecommittee.app.action.sendEvent" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="intentActionRegisterRace">com.sap.sailing.racecommittee.app.action.registerRace</string>
|
||||
<!-- <string name="intentActionSaveIntent">com.sap.sailing.racecommittee.app.action.saveIntent</string> -->
|
||||
<string name="intentActionSendSavedIntents">com.sap.sailing.racecommittee.app.action.sendSavedIntents</string>
|
||||
<string name="intentActionSendEvent">com.sap.sailing.racecommittee.app.action.sendEvent</string>
|
||||
|
||||
<string name="hello">Hello World, RaceCommitteeActivity!</string>
|
||||
<string name="running_on_course">(on course %s)</string>
|
||||
<string name="course_design_number_waypoints">Course has %s waypoints</string>
|
||||
|
||||
+47
-57
@@ -6,64 +6,54 @@ import android.preference.PreferenceManager;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.raceinfo.SetTimeRaceFragment;
|
||||
|
||||
|
||||
public class AppConstants {
|
||||
|
||||
public static final boolean IS_DATA_OFFLINE = false;
|
||||
|
||||
public final static String ApplicationVersion = "2.0 Beta 1 - Jumbotron";
|
||||
|
||||
// Communication between the Connectivity watcher and the event sender
|
||||
public final static String SAVE_INTENT_ACTION = "com.sap.sailing.racecommittee.app.action.saveIntent";
|
||||
public final static String SEND_SAVED_INTENTS_ACTION = "com.sap.sailing.racecommittee.app.action.sendSavedIntents";
|
||||
public final static String REGISTER_RACE_ACTION = "com.sap.sailing.racecommittee.app.action.registerRace";
|
||||
public final static String SEND_EVENT_ACTION = "com.sap.sailing.racecommittee.app.action.sendEvent";
|
||||
|
||||
// Intent extra fields
|
||||
public final static String COURSE_AREA_UUID_KEY = "courseUuid";
|
||||
public final static String RACE_ID_KEY = "raceUuid";
|
||||
public final static String SERVICE_UNIQUE_ID = "serviceUID";
|
||||
public final static String RACING_EVENT_TIME = "racingEventTime";
|
||||
public final static String EXTRAS_JSON_KEY = "json";
|
||||
public final static String EXTRAS_URL = "url";
|
||||
public final static String FLAG_KEY = "raceFlag";
|
||||
|
||||
public final static String LogFolder = "/racecommittee";
|
||||
|
||||
// Login activity
|
||||
public final static String EventIdTag = "EventId";
|
||||
|
||||
private final static String PREFERENCE_SERVICE_URL = "webserviceUrlPref";
|
||||
private final static String PREFERENCE_SENDING_ACTIVE = "sendingActivePref";
|
||||
private final static String PREFERENCE_RACE_FINISHING_TIME_FRAME = "edittextRaceTimeFrameAfterFinish";
|
||||
|
||||
public static final String RESET_TIME_FRAGMENT_IS_RESET = SetTimeRaceFragment.class.getName() + ".isReset";
|
||||
|
||||
public static final int DefaultStartTimeMinuteOffset = 10;
|
||||
public static final boolean IS_DATA_OFFLINE = false;
|
||||
|
||||
public final static String ApplicationVersion = "2.0 Beta 1 - Jumbotron";
|
||||
|
||||
// Intent extra fields
|
||||
public final static String COURSE_AREA_UUID_KEY = "courseUuid";
|
||||
public final static String RACE_ID_KEY = "raceUuid";
|
||||
public final static String SERVICE_UNIQUE_ID = "serviceUID";
|
||||
public final static String RACING_EVENT_TIME = "racingEventTime";
|
||||
public final static String EXTRAS_JSON_KEY = "json";
|
||||
public final static String EXTRAS_URL = "url";
|
||||
public final static String FLAG_KEY = "raceFlag";
|
||||
|
||||
public final static String LogFolder = "/racecommittee";
|
||||
|
||||
// Login activity
|
||||
public final static String EventIdTag = "EventId";
|
||||
|
||||
private final static String PREFERENCE_SERVICE_URL = "webserviceUrlPref";
|
||||
private final static String PREFERENCE_SENDING_ACTIVE = "sendingActivePref";
|
||||
private final static String PREFERENCE_RACE_FINISHING_TIME_FRAME = "edittextRaceTimeFrameAfterFinish";
|
||||
|
||||
public static final String RESET_TIME_FRAGMENT_IS_RESET = SetTimeRaceFragment.class.getName() + ".isReset";
|
||||
|
||||
public static final int DefaultStartTimeMinuteOffset = 10;
|
||||
|
||||
public static String getServerBaseURL(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getString(PREFERENCE_SERVICE_URL, "http://192.168.1.141:8888");
|
||||
}
|
||||
|
||||
public static boolean isSendingActive(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getBoolean(PREFERENCE_SENDING_ACTIVE, false);
|
||||
}
|
||||
|
||||
public static void setSendingActive(Context context, boolean activate) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putBoolean(PREFERENCE_SENDING_ACTIVE, activate).apply();
|
||||
}
|
||||
|
||||
public static long getRaceFinishingTimeFrame(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String result = sp.getString(PREFERENCE_RACE_FINISHING_TIME_FRAME, "30");
|
||||
long resultLong = Long.parseLong(result);
|
||||
return (resultLong <= 0 ? 0 : resultLong * 60 * 1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static String getServerBaseURL(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getString(PREFERENCE_SERVICE_URL, "http://192.168.1.141:8888");
|
||||
}
|
||||
|
||||
public static boolean isSendingActive(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getBoolean(PREFERENCE_SENDING_ACTIVE, false);
|
||||
}
|
||||
|
||||
public static void setSendingActive(Context context, boolean activate) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putBoolean(PREFERENCE_SENDING_ACTIVE, activate).apply();
|
||||
}
|
||||
|
||||
public static long getRaceFinishingTimeFrame(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String result = sp.getString(PREFERENCE_RACE_FINISHING_TIME_FRAME, "30");
|
||||
long resultLong = Long.parseLong(result);
|
||||
return (resultLong <= 0 ? 0 : resultLong * 60 * 1000);
|
||||
}
|
||||
|
||||
}
|
||||
+26
-25
@@ -11,31 +11,32 @@ import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class HttpJsonPostRequest extends HttpRequest {
|
||||
public final static String ContentType = "application/json;charset=UTF-8";
|
||||
|
||||
private String requestBody;
|
||||
public final static String ContentType = "application/json;charset=UTF-8";
|
||||
|
||||
public HttpJsonPostRequest(URI requestUri, String body) throws MalformedURLException, IOException {
|
||||
super(requestUri.toURL());
|
||||
this.requestBody = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream execute(HttpURLConnection connection)
|
||||
throws IOException {
|
||||
connection.setDoInput(true);
|
||||
connection.setChunkedStreamingMode(0);
|
||||
|
||||
connection.setRequestProperty("Content-Type", ContentType);
|
||||
connection.setRequestProperty("Accept", ContentType);
|
||||
|
||||
OutputStream outputStream = new BufferedOutputStream(connection.getOutputStream());
|
||||
sendBody(outputStream);
|
||||
|
||||
return new BufferedInputStream(connection.getInputStream());
|
||||
}
|
||||
private String requestBody;
|
||||
|
||||
private void sendBody(OutputStream outputStream) throws IOException {
|
||||
outputStream.write(requestBody.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
public HttpJsonPostRequest(URI requestUri, String body) throws MalformedURLException, IOException {
|
||||
super(requestUri.toURL());
|
||||
this.requestBody = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream execute(HttpURLConnection connection) throws IOException {
|
||||
// connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
connection.setChunkedStreamingMode(0);
|
||||
|
||||
connection.setRequestProperty("Content-Type", ContentType);
|
||||
connection.setRequestProperty("Accept", ContentType);
|
||||
|
||||
OutputStream outputStream = new BufferedOutputStream(connection.getOutputStream());
|
||||
sendBody(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
return new BufferedInputStream(connection.getInputStream());
|
||||
}
|
||||
|
||||
private void sendBody(OutputStream outputStream) throws IOException {
|
||||
outputStream.write(requestBody.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -40,10 +40,9 @@ public abstract class HttpRequest {
|
||||
protected abstract InputStream execute(HttpURLConnection connection) throws IOException;
|
||||
|
||||
public InputStream execute() throws Exception {
|
||||
ExLog.i(TAG,
|
||||
String.format("Executing HTTP request %s on %s", connection.getRequestMethod(), connection.getURL()));
|
||||
ExLog.i(TAG, String.format("Executing HTTP request on %s.", connection.getURL()));
|
||||
|
||||
connection.setConnectTimeout(2000);
|
||||
connection.setConnectTimeout(5000);
|
||||
|
||||
InputStream stream = execute(connection);
|
||||
validateHttpResponse(connection);
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ public class RaceStateService extends Service {
|
||||
String action = intent.getAction();
|
||||
ExLog.i(TAG, String.format("Command action '%s' received.", action));
|
||||
|
||||
if (AppConstants.REGISTER_RACE_ACTION.equals(action)) {
|
||||
if (getString(R.string.intentActionRegisterRace).equals(action)) {
|
||||
handleRegisterRace(intent);
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-3
@@ -4,6 +4,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,9 +17,10 @@ import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
import com.sap.sailing.racecommittee.app.utils.FileHandlerUtils;
|
||||
|
||||
public class EventPersistenceManager {
|
||||
|
||||
private final static String TAG = EventPersistenceManager.class.getName();
|
||||
|
||||
private final static String delayedEventFileName = "delayedEvents.txt";
|
||||
private final static String TAG = "EventPersistanceManager";
|
||||
|
||||
private Context context;
|
||||
private String fileContent;
|
||||
@@ -36,13 +38,13 @@ public class EventPersistenceManager {
|
||||
public void persistIntent(Intent intent) {
|
||||
Bundle extras = intent.getExtras();
|
||||
|
||||
String serializedEvent = extras.getString(AppConstants.EXTRAS_JSON_KEY);
|
||||
Serializable serializedEvent = extras.getSerializable(AppConstants.EXTRAS_JSON_KEY);
|
||||
String raceUuid = extras.getSerializable(AppConstants.RACE_ID_KEY).toString();
|
||||
|
||||
persistEvent(raceUuid, serializedEvent);
|
||||
}
|
||||
|
||||
private void persistEvent(String raceUuid, String serializedEvent) {
|
||||
private void persistEvent(String raceUuid, Serializable serializedEvent) {
|
||||
String eventLine = String.format("%s;%s\n", raceUuid, serializedEvent);
|
||||
ExLog.i(TAG, "Called to persist following event " + eventLine);
|
||||
|
||||
|
||||
+10
-8
@@ -1,6 +1,7 @@
|
||||
package com.sap.sailing.racecommittee.app.services.sending;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -15,6 +16,7 @@ import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.DataManager;
|
||||
import com.sap.sailing.racecommittee.app.data.ReadonlyDataManager;
|
||||
import com.sap.sailing.racecommittee.app.domain.ManagedRace;
|
||||
@@ -33,7 +35,7 @@ import com.sap.sailing.racecommittee.app.services.sending.EventSenderTask.EventS
|
||||
*/
|
||||
public class EventSendingService extends Service implements EventSendingListener {
|
||||
|
||||
protected final static String TAG = "EventSendingService";
|
||||
protected final static String TAG = EventSendingService.class.getName();
|
||||
|
||||
private ConnectivityManager connectivityManager;
|
||||
private Handler handler;
|
||||
@@ -75,13 +77,13 @@ public class EventSendingService extends Service implements EventSendingListener
|
||||
*/
|
||||
public static Intent createEventIntent(Context context, ManagedRace race, Serializable serializedEvent) {
|
||||
String url = String.format(
|
||||
"%s/rc/racelog?leaderboard=%s&raceColumn=%s&fleet=%s",
|
||||
"%s/sailingserver/rc/racelog?leaderboard=%s&raceColumn=%s&fleet=%s",
|
||||
AppConstants.getServerBaseURL(context),
|
||||
race.getRaceGroup().getName(),
|
||||
race.getName(),
|
||||
race.getFleet().getName());
|
||||
URLEncoder.encode(race.getRaceGroup().getName()),
|
||||
URLEncoder.encode(race.getName()),
|
||||
URLEncoder.encode(race.getFleet().getName()));
|
||||
|
||||
Intent eventIntent = new Intent(AppConstants.SEND_EVENT_ACTION);
|
||||
Intent eventIntent = new Intent(context.getString(R.string.intentActionSendEvent));
|
||||
eventIntent.putExtra(AppConstants.RACE_ID_KEY, race.getId());
|
||||
eventIntent.putExtra(AppConstants.EXTRAS_JSON_KEY, serializedEvent);
|
||||
eventIntent.putExtra(AppConstants.EXTRAS_URL, url);
|
||||
@@ -133,9 +135,9 @@ public class EventSendingService extends Service implements EventSendingListener
|
||||
|
||||
private void handleCommand(Intent intent, int startId) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(AppConstants.SEND_SAVED_INTENTS_ACTION)) {
|
||||
if (action.equals(getString(R.string.intentActionSendSavedIntents))) {
|
||||
handleDelayedEvents();
|
||||
} else if (action.equals(AppConstants.SEND_EVENT_ACTION)) {
|
||||
} else if (action.equals(getString(R.string.intentActionSendEvent))) {
|
||||
handleSendEvents(intent);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package com.sap.sailing.racecommittee.app.services.sending;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import android.app.Service;
|
||||
|
||||
@@ -22,9 +22,9 @@ public class RaceEventSender implements RaceLogChangedListener {
|
||||
}
|
||||
|
||||
public void eventAdded(RaceLogEvent event) {
|
||||
Serializable serializedEvent = serializer.serialize(event);
|
||||
|
||||
service.startService(EventSendingService.createEventIntent(service, race, serializedEvent));
|
||||
JSONObject serializedEvent = serializer.serialize(event);
|
||||
service.startService(
|
||||
EventSendingService.createEventIntent(service, race, serializedEvent.toJSONString()));
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,11 +1,11 @@
|
||||
package com.sap.sailing.racecommittee.app.services.sending;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
|
||||
public class SendDelayedEventsCaller implements Runnable {
|
||||
|
||||
private final static String TAG = "SendDelayedEventsCaller";
|
||||
@@ -17,7 +17,7 @@ public class SendDelayedEventsCaller implements Runnable {
|
||||
|
||||
public void run() {
|
||||
ExLog.i(TAG, "The Event Sending Service is called to send possibly delayed intents");
|
||||
Intent sendSavedIntent = new Intent(AppConstants.SEND_SAVED_INTENTS_ACTION);
|
||||
Intent sendSavedIntent = new Intent(context.getString(R.string.intentActionSendSavedIntents));
|
||||
context.startService(sendSavedIntent);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -156,7 +156,7 @@ public class RacingActivity extends TwoPaneActivity implements RaceInfoListener
|
||||
// he should decide whether these races are already
|
||||
// registered or not.
|
||||
for (ManagedRace race : races) {
|
||||
Intent registerIntent = new Intent(AppConstants.REGISTER_RACE_ACTION);
|
||||
Intent registerIntent = new Intent(getString(R.string.intentActionRegisterRace));
|
||||
registerIntent.putExtra(AppConstants.RACE_ID_KEY, race.getId());
|
||||
this.startService(registerIntent);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user