small cleanups

This commit is contained in:
CiufudeanDani 2022-03-18 15:03:34 +02:00
parent 0fabbc73be
commit f554356af1
4 changed files with 62 additions and 75 deletions

View File

@ -198,12 +198,11 @@ public abstract class AbstractSDParentActivity extends TabActivity {
return res; return res;
} }
public boolean getHistoryPositions(int sc_id, long timeGMTStart, long timeGMTStop) public boolean getHistoryPositions(int sc_id, long timeGMTStart, long timeGMTStop) {
{
if(tcp == null) if(tcp == null)
return false; return false;
String histSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); String histSeqID = "1."+ (int) (System.currentTimeMillis() / 1000L);
boolean res = tcp.Write(histSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#"); boolean res = tcp.Write(histSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#");
if(res) if(res)
SM.Debug("Message [getHistoryPositions] sent to app server"); SM.Debug("Message [getHistoryPositions] sent to app server");
@ -213,8 +212,7 @@ public abstract class AbstractSDParentActivity extends TabActivity {
return res; return res;
} }
public boolean getRadiosList() public boolean getRadiosList() {
{
if(tcp == null) if(tcp == null)
return false; return false;

View File

@ -1,5 +1,6 @@
package com.safemobile.dispatch; package com.safemobile.dispatch;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
@ -9,8 +10,12 @@ import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.safemobile.lib.AppParams; import com.safemobile.lib.AppParams;
import com.safemobile.lib.SM; import com.safemobile.lib.SM;
import com.safemobile.lib.Vehicle; import com.safemobile.lib.Vehicle;
@ -21,7 +26,7 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
public class HistoryActivity extends AppCompatActivity { public class HistoryActivity extends AppCompatActivity implements OnMapReadyCallback {
public Bundle savedInstanceState; public Bundle savedInstanceState;
private TabLayoutActivity parentTab; private TabLayoutActivity parentTab;
@ -47,9 +52,10 @@ public class HistoryActivity extends AppCompatActivity {
Locale locale = new Locale(AppParams.LANGUAGETMP); Locale locale = new Locale(AppParams.LANGUAGETMP);
Locale.setDefault(locale); Locale.setDefault(locale);
googleMap = parentTab.liveActivity.getMap(); // googleMap = parentTab.liveActivity.getMap();
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map); .findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
spinnerVehicle = findViewById(R.id.spinnerVehicle); spinnerVehicle = findViewById(R.id.spinnerVehicle);
getVehicles(); getVehicles();
@ -78,7 +84,10 @@ public class HistoryActivity extends AppCompatActivity {
// return false; // return false;
// }); // });
parentTab.demoPositionsList();
setDate(); setDate();
// parentTab.HistPosList
} }
private void setDate() { private void setDate() {
@ -159,4 +168,16 @@ public class HistoryActivity extends AppCompatActivity {
public void UpdateNrPos(int size) { public void UpdateNrPos(int size) {
SM.Debug("Do Cancelwindow"); SM.Debug("Do Cancelwindow");
} }
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
this.googleMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
this.googleMap.addMarker(new MarkerOptions()
.position(sydney)
.title("Marker in Sydney"));
this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
} }

View File

@ -109,14 +109,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
/* Lists */ /* Lists */
public ArrayList<RadioGW> allRadios; public ArrayList<RadioGW> allRadios;
public volatile ArrayList<HistPos> HistPosList = new ArrayList<HistPos>(); public volatile ArrayList<HistPos> HistPosList = new ArrayList<>();
public volatile Boolean firstHistData = false; public volatile Boolean firstHistData = false;
public volatile Boolean dropAllData = false; public volatile Boolean dropAllData = false;
public volatile ArrayList<Boolean> HistMsgList = new ArrayList<Boolean>(); public volatile ArrayList<Boolean> HistMsgList = new ArrayList<>();
/* DEMO lists */ /* DEMO lists */
public ArrayList<SMS> listSMS; public ArrayList<SMS> listSMS;
public ArrayList<HistPos> demoPositions = new ArrayList<HistPos>(); public ArrayList<HistPos> demoPositions = new ArrayList<>();
/* Tab */ /* Tab */
private TabWidget tabWidget; private TabWidget tabWidget;
@ -737,33 +737,26 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
// hide buttons if safenet // hide buttons if safenet
if(AppParams.theme == AppParams.Theme.SAFENET) if (AppParams.theme == AppParams.Theme.SAFENET) {
{
buttonRadio.setVisibility(View.GONE); buttonRadio.setVisibility(View.GONE);
buttonRecordings.setVisibility(View.GONE); buttonRecordings.setVisibility(View.GONE);
} }
if(AppParams.DEMO && liveActivity != null) if (AppParams.DEMO && liveActivity != null) {
{
liveActivity.vehiclesReceived(getAllVehicle()); liveActivity.vehiclesReceived(getAllVehicle());
demoPositionsList(); demoPositionsList();
} }
if(!AppParams.DEMO) if (!AppParams.DEMO) {
{
//TCPinit();
//*
Timer t = new Timer(); Timer t = new Timer();
t.schedule(new TimerTask() { t.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
// init tcp // init tcp
TCPinit(); TCPinit();
} }
}, 100); }, 100);
//*/
} }
// Notification Click Filter // Notification Click Filter
@ -871,17 +864,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
} }
private void demoPositionsList() { public void demoPositionsList() {
AssetManager assetManager = res.getAssets(); AssetManager assetManager = res.getAssets();
SM.Debug("TRY 2 OPEN demo_positions.txt"); SM.Debug("TRY 2 OPEN demo_positions.txt");
InputStream input = null; InputStream input;
try { try {
input = assetManager.open("demo_positions.txt"); input = assetManager.open("demo_positions.txt");
InputStreamReader inputreader = new InputStreamReader(input); InputStreamReader inputreader = new InputStreamReader(input);
BufferedReader buffreader = new BufferedReader(inputreader); BufferedReader buffreader = new BufferedReader(inputreader);
String line = ""; String line;
while ((line = buffreader.readLine()) != null) while ((line = buffreader.readLine()) != null) {
{
String[] posi = line.split("#"); String[] posi = line.split("#");
HistPos gps = new HistPos(); HistPos gps = new HistPos();
gps.lat = Double.parseDouble(posi[1]); gps.lat = Double.parseDouble(posi[1]);
@ -892,7 +884,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
} }
HistPosmsg msg = new HistPosmsg(new TCPmsg(new char[]{})); HistPosmsg msg = new HistPosmsg(new TCPmsg(new char[]{}));
demoPositions = msg.CalcHeadingForArray(demoPositions); demoPositions = msg.CalcHeadingForArray(demoPositions);
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -1057,7 +1048,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
SM.Debug("########### UPDATE"); SM.Debug("########### UPDATE");
int sc_id = demoPosition%3 == 0 ? 101:102; int sc_id = demoPosition%3 == 0 ? 101:102;
((SuperVehicle) getSuperVehHash().get((long)sc_id)).SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed); getSuperVehHash().get((long)sc_id).SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed);
liveActivity.refreshMap(); liveActivity.refreshMap();
} }
} }
@ -1071,7 +1062,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
SM.Debug("########### UPDATE"); SM.Debug("########### UPDATE");
int sc_id = Integer.parseInt(getImei()); int sc_id = Integer.parseInt(getImei());
((SuperVehicle) getSuperVehHash().get((long)sc_id)).SetNewPosition(crtPos.lat + 0.0002, crtPos.lng + 0.0002, Calendar.getInstance().getTime().getTime(), crtPos.speed+2); getSuperVehHash().get((long)sc_id).SetNewPosition(crtPos.lat + 0.0002, crtPos.lng + 0.0002, Calendar.getInstance().getTime().getTime(), crtPos.speed+2);
setMess("Lat:" + String.format("%5f", crtPos.lat + 0.0002) + ", Lng:" + String.format("%5f", crtPos.lng + 0.0002)); setMess("Lat:" + String.format("%5f", crtPos.lat + 0.0002) + ", Lng:" + String.format("%5f", crtPos.lng + 0.0002));
liveActivity.refreshMap(); liveActivity.refreshMap();
} }
@ -1234,7 +1225,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
if (getSuperVehHash().get(GPSPos.gpsValue.imei) != null) { if (getSuperVehHash().get(GPSPos.gpsValue.imei) != null) {
getSuperVehHash().get(GPSPos.gpsValue.imei).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); getSuperVehHash().get(GPSPos.gpsValue.imei).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed);
// if (getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { // if (getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) {
//list for live //list for live
if (AppParams.crtTab == AppParams.Tabs.live) { if (AppParams.crtTab == AppParams.Tabs.live) {
@ -1505,7 +1496,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
SM.Debug("Got last pos"); SM.Debug("Got last pos");
LastPosmsg lastPos= new LastPosmsg(msg); LastPosmsg lastPos= new LastPosmsg(msg);
//SM.Debug("Got LastPost msg.data:" + msg.data);
for(LastPos posMsg: lastPos.PosList) { for(LastPos posMsg: lastPos.PosList) {
if(getSuperVehHash().get(posMsg.imei) != null) if(getSuperVehHash().get(posMsg.imei) != null)
getSuperVehHash().get(posMsg.imei).SetDataFromLastPos(posMsg.lat, posMsg.lng, posMsg.timeGMT, posMsg.speed, posMsg.Address, posMsg.isON); getSuperVehHash().get(posMsg.imei).SetDataFromLastPos(posMsg.lat, posMsg.lng, posMsg.timeGMT, posMsg.speed, posMsg.Address, posMsg.isON);
@ -1516,30 +1506,20 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
public void onHistoryPositionsCountReceived(TCPEvent event) { public void onHistoryPositionsCountReceived(TCPEvent event) {
TCPmsg msg= event.msg(); TCPmsg msg= event.msg();
SM.Debug("Got POS Count"); SM.Debug("Got POS Count");
//SM.Debug("Got lastpos :" + msg.allData);
HistCountmsg histcount= new HistCountmsg(msg); HistCountmsg histcount= new HistCountmsg(msg);
SM.Debug("Message Count:"+histcount.histcountValue.count); SM.Debug("Message Count:"+histcount.histcountValue.count);
//SM.Debug("Got LastPost msg.data:" + msg.data); if (histcount.histcountValue.count>=2000) {
if (histcount.histcountValue.count>=2000)
{
//list for live //list for live
if(AppParams.crtTab == AppParams.Tabs.history) if(AppParams.crtTab == AppParams.Tabs.history) {
{
//SM.Debug("+++++ duda +++++");
SM.Debug("currentActivity instanceof HistoryActivity"); SM.Debug("currentActivity instanceof HistoryActivity");
try try {
{ if(historyActivity != null) {
if(historyActivity != null)
{
historyActivity.UpdateCancel(); historyActivity.UpdateCancel();
historyActivity.UpdateUnableDisp(); historyActivity.UpdateUnableDisp();
} }
//dialogLoading.cancel(); } catch (Exception ex) {
} SM.Debug("Error load hash:"+ ex);
catch (Exception ex)
{
SM.Debug("Error load hash:"+ex.toString());
} }
} }
} }
@ -1553,7 +1533,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
HistPosmsg tmpHist= new HistPosmsg(msg); HistPosmsg tmpHist= new HistPosmsg(msg);
Boolean SendDataToMap =true; Boolean SendDataToMap =true;
try{ try{
for (HistPos obj : tmpHist.PosList) for (HistPos obj : tmpHist.PosList)
HistPosList.add(obj); HistPosList.add(obj);
@ -1561,25 +1540,18 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
// //
int pos = Integer.parseInt(tmpHist.seqID.substring(0,tmpHist.seqID.indexOf('.'))); int pos = Integer.parseInt(tmpHist.seqID.substring(0,tmpHist.seqID.indexOf('.')));
int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.')+1,tmpHist.seqID.length())); int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.')+1,tmpHist.seqID.length()));
if (all!=0) if (all!=0) {
{ if (firstHistData) {
if (firstHistData) try {
{
try
{
for(int i=0;i<all;i++) for(int i=0;i<all;i++)
HistMsgList.add(false); HistMsgList.add(false);
} } catch (Exception e) {
catch (Exception e)
{
SM.Debug("Error on init hashTable:"+e.toString()); SM.Debug("Error on init hashTable:"+e.toString());
} }
firstHistData =false; firstHistData =false;
} }
HistMsgList.set(pos-1, true); HistMsgList.set(pos-1, true);
//for(int i=0;i<(all);i++)
// SM.Debug("i:"+i+" value:"+HistMsgList.get(i));
for(int i=0;i<(all);i++) for(int i=0;i<(all);i++)
{ {
if (!HistMsgList.get(i)) if (!HistMsgList.get(i))
@ -1593,20 +1565,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
} }
catch (Exception e) catch (Exception e)
{ {
SM.Debug("Error on parse:"+e.toString()); SM.Debug("Error on parse: "+ e);
} }
if (SendDataToMap) if (SendDataToMap) {
{ Collections.sort(HistPosList, (Comparator<Object>) (o1, o2) -> {
Collections.sort(HistPosList, new Comparator<Object>() HistPos p1 = (HistPos) o1;
{ HistPos p2 = (HistPos) o2;
public int compare(Object o1, Object o2) { if (p1.timeGMT<p2.timeGMT) return -1;
HistPos p1 = (HistPos) o1; else if (p1.timeGMT==p2.timeGMT) return 0;
HistPos p2 = (HistPos) o2; else return 1;
if (p1.timeGMT<p2.timeGMT) return -1; });
else if (p1.timeGMT==p2.timeGMT) return 0;
else return 1;
}
});
//list for live //list for live
if(AppParams.crtTab == AppParams.Tabs.history) if(AppParams.crtTab == AppParams.Tabs.history)
@ -1623,7 +1591,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
Thread.sleep(101); Thread.sleep(101);
if (HistPosList.size()<2000) if (HistPosList.size()<2000)
{ {
if ((HistPosList.size()==1) && (((HistPos)(HistPosList.get(0))).timeGMT==0)) if ((HistPosList.size()==1) && (HistPosList.get(0).timeGMT==0))
;// do nothing is not data message ;// do nothing is not data message
else else
historyActivity.UpdateNrPos(HistPosList.size()); historyActivity.UpdateNrPos(HistPosList.size());
@ -1634,7 +1602,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{
else else
historyActivity.UpdateUnableDisp(); // update with more than 200 points historyActivity.UpdateUnableDisp(); // update with more than 200 points
} }
//((HistoryActivity)currentActivity).UpdateMap(HistPosList.size());
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -284,14 +284,15 @@
</LinearLayout> </LinearLayout>
<fragment <fragment
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:id="@+id/map" android:id="@+id/map"
android:layout_toRightOf="@id/slidelayout" android:layout_toRightOf="@id/slidelayout"
android:layout_weight="1" android:layout_weight="1"
tools:context=".HistoryActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" /> android:name="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/changeMapType" android:id="@+id/changeMapType"