From f554356af177d0c25bbebbba4266ce4ba54c2b89 Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Fri, 18 Mar 2022 15:03:34 +0200 Subject: [PATCH] small cleanups --- .../activities/AbstractSDParentActivity.java | 8 +- .../safemobile/dispatch/HistoryActivity.java | 25 ++++- .../dispatch/TabLayoutActivity.java | 101 ++++++------------ .../src/main/res/layout/tabhistory.xml | 3 +- 4 files changed, 62 insertions(+), 75 deletions(-) diff --git a/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java b/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java index 1564341..77f0876 100644 --- a/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java +++ b/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java @@ -198,12 +198,11 @@ public abstract class AbstractSDParentActivity extends TabActivity { 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) 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+"#"); if(res) SM.Debug("Message [getHistoryPositions] sent to app server"); @@ -213,8 +212,7 @@ public abstract class AbstractSDParentActivity extends TabActivity { return res; } - public boolean getRadiosList() - { + public boolean getRadiosList() { if(tcp == null) return false; diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index eaa171c..e728a2c 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -1,5 +1,6 @@ package com.safemobile.dispatch; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; @@ -9,8 +10,12 @@ import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; +import com.google.android.gms.maps.CameraUpdateFactory; 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.model.LatLng; +import com.google.android.gms.maps.model.MarkerOptions; import com.safemobile.lib.AppParams; import com.safemobile.lib.SM; import com.safemobile.lib.Vehicle; @@ -21,7 +26,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; -public class HistoryActivity extends AppCompatActivity { +public class HistoryActivity extends AppCompatActivity implements OnMapReadyCallback { public Bundle savedInstanceState; private TabLayoutActivity parentTab; @@ -47,9 +52,10 @@ public class HistoryActivity extends AppCompatActivity { Locale locale = new Locale(AppParams.LANGUAGETMP); Locale.setDefault(locale); - googleMap = parentTab.liveActivity.getMap(); +// googleMap = parentTab.liveActivity.getMap(); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); + mapFragment.getMapAsync(this); spinnerVehicle = findViewById(R.id.spinnerVehicle); getVehicles(); @@ -78,7 +84,10 @@ public class HistoryActivity extends AppCompatActivity { // return false; // }); + parentTab.demoPositionsList(); setDate(); + +// parentTab.HistPosList } private void setDate() { @@ -159,4 +168,16 @@ public class HistoryActivity extends AppCompatActivity { public void UpdateNrPos(int size) { 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)); + } } \ No newline at end of file diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java index 255e34d..2d6ef54 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -109,14 +109,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ /* Lists */ public ArrayList allRadios; - public volatile ArrayList HistPosList = new ArrayList(); + public volatile ArrayList HistPosList = new ArrayList<>(); public volatile Boolean firstHistData = false; public volatile Boolean dropAllData = false; - public volatile ArrayList HistMsgList = new ArrayList(); + public volatile ArrayList HistMsgList = new ArrayList<>(); /* DEMO lists */ public ArrayList listSMS; - public ArrayList demoPositions = new ArrayList(); + public ArrayList demoPositions = new ArrayList<>(); /* Tab */ private TabWidget tabWidget; @@ -737,33 +737,26 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // hide buttons if safenet - if(AppParams.theme == AppParams.Theme.SAFENET) - { + if (AppParams.theme == AppParams.Theme.SAFENET) { buttonRadio.setVisibility(View.GONE); buttonRecordings.setVisibility(View.GONE); } - if(AppParams.DEMO && liveActivity != null) - { + if (AppParams.DEMO && liveActivity != null) { liveActivity.vehiclesReceived(getAllVehicle()); demoPositionsList(); } - if(!AppParams.DEMO) - { - //TCPinit(); - //* + if (!AppParams.DEMO) { Timer t = new Timer(); t.schedule(new TimerTask() { - @Override public void run() { // init tcp TCPinit(); } }, 100); - //*/ } // Notification Click Filter @@ -871,17 +864,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } - private void demoPositionsList() { + public void demoPositionsList() { AssetManager assetManager = res.getAssets(); SM.Debug("TRY 2 OPEN demo_positions.txt"); - InputStream input = null; + InputStream input; try { input = assetManager.open("demo_positions.txt"); InputStreamReader inputreader = new InputStreamReader(input); BufferedReader buffreader = new BufferedReader(inputreader); - String line = ""; - while ((line = buffreader.readLine()) != null) - { + String line; + while ((line = buffreader.readLine()) != null) { String[] posi = line.split("#"); HistPos gps = new HistPos(); gps.lat = Double.parseDouble(posi[1]); @@ -892,7 +884,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } HistPosmsg msg = new HistPosmsg(new TCPmsg(new char[]{})); demoPositions = msg.CalcHeadingForArray(demoPositions); - } catch (IOException e1) { e1.printStackTrace(); } @@ -1057,7 +1048,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("########### UPDATE"); 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(); } } @@ -1071,7 +1062,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("########### UPDATE"); 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)); liveActivity.refreshMap(); } @@ -1234,7 +1225,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ 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); - + // if (getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { //list for live if (AppParams.crtTab == AppParams.Tabs.live) { @@ -1505,7 +1496,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("Got last pos"); LastPosmsg lastPos= new LastPosmsg(msg); - //SM.Debug("Got LastPost msg.data:" + msg.data); for(LastPos posMsg: lastPos.PosList) { if(getSuperVehHash().get(posMsg.imei) != null) 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) { TCPmsg msg= event.msg(); SM.Debug("Got POS Count"); - //SM.Debug("Got lastpos :" + msg.allData); - + HistCountmsg histcount= new HistCountmsg(msg); 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 - if(AppParams.crtTab == AppParams.Tabs.history) - { - //SM.Debug("+++++ duda +++++"); + if(AppParams.crtTab == AppParams.Tabs.history) { SM.Debug("currentActivity instanceof HistoryActivity"); - try - { - if(historyActivity != null) - { + try { + if(historyActivity != null) { historyActivity.UpdateCancel(); historyActivity.UpdateUnableDisp(); } - //dialogLoading.cancel(); - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); + } catch (Exception ex) { + SM.Debug("Error load hash:"+ ex); } } } @@ -1553,7 +1533,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ HistPosmsg tmpHist= new HistPosmsg(msg); Boolean SendDataToMap =true; try{ - for (HistPos obj : tmpHist.PosList) HistPosList.add(obj); @@ -1561,25 +1540,18 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // 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())); - if (all!=0) - { - if (firstHistData) - { - try - { + if (all!=0) { + if (firstHistData) { + try { for(int i=0;i() - { - public int compare(Object o1, Object o2) { - HistPos p1 = (HistPos) o1; - HistPos p2 = (HistPos) o2; - if (p1.timeGMT) (o1, o2) -> { + HistPos p1 = (HistPos) o1; + HistPos p2 = (HistPos) o2; + if (p1.timeGMT -