Skip to content

Commit a1343a6

Browse files
committed
code cleanup
1 parent 6ee06d5 commit a1343a6

File tree

4 files changed

+52
-195
lines changed

4 files changed

+52
-195
lines changed

EGM/app/src/main/java/eatgreedi/mobile/com/egm/LocationService.java

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ private void startTracking() {
9797

9898
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
9999
// TODO recheck this
100-
// mLocationClient = new LocationClient(this,this,this);
101-
102100
if (!mLocationClient.isConnected() || !mLocationClient.isConnecting()) {
103101
mLocationClient.connect();
104102
}
@@ -108,90 +106,10 @@ private void startTracking() {
108106
}
109107

110108
protected void sendLocationDataToWebsite(Location location) {
111-
// formatted for mysql datetime format
112-
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
113-
dateFormat.setTimeZone(TimeZone.getDefault());
114-
Date date = new Date(location.getTime());
115-
116-
SharedPreferences sharedPreferences = this.getSharedPreferences("com.websmithing.gpstracker.prefs", Context.MODE_PRIVATE);
117-
SharedPreferences.Editor editor = sharedPreferences.edit();
118-
119-
float totalDistanceInMeters = sharedPreferences.getFloat("totalDistanceInMeters", 0f);
120-
121-
boolean firstTimeGettingPosition = sharedPreferences.getBoolean("firstTimeGettingPosition", true);
122-
123-
if (firstTimeGettingPosition) {
124-
editor.putBoolean("firstTimeGettingPosition", false);
125-
} else {
126-
Location previousLocation = new Location("");
127-
previousLocation.setLatitude(sharedPreferences.getFloat("previousLatitude", 0f));
128-
previousLocation.setLongitude(sharedPreferences.getFloat("previousLongitude", 0f));
129-
130-
float distance = location.distanceTo(previousLocation);
131-
totalDistanceInMeters += distance;
132-
editor.putFloat("totalDistanceInMeters", totalDistanceInMeters);
133-
}
134-
135-
editor.putFloat("previousLatitude", (float)location.getLatitude());
136-
editor.putFloat("previousLongitude", (float)location.getLongitude());
137-
editor.apply();
138-
139109

140110
Log.i(TAG,"sending location to server");
141111
mSocket.emit("updatelocation",Double.toString(location.getLatitude()));
142112
// TODO use the following requestParams to create a JSON payload
143-
/* final RequestParams requestParams = new RequestParams();
144-
requestParams.put("latitude", Double.toString(location.getLatitude()));
145-
requestParams.put("longitude", Double.toString(location.getLongitude()));
146-
147-
Double speedInMilesPerHour = location.getSpeed()* 2.2369;
148-
requestParams.put("speed", Integer.toString(speedInMilesPerHour.intValue()));
149-
150-
try {
151-
requestParams.put("date", URLEncoder.encode(dateFormat.format(date), "UTF-8"));
152-
} catch (UnsupportedEncodingException e) {}
153-
154-
requestParams.put("locationmethod", location.getProvider());
155-
156-
if (totalDistanceInMeters > 0) {
157-
requestParams.put("distance", String.format("%.1f", totalDistanceInMeters / 1609)); // in miles,
158-
} else {
159-
requestParams.put("distance", "0.0"); // in miles
160-
}
161-
162-
requestParams.put("username", sharedPreferences.getString("userName", ""));
163-
requestParams.put("phonenumber", sharedPreferences.getString("appID", "")); // uuid
164-
requestParams.put("sessionid", sharedPreferences.getString("sessionID", "")); // uuid
165-
166-
Double accuracyInFeet = location.getAccuracy()* 3.28;
167-
requestParams.put("accuracy", Integer.toString(accuracyInFeet.intValue()));
168-
169-
Double altitudeInFeet = location.getAltitude() * 3.28;
170-
requestParams.put("extrainfo", Integer.toString(altitudeInFeet.intValue()));
171-
172-
requestParams.put("eventtype", "android");
173-
174-
Float direction = location.getBearing();
175-
requestParams.put("direction", Integer.toString(direction.intValue()));*/
176-
177-
//final String uploadWebsite = sharedPreferences.getString("defaultUploadWebsite", defaultUploadWebsite);
178-
179-
/* TODO create a JSON payload of username, locationdata
180-
Emit the Payload
181-
*/
182-
183-
/*LoopjHttpClient.get(uploadWebsite, requestParams, new AsyncHttpResponseHandler() {
184-
@Override
185-
public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) {
186-
LoopjHttpClient.debugLoopJ(TAG, "sendLocationDataToWebsite - success", uploadWebsite, requestParams, responseBody, headers, statusCode, null);
187-
stopSelf();
188-
}
189-
@Override
190-
public void onFailure(int statusCode, org.apache.http.Header[] headers, byte[] errorResponse, Throwable e) {
191-
LoopjHttpClient.debugLoopJ(TAG, "sendLocationDataToWebsite - failure", uploadWebsite, requestParams, errorResponse, headers, statusCode, e);
192-
stopSelf();
193-
}
194-
});*/
195113
}
196114

197115
@Override
@@ -210,11 +128,7 @@ public void onLocationChanged(Location location) {
210128
if (location != null) {
211129
Log.e(TAG, "position: " + location.getLatitude() + ", " + location.getLongitude() + " accuracy: " + location.getAccuracy());
212130

213-
// we have our desired accuracy of 500 meters so lets quit this service,
214-
// onDestroy will be called and stop our location uodates
215131
if (location.getAccuracy() < 500.0f) {
216-
// TODO no need to stop location updates in our case
217-
// stopLocationUpdates();
218132
sendLocationDataToWebsite(location);
219133
}
220134
}
@@ -238,26 +152,20 @@ public void onConnected(Bundle bundle) {
238152
Log.d(TAG, "onConnected");
239153

240154
mLocationRequest = LocationRequest.create();
241-
mLocationRequest.setInterval(1000); // milliseconds
242-
mLocationRequest.setFastestInterval(1000); // the fastest rate in milliseconds at which your app can handle location updates
155+
mLocationRequest.setInterval(5000); // milliseconds
243156
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
244157

245-
//mLocationClient.requestLocationUpdates(mLocationRequest, this);
246158
LocationServices.FusedLocationApi.requestLocationUpdates(mLocationClient, mLocationRequest, this);
247159

248160
// connect to socket for upload
249161
mSocket.connect();
250-
251162
}
252163

253164
/**
254165
* Called by Location Services if the connection to the
255166
* location client drops because of an error.
256167
*/
257168

258-
/*
259-
* TODO a good idea would be to try to restart/reconnect the service using alarm manager
260-
*/
261169
@Override
262170
public void onConnectionSuspended(int i) {
263171
Log.e(TAG, "onDisconnected");
@@ -294,11 +202,6 @@ public void call(Object... args) {
294202
new Handler(Looper.getMainLooper()).post(new Runnable() {
295203
@Override
296204
public void run() {
297-
/*
298-
Intent notifyIntent = new Intent("eatgreedi.mobile.com.egm.NotifyUser");
299-
notifyIntent.putExtra("message","some message");
300-
sendBroadcast(notifyIntent);
301-
*/
302205
Toast.makeText(getApplicationContext(),
303206
"Some Message Received", Toast.LENGTH_LONG).show();
304207

EGM/app/src/main/java/eatgreedi/mobile/com/egm/MainActivity.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ public void onClick(DialogInterface dialog, int id) {
143143
userInput.setError("Try again. 1 word only");
144144
}
145145
});
146-
/*.setNegativeButton("Cancel",
147-
new DialogInterface.OnClickListener() {
148-
public void onClick(DialogInterface dialog, int id) {
149-
dialog.cancel();
150-
}
151-
});*/
152146

153147
// create alert dialog
154148
AlertDialog alertDialog = alertDialogBuilder.create();
@@ -250,11 +244,6 @@ public void call(Object... args) {
250244
new Handler(Looper.getMainLooper()).post(new Runnable() {
251245
@Override
252246
public void run() {
253-
/*
254-
Intent notifyIntent = new Intent("eatgreedi.mobile.com.egm.NotifyUser");
255-
notifyIntent.putExtra("message","some message");
256-
sendBroadcast(notifyIntent);
257-
*/
258247
Toast.makeText(getApplicationContext(),
259248
"Some Message Received in main", Toast.LENGTH_LONG).show();
260249
}

node-socket-server/public/index.html

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title>Node Cellar</title>
5+
<title>DashBoard</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta name="description" content="">
88
<meta name="author" content="">
@@ -35,7 +35,7 @@
3535
<div class="navbar navbar-fixed-top" style="z-index: 10;">
3636
<div class="navbar-inner">
3737
<div class="container">
38-
<a class="brand" href="#">Real Time Analytics</a>
38+
<a class="brand" href="#">Dashboard</a>
3939
</div>
4040
</div>
4141
</div>
@@ -56,19 +56,19 @@ <h5>active users</h5>
5656

5757
<div class="span9">
5858

59-
<legend>Real Time Activity</legend>
59+
<legend>Real Time Location Updates</legend>
6060
<div class="row-fluid">
61-
<table id="visits" class="table table-bordered table-striped table-condensed">
61+
<table id="userUpdates" class="table table-bordered table-striped table-condensed">
6262
<thead>
63-
<tr><td>Username</td><td>latitude</td><td>longitude</td><td>timestamp</td></tr>
63+
<tr><td>Username</td><td>Latitude</td><td>Longitude</td><td>Timestamp</td></tr>
6464
</thead>
6565
<tbody></tbody>
6666
</table>
6767
</div>
6868

69-
<legend>user status</legend>
69+
<legend>User Status</legend>
7070
<div class="row-fluid">
71-
<table id="pageViews" class="table table-bordered table-striped table-condensed">
71+
<table id="clientUsers" class="table table-bordered table-striped table-condensed">
7272
<thead>
7373
<tr><td>username</td><td>status</td></tr>
7474
</thead>
@@ -85,15 +85,10 @@ <h5>active users</h5>
8585
<script type="text/javascript" src="lib/jquery-1.8.2.min.js"></script>
8686

8787
<script>
88-
//var io = require('socket.io');
89-
var SERVER_URL = "http://192.168.0.9:8100/admin";
90-
//var io = io('/admin');
91-
var socket = io(SERVER_URL);
9288
// connect to the admin namespaces
93-
//socket = socket.of('/admin');
89+
var SERVER_URL = "http://192.168.0.9:8100/admin";
90+
var socket = io(SERVER_URL);
9491
var clients = {};
95-
var pages = {};
96-
var lastPageId = 0;
9792

9893
socket.on('connect', function () {
9994
var totalconnections = 0;
@@ -106,7 +101,7 @@ <h5>active users</h5>
106101
for(var key in data){
107102
var uname = data[key];
108103
clients[uname] = {username: uname, status : 'Active'};
109-
$('#pageViews tbody').append('<tr id = '+ uname +'><td>' + uname + '</td><td id="page Active"> Active </td><td><button type= "button" class="notifyuser">Notify</button></td></tr>');
104+
$('#clientUsers tbody').append('<tr id = '+ uname +'><td>' + uname + '</td><td id="page Active"> Active </td><td><button type= "button" class="notifyuser">Notify</button></td></tr>');
110105
}
111106
});
112107

@@ -122,7 +117,7 @@ <h5>active users</h5>
122117
clients[msg.username].status = msg.status;
123118
} else {
124119
clients[msg.username] = {username: msg.username, status : msg.status};
125-
$('#pageViews tbody').append('<tr id = '+msg.username+'><td>' + msg.username + '</td><td id="page ' + msg.status + '">'+msg.status+'</td><td><button type= "button" class="notifyuser">Notify</button></td></tr>');
120+
$('#clientUsers tbody').append('<tr id = '+msg.username+'><td>' + msg.username + '</td><td id="page ' + msg.status + '">'+msg.status+'</td><td><button type= "button" class="notifyuser">Notify</button></td></tr>');
126121
}
127122
}
128123
});
@@ -132,27 +127,25 @@ <h5>active users</h5>
132127
socket.on('updatelocation', function (msg) {
133128
console.log('admin page, location update');
134129
if (msg.username) {
135-
if ($('#visits tr').length > 10) {
136-
$('#visits tr:last').remove();
130+
if ($('#userUpdates tr').length > 10) {
131+
$('#userUpdates tr:last').remove();
137132
}
138133
console.log("add row to locatios");
139-
$('#visits tbody').prepend('<tr><td>' + msg.username + '</td><td>' + msg.latitude + '</td><td>' + msg.longitude + '</td><td>' + msg.timestamp + '</td></tr>');
134+
$('#userUpdates tbody').prepend('<tr><td>' + msg.username + '</td><td>' + msg.latitude + '</td><td>' + msg.longitude + '</td><td>' + msg.timestamp + '</td></tr>');
140135
}
141136
});
142137

143138
socket.on('disconnect', function () {
144139
//$('#connections').html(totalconnections-1);
140+
145141
});
146142
});
147-
$('.notifyuser').click(function(){
148-
149-
});
150143

151-
$("#pageViews").on('click', '.notifyuser', function() {
152-
var username = $(this).closest("tr").attr('id');
153-
console.log('notifying user ' + username);
154-
socket.emit('notifyuser',username);
155-
});
144+
$("#clientUsers").on('click', '.notifyuser', function() {
145+
var username = $(this).closest("tr").attr('id');
146+
console.log('notifying user ' + username);
147+
socket.emit('notifyuser',username);
148+
});
156149

157150

158151
</script>

0 commit comments

Comments
 (0)