mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-09 22:01:02 +00:00
Introduced AppPreferences for SharedPreference calls, implemented missing bits and pieces in WindActivity, introduced the domains Wind to WindActivity
This commit is contained in:
1 parent
730e339fd2
commit
5cb7dc6105
12 files changed
+185
-138
No files matched your search
@@ -23,11 +23,11 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1. Enter the wind direction"
|
||||
android:text="@string/enter_wind_direction"
|
||||
android:textAppearance="@style/TextAppearance.Welter.BigTitleLabel" />
|
||||
|
||||
<com.sap.sailing.racecommittee.app.ui.views.CompassView
|
||||
android:id="@+id/compassView1"
|
||||
android:id="@+id/compassView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
</com.sap.sailing.racecommittee.app.ui.views.CompassView>
|
||||
@@ -35,30 +35,16 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="2. Enter the wind speed"
|
||||
android:text="@string/enter_wind_speed"
|
||||
android:textAppearance="@style/TextAppearance.Welter.BigTitleLabel" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/sb_wind_speed"
|
||||
android:id="@+id/seekbar_wind_speed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:progress="100"
|
||||
android:max="400"
|
||||
android:padding="18dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="3. Obtain your position"
|
||||
android:textAppearance="@style/TextAppearance.Welter.BigTitleLabel" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_wind_query_gps"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Query GPS"
|
||||
android:layout_gravity="center"
|
||||
android:padding="18dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -81,33 +67,33 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="9dp"
|
||||
android:text="4. Check all data"
|
||||
android:text="@string/check_all_data"
|
||||
android:textAppearance="@style/TextAppearance.Welter.BigTitleLabel" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wind direction (degrees)" />
|
||||
android:text="@string/wind_direction_degrees" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_wind_direction"
|
||||
android:id="@+id/editTextWindDirection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:hint="in degrees"
|
||||
android:hint="@string/in_degrees"
|
||||
android:minWidth="200dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wind speed (knots)" />
|
||||
android:text="@string/wind_speed_knots" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_wind_speed"
|
||||
android:id="@+id/editTextWindSpeed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal"
|
||||
android:hint="in knots"
|
||||
android:hint="@string/in_knots"
|
||||
android:minWidth="200dp">
|
||||
</EditText>
|
||||
|
||||
@@ -120,7 +106,7 @@
|
||||
android:id="@+id/et_position_lat"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="latitude"
|
||||
android:hint="@string/latitude"
|
||||
android:minWidth="200dp">
|
||||
</EditText>
|
||||
|
||||
@@ -128,7 +114,7 @@
|
||||
android:id="@+id/et_position_lon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="longitude"
|
||||
android:hint="@string/longitude"
|
||||
android:minWidth="200dp">
|
||||
</EditText>
|
||||
|
||||
|
||||
@@ -180,5 +180,16 @@
|
||||
|
||||
<string name="results_mail_subject">[Race Committee] %s</string>
|
||||
<string name="results_mail_body">Results for race %s are attached.</string>
|
||||
<string name="wind_direction_degrees">Wind direction (degrees)</string>
|
||||
<string name="wind_speed_knots">Wind speed (knots)</string>
|
||||
<string name="enter_wind_direction">1. Enter the wind direction</string>
|
||||
<string name="enter_wind_speed">2. Enter the wind speed</string>
|
||||
<string name="check_all_data">3. Check all data</string>
|
||||
<string name="in_degrees">in degrees</string>
|
||||
<string name="in_knots">in knots</string>
|
||||
<string name="latitude">Latitude</string>
|
||||
<string name="longitude">Longitude</string>
|
||||
<string name="wind_speed_direction_not_a_valid_number">The wind speed or direction is not a valid number. Please correct the value.</string>
|
||||
<string name="wind_location_or_fields_not_valid">The entered location, wind speed or direction is empty. Please correct the values.</string>
|
||||
|
||||
</resources>
|
||||
+1
-24
@@ -1,8 +1,5 @@
|
||||
package com.sap.sailing.racecommittee.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.raceinfo.SetStartTimeRaceFragment;
|
||||
|
||||
@@ -22,34 +19,14 @@ public class AppConstants {
|
||||
public final static String EXTRAS_URL = "url";
|
||||
public final static String OPTIONAL_EXTRAS = "optionalExtra";
|
||||
public final static String FLAG_KEY = "raceFlag";
|
||||
public final static String EXTRAS_WIND_FIX = "windfix";
|
||||
|
||||
public final static String ApplicationFolder = "/racecommittee";
|
||||
|
||||
// Login activity
|
||||
public final static String EventIdTag = "EventId";
|
||||
|
||||
private final static String PREFERENCE_SERVICE_URL = "webserviceUrlPref";
|
||||
private final static String PREFERENCE_SENDING_ACTIVE = "sendingActivePref";
|
||||
|
||||
public static final String RESET_TIME_FRAGMENT_IS_RESET = SetStartTimeRaceFragment.class.getName() + ".isReset";
|
||||
|
||||
public static final int DefaultStartTimeMinuteOffset = 10;
|
||||
|
||||
public static String getServerBaseURL(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if(sp.getString(PREFERENCE_SERVICE_URL, "").equals(""))
|
||||
return "http://localhost:8889";
|
||||
return sp.getString(PREFERENCE_SERVICE_URL, "http://192.168.56.1:8888");
|
||||
}
|
||||
|
||||
public static boolean isSendingActive(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getBoolean(PREFERENCE_SENDING_ACTIVE, false);
|
||||
}
|
||||
|
||||
public static void setSendingActive(Context context, boolean activate) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putBoolean(PREFERENCE_SENDING_ACTIVE, activate).apply();
|
||||
}
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.sap.sailing.racecommittee.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class AppPreferences {
|
||||
|
||||
private final static String PREFERENCE_SERVICE_URL = "webserviceUrlPref";
|
||||
private final static String PREFERENCE_SENDING_ACTIVE = "sendingActivePref";
|
||||
private final static String PREFERENCE_WIND_BEARING = "windBearingPref";
|
||||
private final static String PREFERENCE_WIND_SPEED = "windSpeedPref";
|
||||
private final static String PREFERENCE_MAIL_RECIPIENT = "mailRecipientPreference";
|
||||
|
||||
public static double getWindBearing(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
long windBearingAsLong = sp.getLong(PREFERENCE_WIND_BEARING, 0);
|
||||
return Double.longBitsToDouble(windBearingAsLong);
|
||||
}
|
||||
|
||||
public static void setWindBearing(Context context, double enteredWindBearing) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
long windBearingAsLong = Double.doubleToLongBits(enteredWindBearing);
|
||||
sp.edit().putLong(PREFERENCE_WIND_BEARING, windBearingAsLong).apply();
|
||||
}
|
||||
|
||||
public static double getWindSpeed(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
long windSpeedAsLong = sp.getLong(PREFERENCE_WIND_SPEED, 0);
|
||||
return Double.longBitsToDouble(windSpeedAsLong);
|
||||
}
|
||||
|
||||
public static void setWindSpeed(Context context, double enteredWindSpeed) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
long windSpeedAsLong = Double.doubleToLongBits(enteredWindSpeed);
|
||||
sp.edit().putLong(PREFERENCE_WIND_SPEED, windSpeedAsLong).apply();
|
||||
}
|
||||
|
||||
public static String getServerBaseURL(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if(sp.getString(PREFERENCE_SERVICE_URL, "").equals(""))
|
||||
return "http://localhost:8889";
|
||||
return sp.getString(PREFERENCE_SERVICE_URL, "http://192.168.56.1:8888");
|
||||
}
|
||||
|
||||
public static boolean isSendingActive(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getBoolean(PREFERENCE_SENDING_ACTIVE, false);
|
||||
}
|
||||
|
||||
public static void setSendingActive(Context context, boolean activate) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putBoolean(PREFERENCE_SENDING_ACTIVE, activate).apply();
|
||||
}
|
||||
|
||||
public static String getMailRecipient(Context context) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sp.getString(PREFERENCE_MAIL_RECIPIENT, context.getString(R.string.settings_advanced_mail_default));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.sap.sailing.racecommittee.app.courseDesigner;
|
||||
package com.sap.sailing.racecommittee.app.coursedesigner;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.sap.sailing.domain.common.coursedesign.BoatClassType;
|
||||
|
||||
+6
-6
@@ -16,7 +16,7 @@ import com.sap.sailing.domain.base.CourseBase;
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.SharedDomainFactory;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.data.clients.LoadClient;
|
||||
import com.sap.sailing.racecommittee.app.data.handlers.CompetitorsDataHandler;
|
||||
import com.sap.sailing.racecommittee.app.data.handlers.CourseDataHandler;
|
||||
@@ -91,7 +91,7 @@ public class OnlineDataManager extends DataManager {
|
||||
DataHandler<Collection<EventBase>> handler = new EventsDataHandler(this, client);
|
||||
|
||||
try {
|
||||
new DataLoader<Collection<EventBase>>(context, URI.create(AppConstants.getServerBaseURL(context)
|
||||
new DataLoader<Collection<EventBase>>(context, URI.create(AppPreferences.getServerBaseURL(context)
|
||||
+ "/sailingserver/events"), parser, handler).forceLoad();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -146,7 +146,7 @@ public class OnlineDataManager extends DataManager {
|
||||
new RaceLogDeserializer(RaceLogEventDeserializer.create(domainFactory)))))));
|
||||
DataHandler<Collection<ManagedRace>> handler = new ManagedRacesDataHandler(this, client);
|
||||
try {
|
||||
new DataLoader<Collection<ManagedRace>>(context, URI.create(AppConstants.getServerBaseURL(context)
|
||||
new DataLoader<Collection<ManagedRace>>(context, URI.create(AppPreferences.getServerBaseURL(context)
|
||||
+ "/sailingserver/rc/racegroups?courseArea=" + courseAreaId.toString()), parser, handler)
|
||||
.forceLoad();
|
||||
} catch (MalformedURLException e) {
|
||||
@@ -175,7 +175,7 @@ public class OnlineDataManager extends DataManager {
|
||||
String fleetName = URLEncoder.encode(identifier.getFleet().getName());
|
||||
|
||||
try {
|
||||
new DataLoader<Collection<Mark>>(context, URI.create(AppConstants.getServerBaseURL(context)
|
||||
new DataLoader<Collection<Mark>>(context, URI.create(AppPreferences.getServerBaseURL(context)
|
||||
+ "/sailingserver/rc/marks?leaderboard=" + raceGroupName + "&raceColumn=" + raceColumnName
|
||||
+ "&fleet=" + fleetName), parser, handler)
|
||||
.forceLoad();
|
||||
@@ -205,7 +205,7 @@ public class OnlineDataManager extends DataManager {
|
||||
String fleetName = URLEncoder.encode(identifier.getFleet().getName());
|
||||
|
||||
try {
|
||||
new DataLoader<CourseBase>(context, URI.create(AppConstants.getServerBaseURL(context)
|
||||
new DataLoader<CourseBase>(context, URI.create(AppPreferences.getServerBaseURL(context)
|
||||
+ "/sailingserver/rc/currentcourse?leaderboard=" + raceGroupName + "&raceColumn=" + raceColumnName
|
||||
+ "&fleet=" + fleetName), parser, handler)
|
||||
.forceLoad();
|
||||
@@ -230,7 +230,7 @@ public class OnlineDataManager extends DataManager {
|
||||
String fleetName = URLEncoder.encode(identifier.getFleet().getName());
|
||||
|
||||
try {
|
||||
new DataLoader<Collection<Competitor>>(context, URI.create(AppConstants.getServerBaseURL(context)
|
||||
new DataLoader<Collection<Competitor>>(context, URI.create(AppPreferences.getServerBaseURL(context)
|
||||
+ "/sailingserver/rc/competitors?leaderboard=" + raceGroupName + "&raceColumn=" + raceColumnName
|
||||
+ "&fleet=" + fleetName), parser, handler)
|
||||
.forceLoad();
|
||||
|
||||
+3
-2
@@ -16,6 +16,7 @@ import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.domain.ManagedRace;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
@@ -91,7 +92,7 @@ public class EventSendingService extends Service implements EventSendingListener
|
||||
public static Intent createEventIntent(Context context, ManagedRace race, Serializable serializedEvent) {
|
||||
String url = String.format(
|
||||
"%s/sailingserver/rc/racelog?leaderboard=%s&raceColumn=%s&fleet=%s",
|
||||
AppConstants.getServerBaseURL(context),
|
||||
AppPreferences.getServerBaseURL(context),
|
||||
URLEncoder.encode(race.getRaceGroup().getName()),
|
||||
URLEncoder.encode(race.getName()),
|
||||
URLEncoder.encode(race.getFleet().getName()));
|
||||
@@ -183,7 +184,7 @@ public class EventSendingService extends Service implements EventSendingListener
|
||||
}
|
||||
|
||||
private void sendEvent(Intent intent) {
|
||||
if (!AppConstants.isSendingActive(this)) {
|
||||
if (!AppPreferences.isSendingActive(this)) {
|
||||
ExLog.i(TAG, "Sending deactivated. Event will not be sent to server.");
|
||||
} else {
|
||||
EventSenderTask task = new EventSenderTask(this);
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.services.sending.EventSendingService;
|
||||
@@ -141,7 +141,7 @@ public abstract class BaseActivity extends Activity {
|
||||
}
|
||||
|
||||
private String getLiveIconText() {
|
||||
return String.format("Connected to: %s\n%s", AppConstants.getServerBaseURL(this), sendingServiceStatus);
|
||||
return String.format("Connected to: %s\n%s", AppPreferences.getServerBaseURL(this), sendingServiceStatus);
|
||||
}
|
||||
|
||||
protected void fadeActivity(Class<?> activity) {
|
||||
|
||||
+3
-2
@@ -12,6 +12,7 @@ import android.widget.Toast;
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
import com.sap.sailing.racecommittee.app.ui.fragments.dialogs.DialogFragmentButtonListener;
|
||||
@@ -114,11 +115,11 @@ public class LoginActivity extends BaseActivity implements EventSelectedListener
|
||||
switch (loginDialog.getSelectedLoginType()) {
|
||||
case OFFICER:
|
||||
ExLog.i(TAG, "Communication with backend is active.");
|
||||
AppConstants.setSendingActive(this, true);
|
||||
AppPreferences.setSendingActive(this, true);
|
||||
break;
|
||||
case VIEWER:
|
||||
ExLog.i(TAG, "Communication with backend is inactive.");
|
||||
AppConstants.setSendingActive(this, false);
|
||||
AppPreferences.setSendingActive(this, false);
|
||||
break;
|
||||
default:
|
||||
Toast.makeText(this, "Invalid login type. Ignoring.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
+2
-6
@@ -6,11 +6,9 @@ import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
@@ -21,6 +19,7 @@ import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.ui.adapters.PhotoAdapter;
|
||||
import com.sap.sailing.racecommittee.app.utils.MailHelper;
|
||||
@@ -93,10 +92,7 @@ public class ResultsCapturingActivity extends BaseActivity {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SharedPreferences preferences = PreferenceManager
|
||||
.getDefaultSharedPreferences(ResultsCapturingActivity.this);
|
||||
String recipient = preferences.getString("mailRecipientPreference",
|
||||
getString(R.string.settings_advanced_mail_default));
|
||||
String recipient = AppPreferences.getMailRecipient(ResultsCapturingActivity.this);
|
||||
MailHelper.send(new String[] { recipient }, getSubjectText(), getBodyText(), listAdapter.getItems(),
|
||||
ResultsCapturingActivity.this);
|
||||
finish();
|
||||
|
||||
+81
-67
@@ -17,44 +17,61 @@ import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.sap.sailing.domain.base.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.base.impl.KnotSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.Bearing;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
||||
import com.sap.sailing.domain.common.impl.DegreePosition;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.domain.tracking.impl.WindImpl;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
import com.sap.sailing.racecommittee.app.AppPreferences;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
import com.sap.sailing.racecommittee.app.ui.views.CompassView;
|
||||
import com.sap.sailing.racecommittee.app.ui.views.CompassView.CompassDirectionListener;
|
||||
|
||||
public class WindActivity extends BaseActivity implements CompassDirectionListener, LocationListener {
|
||||
|
||||
|
||||
private final static int FIVE_SEC = 5000;
|
||||
private final static int EVERY_POSITION_CHANGE = 0;
|
||||
|
||||
CompassView compassView;
|
||||
EditText windDirection;
|
||||
EditText windSpeed;
|
||||
EditText latitude;
|
||||
EditText longitude;
|
||||
SeekBar seekWindSpeed;
|
||||
Button btnGps;
|
||||
Button btnSend;
|
||||
EditText windBearingEditText;
|
||||
EditText windSpeedEditText;
|
||||
EditText latitudeEditText;
|
||||
EditText longitudeEditText;
|
||||
SeekBar windSpeedSeekBar;
|
||||
Button sendButton;
|
||||
LocationManager locationManager;
|
||||
Location currentLocation;
|
||||
DecimalFormat speedFormat;
|
||||
DecimalFormat bearingFormat;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.wind_view);
|
||||
|
||||
compassView = (CompassView) findViewById(R.id.compassView1);
|
||||
windDirection = (EditText) findViewById(R.id.et_wind_direction);
|
||||
windSpeed = (EditText) findViewById(R.id.et_wind_speed);
|
||||
latitude = (EditText) findViewById(R.id.et_position_lat);
|
||||
longitude = (EditText) findViewById(R.id.et_position_lon);
|
||||
seekWindSpeed = (SeekBar) findViewById(R.id.sb_wind_speed);
|
||||
btnGps = (Button) findViewById(R.id.btn_wind_query_gps);
|
||||
btnSend = (Button) findViewById(R.id.btn_wind_send);
|
||||
compassView = (CompassView) findViewById(R.id.compassView);
|
||||
windBearingEditText = (EditText) findViewById(R.id.editTextWindDirection);
|
||||
windSpeedEditText = (EditText) findViewById(R.id.editTextWindSpeed);
|
||||
latitudeEditText = (EditText) findViewById(R.id.et_position_lat);
|
||||
longitudeEditText = (EditText) findViewById(R.id.et_position_lon);
|
||||
windSpeedSeekBar = (SeekBar) findViewById(R.id.seekbar_wind_speed);
|
||||
sendButton = (Button) findViewById(R.id.btn_wind_send);
|
||||
|
||||
currentLocation = null;
|
||||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, FIVE_SEC, EVERY_POSITION_CHANGE, this);
|
||||
|
||||
seekWindSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||
windSpeedSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
float speed = round(progress / 10.0f, 1);
|
||||
windSpeed.setText(speedFormat.format(speed));
|
||||
windSpeedEditText.setText(speedFormat.format(speed));
|
||||
}
|
||||
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
@@ -64,53 +81,35 @@ public class WindActivity extends BaseActivity implements CompassDirectionListen
|
||||
}
|
||||
});
|
||||
|
||||
btnGps.setOnClickListener(new OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
LocationManager locationManager = (LocationManager) WindActivity.this
|
||||
.getSystemService(Context.LOCATION_SERVICE);
|
||||
Location loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||
latitude.setText(loc.getLatitude() + "");
|
||||
longitude.setText(loc.getLongitude() + "");
|
||||
}
|
||||
});
|
||||
|
||||
btnSend.setOnClickListener(new OnClickListener() {
|
||||
sendButton.setEnabled(false);
|
||||
sendButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
InMemoryDataStore.INSTANCE.setLastWindSpeed(Double.valueOf(windSpeed.getText().toString()
|
||||
.replace(",", ".")));
|
||||
InMemoryDataStore.INSTANCE.setLastWindDirection(Integer.valueOf(windDirection.getText().toString()));
|
||||
LatLng lastWindPosition = new LatLng(Double.valueOf(latitude.getText().toString()), Double
|
||||
.valueOf(longitude.getText().toString()));
|
||||
InMemoryDataStore.INSTANCE.setLastWindPosition(lastWindPosition);
|
||||
// TODO uses domain Wind and send result to calling activity instead of using InMemoryDataStore
|
||||
// Wind windMeasurement = new WindImpl();
|
||||
Intent returnIntent = new Intent();
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
Wind wind = getResultingWindFix();
|
||||
if (wind == null) {
|
||||
Toast.makeText(WindActivity.this, R.string.wind_location_or_fields_not_valid, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Intent resultData = new Intent();
|
||||
resultData.putExtra(AppConstants.EXTRAS_WIND_FIX, wind);
|
||||
setResult(RESULT_OK, resultData);
|
||||
finish();
|
||||
} catch (NumberFormatException nfe) {
|
||||
Toast.makeText(WindActivity.this, "The entered information is not valid", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(WindActivity.this, R.string.wind_speed_direction_not_a_valid_number, Toast.LENGTH_LONG).show();
|
||||
ExLog.i(this.getClass().getCanonicalName(), nfe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, this);
|
||||
|
||||
windSpeed.setText(InMemoryDataStore.INSTANCE.getLastWindSpeed() + "");
|
||||
windDirection.setText(InMemoryDataStore.INSTANCE.getLastWindDirection() + "");
|
||||
if (InMemoryDataStore.INSTANCE.getLastWindPosition() != null) {
|
||||
latitude.setText(InMemoryDataStore.INSTANCE.getLastWindPosition().latitude + "");
|
||||
longitude.setText(InMemoryDataStore.INSTANCE.getLastWindPosition().longitude + "");
|
||||
}
|
||||
|
||||
speedFormat = new DecimalFormat("##.0");
|
||||
bearingFormat = new DecimalFormat("###");
|
||||
|
||||
windSpeedEditText.setText(speedFormat.format(AppPreferences.getWindSpeed(getBaseContext())));
|
||||
windBearingEditText.setText(bearingFormat.format(AppPreferences.getWindBearing(getBaseContext())));
|
||||
}
|
||||
|
||||
DecimalFormat speedFormat = new DecimalFormat("##.0");
|
||||
DecimalFormat directionFormat = new DecimalFormat("###");
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
@@ -118,15 +117,10 @@ public class WindActivity extends BaseActivity implements CompassDirectionListen
|
||||
compassView.setDirectionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDirectionChanged(float degree) {
|
||||
float direction = round(degree, 0);
|
||||
windDirection.setText(directionFormat.format(direction));
|
||||
}
|
||||
|
||||
public static float round(float unrounded, int precision) {
|
||||
BigDecimal decimal = new BigDecimal(unrounded);
|
||||
BigDecimal round = decimal.setScale(precision, BigDecimal.ROUND_UP);
|
||||
return round.floatValue();
|
||||
windBearingEditText.setText(bearingFormat.format(direction));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -137,25 +131,45 @@ public class WindActivity extends BaseActivity implements CompassDirectionListen
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
|
||||
currentLocation = location;
|
||||
latitudeEditText.setText(String.valueOf(location.getLatitude()));
|
||||
longitudeEditText.setText(String.valueOf(location.getLongitude()));
|
||||
sendButton.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
protected static float round(float unrounded, int precision) {
|
||||
BigDecimal decimal = new BigDecimal(unrounded);
|
||||
BigDecimal round = decimal.setScale(precision, BigDecimal.ROUND_UP);
|
||||
return round.floatValue();
|
||||
}
|
||||
|
||||
private Wind getResultingWindFix() throws NumberFormatException {
|
||||
if (currentLocation == null || windSpeedEditText.getText().toString().isEmpty() || windBearingEditText.getText().toString().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Position currentPosition = new DegreePosition(currentLocation.getLatitude(), currentLocation.getLongitude());
|
||||
double windSpeed = Double.valueOf(windSpeedEditText.getText().toString());
|
||||
double windBearing = Double.valueOf(windBearingEditText.getText().toString());
|
||||
Bearing bearing = new DegreeBearingImpl(windBearing);
|
||||
SpeedWithBearing speedBearing = new KnotSpeedWithBearingImpl(windSpeed, bearing);
|
||||
|
||||
return new WindImpl(currentPosition, MillisecondsTimePoint.now(), speedBearing);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -32,7 +32,7 @@ import com.sap.sailing.domain.common.coursedesign.CourseLayout;
|
||||
import com.sap.sailing.domain.common.coursedesign.NumberOfRounds;
|
||||
import com.sap.sailing.domain.common.coursedesign.TargetTime;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.courseDesigner.CourseDesignComputer;
|
||||
import com.sap.sailing.racecommittee.app.coursedesigner.CourseDesignComputer;
|
||||
import com.sap.sailing.racecommittee.app.data.DataStore;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.ui.activities.WindActivity;
|
||||
|
||||
Reference in new issue
Block a user