Revert "adding white space mess "

This reverts commit ec12301feee614dc356732850564b754e0bfc33a.
This commit is contained in:
Bennet Brunsen committed 2015-04-30 11:54:47 +02:00
1 parent ff1b0c6f87
commit 639d109e39
50 files changed
+380 -390

No files matched your search

@@ -40,6 +40,7 @@ public class AddDeviceMappingToRegattaLogDialog extends AbstractCancelableDialog
@Override @Override
protected void addMainContent(Panel mainPanel) { protected void addMainContent(Panel mainPanel) {
super.addMainContent(mainPanel); super.addMainContent(mainPanel);
CaptionPanel inputPanel = new CaptionPanel(); CaptionPanel inputPanel = new CaptionPanel();
Grid inputGrid = new Grid(1, 2); Grid inputGrid = new Grid(1, 2);
inputPanel.add(inputGrid); inputPanel.add(inputGrid);
@@ -33,6 +33,7 @@ public class RaceLogTrackingCompetitorRegistrationsDialog extends AbstractSaveDi
static interface CompetitorRegistrationHandler { static interface CompetitorRegistrationHandler {
void getRegisteredCompetitors(Callback<Collection<CompetitorDTO>, Throwable> callback); void getRegisteredCompetitors(Callback<Collection<CompetitorDTO>, Throwable> callback);
void setRegisteredCompetitors(Set<CompetitorDTO> competitors); void setRegisteredCompetitors(Set<CompetitorDTO> competitors);
} }
@@ -41,6 +42,7 @@ public class RaceLogTrackingCompetitorRegistrationsDialog extends AbstractSaveDi
CompetitorRegistrationHandler competitorRegistrationHandler) { CompetitorRegistrationHandler competitorRegistrationHandler) {
super(sailingService, stringMessages, errorReporter, editable); super(sailingService, stringMessages, errorReporter, editable);
this.competitorRegistrationsHandler = competitorRegistrationHandler; this.competitorRegistrationsHandler = competitorRegistrationHandler;
setupUi(); setupUi();
refreshCompetitors(); refreshCompetitors();
} }
@@ -55,6 +57,7 @@ public class RaceLogTrackingCompetitorRegistrationsDialog extends AbstractSaveDi
} }
}); });
buttonPanel.add(addCompetitorButton); buttonPanel.add(addCompetitorButton);
super.addButtons(buttonPanel); super.addButtons(buttonPanel);
} }
@@ -79,6 +82,7 @@ public class RaceLogTrackingCompetitorRegistrationsDialog extends AbstractSaveDi
@Override @Override
protected void addMainContent(Panel mainPanel) { protected void addMainContent(Panel mainPanel) {
super.addMainContent(mainPanel); super.addMainContent(mainPanel);
HorizontalPanel panel = new HorizontalPanel(); HorizontalPanel panel = new HorizontalPanel();
mainPanel.add(panel); mainPanel.add(panel);
CaptionPanel allCompetitorsPanel = new CaptionPanel(stringMessages.competitorPool()); CaptionPanel allCompetitorsPanel = new CaptionPanel(stringMessages.competitorPool());
@@ -138,6 +142,7 @@ public class RaceLogTrackingCompetitorRegistrationsDialog extends AbstractSaveDi
protected void refreshCompetitors() { protected void refreshCompetitors() {
registeredCompetitorsTable.getDataProvider().getList().clear(); registeredCompetitorsTable.getDataProvider().getList().clear();
allCompetitorsTable.refreshCompetitorList(null, true, new Callback<Iterable<CompetitorDTO>, Throwable>() { allCompetitorsTable.refreshCompetitorList(null, true, new Callback<Iterable<CompetitorDTO>, Throwable>() {
@Override @Override
public void onSuccess(Iterable<CompetitorDTO> result) { public void onSuccess(Iterable<CompetitorDTO> result) {
@@ -1,24 +1,26 @@
package com.sap.sailing.gwt.ui.shared; package com.sap.sailing.gwt.ui.shared;
import java.io.Serializable; import java.io.Serializable;
import com.sap.sailing.domain.common.Position; import com.sap.sailing.domain.common.Position;
public class WindLatticeDTO implements Serializable {
/** public class WindLatticeDTO implements Serializable {
* Generated uid for serialisation
*/ /**
private static final long serialVersionUID = -2110785502151983845L; * Generated uid for serialisation
private Position[][] matrix; */
private static final long serialVersionUID = -2110785502151983845L;
public WindLatticeDTO() { private Position [][] matrix;
}
public WindLatticeDTO() {
public void setMatrix(Position[][] matrix) { }
this.matrix = matrix;
} public void setMatrix( Position [][] matrix ) {
this.matrix = matrix;
public Position[][] getMatrix() { }
return matrix;
} public Position[][] getMatrix() {
} return matrix;
}
}
@@ -1,61 +1,64 @@
package com.sap.sailing.gwt.ui.shared; package com.sap.sailing.gwt.ui.shared;
import java.io.Serializable; import java.io.Serializable;
import com.sap.sailing.domain.common.Position; import com.sap.sailing.domain.common.Position;
public class WindLatticeGenParamsDTO implements Serializable {
/** public class WindLatticeGenParamsDTO implements Serializable {
* Generated uid for serialisation
*/ /**
private static final long serialVersionUID = 6074038176026601942L; * Generated uid for serialisation
*/
private Position center; private static final long serialVersionUID = 6074038176026601942L;
private double xSize = 1;
private double ySize = 1; private Position center;
private int gridsizeX = 20; private double xSize = 1;
private int gridsizeY = 20; private double ySize = 1;
private int gridsizeX = 20;
public WindLatticeGenParamsDTO() { private int gridsizeY = 20;
}
public WindLatticeGenParamsDTO() {
public void setCenter(Position center) { }
this.center = center;
} public void setCenter(Position center) {
this.center = center;
public Position getCenter() { }
return center;
} public Position getCenter() {
return center;
public double getxSize() { }
return xSize;
} public double getxSize() {
return xSize;
public void setxSize(double xSize) { }
this.xSize = xSize;
} public void setxSize(double xSize) {
this.xSize = xSize;
public double getySize() { }
return ySize;
} public double getySize() {
return ySize;
public void setySize(double ySize) { }
this.ySize = ySize;
} public void setySize(double ySize) {
this.ySize = ySize;
public int getGridsizeX() { }
return gridsizeX;
} public int getGridsizeX() {
return gridsizeX;
public void setGridsizeX(int gridsizeX) { }
this.gridsizeX = gridsizeX;
} public void setGridsizeX(int gridsizeX) {
this.gridsizeX = gridsizeX;
public int getGridsizeY() { }
return gridsizeY;
} public int getGridsizeY() {
return gridsizeY;
public void setGridsizeY(int gridsizeY) { }
this.gridsizeY = gridsizeY;
} public void setGridsizeY(int gridsizeY) {
} this.gridsizeY = gridsizeY;
}
}
@@ -23,6 +23,7 @@ import com.sap.sse.common.Util.Pair;
*/ */
public class FlatSmartphoneUuidAndGPSFixMovingJsonDeserializer implements public class FlatSmartphoneUuidAndGPSFixMovingJsonDeserializer implements
JsonDeserializer<Pair<UUID, List<GPSFixMoving>>> { JsonDeserializer<Pair<UUID, List<GPSFixMoving>>> {
@Override @Override
public Pair<UUID, List<GPSFixMoving>> deserialize(JSONObject object) throws JsonDeserializationException { public Pair<UUID, List<GPSFixMoving>> deserialize(JSONObject object) throws JsonDeserializationException {
UUID device = UUID.fromString(object.get(FlatSmartphoneUuidAndGPSFixMovingJsonSerializer.DEVICE_UUID).toString()); UUID device = UUID.fromString(object.get(FlatSmartphoneUuidAndGPSFixMovingJsonSerializer.DEVICE_UUID).toString());
@@ -129,6 +129,7 @@ public class CompetitorsResource extends AbstractSailingServerResource {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST) throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
.entity("Could not find competitor with id " + competitorId).type(MediaType.TEXT_PLAIN).build()); .entity("Could not find competitor with id " + competitorId).type(MediaType.TEXT_PLAIN).build());
} }
String fileExtension = ""; String fileExtension = "";
if (fileType.equals("image/jpeg")) { if (fileType.equals("image/jpeg")) {
fileExtension = ".jpg"; fileExtension = ".jpg";
+19 -19
View File
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project <project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.sap.sailing</groupId> <groupId>com.sap.sailing</groupId>
<artifactId>mobile</artifactId> <artifactId>mobile</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>com.sap.sailing.android.shared</artifactId> <artifactId>com.sap.sailing.android.shared</artifactId>
<packaging>apklib</packaging> <packaging>apklib</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.sap.sailing</groupId> <groupId>com.sap.sailing</groupId>
<artifactId>org.json.simple</artifactId> <artifactId>org.json.simple</artifactId>
@@ -39,7 +39,7 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sap.sailing</groupId> <groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sse.common</artifactId> <artifactId>com.sap.sse.common</artifactId>
@@ -86,12 +86,12 @@
<groupId>android</groupId> <groupId>android</groupId>
<artifactId>android</artifactId> <artifactId>android</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId> <artifactId>android-maven-plugin</artifactId>
@@ -101,6 +101,6 @@
</sdk> </sdk>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
@@ -1,9 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
android:shape="rectangle"> <gradient android:startColor="#FF216AA6" android:endColor="#FF184C77" android:angle="90"/>
<gradient
android:startColor="#FF216AA6"
android:endColor="#FF184C77"
android:angle="90"/>
</shape> </shape>
@@ -16,10 +16,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" <item android:state_enabled="false"
android:drawable="@drawable/spinner_disabled_holo_dark"/> android:drawable="@drawable/spinner_disabled_holo_dark" />
<item android:state_pressed="true" <item android:state_pressed="true"
android:drawable="@drawable/spinner_pressed_holo_dark"/> android:drawable="@drawable/spinner_pressed_holo_dark" />
<item android:state_pressed="false" android:state_focused="true" <item android:state_pressed="false" android:state_focused="true"
android:drawable="@drawable/spinner_focused_holo_dark"/> android:drawable="@drawable/spinner_focused_holo_dark" />
<item android:drawable="@drawable/spinner_default_holo_dark"/> <item android:drawable="@drawable/spinner_default_holo_dark" />
</selector> </selector>
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item <item
android:left="@dimen/tab_space" android:left="@dimen/tab_space"
android:right="@dimen/tab_space"> android:right="@dimen/tab_space">
<shape android:shape="rectangle"> <shape android:shape="rectangle" >
<gradient <gradient
android:angle="-90" android:angle="-90"
android:endColor="@color/tabDark" android:endColor="@color/tabDark"
android:startColor="@color/tabMedium"/> android:startColor="@color/tabMedium" />
</shape> </shape>
</item> </item>
<!-- <!--
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal" >
<include <include
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
layout="@android:layout/simple_list_item_1"/> layout="@android:layout/simple_list_item_1" />
<ImageButton <ImageButton
android:id="@+id/array_remove_adapter_remove" android:id="@+id/array_remove_adapter_remove"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -17,6 +17,6 @@
android:layout_weight="0" android:layout_weight="0"
android:layout_gravity="center" android:layout_gravity="center"
android:src="@drawable/ic_menu_delete_dark" android:src="@drawable/ic_menu_delete_dark"
android:contentDescription="@string/remove"/> android:contentDescription="@string/remove" />
</LinearLayout> </LinearLayout>
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:padding="12dp"> android:padding="12dp" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal" >
<AutoCompleteTextView <AutoCompleteTextView
android:id="@+id/edit_set_preference_input" android:id="@+id/edit_set_preference_input"
@@ -17,22 +17,22 @@
android:layout_weight="1" android:layout_weight="1"
android:completionThreshold="1" android:completionThreshold="1"
android:hint="@string/enter_new_item" android:hint="@string/enter_new_item"
android:inputType="textNoSuggestions|textVisiblePassword"/> android:inputType="textNoSuggestions|textVisiblePassword" />
<Button <Button
android:id="@+id/edit_set_preference_add" android:id="@+id/edit_set_preference_add"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0" android:layout_weight="0"
android:text="@string/add"/> android:text="@string/add" />
</LinearLayout> </LinearLayout>
<ListView <ListView
android:id="@+id/edit_set_preference_list" android:id="@+id/edit_set_preference_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent" />
<TextView <TextView
android:id="@+id/edit_set_preference_list_empty" android:id="@+id/edit_set_preference_list_empty"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -40,6 +40,6 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="6dp" android:layout_margin="6dp"
android:gravity="center" android:gravity="center"
android:text="@string/there_are_no_items_yet_"/> android:text="@string/there_are_no_items_yet_" />
</LinearLayout> </LinearLayout>
@@ -5,10 +5,10 @@
<color name="welter_selection_bottom">#ff0062a9</color> <color name="welter_selection_bottom">#ff0062a9</color>
<color name="welter_extralight_gray">#ffe6e6e6</color> <color name="welter_extralight_gray">#ffe6e6e6</color>
<color name="welter_extralight_gray_transparent">#eee6e6e6</color> <color name="welter_extralight_gray_transparent">#eee6e6e6</color>
<color name="welter_light_gray">#ffcccccc</color> <color name="welter_light_gray">#ffcccccc</color>
<color name="welter_light_gray_transparent">#eecccccc</color> <color name="welter_light_gray_transparent">#eecccccc</color>
<color name="welter_medium_gray">#ff999999</color> <color name="welter_medium_gray">#ff999999</color>
<color name="welter_medium_darkgray">#ff808080</color> <color name="welter_medium_darkgray">#ff808080</color>
<color name="welter_dark_gray">#ff666666</color> <color name="welter_dark_gray">#ff666666</color>
@@ -18,10 +18,10 @@
<color name="welter_medium_blue">#ff226ca9</color> <color name="welter_medium_blue">#ff226ca9</color>
<color name="welter_black">#ff000000</color> <color name="welter_black">#ff000000</color>
<color name="welter_title_bar_background">#323232</color> <color name="welter_title_bar_background">#323232</color>
<color name="sapstore_background_gray">#FFD5D5D6</color> <color name="sapstore_background_gray">#FFD5D5D6</color>
<color name="sapstore_background_light_gray">#FFF3F3F3</color> <color name="sapstore_background_light_gray">#FFF3F3F3</color>
<!-- <!--
<color name="tabMedium">#D6D6D7</color> <color name="tabMedium">#D6D6D7</color>
<color name="tabDark">#CBCBCC</color> <color name="tabDark">#CBCBCC</color>
@@ -3,7 +3,7 @@
<dimen name="Welter.PaddingLeft">7dip</dimen> <dimen name="Welter.PaddingLeft">7dip</dimen>
<dimen name="Welter.TitleBarSize">27dip</dimen> <dimen name="Welter.TitleBarSize">27dip</dimen>
<dimen name="Welter.DividerHeight">1dip</dimen> <dimen name="Welter.DividerHeight">1dip</dimen>
<dimen name="Welter.TitleTextSize">15dip</dimen> <dimen name="Welter.TitleTextSize">15dip</dimen>
<dimen name="Welter.RegularTextSize">16dip</dimen> <dimen name="Welter.RegularTextSize">16dip</dimen>
<dimen name="Welter.BigTitleTextSize">23dip</dimen> <dimen name="Welter.BigTitleTextSize">23dip</dimen>
@@ -2,13 +2,13 @@
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation"> <resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="preference_messageResendIntervalMillis_key">messageResendIntervalMillis</string> <string name="preference_messageResendIntervalMillis_key">messageResendIntervalMillis</string>
<integer name="preference_messageResendIntervalMillis_default">30000</integer> <integer name="preference_messageResendIntervalMillis_default">30000</integer>
<string name="preference_isSendingActive_key">isSendingActive</string> <string name="preference_isSendingActive_key">isSendingActive</string>
<bool name="preference_isSendingActive_default">true</bool> <bool name="preference_isSendingActive_default">true</bool>
<string name="preference_server_url_key">webserviceUrlPref</string> <string name="preference_server_url_key">webserviceUrlPref</string>
<string name="preference_server_url_default">http://dev.sapsailing.com/</string> <string name="preference_server_url_default">http://dev.sapsailing.com/</string>
<string name="preference_enableLifecycleLogging_key">enableLifecycleLogging</string> <string name="preference_enableLifecycleLogging_key">enableLifecycleLogging</string>
<bool name="preference_enableLifecycleLogging_default">false</bool> <bool name="preference_enableLifecycleLogging_default">false</bool>
@@ -23,5 +23,4 @@
<string name="app_folder">com.sap.sailing</string> <string name="app_folder">com.sap.sailing</string>
<string name="intent_send_saved_intents">com.sap.sailing.android.shared.action.sendSavedIntents</string> <string name="intent_send_saved_intents">com.sap.sailing.android.shared.action.sendSavedIntents</string>
<string name="intent_send_message">com.sap.sailing.android.shared.action.sendMessage</string> <string name="intent_send_message">com.sap.sailing.android.shared.action.sendMessage</string>
</resources> </resources>
@@ -6,10 +6,10 @@
<item name="android:layout">@layout/welter_timepicker</item> <item name="android:layout">@layout/welter_timepicker</item>
</style> </style>
--> -->
<style name="MyDropDownNav" parent="@android:style/Widget.Holo.Light.Spinner"> <style name="MyDropDownNav" parent="@android:style/Widget.Holo.Light.Spinner">
<item name="android:background">@drawable/spinner_background_holo_dark</item> <item name="android:background">@drawable/spinner_background_holo_dark</item>
</style> </style>
<style name="Widget.Welter.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar"> <style name="Widget.Welter.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@drawable/title_bar_bg</item> <item name="android:background">@drawable/title_bar_bg</item>
@@ -60,7 +60,7 @@
<item name="android:textSize">@dimen/Welter.BigTitleTextSize</item> <item name="android:textSize">@dimen/Welter.BigTitleTextSize</item>
<item name="android:textColor">@color/welter_deep_gray</item> <item name="android:textColor">@color/welter_deep_gray</item>
</style> </style>
<style name="TextAppearance.Welter.BoldBigTitleLabel" parent="TextAppearance.Welter.BigTitleLabel"> <style name="TextAppearance.Welter.BoldBigTitleLabel" parent="TextAppearance.Welter.BigTitleLabel">
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
</style> </style>
@@ -80,7 +80,7 @@
<style name="TextAppearance.Welter.ExtraBigTitleLabel" parent="TextAppearance.Welter.BigTitleLabel"> <style name="TextAppearance.Welter.ExtraBigTitleLabel" parent="TextAppearance.Welter.BigTitleLabel">
<item name="android:textSize">@dimen/Welter.ExtraBigTitleTextSize</item> <item name="android:textSize">@dimen/Welter.ExtraBigTitleTextSize</item>
</style> </style>
<style name="TextAppearance.Welter.TextLabel" parent="TextAppearance.Welter.BigTitleLabel"> <style name="TextAppearance.Welter.TextLabel" parent="TextAppearance.Welter.BigTitleLabel">
<item name="android:textSize">@dimen/Welter.LabelTextSize</item> <item name="android:textSize">@dimen/Welter.LabelTextSize</item>
</style> </style>
@@ -13,22 +13,16 @@ import com.sap.sailing.android.shared.logging.LoggingExceptionHandler;
import com.sap.sailing.android.shared.util.PrefUtils; import com.sap.sailing.android.shared.util.PrefUtils;
/** /**
* <p> * <p>Registers an additional exception handler for uncaught exception to have some crash logging.</p>
* Registers an additional exception handler for uncaught exception to have some crash logging. * <p>Offers a static {@link StringContext} to handle i18n in ugly cases.</p>
* </p> * <p>Sets the default preference values (if not set)</p>
* <p>
* Offers a static {@link StringContext} to handle i18n in ugly cases.
* </p>
* <p>
* Sets the default preference values (if not set)
* </p>
*/ */
public class LoggableApplication extends Application { public class LoggableApplication extends Application {
private final static String TAG = LoggableApplication.class.getName(); private final static String TAG = LoggableApplication.class.getName();
private static StringContext stringContext; private static StringContext stringContext;
public static StringContext getStringContext() { public static StringContext getStringContext() {
return stringContext; return stringContext;
} }
@@ -37,15 +31,15 @@ public class LoggableApplication extends Application {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
ExLog.i(this, TAG, "Application is starting."); ExLog.i(this, TAG, "Application is starting.");
Thread.setDefaultUncaughtExceptionHandler(new LoggingExceptionHandler(Thread Thread.setDefaultUncaughtExceptionHandler(new LoggingExceptionHandler(Thread
.getDefaultUncaughtExceptionHandler(), this)); .getDefaultUncaughtExceptionHandler(), this));
LifecycleLogger.enableLifecycleLogging(PrefUtils.getBoolean(this, LifecycleLogger.enableLifecycleLogging(PrefUtils.getBoolean(this, R.string.preference_enableLifecycleLogging_key,
R.string.preference_enableLifecycleLogging_key, R.bool.preference_enableLifecycleLogging_default)); R.bool.preference_enableLifecycleLogging_default));
stringContext = new StringContext(new WeakReference<Context>(getApplicationContext())); stringContext = new StringContext(new WeakReference<Context>(getApplicationContext()));
} }
public static void restartApp(Context context) { public static void restartApp(Context context) {
Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@@ -18,7 +18,7 @@ public class StringContext {
/** /**
* Return a localized string from the application's package's default string table. * Return a localized string from the application's package's default string table.
* *
* @param resId * @param resId
* Resource id for the string * Resource id for the string
* @return the string * @return the string
@@ -19,7 +19,7 @@ public class FileBasedHttpGetRequest extends HttpGetRequest {
super(url, listener, context); super(url, listener, context);
this.outputFile = outputFile; this.outputFile = outputFile;
} }
public File getOutputFile() { public File getOutputFile() {
return outputFile; return outputFile;
} }
@@ -18,6 +18,8 @@ public class HttpGetRequest extends HttpRequest {
super(url, listener, context); super(url, listener, context);
} }
@Override @Override
protected BufferedInputStream doRequest(HttpURLConnection connection) throws IOException { protected BufferedInputStream doRequest(HttpURLConnection connection) throws IOException {
InputStream stream = connection.getInputStream(); InputStream stream = connection.getInputStream();
@@ -18,7 +18,7 @@ public class HttpJsonPostRequest extends HttpRequest {
public HttpJsonPostRequest(URL requestUrl, Context context) { public HttpJsonPostRequest(URL requestUrl, Context context) {
this(requestUrl, null, context); this(requestUrl, null, context);
} }
public HttpJsonPostRequest(URL requestUrl, String body, Context context) { public HttpJsonPostRequest(URL requestUrl, String body, Context context) {
super(requestUrl, context); super(requestUrl, context);
this.requestBody = body; this.requestBody = body;
@@ -67,7 +67,8 @@ public abstract class HttpRequest {
} }
/** /**
* Returns a copied {@link InputStream} of the server's response. You must close this stream when done. * Returns a copied {@link InputStream} of the server's response.
* You must close this stream when done.
*/ */
public InputStream execute() throws IOException { public InputStream execute() throws IOException {
ExLog.i(context, TAG, String.format("(Request %d) Executing HTTP request on %s.", this.hashCode(), url)); ExLog.i(context, TAG, String.format("(Request %d) Executing HTTP request on %s.", this.hashCode(), url));
@@ -92,13 +93,13 @@ public abstract class HttpRequest {
validateHttpResponseCode(connection); validateHttpResponseCode(connection);
InputStream copiedResponseInputStream = readAndCopyResponse(connection, responseInputStream); InputStream copiedResponseInputStream = readAndCopyResponse(connection, responseInputStream);
if (copiedResponseInputStream != null) { if (copiedResponseInputStream != null) {
ExLog.i(context, TAG, String.format("(Request %d) HTTP request executed.", this.hashCode())); ExLog.i(context, TAG, String.format("(Request %d) HTTP request executed.", this.hashCode()));
} else { } else {
ExLog.i(context, TAG, String.format("(Request %d) HTTP request aborted.", this.hashCode())); ExLog.i(context, TAG, String.format("(Request %d) HTTP request aborted.", this.hashCode()));
} }
connection.disconnect(); connection.disconnect();
return copiedResponseInputStream; return copiedResponseInputStream;
} catch (IOException e) { } catch (IOException e) {
@@ -13,13 +13,14 @@ import android.util.Log;
/** /**
* Simple wrapper for logging to various targets. * Simple wrapper for logging to various targets.
* <p/> *
* Log by using {@link ExLog#i(String, String)}, {@link ExLog#w(String, String)} and {@link ExLog#e(String, String)}. * Log by using {@link ExLog#i(String, String)}, {@link ExLog#w(String, String)} and {@link ExLog#e(String, String)}.
* Activate a set of targets by using {@link ExLog#activate(Target)} or {@link ExLog#activate(EnumSet)}. Currently * Activate a set of targets by using {@link ExLog#activate(Target)} or {@link ExLog#activate(EnumSet)}. Currently
* available are logging to android.util.Log LogCat and logging to a file on SD-card. * available are logging to android.util.Log LogCat and logging to a file on SD-card.
* <p/> *
* The file logging in very defensive in a way that opening and writing to the file is secured by various exception * The file logging in very defensive in a way that opening and writing to the file is secured by various exception
* handlers trying to silence all possible errors. * handlers trying to silence all possible errors.
*
*/ */
public class ExLog { public class ExLog {
private final static String TAG = "ExLogInternal"; private final static String TAG = "ExLogInternal";
@@ -45,8 +46,8 @@ public class ExLog {
if (UNIQUE_ID == null) { if (UNIQUE_ID == null) {
UNIQUE_ID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); UNIQUE_ID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
} }
i(context, "ID: " + String.valueOf(eventID), System.currentTimeMillis() + ":" i(context, "ID: " + String.valueOf(eventID), System.currentTimeMillis() + ":" + (UNIQUE_ID == null ? "" : UNIQUE_ID)
+ (UNIQUE_ID == null ? "" : UNIQUE_ID) + ":" + (msg == null ? "" : msg)); + ":" + (msg == null ? "" : msg));
} }
public static String UNIQUE_ID = null; public static String UNIQUE_ID = null;
@@ -62,7 +63,7 @@ public class ExLog {
public synchronized static void e(Context context, String tag, String msg) { public synchronized static void e(Context context, String tag, String msg) {
getInstance().error(context, tag, msg); getInstance().error(context, tag, msg);
} }
public synchronized static void ex(Context context, String tag, Exception e) { public synchronized static void ex(Context context, String tag, Exception e) {
getInstance().exception(context, tag, e); getInstance().exception(context, tag, e);
} }
@@ -118,13 +119,13 @@ public class ExLog {
if (isTargetActive(Target.FILE)) if (isTargetActive(Target.FILE))
logToFile(context, LogLevel.ERROR, tag, msg); logToFile(context, LogLevel.ERROR, tag, msg);
} }
private void exception(Context context, String tag, Exception e) { private void exception(Context context, String tag, Exception e) {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
PrintWriter stream = new PrintWriter(stringWriter); PrintWriter stream = new PrintWriter(stringWriter);
e.printStackTrace(stream); e.printStackTrace(stream);
String msg = stringWriter.toString(); String msg = stringWriter.toString();
if (isTargetActive(Target.LOGCAT)) if (isTargetActive(Target.LOGCAT))
Log.e(tag, msg); Log.e(tag, msg);
@@ -28,7 +28,7 @@ public class FileLoggingTask implements Runnable {
private String logFileName; private String logFileName;
private File logFile; private File logFile;
private BufferedWriter logWriter; private BufferedWriter logWriter;
private final Context context; private final Context context;
public FileLoggingTask(BlockingQueue<String> queue, Context context) { public FileLoggingTask(BlockingQueue<String> queue, Context context) {
@@ -2,6 +2,7 @@ package com.sap.sailing.android.shared.logging;
/** /**
* Stolen from API Level 14. * Stolen from API Level 14.
*
*/ */
public interface LifecycleCallbacks { public interface LifecycleCallbacks {
void onCreate(Object activityOrFragment); void onCreate(Object activityOrFragment);
@@ -24,8 +24,7 @@ public class LifecycleLogger implements LifecycleCallbacks {
context = ((Fragment) activityOrFragment).getActivity(); context = ((Fragment) activityOrFragment).getActivity();
} }
if (isLifecycleLoggingEnabled) { if (isLifecycleLoggingEnabled) {
ExLog.i(context, ExLog.i(context, TAG,
TAG,
String.format("%s %s %s", action, activityOrFragment.getClass().getSimpleName(), String.format("%s %s %s", action, activityOrFragment.getClass().getSimpleName(),
Integer.toHexString(System.identityHashCode(activityOrFragment)))); Integer.toHexString(System.identityHashCode(activityOrFragment))));
} }
@@ -7,7 +7,7 @@ import android.content.Context;
import android.util.Log; import android.util.Log;
public class LoggingExceptionHandler implements UncaughtExceptionHandler { public class LoggingExceptionHandler implements UncaughtExceptionHandler {
private static final String TAG = LoggingExceptionHandler.class.getName(); private static final String TAG = LoggingExceptionHandler.class.getName();
private UncaughtExceptionHandler defaultHandler; private UncaughtExceptionHandler defaultHandler;
@@ -1,5 +1,5 @@
/** /**
* *
*/ */
package com.sap.sailing.android.shared.services.sending; package com.sap.sailing.android.shared.services.sending;
@@ -14,32 +14,29 @@ import android.net.NetworkInfo;
import com.sap.sailing.android.shared.logging.ExLog; import com.sap.sailing.android.shared.logging.ExLog;
/** /**
* Informs {@link MessageSendingService} whenever connectivity is restored, so that it can start sending messages again. * Informs {@link MessageSendingService} whenever connectivity is restored, so that it can start sending
* <p/> * messages again.
* Register in manifest:
* *
* <pre> * Register in manifest:
* {@code * <pre>{@code
* <receiver android:name="com.sap.sailing.android.shared.services.sending.ConnectivityChangedReceiver" > * <receiver android:name="com.sap.sailing.android.shared.services.sending.ConnectivityChangedReceiver" >
* <intent-filter> * <intent-filter>
* <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> * <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
* </intent-filter> * </intent-filter>
* </receiver> * </receiver>
* } * }</pre>
* </pre>
*/ */
public class ConnectivityChangedReceiver extends BroadcastReceiver { public class ConnectivityChangedReceiver extends BroadcastReceiver {
private final static String TAG = ConnectivityChangedReceiver.class.getName(); private final static String TAG = ConnectivityChangedReceiver.class.getName();
/* /* (non-Javadoc)
* (non-Javadoc)
*
* @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent) * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
*/ */
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
ConnectivityManager cService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cService = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = (NetworkInfo) cService.getActiveNetworkInfo(); NetworkInfo networkInfo = (NetworkInfo) cService.getActiveNetworkInfo();
if (!networkInfo.isConnected()) if (!networkInfo.isConnected())
return; return;
@@ -50,29 +47,23 @@ public class ConnectivityChangedReceiver extends BroadcastReceiver {
/** /**
* disables the Connectivity Changed Receiver as there is currently connectivity * disables the Connectivity Changed Receiver as there is currently connectivity
* * @param context the context to work on
* @param context
* the context to work on
*/ */
public static void disable(Context context) { public static void disable(Context context) {
ComponentName receiver = new ComponentName(context, ConnectivityChangedReceiver.class); ComponentName receiver = new ComponentName(context, ConnectivityChangedReceiver.class);
PackageManager packageManager = context.getPackageManager(); PackageManager packageManager = context.getPackageManager();
packageManager.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, packageManager.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
PackageManager.DONT_KILL_APP);
ExLog.w(context, TAG, "Regained connectivity. ConnectivityChangedReceiver disabled"); ExLog.w(context, TAG, "Regained connectivity. ConnectivityChangedReceiver disabled");
} }
/** /**
* enables the Connectivity Changed Receiver to listen on connectivity changes as there is currently no connectivity * enables the Connectivity Changed Receiver to listen on connectivity changes as there is currently no connectivity
* * @param context the context to work on
* @param context
* the context to work on
*/ */
public static void enable(Context context) { public static void enable(Context context) {
ComponentName receiver = new ComponentName(context, ConnectivityChangedReceiver.class); ComponentName receiver = new ComponentName(context, ConnectivityChangedReceiver.class);
PackageManager packageManager = context.getPackageManager(); PackageManager packageManager = context.getPackageManager();
packageManager.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, packageManager.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
PackageManager.DONT_KILL_APP);
ExLog.w(context, TAG, "Connectivity lost. ConnectivityChangedReceiver enabled"); ExLog.w(context, TAG, "Connectivity lost. ConnectivityChangedReceiver enabled");
} }
@@ -18,14 +18,14 @@ import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sailing.android.shared.util.FileHandlerUtils; import com.sap.sailing.android.shared.util.FileHandlerUtils;
public class MessagePersistenceManager { public class MessagePersistenceManager {
private final static String TAG = MessagePersistenceManager.class.getName(); private final static String TAG = MessagePersistenceManager.class.getName();
private final static String delayedMessagesFileName = "delayedMessages.txt"; private final static String delayedMessagesFileName = "delayedMessages.txt";
protected Context context; protected Context context;
protected List<String> persistedMessages; protected List<String> persistedMessages;
private final MessageRestorer messageRestorer; private final MessageRestorer messageRestorer;
public MessagePersistenceManager(Context context, MessageRestorer messageRestorer) { public MessagePersistenceManager(Context context, MessageRestorer messageRestorer) {
@@ -48,8 +48,7 @@ public class MessagePersistenceManager {
persistMessage(url, callbackPayload, payload, callbackClass); persistMessage(url, callbackPayload, payload, callbackClass);
} }
private void persistMessage(String url, String callbackPayload, String payload, String callbackClass) private void persistMessage(String url, String callbackPayload, String payload, String callbackClass) throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
String messageLine = getSerializedIntentForPersistence(url, callbackPayload, payload, callbackClass); String messageLine = getSerializedIntentForPersistence(url, callbackPayload, payload, callbackClass);
ExLog.i(context, TAG, String.format("Persisting message \"%s\".", messageLine)); ExLog.i(context, TAG, String.format("Persisting message \"%s\".", messageLine));
if (persistedMessages.contains(messageLine)) { if (persistedMessages.contains(messageLine)) {
@@ -60,14 +59,14 @@ public class MessagePersistenceManager {
} }
/** /**
* @param payload * @param payload will be URL-encoded to ensure that the resulting string does not contain newlines
* will be URL-encoded to ensure that the resulting string does not contain newlines * @throws UnsupportedEncodingException
* @throws UnsupportedEncodingException
*/ */
private String getSerializedIntentForPersistence(String url, String callbackPayload, String payload, private String getSerializedIntentForPersistence(String url, String callbackPayload,
String callbackClass) throws UnsupportedEncodingException { String payload, String callbackClass) throws UnsupportedEncodingException {
String messageLine = String.format("%s;%s;%s;%s", callbackPayload, String messageLine = String.format("%s;%s;%s;%s", callbackPayload, URLEncoder.encode(payload,
URLEncoder.encode(payload, MessageSendingService.charsetName), url, callbackClass); MessageSendingService.charsetName),
url, callbackClass);
return messageLine; return messageLine;
} }
@@ -80,15 +79,14 @@ public class MessagePersistenceManager {
removeMessage(url, callbackPayload, payload, callbackClass); removeMessage(url, callbackPayload, payload, callbackClass);
} }
private void removeMessage(String url, String callbackPayload, String payload, String callbackClass) private void removeMessage(String url, String callbackPayload, String payload, String callbackClass) throws UnsupportedEncodingException {
throws UnsupportedEncodingException {
if (!persistedMessages.isEmpty()) { if (!persistedMessages.isEmpty()) {
ExLog.i(context, TAG, String.format("Removing message \"%s\".", payload)); ExLog.i(context, TAG, String.format("Removing message \"%s\".", payload));
String messageLine = getSerializedIntentForPersistence(url, callbackPayload, payload, callbackClass); String messageLine = getSerializedIntentForPersistence(url, callbackPayload, payload, callbackClass);
removePersistedMessage(messageLine); removePersistedMessage(messageLine);
} }
} }
/** /**
* Removes all pending messages and clears the persistence file. * Removes all pending messages and clears the persistence file.
*/ */
@@ -108,11 +106,11 @@ public class MessagePersistenceManager {
public int getMessageCount() { public int getMessageCount() {
return persistedMessages.size(); return persistedMessages.size();
} }
public List<String> getContent() { public List<String> getContent() {
return persistedMessages; return persistedMessages;
} }
public static interface MessageRestorer { public static interface MessageRestorer {
void restoreMessage(Context context, Intent messageIntent); void restoreMessage(Context context, Intent messageIntent);
} }
@@ -127,26 +125,26 @@ public class MessagePersistenceManager {
String callbackClassString = lineParts[3]; String callbackClassString = lineParts[3];
Class<? extends ServerReplyCallback> callbackClass = null; Class<? extends ServerReplyCallback> callbackClass = null;
if (!"null".equals(callbackClassString)) { if (! "null".equals(callbackClassString)) {
try { try {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<? extends ServerReplyCallback> tmp = (Class<? extends ServerReplyCallback>) Class Class<? extends ServerReplyCallback> tmp =
.forName(callbackClassString); (Class<? extends ServerReplyCallback>) Class.forName(callbackClassString);
callbackClass = tmp; callbackClass = tmp;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
ExLog.e(context, TAG, "Could not find class for callback name: " + callbackClassString); ExLog.e(context, TAG, "Could not find class for callback name: " + callbackClassString);
} }
} }
// We are passing no message id, because we know it used to suppress message sending and // We are passing no message id, because we know it used to suppress message sending and
// we want this message to be sent. // we want this message to be sent.
Intent messageIntent = MessageSendingService.createMessageIntent(context, url, callbackPayload, null, Intent messageIntent = MessageSendingService.createMessageIntent(context, url, callbackPayload,
payload, callbackClass); null, payload, callbackClass);
if (messageRestorer != null) { if (messageRestorer != null) {
messageRestorer.restoreMessage(context, messageIntent); messageRestorer.restoreMessage(context, messageIntent);
} }
if (messageIntent != null) { if (messageIntent != null) {
delayedIntents.add(messageIntent); delayedIntents.add(messageIntent);
} }
@@ -168,8 +166,7 @@ public class MessagePersistenceManager {
fileContent = FileHandlerUtils.convertStreamToString(inputStream, context); fileContent = FileHandlerUtils.convertStreamToString(inputStream, context);
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
ExLog.w(context, TAG, "In Method getFileContent(): " + e.getClass().getName() + " / " + e.getMessage() ExLog.w(context, TAG, "In Method getFileContent(): " + e.getClass().getName()+" / "+e.getMessage() + " fileContent is empty");
+ " fileContent is empty");
} }
return fileContent; return fileContent;
} }
@@ -217,8 +214,7 @@ public class MessagePersistenceManager {
outputStream.write(content.getBytes()); outputStream.write(content.getBytes());
outputStream.close(); outputStream.close();
} catch (IOException e) { } catch (IOException e) {
ExLog.e(context, TAG, "In Method writeToFile: " + e.getMessage() + " with content " + content ExLog.e(context, TAG, "In Method writeToFile: " + e.getMessage() + " with content " + content + " and mode " + mode);
+ " and mode " + mode);
} }
} }
@@ -15,7 +15,7 @@ import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sse.common.Util; import com.sap.sse.common.Util;
public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Intent, Boolean, InputStream>> { public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Intent, Boolean, InputStream>> {
private static String TAG = MessageSenderTask.class.getName(); private static String TAG = MessageSenderTask.class.getName();
public interface MessageSendingListener { public interface MessageSendingListener {
@@ -55,8 +55,7 @@ public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Inten
if (responseStream != null) { if (responseStream != null) {
try { try {
responseStream.close(); responseStream.close();
} catch (IOException ie) { } catch (IOException ie) { }
}
} }
ExLog.e(context, TAG, String.format("Post not successful, exception occured: %s", e.toString())); ExLog.e(context, TAG, String.format("Post not successful, exception occured: %s", e.toString()));
result = new Util.Triple<Intent, Boolean, InputStream>(intent, false, null); result = new Util.Triple<Intent, Boolean, InputStream>(intent, false, null);
@@ -69,4 +68,5 @@ public class MessageSenderTask extends AsyncTask<Intent, Void, Util.Triple<Inten
super.onPostExecute(resultTriple); super.onPostExecute(resultTriple);
listener.onMessageSent(resultTriple.getA(), resultTriple.getB(), resultTriple.getC()); listener.onMessageSent(resultTriple.getA(), resultTriple.getB(), resultTriple.getC());
} }
} }
@@ -31,34 +31,30 @@ import com.sap.sailing.android.shared.util.PrefUtils;
import com.sap.sailing.domain.common.racelog.RaceLogServletConstants; import com.sap.sailing.domain.common.racelog.RaceLogServletConstants;
/** /**
* Service that handles sending messages to a webservice. Deals with an offline setting by buffering the messages in a * Service that handles sending messages to a webservice. Deals with an offline setting
* file, so that they can be sent when the connection is re-established.<br> * by buffering the messages in a file, so that they can be sent when the connection is
* <p/> * re-established.<br>
* <b>Use in the following way:</b> Add the service declaration to your {@code AndroidManifest.xml}, and also specify
* your class implementing the {@link MessagePersistenceManager.MessageRestorer} as a meta-data tag with the key
* {@code com.sap.sailing.android.shared.services.sending.messageRestorer}. Also refer to
* {@link ConnectivityChangedReceiver}, which has to be registered as well. For example:
* *
* <pre> * <b>Use in the following way:</b> Add the service declaration to your {@code AndroidManifest.xml},
* {@code * and also specify your class implementing the {@link MessagePersistenceManager.MessageRestorer}
* as a meta-data tag with the key {@code com.sap.sailing.android.shared.services.sending.messageRestorer}.
* Also refer to {@link ConnectivityChangedReceiver}, which has to be registered as well.
* For example:
* <pre>{@code
* <service * <service
* android:name="com.sap.sailing.android.shared.services.sending.MessageSendingService" * android:name="com.sap.sailing.android.shared.services.sending.MessageSendingService"
* android:exported="false" > * android:exported="false" >
* <meta-data android:name="com.sap.sailing.android.shared.services.sending.messageRestorer" * <meta-data android:name="com.sap.sailing.android.shared.services.sending.messageRestorer"
* android:value="com.sap.sailing.racecommittee.app.services.sending.EventRestorer" /> * android:value="com.sap.sailing.racecommittee.app.services.sending.EventRestorer" />
* </service> * </service>
* } * }</pre>
* </pre>
* <p/>
* <p/>
* Message sending example:
* *
* <pre> *
* {@code * Message sending example:
* <pre>{@code
* context.startService(MessageSendingService.createMessageIntent( * context.startService(MessageSendingService.createMessageIntent(
* context, url, race.getId(), eventId, serializedEventAsJson, callbackClass)); * context, url, race.getId(), eventId, serializedEventAsJson, callbackClass));
* } * }</pre>
* </pre>
*/ */
public class MessageSendingService extends Service implements MessageSendingListener { public class MessageSendingService extends Service implements MessageSendingListener {
public final static String URL = "url"; public final static String URL = "url";
@@ -66,7 +62,7 @@ public class MessageSendingService extends Service implements MessageSendingList
public final static String CALLBACK_CLASS = "callback"; public final static String CALLBACK_CLASS = "callback";
public final static String CALLBACK_PAYLOAD = "callbackPayload"; // passed back to callback public final static String CALLBACK_PAYLOAD = "callbackPayload"; // passed back to callback
public final static String MESSAGE_ID = "messageId"; public final static String MESSAGE_ID = "messageId";
public static final String charsetName = "UTF-8"; public static final String charsetName = "UTF-8";
protected final static String TAG = MessageSendingService.class.getName(); protected final static String TAG = MessageSendingService.class.getName();
@@ -76,7 +72,7 @@ public class MessageSendingService extends Service implements MessageSendingList
private final IBinder mBinder = new MessageSendingBinder(); private final IBinder mBinder = new MessageSendingBinder();
private MessagePersistenceManager persistenceManager; private MessagePersistenceManager persistenceManager;
private boolean isHandlerSet; private boolean isHandlerSet;
private Set<Serializable> suppressedMessageIds = new HashSet<Serializable>(); private Set<Serializable> suppressedMessageIds = new HashSet<Serializable>();
private APIConnectivityListener apiConnectivityListener; private APIConnectivityListener apiConnectivityListener;
@@ -117,7 +113,7 @@ public class MessageSendingService extends Service implements MessageSendingList
} }
private Date lastSuccessfulSend; private Date lastSuccessfulSend;
public List<String> getDelayedIntentsContent() { public List<String> getDelayedIntentsContent() {
return persistenceManager.getContent(); return persistenceManager.getContent();
} }
@@ -129,15 +125,15 @@ public class MessageSendingService extends Service implements MessageSendingList
public Date getLastSuccessfulSend() { public Date getLastSuccessfulSend() {
return lastSuccessfulSend; return lastSuccessfulSend;
} }
public void clearDelayedIntents() { public void clearDelayedIntents() {
persistenceManager.removeAllMessages(); persistenceManager.removeAllMessages();
// let's fake a successful send! // let's fake a successful send!
serviceLogger.onMessageSentSuccessful(); serviceLogger.onMessageSentSuccessful();
} }
public static Intent createMessageIntent(Context context, String url, Serializable callbackPayload, public static Intent createMessageIntent(Context context, String url, Serializable callbackPayload, Serializable messageId, String payload,
Serializable messageId, String payload, Class<? extends ServerReplyCallback> callbackClass) { Class<? extends ServerReplyCallback> callbackClass) {
Intent messageIntent = new Intent(context, MessageSendingService.class); Intent messageIntent = new Intent(context, MessageSendingService.class);
messageIntent.setAction(context.getString(R.string.intent_send_message)); messageIntent.setAction(context.getString(R.string.intent_send_message));
messageIntent.putExtra(CALLBACK_PAYLOAD, callbackPayload); messageIntent.putExtra(CALLBACK_PAYLOAD, callbackPayload);
@@ -147,7 +143,7 @@ public class MessageSendingService extends Service implements MessageSendingList
messageIntent.putExtra(CALLBACK_CLASS, callbackClass == null ? null : callbackClass.getName()); messageIntent.putExtra(CALLBACK_CLASS, callbackClass == null ? null : callbackClass.getName());
return messageIntent; return messageIntent;
} }
public static Intent createSendDelayedIntent(Context context) { public static Intent createSendDelayedIntent(Context context) {
Intent intent = new Intent(context, MessageSendingService.class); Intent intent = new Intent(context, MessageSendingService.class);
intent.setAction(context.getString(R.string.intent_send_saved_intents)); intent.setAction(context.getString(R.string.intent_send_saved_intents));
@@ -162,7 +158,7 @@ public class MessageSendingService extends Service implements MessageSendingList
ExLog.w(this, TAG, "Unable to extract message identifier from message intent."); ExLog.w(this, TAG, "Unable to extract message identifier from message intent.");
return null; return null;
} }
private MessagePersistenceManager getPersistenceManager() { private MessagePersistenceManager getPersistenceManager() {
ComponentName thisService = new ComponentName(this, this.getClass()); ComponentName thisService = new ComponentName(this, this.getClass());
MessageRestorer restorer = null; MessageRestorer restorer = null;
@@ -274,7 +270,7 @@ public class MessageSendingService extends Service implements MessageSendingList
private void sendMessage(Intent intent) { private void sendMessage(Intent intent) {
boolean sendingActive = PrefUtils.getBoolean(this, R.string.preference_isSendingActive_key, boolean sendingActive = PrefUtils.getBoolean(this, R.string.preference_isSendingActive_key,
R.bool.preference_isSendingActive_default); R.bool.preference_isSendingActive_default);
if (!sendingActive) { if (! sendingActive) {
ExLog.i(this, TAG, "Sending deactivated. Message will not be sent to server."); ExLog.i(this, TAG, "Sending deactivated. Message will not be sent to server.");
} else { } else {
Serializable messageId = getMessageId(intent); Serializable messageId = getMessageId(intent);
@@ -322,7 +318,7 @@ public class MessageSendingService extends Service implements MessageSendingList
} }
lastSuccessfulSend = Calendar.getInstance().getTime(); lastSuccessfulSend = Calendar.getInstance().getTime();
serviceLogger.onMessageSentSuccessful(); serviceLogger.onMessageSentSuccessful();
String callbackClassString = intent.getStringExtra(CALLBACK_CLASS); String callbackClassString = intent.getStringExtra(CALLBACK_CLASS);
ServerReplyCallback callback = null; ServerReplyCallback callback = null;
if (callbackClassString != null) { if (callbackClassString != null) {
@@ -344,7 +340,7 @@ public class MessageSendingService extends Service implements MessageSendingList
/** /**
* checks if there is network connectivity * checks if there is network connectivity
* *
* @return connectivity check value * @return connectivity check value
*/ */
private boolean isConnected() { private boolean isConnected() {
@@ -354,21 +350,22 @@ public class MessageSendingService extends Service implements MessageSendingList
} }
return activeNetwork.isConnected(); return activeNetwork.isConnected();
} }
/** /**
* a UUID that identifies this client session; can be used, e.g., to let the server identify subsequent requests * a UUID that identifies this client session; can be used, e.g., to let the server identify subsequent requests coming from the same client
* coming from the same client
*/ */
public final static UUID uuid = UUID.randomUUID(); public final static UUID uuid = UUID.randomUUID();
public static String getRaceLogEventSendAndReceiveUrl(Context context, final String raceGroupName, public static String getRaceLogEventSendAndReceiveUrl(Context context, final String raceGroupName,
final String raceName, final String fleetName) throws UnsupportedEncodingException { final String raceName, final String fleetName) throws UnsupportedEncodingException {
String url = String.format("%s/sailingserver/rc/racelog?" + RaceLogServletConstants.PARAMS_LEADERBOARD_NAME String url = String.format("%s/sailingserver/rc/racelog?"+
+ "=%s&" + RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME + "=%s&" RaceLogServletConstants.PARAMS_LEADERBOARD_NAME+"=%s&"+
+ RaceLogServletConstants.PARAMS_RACE_FLEET_NAME + "=%s&" + RaceLogServletConstants.PARAMS_CLIENT_UUID RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME+"=%s&"+
+ "=%s", PrefUtils.getString(context, R.string.preference_server_url_key, RaceLogServletConstants.PARAMS_RACE_FLEET_NAME+"=%s&"+
R.string.preference_server_url_default), URLEncoder.encode(raceGroupName, charsetName), URLEncoder RaceLogServletConstants.PARAMS_CLIENT_UUID+"=%s",
.encode(raceName, charsetName), URLEncoder.encode(fleetName, charsetName), uuid); PrefUtils.getString(context, R.string.preference_server_url_key, R.string.preference_server_url_default),
URLEncoder.encode(raceGroupName, charsetName),
URLEncoder.encode(raceName, charsetName), URLEncoder.encode(fleetName, charsetName), uuid);
return url; return url;
} }
@@ -6,13 +6,13 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
/** /**
* This callback is used to attach an operation to the sending of a message, so that the server reply to the performed * This callback is used to attach an operation to the sending of a message, so
* POST request can be evaluated. * that the server reply to the performed POST request can be evaluated.
* <p/> *
* Important: As the callback needs to be passed around in an {@link Intent} and also written to a file, a default * Important: As the callback needs to be passed around in an {@link Intent} and also written
* public constructor without parameters is required. * to a file, a default public constructor without parameters is required.
*
* @author Fredrik Teschke * @author Fredrik Teschke
*
*/ */
public interface ServerReplyCallback { public interface ServerReplyCallback {
/** /**
@@ -49,7 +49,7 @@ public abstract class LoggableActivity extends BaseActivity {
super.onDestroy(); super.onDestroy();
lifeLogger.onDestroy(this); lifeLogger.onDestroy(this);
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {
super.onBackPressed(); super.onBackPressed();
@@ -7,7 +7,7 @@ import com.sap.sailing.android.shared.logging.ExLog;
public class ResilientActivity extends LoggableActivity { public class ResilientActivity extends LoggableActivity {
private static final String TAG = ResilientActivity.class.getName(); private static final String TAG = ResilientActivity.class.getName();
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@@ -18,7 +18,7 @@ public class ResilientActivity extends LoggableActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
protected boolean onHomeClicked() { protected boolean onHomeClicked() {
return false; return false;
} }
@@ -26,7 +26,7 @@ public class ResilientActivity extends LoggableActivity {
protected void fadeActivity(Class<?> activity, boolean newTopTask) { protected void fadeActivity(Class<?> activity, boolean newTopTask) {
Intent intent = new Intent(getBaseContext(), activity); Intent intent = new Intent(getBaseContext(), activity);
if (newTopTask) { if (newTopTask) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} }
fadeActivity(intent); fadeActivity(intent);
@@ -20,7 +20,7 @@ import com.sap.sailing.android.shared.services.sending.MessageSendingService.Mes
import com.sap.sailing.android.shared.util.PrefUtils; import com.sap.sailing.android.shared.util.PrefUtils;
public abstract class SendingServiceAwareActivity extends ResilientActivity { public abstract class SendingServiceAwareActivity extends ResilientActivity {
private class MessageSendingServiceConnection implements ServiceConnection, MessageSendingServiceLogger { private class MessageSendingServiceConnection implements ServiceConnection, MessageSendingServiceLogger {
@Override @Override
public void onServiceConnected(ComponentName className, IBinder service) { public void onServiceConnected(ComponentName className, IBinder service) {
@@ -55,9 +55,9 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
protected boolean boundSendingService = false; protected boolean boundSendingService = false;
protected MessageSendingService sendingService; protected MessageSendingService sendingService;
private MessageSendingServiceConnection sendingServiceConnection; private MessageSendingServiceConnection sendingServiceConnection;
private String sendingServiceStatus = ""; private String sendingServiceStatus = "";
public SendingServiceAwareActivity() { public SendingServiceAwareActivity() {
this.sendingServiceConnection = new MessageSendingServiceConnection(); this.sendingServiceConnection = new MessageSendingServiceConnection();
} }
@@ -65,15 +65,15 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
Intent intent = new Intent(this, MessageSendingService.class); Intent intent = new Intent(this, MessageSendingService.class);
bindService(intent, sendingServiceConnection, Context.BIND_AUTO_CREATE); bindService(intent, sendingServiceConnection, Context.BIND_AUTO_CREATE);
} }
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
if (boundSendingService) { if (boundSendingService) {
unbindService(sendingServiceConnection); unbindService(sendingServiceConnection);
boundSendingService = false; boundSendingService = false;
@@ -83,29 +83,28 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
protected void updateSendingServiceInformation() { protected void updateSendingServiceInformation() {
if (menuItemLive == null) if (menuItemLive == null)
return; return;
if (!boundSendingService) if (!boundSendingService)
return; return;
int errorCount = this.sendingService.getDelayedIntentsCount(); int errorCount = this.sendingService.getDelayedIntentsCount();
if (errorCount > 0) { if (errorCount > 0) {
menuItemLive.setIcon(R.drawable.ic_menu_share_red); menuItemLive.setIcon(R.drawable.ic_menu_share_red);
Date lastSuccessfulSend = this.sendingService.getLastSuccessfulSend(); Date lastSuccessfulSend = this.sendingService.getLastSuccessfulSend();
sendingServiceStatus = String.format( sendingServiceStatus = String.format("Currently %d events waiting to be sent.\nLast successful sent was at %s",
"Currently %d events waiting to be sent.\nLast successful sent was at %s", errorCount, errorCount, lastSuccessfulSend == null ? "never" : lastSuccessfulSend);
lastSuccessfulSend == null ? "never" : lastSuccessfulSend);
} else { } else {
menuItemLive.setIcon(R.drawable.ic_menu_share); menuItemLive.setIcon(R.drawable.ic_menu_share);
sendingServiceStatus = String.format("Currently no event waiting to be sent.", errorCount); sendingServiceStatus = String.format("Currently no event waiting to be sent.", errorCount);
} }
} }
/** /**
* @return the resource ID for the options menu, {@code 0} if none. The menu item displaying the connection status * @return the resource ID for the options menu, {@code 0} if none.
* is added automatically. * The menu item displaying the connection status is added automatically.
*/ */
protected abstract int getOptionsMenuResId(); protected abstract int getOptionsMenuResId();
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
@@ -116,7 +115,7 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
} }
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (R.id.options_menu_live == item.getItemId()) { if (R.id.options_menu_live == item.getItemId()) {
@@ -127,7 +126,7 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
} }
@Override @Override
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
updateSendingServiceInformation(); updateSendingServiceInformation();
@@ -135,8 +134,7 @@ public abstract class SendingServiceAwareActivity extends ResilientActivity {
} }
private String getLiveIconText() { private String getLiveIconText() {
return String.format("Connected to: %s\n%s", return String.format("Connected to: %s\n%s", PrefUtils.getString(this, R.string.preference_server_url_key,
PrefUtils.getString(this, R.string.preference_server_url_key, R.string.preference_server_url_default), R.string.preference_server_url_default), sendingServiceStatus);
sendingServiceStatus);
} }
} }
@@ -34,12 +34,11 @@ public class SystemInformationActivityHelper {
ListView waitingView = (ListView) activity.findViewById(R.id.system_information_persistence_waiting); ListView waitingView = (ListView) activity.findViewById(R.id.system_information_persistence_waiting);
if (activity.boundSendingService) { if (activity.boundSendingService) {
Date lastSuccessfulSend = activity.sendingService.getLastSuccessfulSend(); Date lastSuccessfulSend = activity.sendingService.getLastSuccessfulSend();
statusView.setText(String.format( statusView.setText(String.format("Currently %d events waiting to be sent.\nLast successful sent was at: %s.",
"Currently %d events waiting to be sent.\nLast successful sent was at: %s.", activity.sendingService.getDelayedIntentsCount(), lastSuccessfulSend == null ? "never" : lastSuccessfulSend));
activity.sendingService.getDelayedIntentsCount(), lastSuccessfulSend == null ? "never"
: lastSuccessfulSend)); waitingView.setAdapter(new ArrayAdapter<String>(activity,
android.R.layout.simple_list_item_1,
waitingView.setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1,
activity.sendingService.getDelayedIntentsContent())); activity.sendingService.getDelayedIntentsContent()));
} else { } else {
statusView.setText(activity.getString(R.string.generic_error)); statusView.setText(activity.getString(R.string.generic_error));
@@ -64,7 +63,7 @@ public class SystemInformationActivityHelper {
private void setupVersionView(String deviceIdentifier) { private void setupVersionView(String deviceIdentifier) {
TextView identifierView = (TextView) activity.findViewById(R.id.system_information_application_identifier); TextView identifierView = (TextView) activity.findViewById(R.id.system_information_application_identifier);
identifierView.setText(deviceIdentifier); identifierView.setText(deviceIdentifier);
TextView versionView = (TextView) activity.findViewById(R.id.system_information_application_version); TextView versionView = (TextView) activity.findViewById(R.id.system_information_application_version);
PackageInfo info = AppUtils.getPackageInfo(activity); PackageInfo info = AppUtils.getPackageInfo(activity);
if (info == null) { if (info == null) {
@@ -14,27 +14,27 @@ import android.widget.TextView;
import com.sap.sailing.android.shared.R; import com.sap.sailing.android.shared.R;
public class ArrayRemoveAdapter<T> extends ArrayAdapter<T> { public class ArrayRemoveAdapter<T> extends ArrayAdapter<T> {
public interface NotifyDataSetChangedListener<T> { public interface NotifyDataSetChangedListener<T> {
void onNotifyDataSetChanged(ArrayRemoveAdapter<T> adapter); void onNotifyDataSetChanged(ArrayRemoveAdapter<T> adapter);
} }
private NotifyDataSetChangedListener<T> listener; private NotifyDataSetChangedListener<T> listener;
public ArrayRemoveAdapter(Context context, List<T> objects) { public ArrayRemoveAdapter(Context context, List<T> objects) {
super(context, R.layout.array_remove_adapter, objects); super(context, R.layout.array_remove_adapter, objects);
} }
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) { if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.array_remove_adapter, parent, false); convertView = inflater.inflate(R.layout.array_remove_adapter, parent, false);
} }
TextView text = (TextView) convertView.findViewById(android.R.id.text1); TextView text = (TextView) convertView.findViewById(android.R.id.text1);
ImageButton button = (ImageButton) convertView.findViewById(R.id.array_remove_adapter_remove); ImageButton button = (ImageButton) convertView.findViewById(R.id.array_remove_adapter_remove);
final T item = getItem(position); final T item = getItem(position);
text.setText(item.toString()); text.setText(item.toString());
button.setOnClickListener(new OnClickListener() { button.setOnClickListener(new OnClickListener() {
@@ -45,7 +45,7 @@ public class ArrayRemoveAdapter<T> extends ArrayAdapter<T> {
}); });
return convertView; return convertView;
} }
@Override @Override
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
super.notifyDataSetChanged(); super.notifyDataSetChanged();
@@ -21,12 +21,12 @@ import com.sap.sailing.android.shared.ui.views.EditSetPreference;
* Created by I074137 on 18.09.13. * Created by I074137 on 18.09.13.
*/ */
public class BasePreferenceFragment extends PreferenceFragment { public class BasePreferenceFragment extends PreferenceFragment {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T extends Preference> T findPreference(int resourceId) { protected <T extends Preference> T findPreference(int resourceId) {
return (T) findPreference(getString(resourceId)); return (T) findPreference(getString(resourceId));
} }
protected static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { protected static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object value) { public boolean onPreferenceChange(Preference preference, Object value) {
@@ -35,7 +35,10 @@ public class BasePreferenceFragment extends PreferenceFragment {
if (preference instanceof ListPreference) { if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference; ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue); int index = listPreference.findIndexOfValue(stringValue);
preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
} else if (preference instanceof MultiSelectListPreference || preference instanceof EditSetPreference) { } else if (preference instanceof MultiSelectListPreference || preference instanceof EditSetPreference) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -53,24 +56,28 @@ public class BasePreferenceFragment extends PreferenceFragment {
protected static void bindPreferenceSummaryToValue(Preference preference) { protected static void bindPreferenceSummaryToValue(Preference preference) {
addOnPreferenceChangeListener(preference, sBindPreferenceSummaryToValueListener); addOnPreferenceChangeListener(preference, sBindPreferenceSummaryToValueListener);
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
.getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), "")); PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
} }
protected static void bindPreferenceSummaryToInteger(Preference preference) { protected static void bindPreferenceSummaryToInteger(Preference preference) {
addOnPreferenceChangeListener(preference, sBindPreferenceSummaryToValueListener); addOnPreferenceChangeListener(preference, sBindPreferenceSummaryToValueListener);
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
.getDefaultSharedPreferences(preference.getContext()).getInt(preference.getKey(), 0)); PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getInt(preference.getKey(), 0));
} }
protected static void bindPreferenceSummaryToSet(Preference preference) { protected static void bindPreferenceSummaryToSet(Preference preference) {
addOnPreferenceChangeListener(preference, sBindPreferenceSummaryToValueListener); addOnPreferenceChangeListener(preference, sBindPreferenceSummaryToValueListener);
sBindPreferenceSummaryToValueListener.onPreferenceChange( sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
preference, PreferenceManager
PreferenceManager.getDefaultSharedPreferences(preference.getContext()).getStringSet( .getDefaultSharedPreferences(preference.getContext())
preference.getKey(), new HashSet<String>())); .getStringSet(preference.getKey(), new HashSet<String>()));
} }
protected static void bindPreferenceToCheckbox(CheckBoxPreference checkboxPreference, final Preference target) { protected static void bindPreferenceToCheckbox(CheckBoxPreference checkboxPreference, final Preference target) {
@@ -83,7 +90,7 @@ public class BasePreferenceFragment extends PreferenceFragment {
} }
}); });
} }
protected static void addOnPreferenceChangeListener(Preference preference, OnPreferenceChangeListener newListener) { protected static void addOnPreferenceChangeListener(Preference preference, OnPreferenceChangeListener newListener) {
OnPreferenceChangeListener oldListener = preference.getOnPreferenceChangeListener(); OnPreferenceChangeListener oldListener = preference.getOnPreferenceChangeListener();
if (oldListener == null) { if (oldListener == null) {
@@ -7,9 +7,9 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
public class MultiplePreferenceChangeListener implements OnPreferenceChangeListener { public class MultiplePreferenceChangeListener implements OnPreferenceChangeListener {
private final Set<OnPreferenceChangeListener> listeners; private final Set<OnPreferenceChangeListener> listeners;
public MultiplePreferenceChangeListener() { public MultiplePreferenceChangeListener() {
this.listeners = new HashSet<Preference.OnPreferenceChangeListener>(); this.listeners = new HashSet<Preference.OnPreferenceChangeListener>();
} }
@@ -17,11 +17,12 @@ public class MultiplePreferenceChangeListener implements OnPreferenceChangeListe
public void addOnPreferenceChangeListener(OnPreferenceChangeListener listener) { public void addOnPreferenceChangeListener(OnPreferenceChangeListener listener) {
listeners.add(listener); listeners.add(listener);
} }
public void removeOnPreferenceChangeListener(OnPreferenceChangeListener listener) { public void removeOnPreferenceChangeListener(OnPreferenceChangeListener listener) {
listeners.remove(listener); listeners.remove(listener);
} }
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean result = true; boolean result = true;
@@ -27,12 +27,12 @@ import com.sap.sailing.android.shared.ui.adapters.ArrayRemoveAdapter;
public class EditSetPreference extends DialogPreference { public class EditSetPreference extends DialogPreference {
private static final String TAG = EditSetPreference.class.getName(); private static final String TAG = EditSetPreference.class.getName();
private static final List<String> defaultFallbackValue = new ArrayList<String>(); private static final List<String> defaultFallbackValue = new ArrayList<String>();
private List<String> currentValue; private List<String> currentValue;
private List<String> exampleValues; private List<String> exampleValues;
public EditSetPreference(Context context, AttributeSet attrs) { public EditSetPreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.exampleValues = new ArrayList<String>(); this.exampleValues = new ArrayList<String>();
@@ -46,19 +46,18 @@ public class EditSetPreference extends DialogPreference {
@Override @Override
protected View onCreateDialogView() { protected View onCreateDialogView() {
View view = super.onCreateDialogView(); View view = super.onCreateDialogView();
final AutoCompleteTextView inputView = (AutoCompleteTextView) view.findViewById(R.id.edit_set_preference_input); final AutoCompleteTextView inputView = (AutoCompleteTextView) view.findViewById(R.id.edit_set_preference_input);
final Button addButton = (Button) view.findViewById(R.id.edit_set_preference_add); final Button addButton = (Button) view.findViewById(R.id.edit_set_preference_add);
final ListView listView = (ListView) view.findViewById(R.id.edit_set_preference_list); final ListView listView = (ListView) view.findViewById(R.id.edit_set_preference_list);
// setup list view // setup list view
final ArrayRemoveAdapter<String> adapter = new ArrayRemoveAdapter<String>(view.getContext(), currentValue); final ArrayRemoveAdapter<String> adapter = new ArrayRemoveAdapter<String>(view.getContext(), currentValue);
listView.setEmptyView(view.findViewById(R.id.edit_set_preference_list_empty)); listView.setEmptyView(view.findViewById(R.id.edit_set_preference_list_empty));
listView.setAdapter(adapter); listView.setAdapter(adapter);
// setup inputView // setup inputView
ArrayAdapter<String> autoCompleteAdapter = new ArrayAdapter<String>(view.getContext(), ArrayAdapter<String> autoCompleteAdapter = new ArrayAdapter<String>(view.getContext(), android.R.layout.simple_dropdown_item_1line, exampleValues);
android.R.layout.simple_dropdown_item_1line, exampleValues);
inputView.setAdapter(autoCompleteAdapter); inputView.setAdapter(autoCompleteAdapter);
inputView.addTextChangedListener(new TextWatcher() { inputView.addTextChangedListener(new TextWatcher() {
@Override @Override
@@ -66,19 +65,17 @@ public class EditSetPreference extends DialogPreference {
boolean invalid = s.length() == 0 || currentValue.contains(s.toString()); boolean invalid = s.length() == 0 || currentValue.contains(s.toString());
addButton.setEnabled(!invalid); addButton.setEnabled(!invalid);
} }
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) { }
}
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
}
}); });
// setup add button // setup add button
addButton.setOnClickListener(new OnClickListener() { addButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View arg0) { public void onClick(View arg0) {
Editable text = inputView.getText(); Editable text = inputView.getText();
@@ -86,10 +83,10 @@ public class EditSetPreference extends DialogPreference {
text.clear(); text.clear();
} }
}); });
return view; return view;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) { protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
@@ -102,7 +99,7 @@ public class EditSetPreference extends DialogPreference {
persistStringSet(currentValue); persistStringSet(currentValue);
} }
} }
@Override @Override
protected Object onGetDefaultValue(TypedArray a, int index) { protected Object onGetDefaultValue(TypedArray a, int index) {
Set<String> defaultValue = new HashSet<String>(); Set<String> defaultValue = new HashSet<String>();
@@ -111,7 +108,7 @@ public class EditSetPreference extends DialogPreference {
} }
return defaultValue; return defaultValue;
} }
@Override @Override
protected void onDialogClosed(boolean positiveResult) { protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) { if (positiveResult) {
@@ -129,27 +126,28 @@ public class EditSetPreference extends DialogPreference {
// It's already there, so the same as persisting // It's already there, so the same as persisting
return true; return true;
} }
SharedPreferences.Editor editor = getEditor(); SharedPreferences.Editor editor = getEditor();
editor.putStringSet(getKey(), new HashSet<String>(value)); editor.putStringSet(getKey(), new HashSet<String>(value));
if (shouldCommit()) { if (shouldCommit()) {
editor.commit(); editor.commit();
} }
return true; return true;
} }
return false; return false;
} }
protected List<String> getPersistedStringSet(List<String> defaultReturnValue) { protected List<String> getPersistedStringSet(List<String> defaultReturnValue) {
if (!shouldPersist()) { if (!shouldPersist()) {
return defaultReturnValue; return defaultReturnValue;
} }
Set<String> fallbackDefault = defaultReturnValue == null ? null : new HashSet<String>(defaultReturnValue); Set<String> fallbackDefault = defaultReturnValue == null ? null : new HashSet<String>(defaultReturnValue);
Set<String> value = getSharedPreferences().getStringSet(getKey(), fallbackDefault); Set<String> value = getSharedPreferences().getStringSet(getKey(), fallbackDefault);
return value == null ? null : new ArrayList<String>(value); return value == null ? null : new ArrayList<String>(value);
} }
} }
@@ -12,12 +12,12 @@ public class CollectionUtils {
Util.addAll(iterable, list); Util.addAll(iterable, list);
return list; return list;
} }
public static boolean isEqualCollection(final Collection<?> left, final Collection<?> right) { public static boolean isEqualCollection(final Collection<?> left, final Collection<?> right) {
if (left.size() != right.size()) { if (left.size() != right.size()) {
return false; return false;
} }
// There may be better implementations ;-) // There may be better implementations ;-)
return left.containsAll(right) && right.containsAll(left); return left.containsAll(right) && right.containsAll(left);
} }
@@ -31,19 +31,17 @@ public class FileHandlerUtils {
stringBuilder.append(line + "\n"); stringBuilder.append(line + "\n");
} }
} catch (IOException e) { } catch (IOException e) {
ExLog.e(context, TAG, ExLog.e(context, TAG, "In Method convertStreamToString while converting stream to string: " + e.getMessage());
"In Method convertStreamToString while converting stream to string: " + e.getMessage());
} finally { } finally {
try { try {
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
ExLog.e(context, TAG, ExLog.e(context, TAG, "In Method convertStreamToString while closing the input stream: " + e.getMessage());
"In Method convertStreamToString while closing the input stream: " + e.getMessage());
} }
} }
return stringBuilder.toString(); return stringBuilder.toString();
} }
public static File getExternalApplicationFolder(Context context) { public static File getExternalApplicationFolder(Context context) {
String appFolder = context.getResources().getString(R.string.app_folder); String appFolder = context.getResources().getString(R.string.app_folder);
File dir = new File(Environment.getExternalStorageDirectory() + File.separator + appFolder); File dir = new File(Environment.getExternalStorageDirectory() + File.separator + appFolder);
@@ -8,7 +8,7 @@ public class PrefUtils {
private static String key; private static String key;
private static SharedPreferences prefs; private static SharedPreferences prefs;
private static Context lastContext; private static Context lastContext;
private static void setup(Context context, int keyResId) { private static void setup(Context context, int keyResId) {
Context appContext = context.getApplicationContext(); Context appContext = context.getApplicationContext();
if (appContext != lastContext) { if (appContext != lastContext) {
@@ -17,19 +17,19 @@ public class PrefUtils {
} }
key = appContext.getString(keyResId); key = appContext.getString(keyResId);
} }
public static String getString(Context context, int keyResId, int defaultResId) { public static String getString(Context context, int keyResId, int defaultResId) {
setup(context, keyResId); setup(context, keyResId);
String defVal = context.getString(defaultResId); String defVal = context.getString(defaultResId);
return prefs.getString(key, defVal); return prefs.getString(key, defVal);
} }
public static boolean getBoolean(Context context, int keyResId, int defaultResId) { public static boolean getBoolean(Context context, int keyResId, int defaultResId) {
setup(context, keyResId); setup(context, keyResId);
boolean defVal = context.getResources().getBoolean(defaultResId); boolean defVal = context.getResources().getBoolean(defaultResId);
return prefs.getBoolean(key, defVal); return prefs.getBoolean(key, defVal);
} }
public static int getInt(Context context, int keyResId, int defaultResId) { public static int getInt(Context context, int keyResId, int defaultResId) {
setup(context, keyResId); setup(context, keyResId);
int defVal = context.getResources().getInteger(defaultResId); int defVal = context.getResources().getInteger(defaultResId);
@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.sap.sailing</groupId> <groupId>com.sap.sailing</groupId>
<artifactId>mobile</artifactId> <artifactId>mobile</artifactId>
@@ -15,8 +15,7 @@
<properties> <properties>
<!-- If you change this name, change in app too! --> <!-- If you change this name, change in app too! -->
<additional-deployment-version-file>com.sap.sailing.android.tracking.app.version <additional-deployment-version-file>com.sap.sailing.android.tracking.app.version</additional-deployment-version-file>
</additional-deployment-version-file>
<!-- passed by buildAndUpdateProduct.sh (parsed from AndroidManifest.xml) --> <!-- passed by buildAndUpdateProduct.sh (parsed from AndroidManifest.xml) -->
<app-version>${tracking-app-version}</app-version> <app-version>${tracking-app-version}</app-version>
</properties> </properties>
@@ -58,10 +57,10 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sap.sailing</groupId> <groupId>com.sap.sailing</groupId>
<artifactId>com.sap.sailing.android.shared</artifactId> <artifactId>com.sap.sailing.android.shared</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<type>apklib</type> <type>apklib</type>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -80,7 +79,7 @@
</sdk> </sdk>
<release>true</release> <release>true</release>
<proguard> <proguard>
<!-- Someone needs to look into this - quite hard to find a configuration that doesnt break everything --> <!-- Someone needs to look into this - quite hard to find a configuration that doesnt break everything -->
<skip>true</skip> <skip>true</skip>
<config>proguard-project.txt</config> <config>proguard-project.txt</config>
<configs> <configs>
@@ -16,7 +16,7 @@ public class BaseActivity extends AbstractBaseActivity {
private static final String TAG = BaseActivity.class.getName(); private static final String TAG = BaseActivity.class.getName();
protected AppPreferences prefs; protected AppPreferences prefs;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -29,7 +29,7 @@ public class BaseActivity extends AbstractBaseActivity {
inflater.inflate(R.menu.options_menu, menu); inflater.inflate(R.menu.options_menu, menu);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@@ -52,7 +52,7 @@ public class RacingActivity extends SessionActivity implements RaceInfoListener
private ActionBar actionBar; private ActionBar actionBar;
private List<FilterMode> items; private List<FilterMode> items;
public FilterModeSelectionBinder(ManagedRaceListFragment list, ActionBar actionBar, public FilterModeSelectionBinder(ManagedRaceListFragment list, ActionBar actionBar,
ArrayAdapter<FilterMode> adapter, FilterMode... rawItems) { ArrayAdapter<FilterMode> adapter, FilterMode... rawItems) {
this.targetList = list; this.targetList = list;
this.actionBar = actionBar; this.actionBar = actionBar;
@@ -62,7 +62,7 @@ public class RacingActivity extends SessionActivity implements RaceInfoListener
trackSelection(list); trackSelection(list);
} }
private void trackSelection(ManagedRaceListFragment list) { private void trackSelection(ManagedRaceListFragment list) {
int selectedIndex = this.items.indexOf(list.getFilterMode()); int selectedIndex = this.items.indexOf(list.getFilterMode());
if (selectedIndex >= 0) { if (selectedIndex >= 0) {
this.actionBar.setSelectedNavigationItem(selectedIndex); this.actionBar.setSelectedNavigationItem(selectedIndex);
@@ -205,7 +205,7 @@ public class RacingActivity extends SessionActivity implements RaceInfoListener
return courseId; return courseId;
} }
private void setupActionBar(CourseArea courseArea) { private void setupActionBar(CourseArea courseArea) {
ActionBar actionBar = getActionBar(); ActionBar actionBar = getActionBar();
AbstractLogEventAuthor author = preferences.getAuthor(); AbstractLogEventAuthor author = preferences.getAuthor();
String title = String.format(getString(R.string.racingview_header), courseArea.getName()); String title = String.format(getString(R.string.racingview_header), courseArea.getName());
@@ -133,7 +133,7 @@ public class ResultsCapturingActivity extends SessionActivity {
} }
} }
private int getBackCameraId() { private int getBackCameraId() {
for (int i = 0; i < Camera.getNumberOfCameras(); i++) { for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
CameraInfo info = new CameraInfo(); CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info); Camera.getCameraInfo(i, info);
@@ -8,9 +8,6 @@
<enum name="satellite" value="2"/> <enum name="satellite" value="2"/>
<enum name="terrain" value="3"/> <enum name="terrain" value="3"/>
<enum name="hybrid" value="4"/> <enum name="hybrid" value="4"/>
</attr> </attr>
<attr name="cameraBearing" format="float"/> <attr name="cameraBearing" format="float"/>
<attr name="cameraTargetLat" format="float"/> <attr name="cameraTargetLat" format="float"/>
+1
View File
@@ -142,4 +142,5 @@
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>
</project> </project>
+2
View File
@@ -57,5 +57,7 @@
<id>uni-luebeck</id> <id>uni-luebeck</id>
<url>http://www.itm.uni-luebeck.de/projects/maven/releases</url> <url>http://www.itm.uni-luebeck.de/projects/maven/releases</url>
</repository> </repository>
</repositories> </repositories>
</project> </project>