Compare commits
8 Commits
2a1517526d
...
convert_to
Author | SHA1 | Date | |
---|---|---|---|
4b09464638 | |||
a9732e5a52 | |||
31d6b0027f | |||
5c8b857664 | |||
8b89319d09 | |||
b17ba94950 | |||
6fda464ed8 | |||
8cc6dfceca |
3
.gitignore
vendored
3
.gitignore
vendored
@ -184,3 +184,6 @@ $RECYCLE.BIN/
|
||||
/.idea/misc.xml
|
||||
/.idea
|
||||
/.idea/modules.xml
|
||||
|
||||
/safeDispatch/debug
|
||||
/safeDispatch/release
|
||||
|
@ -102,10 +102,8 @@ public class TCPService extends Service {
|
||||
|
||||
|
||||
/** Stop TCP Connection */
|
||||
public void stopTCPConnection()
|
||||
{
|
||||
if(tcp != null)
|
||||
{
|
||||
public void stopTCPConnection() {
|
||||
if(tcp != null) {
|
||||
tcp.Stop();
|
||||
tcp = null;
|
||||
}
|
||||
@ -114,27 +112,7 @@ public class TCPService extends Service {
|
||||
/** restart the TCP Connection after the connection parameters had been changed */
|
||||
public void recreateTCPConnection()
|
||||
{
|
||||
/*
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000*2);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*/
|
||||
// create a tcp connection
|
||||
int port = 13589;
|
||||
try {
|
||||
port = Integer.parseInt(AppParams.PORT);
|
||||
}
|
||||
catch(Exception ex) { }
|
||||
tcp = new TCPhandler(getApplicationContext(), AppParams.IP, port);
|
||||
/* }
|
||||
});
|
||||
t.start();
|
||||
*/
|
||||
recreateTCPConnection(AppParams.IP, AppParams.PORT);
|
||||
}
|
||||
|
||||
public void recreateTCPConnection(String _ip, String _port)
|
||||
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.safemobile.safedispatch",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 8000091,
|
||||
"versionName": "8.0.91",
|
||||
"outputFile": "SafeDispatchMobile_v.8.0.91-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
@ -90,28 +91,38 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
|
||||
boolean isMilitaryTime = false;
|
||||
Date positionTime;
|
||||
long timeGMT = 0;
|
||||
String speed, address, gpsLocation, name = "";
|
||||
if (isLiveTab) {
|
||||
SuperVehicle vehicle = superVehHash.get(key);
|
||||
positionTime = new Date((new Date()).getTime() - vehicle.timeGMT);
|
||||
|
||||
//positionTime = new Date((new Date()).getTime() - vehicle.timeGMT);
|
||||
|
||||
timeGMT = vehicle.timeGMT;
|
||||
address = vehicle.Address != null ? vehicle.Address : "";
|
||||
name = vehicle.name;
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), vehicle.speed);
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), (int)(0.621371192 * vehicle.speed));
|
||||
gpsLocation = "[" + String.format("%.4f", vehicle.lat) + "," + String.format("%.4f",vehicle.lng) + "]";
|
||||
} else {
|
||||
HistPos histPos = histPosList.get(position);
|
||||
positionTime = new Date((new Date()).getTime() - histPos.timeGMT);
|
||||
|
||||
//positionTime = new Date((new Date()).getTime() - histPos.timeGMT);
|
||||
timeGMT = histPos.timeGMT;
|
||||
address = histPos.Address != null ? histPos.Address : "";
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), histPos.speed);
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), (int)(0.621371192 * histPos.speed));
|
||||
gpsLocation = "[" + String.format("%.4f", histPos.lat) + "," + String.format("%.4f",histPos.lng) + "]";
|
||||
}
|
||||
|
||||
String timeFormat = isMilitaryTime
|
||||
? "HH:mm:ss dd.MMM.yyyy"
|
||||
: "hh:mm:ss a dd.MMM.yyy";
|
||||
//String timeFormat = isMilitaryTime
|
||||
// ? "HH:mm:ss dd.MMM.yyyy"
|
||||
// : "hh:mm:ss a dd.MMM.yyy";
|
||||
|
||||
//DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
|
||||
//tvTimeAgo.setText(format.format(positionTime));
|
||||
|
||||
DateFormat format = new SimpleDateFormat("hh:mm:ss", Locale.ENGLISH);
|
||||
tvTimeAgo.setText( getDateTimeAgo(timeGMT * 1000) + " [" + format.format(new Date(timeGMT*1000) ) + "]");
|
||||
|
||||
DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
|
||||
tvTimeAgo.setText(format.format(positionTime));
|
||||
tvStreetView.setText(address);
|
||||
streetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
|
||||
tvStreetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
|
||||
@ -123,5 +134,38 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
tvSpeed.setText(speed);
|
||||
tvGPSLocation.setText(gpsLocation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a text representation for the date time representing
|
||||
/// the difference in minutes/hours/days from now
|
||||
/// </summary>
|
||||
/// <param name="utcTime">DateTime value which needs to be converted</param>
|
||||
/// <returns>String 'Ago' representation fot he date</returns>
|
||||
public static String getDateTimeAgo(long time)
|
||||
{
|
||||
String timeValue = "";
|
||||
|
||||
long diffInMs = (new Date().getTime() - time);
|
||||
|
||||
long secondsDifference = TimeUnit.MILLISECONDS.toSeconds(diffInMs);;
|
||||
|
||||
if (secondsDifference < 60)
|
||||
timeValue = "less than 1 minute";
|
||||
else if (secondsDifference < 3600)
|
||||
timeValue = (secondsDifference / 60) + " minute" + ((secondsDifference / 60) > 1 ? "s" : "") + " ago";
|
||||
else if (secondsDifference < 7200)
|
||||
timeValue = "1 hour ago";
|
||||
else if (secondsDifference < 86400)
|
||||
{
|
||||
timeValue = (secondsDifference / 3600) + " hours ago";
|
||||
}
|
||||
else
|
||||
{
|
||||
timeValue = (secondsDifference / 86400) + " days ago";
|
||||
}
|
||||
|
||||
return timeValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -74,6 +74,9 @@ import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
@ -571,7 +574,58 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
|
||||
/* Create Service and bind to it */
|
||||
getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
|
||||
|
||||
ConnectivityManager connectivityManager =
|
||||
(ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
connectivityManager.registerDefaultNetworkCallback(networkCallback);
|
||||
else {
|
||||
NetworkRequest request = new NetworkRequest.Builder()
|
||||
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
|
||||
connectivityManager.registerNetworkCallback(request, networkCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
|
||||
@Override
|
||||
public void onAvailable(Network network) {
|
||||
// network available
|
||||
Log.v(TAG, "network available");
|
||||
Log.v(TAG, "tcp: " + (tcp != null));
|
||||
|
||||
if (tcp != null) {
|
||||
if (tcp.isConnectionUP)
|
||||
tcp.isConnectionUP = false;
|
||||
|
||||
uiHandler.post(() -> {
|
||||
Log.v(TAG, "myService: " + (myService != null));
|
||||
if (myService != null) {
|
||||
myService.stopTCPConnection();
|
||||
myService.recreateTCPConnection();
|
||||
|
||||
getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
if (getRadioActivity() != null)
|
||||
getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
|
||||
if (getMessageActivity() != null)
|
||||
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
||||
if (getRecordingsActivity() != null)
|
||||
getRecordingsActivity().onCreate(getRecordingsActivity().getSavedInstanceState());
|
||||
if (getAlarmActivity() != null)
|
||||
getAlarmActivity().onCreate(getAlarmActivity().getSavedInstanceState());
|
||||
|
||||
uiHandler.post(initTCPRUN);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLost(Network network) {
|
||||
// network unavailable
|
||||
Log.v(TAG, "network unavailable");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Broadcast Received for notifications
|
||||
@ -755,7 +809,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
if (getHistoryActivity() != null)
|
||||
getHistoryActivity().setLanguage();
|
||||
if (getRadioActivity() != null)
|
||||
getRadioActivity().onCreate(getRadioActivity().savedInstanceState);
|
||||
getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
|
||||
if (getMessageActivity() != null)
|
||||
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
||||
if (getRecordingsActivity() != null)
|
||||
@ -2074,7 +2128,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
|
||||
getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
if (getRadioActivity() != null)
|
||||
getRadioActivity().onCreate(getRadioActivity().savedInstanceState);
|
||||
getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
|
||||
if (getMessageActivity() != null)
|
||||
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
|
||||
if (getRecordingsActivity() != null)
|
||||
@ -2098,7 +2152,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
// whenBackPressed(AppParams.ActivityResult.tcpDown);
|
||||
|
||||
// send a broadcast
|
||||
notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + "");
|
||||
// notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2300,7 +2354,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
// cancel old notification
|
||||
mNotificationManager.cancel(icon);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
PendingIntent pendingIntent;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE);
|
||||
|
||||
}else {
|
||||
pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
createNotificationChannel(icon, contentTitle, contentText, pendingIntent);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user