mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 10:09:42 +00:00
Buoyfragment pings marks now
This commit is contained in:
1 parent
b5e7183e58
commit
ee3437bb5d
8 files changed
+98
-35
No files matched your search
+1
@@ -5,4 +5,5 @@ public class LeaderboardInfo {
|
||||
public String name;
|
||||
public String checkinDigest;
|
||||
public int rowId;
|
||||
public String serverUrl;
|
||||
}
|
||||
+1
@@ -8,6 +8,7 @@ public class AnalyticsContract {
|
||||
|
||||
interface LeaderboardColumns {
|
||||
String LEADERBOARD_NAME = "leaderboard_name";
|
||||
String LEADERBOARD_SERVER_URL = "leaderboard_server_url";
|
||||
String LEADERBOARD_CHECKIN_DIGEST = "leaderboard_checkin_digest";
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -47,6 +47,7 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
|
||||
db.execSQL("CREATE TABLE " + Tables.LEADERBOARDS + " ("
|
||||
+ BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ LeaderboardColumns.LEADERBOARD_CHECKIN_DIGEST + " TEXT, "
|
||||
+ LeaderboardColumns.LEADERBOARD_SERVER_URL + " TEXT, "
|
||||
+ LeaderboardColumns.LEADERBOARD_NAME + " TEXT );");
|
||||
|
||||
db.execSQL("CREATE TABLE " + Tables.CHECKIN_URIS + " ("
|
||||
|
||||
+44
-29
@@ -10,6 +10,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.maps.MapFragment;
|
||||
import com.sap.sailing.android.buoy.positioning.app.R;
|
||||
@@ -23,7 +24,6 @@ import com.sap.sailing.android.shared.ui.customviews.OpenSansButton;
|
||||
import com.sap.sailing.android.shared.ui.customviews.OpenSansTextView;
|
||||
import com.sap.sailing.android.ui.fragments.BaseFragment;
|
||||
|
||||
|
||||
public class BuoyFragment extends BaseFragment implements LocationListener {
|
||||
private OpenSansTextView markHeaderTextView;
|
||||
private OpenSansTextView lattitudeTextView;
|
||||
@@ -41,21 +41,30 @@ public class BuoyFragment extends BaseFragment implements LocationListener{
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
View view = inflater.inflate(R.layout.fragment_buoy_postion_detail, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_buoy_postion_detail,
|
||||
container, false);
|
||||
|
||||
mapFragment = (MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.map);
|
||||
mapFragment = (MapFragment) getActivity().getFragmentManager()
|
||||
.findFragmentById(R.id.map);
|
||||
|
||||
markHeaderTextView = (OpenSansTextView) view.findViewById(R.id.mark_header);
|
||||
lattitudeTextView = (OpenSansTextView) view.findViewById(R.id.marker_gps_latitude);
|
||||
longitudeTextView = (OpenSansTextView) view.findViewById(R.id.marker_gps_longitude);
|
||||
accuracyTextView = (OpenSansTextView) view.findViewById(R.id.marker_gps_accuracy);
|
||||
markHeaderTextView = (OpenSansTextView) view
|
||||
.findViewById(R.id.mark_header);
|
||||
lattitudeTextView = (OpenSansTextView) view
|
||||
.findViewById(R.id.marker_gps_latitude);
|
||||
longitudeTextView = (OpenSansTextView) view
|
||||
.findViewById(R.id.marker_gps_longitude);
|
||||
accuracyTextView = (OpenSansTextView) view
|
||||
.findViewById(R.id.marker_gps_accuracy);
|
||||
Clicklistener clicklistener = new Clicklistener();
|
||||
|
||||
setPositionButton = (OpenSansButton) view.findViewById(R.id.marker_set_position_button);
|
||||
setPositionButton = (OpenSansButton) view
|
||||
.findViewById(R.id.marker_set_position_button);
|
||||
setPositionButton.setOnClickListener(clicklistener);
|
||||
|
||||
resetPostionButton = (OpenSansButton) view.findViewById(R.id.marker_reset_position_button);
|
||||
resetPostionButton = (OpenSansButton) view
|
||||
.findViewById(R.id.marker_reset_position_button);
|
||||
resetPostionButton.setOnClickListener(clicklistener);
|
||||
resetPostionButton.setVisibility(View.GONE);
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -64,17 +73,16 @@ public class BuoyFragment extends BaseFragment implements LocationListener{
|
||||
super.onResume();
|
||||
initLocationProvider();
|
||||
MarkInfo mark = ((PositioningActivity) getActivity()).getMarkInfo();
|
||||
if(mark != null)
|
||||
{
|
||||
if (mark != null) {
|
||||
markHeaderTextView.setText(mark.getName());
|
||||
setUpPingUI();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpPingUI() {
|
||||
MarkPingInfo markPing = ((PositioningActivity)getActivity()).getMarkPing();
|
||||
if(markPing != null)
|
||||
{
|
||||
MarkPingInfo markPing = ((PositioningActivity) getActivity())
|
||||
.getMarkPing();
|
||||
if (markPing != null) {
|
||||
lattitudeTextView.setText(markPing.getLattitude());
|
||||
longitudeTextView.setText(markPing.getLongitude());
|
||||
accuracyTextView.setText("~" + markPing.getAccuracy());
|
||||
@@ -102,14 +110,16 @@ public class BuoyFragment extends BaseFragment implements LocationListener{
|
||||
}
|
||||
|
||||
private void initLocationProvider() {
|
||||
locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager = (LocationManager) getActivity().getSystemService(
|
||||
Context.LOCATION_SERVICE);
|
||||
locationManager.removeUpdates(this);
|
||||
locationProvider = locationManager.getBestProvider(new Criteria(), true);
|
||||
locationManager.requestLocationUpdates(locationProvider, 60000, 10, this);
|
||||
locationProvider = locationManager
|
||||
.getBestProvider(new Criteria(), true);
|
||||
locationManager.requestLocationUpdates(locationProvider, 60000, 10,
|
||||
this);
|
||||
}
|
||||
|
||||
public void setPingListener(pingListener listener)
|
||||
{
|
||||
public void setPingListener(pingListener listener) {
|
||||
pingListener = listener;
|
||||
}
|
||||
|
||||
@@ -122,22 +132,28 @@ public class BuoyFragment extends BaseFragment implements LocationListener{
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
if(id == R.id.marker_set_position_button)
|
||||
{
|
||||
if (id == R.id.marker_set_position_button) {
|
||||
PingHelper helper = new PingHelper();
|
||||
try {
|
||||
MarkInfo mark = ((PositioningActivity)getActivity()).getMarkInfo();
|
||||
LeaderboardInfo leaderboard = ((PositioningActivity)getActivity()).getLeaderBoard();
|
||||
helper.storePingInDatabase(getActivity(), lastKnownLocation, mark);
|
||||
helper.sendPingToServer(getActivity(), lastKnownLocation, leaderboard, mark);
|
||||
if (lastKnownLocation != null) {
|
||||
MarkInfo mark = ((PositioningActivity) getActivity())
|
||||
.getMarkInfo();
|
||||
LeaderboardInfo leaderboard = ((PositioningActivity) getActivity())
|
||||
.getLeaderBoard();
|
||||
helper.storePingInDatabase(getActivity(),
|
||||
lastKnownLocation, mark);
|
||||
helper.sendPingToServer(getActivity(),
|
||||
lastKnownLocation, leaderboard, mark);
|
||||
pingListener.updatePing();
|
||||
setUpPingUI();
|
||||
}
|
||||
else{
|
||||
Toast.makeText(getActivity(), "Location is not available yet", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (GeneralDatabaseHelperException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if(id == R.id.marker_reset_position_button)
|
||||
{
|
||||
} else if (id == R.id.marker_reset_position_button) {
|
||||
// Reset position
|
||||
}
|
||||
|
||||
@@ -145,5 +161,4 @@ public class BuoyFragment extends BaseFragment implements LocationListener{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+1
@@ -194,6 +194,7 @@ public class CheckinManager {
|
||||
|
||||
private void saveCheckinDataAndNotifyListeners(URLData urlData, String leaderboardName) {
|
||||
CheckinData data = new CheckinData();
|
||||
data.serverWithPort = urlData.hostWithPort;
|
||||
data.leaderboardName = leaderboardName;
|
||||
data.marks = urlData.marks;
|
||||
data.deviceUid = urlData.deviceUuid
|
||||
|
||||
+15
@@ -47,6 +47,7 @@ public class DatabaseHelper {
|
||||
if (lc.moveToFirst()) {
|
||||
leaderboard.rowId = lc.getInt(lc.getColumnIndex(BaseColumns._ID));
|
||||
leaderboard.name = lc.getString(lc.getColumnIndex(Leaderboard.LEADERBOARD_NAME));
|
||||
leaderboard.serverUrl = lc.getString(lc.getColumnIndex(Leaderboard.LEADERBOARD_SERVER_URL));
|
||||
}
|
||||
|
||||
lc.close();
|
||||
@@ -158,6 +159,7 @@ public class DatabaseHelper {
|
||||
|
||||
ContentValues clv = new ContentValues();
|
||||
clv.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
|
||||
clv.put(Leaderboard.LEADERBOARD_SERVER_URL, leaderboard.serverUrl);
|
||||
clv.put(Leaderboard.LEADERBOARD_CHECKIN_DIGEST, leaderboard.checkinDigest);
|
||||
cr.insert(Leaderboard.CONTENT_URI, clv);
|
||||
|
||||
@@ -219,6 +221,19 @@ public class DatabaseHelper {
|
||||
|
||||
}
|
||||
|
||||
public boolean markLeaderboardCombnationAvailable(Context context, String checkinDigest) {
|
||||
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
String sel = "leaderboards.leaderboard_checkin_digest = \"" + checkinDigest;
|
||||
|
||||
Cursor cursor = cr.query(AnalyticsContract.Leaderboard.CONTENT_URI, null, sel, null, null);
|
||||
|
||||
int count = cursor.getCount();
|
||||
|
||||
cursor.close();
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
public class GeneralDatabaseHelperException extends Exception {
|
||||
private static final long serialVersionUID = 4333494334720305541L;
|
||||
|
||||
|
||||
+33
-6
@@ -1,25 +1,30 @@
|
||||
package com.sap.sailing.android.buoy.positioning.app.util;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.sap.sailing.android.buoy.positioning.app.util.DatabaseHelper.GeneralDatabaseHelperException;
|
||||
import com.sap.sailing.android.buoy.positioning.app.valueobjects.MarkInfo;
|
||||
import com.sap.sailing.android.buoy.positioning.app.valueobjects.MarkPingInfo;
|
||||
import com.sap.sailing.android.shared.data.LeaderboardInfo;
|
||||
import com.sap.sailing.android.shared.data.http.HttpJsonPostRequest;
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.services.sending.MessageSendingService;
|
||||
import com.sap.sailing.android.shared.util.NetworkHelper;
|
||||
import com.sap.sailing.android.shared.util.NetworkHelper.NetworkHelperError;
|
||||
import com.sap.sailing.android.shared.util.NetworkHelper.NetworkHelperSuccessListener;
|
||||
|
||||
public class PingHelper {
|
||||
private static String TAG = PingHelper.class.getName();
|
||||
|
||||
|
||||
public void sendPingToServer(Context context, Location location, LeaderboardInfo leaderBoard, MarkInfo mark) {
|
||||
public void sendPingToServer(final Context context, Location location, LeaderboardInfo leaderBoard, MarkInfo mark) {
|
||||
AppPreferences prefs = new AppPreferences(context);
|
||||
try {
|
||||
JSONObject fixJson = new JSONObject();
|
||||
@@ -29,17 +34,39 @@ public class PingHelper {
|
||||
fixJson.put("latitude", location.getLatitude());
|
||||
storePingInDatabase(context, location, mark);
|
||||
|
||||
String postUrlStr = "server"
|
||||
String postUrlStr = leaderBoard.serverUrl
|
||||
+ prefs.getServerMarkPingPath(leaderBoard.name, mark.getId());
|
||||
|
||||
context.startService(MessageSendingService.createMessageIntent(context,
|
||||
postUrlStr, null, UUID.randomUUID(), fixJson.toString(), null));
|
||||
HttpJsonPostRequest request = new HttpJsonPostRequest(new URL(postUrlStr),
|
||||
fixJson.toString(), context);
|
||||
NetworkHelper.getInstance(context)
|
||||
.executeHttpJsonRequestAsnchronously(request, new NetworkHelperSuccessListener() {
|
||||
|
||||
@Override
|
||||
public void performAction(JSONObject arg0) {
|
||||
Toast.makeText(context, "DATA SEND TO SERVER", Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
}, new NetworkHelper.NetworkHelperFailureListener() {
|
||||
|
||||
@Override
|
||||
public void performAction(NetworkHelperError arg0) {
|
||||
Toast.makeText(context, "FAILURE SERVER WAS NOT NOTIFIED", Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
});;
|
||||
|
||||
//context.startService(MessageSendingService.createMessageIntent(context,
|
||||
// postUrlStr, null, UUID.randomUUID(), fixJson.toString(), null));
|
||||
|
||||
} catch (JSONException ex) {
|
||||
ExLog.i(context, TAG,
|
||||
"Error while building ping json " + ex.getMessage());
|
||||
} catch (GeneralDatabaseHelperException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -14,6 +14,7 @@ public class CheckinData extends AbstractCheckinData{
|
||||
public String deviceUid;
|
||||
public String uriString;
|
||||
public String checkinDigest;
|
||||
public String serverWithPort;
|
||||
public List<MarkInfo> marks;
|
||||
|
||||
public void setCheckinDigestFromString(String checkinString)
|
||||
@@ -32,6 +33,7 @@ public class CheckinData extends AbstractCheckinData{
|
||||
LeaderboardInfo leaderboard = new LeaderboardInfo();
|
||||
leaderboard.name = leaderboardName;
|
||||
leaderboard.checkinDigest = checkinDigest;
|
||||
leaderboard.serverUrl = serverWithPort;
|
||||
return leaderboard;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user