From 0fabbc73befee0b71d66626bb4b8399982e974ed Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Thu, 17 Mar 2022 15:13:25 +0200 Subject: [PATCH 01/11] comment line in order to move vehicle --- .../java/com/safemobile/dispatch/TabLayoutActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java index ac25ba6..255e34d 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -1234,8 +1234,8 @@ 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) { + +// if (getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { //list for live if (AppParams.crtTab == AppParams.Tabs.live) { //SM.Debug("+++++ duda +++++"); @@ -1247,7 +1247,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("Error load hash:"+ex.toString()); } } - } +// } } } From f554356af177d0c25bbebbba4266ce4ba54c2b89 Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Fri, 18 Mar 2022 15:03:34 +0200 Subject: [PATCH 02/11] 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 - Date: Fri, 18 Mar 2022 15:22:35 +0200 Subject: [PATCH 03/11] display test positions --- .../safemobile/dispatch/HistoryActivity.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index e728a2c..331c3db 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -2,7 +2,6 @@ package com.safemobile.dispatch; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ImageView; @@ -14,9 +13,14 @@ 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.BitmapDescriptor; +import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; +import com.google.android.gms.maps.model.Polyline; +import com.google.android.gms.maps.model.PolylineOptions; import com.safemobile.lib.AppParams; +import com.safemobile.lib.HistPos; import com.safemobile.lib.SM; import com.safemobile.lib.Vehicle; @@ -52,7 +56,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall Locale locale = new Locale(AppParams.LANGUAGETMP); Locale.setDefault(locale); -// googleMap = parentTab.liveActivity.getMap(); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); @@ -84,10 +87,25 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall // return false; // }); - parentTab.demoPositionsList(); setDate(); + } -// parentTab.HistPosList + private void displayHistory(ArrayList demoPositions) { + LatLng latLng = new LatLng(demoPositions.get(0).lat, demoPositions.get(0).lng); + PolylineOptions polylineOptions = new PolylineOptions(); + BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.bus); + + for (HistPos pos : demoPositions) { + latLng = new LatLng(pos.lat, pos.lng); + polylineOptions.add(latLng); + + googleMap.addMarker(new MarkerOptions() + .position(latLng) + .icon(markerIcon)); + } + + Polyline polyline1 = googleMap.addPolyline(polylineOptions); + googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14)); } private void setDate() { @@ -173,11 +191,8 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall 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)); +// replace this with parentTab.HistPosList + parentTab.demoPositionsList(); + displayHistory(parentTab.demoPositions); } } \ No newline at end of file From 4420af337d7b4eb7baef77316608cef22d737248 Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Fri, 18 Mar 2022 15:40:15 +0200 Subject: [PATCH 04/11] cleanups --- .../safemobile/dispatch/HistoryActivity.java | 9 +- .../dispatch/TabLayoutActivity.java | 917 ++++++------------ 2 files changed, 303 insertions(+), 623 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index 331c3db..afb3de2 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -21,6 +21,7 @@ import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.safemobile.lib.AppParams; import com.safemobile.lib.HistPos; +import com.safemobile.lib.OperationCodes; import com.safemobile.lib.SM; import com.safemobile.lib.Vehicle; @@ -38,6 +39,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private Spinner spinnerVehicle; private ImageView changeMapType, checkTraffic, slideLayoutImage; private LinearLayout layoutTraffic, slidelayout, layoutVehicles; + private Date startDate, endDate; private ArrayList allVehicle = new ArrayList<>(); private ArrayList allVehicleNames = new ArrayList<>(); @@ -88,6 +90,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall // }); setDate(); + + parentTab.executeNetworkStuff(new String[] {OperationCodes.GetHistoryPositions + "", allVehicle.get(spinnerVehicle.getSelectedItemPosition()).sc_id + "", + (startDate.getTime()/ 1000L) + "", (endDate.getTime()/ 1000L) + ""}); } private void displayHistory(ArrayList demoPositions) { @@ -110,9 +115,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private void setDate() { Calendar calendar = Calendar.getInstance(); - Date endDate = calendar.getTime(); + endDate = calendar.getTime(); calendar.add(Calendar.DATE, -1); - Date startDate = calendar.getTime(); + startDate = calendar.getTime(); LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker); TextView textViewDate = findViewById(R.id.textViewStartDate); diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java index 2d6ef54..c5d37e1 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -1529,89 +1529,79 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void onHistoryPositionsReceived(TCPEvent event) { TCPmsg msg= event.msg(); SM.Debug("Got HistoryPos :" + msg.allData); - if (!dropAllData){ + if (!dropAllData) { HistPosmsg tmpHist= new HistPosmsg(msg); Boolean SendDataToMap =true; - try{ + try { for (HistPos obj : tmpHist.PosList) HistPosList.add(obj); SM.Debug("tmpHist seqID:"+tmpHist.seqID); // 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) { + int all = Integer.parseInt(tmpHist.seqID.substring(tmpHist.seqID.indexOf('.') + 1)); + if (all != 0) { if (firstHistData) { try { for(int i=0;i) (o1, o2) -> { HistPos p1 = (HistPos) o1; HistPos p2 = (HistPos) o2; - if (p1.timeGMT UpdateZoneCH(" + rmsg.zac.rgwID + "," + rmsg.zac.gwID + "," + rmsg.zac.zoneNr + "," + rmsg.zac.channelNr + ")"); - } - - - - //list for SMS - if(AppParams.crtTab == AppParams.Tabs.radio) - { - SM.Debug("#### RadioActivity"); - // set crt activity to Radio - crtActivity = RADIO; - - SM.Debug("## " + (rmsg.RadioGWList!=null? "RadioGWList" + rmsg.RadioGWList.size() : "RadioGWList = null")); - SM.Debug("## " + (rmsg.zac!=null? "zac" + rmsg.zac.toString() : "zac = null")); - SM.Debug("## " + (rmsg.rStatus!=null? "rStatus" + rmsg.rStatus.toString() : "rStatus = null")); - - if(radioActivity!= null && rmsg.RadioGWList!=null) - { - radioActivity.UpdateRadios(rmsg.RadioGWList); - SM.Debug("Received from Apps -> UpdateRadios( count:" + rmsg.RadioGWList.size() + ")"); - } - - - - if(radioActivity != null &&rmsg.rStatus !=null) - { - - // update status in the crtRadio List - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.rStatus.gwID && radio.ID == rmsg.rStatus.rgwID) - radio.isOnline = (rmsg.rStatus.status == 1 ? true : false); - } - - SM.Debug("Received from Apps -> UpdateRadioStatus(" + rmsg.rStatus.rgwID + "," + rmsg.rStatus.gwID + "," + rmsg.rStatus.status+ ")"); - if ((crtRadio != null)&&(crtRadio.GW_ID == rmsg.rStatus.gwID)&&(crtRadio.ID == rmsg.rStatus.rgwID)) - radioActivity.UpdateRadioStatus(rmsg.rStatus.status); - } - //incCall - if (radioActivity != null && rmsg.incCall !=null) - { - SM.Debug("Received from Apps -> UpdateBroadcastCall(" + rmsg.incCall.Imei + "," + rmsg.incCall.callType + "," + rmsg.incCall.groupId+ ")"); - - // check if radioID and radioGW_ID needs to be changed - if(crtRadio != null && (crtRadio.GW_ID != rmsg.incCall.gwID || crtRadio.ID != rmsg.incCall.rgwID)) { - - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.incCall.gwID && radio.ID == rmsg.incCall.rgwID) { - crtRadio = radio; - notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); - break; - } + if (!NOSOUND) { + // update Zone and Channel + if (radioActivity != null && rmsg.zac != null) { + // update Zone and Channel in the allRadio List + for (RadioGW radio: allRadios) { + if (radio.GW_ID == rmsg.zac.gwID && radio.ID == rmsg.zac.rgwID) { + radio.lastZoneNr = rmsg.zac.zoneNr; + radio.lastChannelNr = rmsg.zac.channelNr; } } - - if(crtRadio != null) - { - if(rmsg.incCall.callStatus == 3) - { - inCall = false; - } - else - inCall = true; - - radioActivity.UpdateBroadcastCall(rmsg.incCall.Imei,rmsg.incCall.callType,rmsg.incCall.groupId,rmsg.incCall.callStatus); - } - - } - } - else - { - if (rmsg.incCall !=null) - { - crtActivity = 0; - //incCall - update UI in Radio Activity - SM.Debug("Received from Apps -> UpdateBroadcastCall(" + rmsg.incCall.Imei + "," + rmsg.incCall.callType + "," + rmsg.incCall.groupId+ ")"); - - // check if radioID and radioGW_ID needs to be changed - if(crtRadio != null && (crtRadio.GW_ID != rmsg.incCall.gwID || crtRadio.ID != rmsg.incCall.rgwID)) { - - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.incCall.gwID && radio.ID == rmsg.incCall.rgwID) { - crtRadio = radio; - notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); - break; - } - } - } - - if (crtRadio != null) - { - if(rmsg.incCall.callStatus == 3) - { - inCall = false; - // update recordings list - if(AppParams.crtTab == AppParams.Tabs.recordings) - { - // no recording is playing - if(recordingsActivity != null && recordingsActivity.playingPosition < 0) - getRecordings(crtRadio.GW_ID, crtRadio.ID); - } - } - else - inCall = true; - radioActivity.UpdateBroadcastCall(rmsg.incCall.Imei,rmsg.incCall.callType,rmsg.incCall.groupId,rmsg.incCall.callStatus); - } - - - } - - if(rmsg.RadioGWList!=null && radioActivity!=null) - radioActivity.UpdateRadios(rmsg.RadioGWList); - - if(rmsg.zac !=null && radioActivity!=null) { - radioActivity.UpdateZoneCH(rmsg.zac.rgwID, rmsg.zac.gwID, rmsg.zac.zoneNr, rmsg.zac.channelNr); - } - - if(rmsg.rStatus !=null && radioActivity!=null) - { - // update status in the allRadio List - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.rStatus.gwID && radio.ID == rmsg.rStatus.rgwID) - radio.isOnline = (rmsg.rStatus.status == 1 ? true : false); - } - - if ((crtRadio != null)&&(crtRadio.GW_ID == rmsg.rStatus.gwID)&&(crtRadio.ID == rmsg.rStatus.rgwID)) - radioActivity.UpdateRadioStatus(rmsg.rStatus.status); - } - - } - - - // save RadioList - if(rmsg.RadioGWList!=null) - { - allRadios = rmsg.RadioGWList; - if(crtRadio == null) - { - crtRadio = allRadios.get(0); - SM.Debug("rmsg set 0 crtRadio GW_ID:"+crtRadio.GW_ID+" ID:"+crtRadio.ID+")"); - - notifyBroadcast(OperationCodes.RADIOID_CHANGED+""); - } - } - - // save crt Radio ID and GW - if(rmsg.zac !=null) - { - for(RadioGW radio: allRadios) { - if(radio.GW_ID == rmsg.zac.gwID && radio.ID == rmsg.zac.rgwID) - crtRadio = radio; - } - } - - if(AppParams.crtTab == AppParams.Tabs.recordings) - { - if(recordingsActivity != null && rmsg.RadioGWList!=null) - { - SM.Debug("GetRecordings Request + crtRadio:"+ crtRadio.toString()); - getRecordings(crtRadio.GW_ID, crtRadio.ID); + AppParams.crtZoneAndChannel = rmsg.zac; + notifyBroadcast(OperationCodes.CHANNEL_BRDCST+""); + SM.Debug("Received from Apps -> UpdateZoneCH(" + rmsg.zac.rgwID + "," + rmsg.zac.gwID + "," + rmsg.zac.zoneNr + "," + rmsg.zac.channelNr + ")"); } - } - - - } - - // used when a unit is enabled / disabled - if(rmsg.suStatus !=null) { - SM.Debug("ENABLED/DISABLED " + rmsg.suStatus); - notifyBroadcast(OperationCodes.UNIT_STATUS_UPDATE+"", rmsg.suStatus.imei + "#" +rmsg.suStatus.status); - } - else - SM.Debug("SUStatus is null"); + + //list for SMS + if (AppParams.crtTab == AppParams.Tabs.radio) { + SM.Debug("#### RadioActivity"); + // set crt activity to Radio + crtActivity = RADIO; + + SM.Debug("## " + (rmsg.RadioGWList!=null? "RadioGWList" + rmsg.RadioGWList.size() : "RadioGWList = null")); + SM.Debug("## " + (rmsg.zac!=null? "zac" + rmsg.zac : "zac = null")); + SM.Debug("## " + (rmsg.rStatus!=null? "rStatus" + rmsg.rStatus : "rStatus = null")); + + if (radioActivity != null && rmsg.RadioGWList != null) { + radioActivity.UpdateRadios(rmsg.RadioGWList); + SM.Debug("Received from Apps -> UpdateRadios( count:" + rmsg.RadioGWList.size() + ")"); + } + + if (radioActivity != null &&rmsg.rStatus != null) { + // update status in the crtRadio List + for (RadioGW radio : allRadios) { + if (radio.GW_ID == rmsg.rStatus.gwID && radio.ID == rmsg.rStatus.rgwID) + radio.isOnline = rmsg.rStatus.status == 1; + } + + SM.Debug("Received from Apps -> UpdateRadioStatus(" + rmsg.rStatus.rgwID + "," + rmsg.rStatus.gwID + "," + rmsg.rStatus.status+ ")"); + if ((crtRadio != null)&&(crtRadio.GW_ID == rmsg.rStatus.gwID)&&(crtRadio.ID == rmsg.rStatus.rgwID)) + radioActivity.UpdateRadioStatus(rmsg.rStatus.status); + } + //incCall + if (radioActivity != null && rmsg.incCall !=null) { + SM.Debug("Received from Apps -> UpdateBroadcastCall(" + rmsg.incCall.Imei + "," + rmsg.incCall.callType + "," + rmsg.incCall.groupId+ ")"); + // check if radioID and radioGW_ID needs to be changed + if (crtRadio != null && (crtRadio.GW_ID != rmsg.incCall.gwID || crtRadio.ID != rmsg.incCall.rgwID)) { + for(RadioGW radio: allRadios) { + if(radio.GW_ID == rmsg.incCall.gwID && radio.ID == rmsg.incCall.rgwID) { + crtRadio = radio; + notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); + break; + } + } + } + + if(crtRadio != null) { + if(rmsg.incCall.callStatus == 3) + inCall = false; + else + inCall = true; + + radioActivity.UpdateBroadcastCall(rmsg.incCall.Imei,rmsg.incCall.callType,rmsg.incCall.groupId,rmsg.incCall.callStatus); + } + } + } else { + if (rmsg.incCall !=null) { + crtActivity = 0; + //incCall - update UI in Radio Activity + SM.Debug("Received from Apps -> UpdateBroadcastCall(" + rmsg.incCall.Imei + "," + rmsg.incCall.callType + "," + rmsg.incCall.groupId+ ")"); + + // check if radioID and radioGW_ID needs to be changed + if(crtRadio != null && (crtRadio.GW_ID != rmsg.incCall.gwID || crtRadio.ID != rmsg.incCall.rgwID)) { + for(RadioGW radio: allRadios) { + if(radio.GW_ID == rmsg.incCall.gwID && radio.ID == rmsg.incCall.rgwID) { + crtRadio = radio; + notifyBroadcast(OperationCodes.RADIOID_CHANGED + ""); + break; + } + } + } + + if (crtRadio != null) { + if(rmsg.incCall.callStatus == 3) { + inCall = false; + // update recordings list + if(AppParams.crtTab == AppParams.Tabs.recordings) { + // no recording is playing + if(recordingsActivity != null && recordingsActivity.playingPosition < 0) + getRecordings(crtRadio.GW_ID, crtRadio.ID); + } + } else + inCall = true; + radioActivity.UpdateBroadcastCall(rmsg.incCall.Imei,rmsg.incCall.callType,rmsg.incCall.groupId,rmsg.incCall.callStatus); + } + } + + if(rmsg.RadioGWList!=null && radioActivity!=null) + radioActivity.UpdateRadios(rmsg.RadioGWList); + + if(rmsg.zac !=null && radioActivity!=null) { + radioActivity.UpdateZoneCH(rmsg.zac.rgwID, rmsg.zac.gwID, rmsg.zac.zoneNr, rmsg.zac.channelNr); + } + + if(rmsg.rStatus !=null && radioActivity!=null) { + // update status in the allRadio List + for(RadioGW radio: allRadios) { + if(radio.GW_ID == rmsg.rStatus.gwID && radio.ID == rmsg.rStatus.rgwID) + radio.isOnline = (rmsg.rStatus.status == 1 ? true : false); + } + + if ((crtRadio != null)&&(crtRadio.GW_ID == rmsg.rStatus.gwID)&&(crtRadio.ID == rmsg.rStatus.rgwID)) + radioActivity.UpdateRadioStatus(rmsg.rStatus.status); + } + } + + // save RadioList + if (rmsg.RadioGWList!=null) { + allRadios = rmsg.RadioGWList; + if (crtRadio == null) { + crtRadio = allRadios.get(0); + SM.Debug("rmsg set 0 crtRadio GW_ID:"+crtRadio.GW_ID+" ID:"+crtRadio.ID+")"); + notifyBroadcast(OperationCodes.RADIOID_CHANGED+""); + } + } + + // save crt Radio ID and GW + if (rmsg.zac !=null) { + for (RadioGW radio: allRadios) { + if (radio.GW_ID == rmsg.zac.gwID && radio.ID == rmsg.zac.rgwID) + crtRadio = radio; + } + } + + if (AppParams.crtTab == AppParams.Tabs.recordings) { + if (recordingsActivity != null && rmsg.RadioGWList!=null) { + SM.Debug("GetRecordings Request + crtRadio:"+ crtRadio.toString()); + getRecordings(crtRadio.GW_ID, crtRadio.ID); + } + } + } + + // used when a unit is enabled / disabled + if (rmsg.suStatus !=null) { + SM.Debug("ENABLED/DISABLED " + rmsg.suStatus); + notifyBroadcast(OperationCodes.UNIT_STATUS_UPDATE+"", rmsg.suStatus.imei + "#" +rmsg.suStatus.status); + } else + SM.Debug("SUStatus is null"); } @Override @@ -1820,21 +1768,17 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ String[] tempArr =msg.data.split("#"); SM.Debug("Unit imei:" + tempArr[0]); String UnitIMEI =tempArr[0]; - //SM.Debug("Message:" + tempArr[1]); - + //list for SMS - if(AppParams.crtTab == AppParams.Tabs.alarms) - { + if (AppParams.crtTab == AppParams.Tabs.alarms) { SM.Debug("currentActivity instanceof AlarmActivity - NewSMS | " + tempArr[0] + " | " + tempArr[1]); getAlarms(AppParams.USERID); } // if tab is not TextTab - if(tabHost.getCurrentTab() != 5) - { + if (tabHost.getCurrentTab() != 5) { // change Visual Elements setImei(UnitIMEI); - switch (msg.opCode) - { + switch (msg.opCode) { case 135: setMess("speed "+tempArr[1]); break; case 136: setMess("landmark "+tempArr[1]); @@ -1850,40 +1794,31 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } myHandler.post(UpdateResultsAlarm); - if ((msg.opCode==138)&&(AppParams.crtTab == AppParams.Tabs.live)) - { - if(getSuperVehHash().get(Long.parseLong(UnitIMEI)) != null) - { + if ((msg.opCode==138)&&(AppParams.crtTab == AppParams.Tabs.live)) { + if(getSuperVehHash().get(Long.parseLong(UnitIMEI)) != null) { //if is not check i need to force check to put on the map Boolean forceChecked =false; - if (!getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate) - { + if (!getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate) { getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate =true; forceChecked =true; } - try - { + try { int x = 0; - if (forceChecked) - { - for (Vehicle veh : getAllVehicle()) - { + if (forceChecked) { + for (Vehicle veh : getAllVehicle()) { if (veh.imei.compareTo(UnitIMEI)==0) break; x++; } - } - else x = -1; - if(liveActivity != null) - { + } else + x = -1; + if (liveActivity != null) { if (x!= getAllVehicle().size()) liveActivity.emergencyAlarmReceived(x , getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); else liveActivity.emergencyAlarmReceived(-1, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); } - } - catch (Exception ex) - { - SM.Debug("Error load hash:"+ex.toString()); + } catch (Exception ex) { + SM.Debug("Error load hash: "+ ex); } } } @@ -1897,19 +1832,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("am primit lista cu Recording"); //list for SMS - if(AppParams.crtTab == AppParams.Tabs.recordings) - { - for(Recording rec: Records.recordList) - { + if (AppParams.crtTab == AppParams.Tabs.recordings) { + for(Recording rec: Records.recordList) { // set the name to be displayed - if (rec.typeID==1) + if (rec.typeID == 1) rec.NameForDisplay = AppParams.USERNAME; else { if (getSuperVehHash().get((long)rec.subID)!=null) rec.NameForDisplay = getSuperVehHash().get((long)rec.subID).name; } } - // save recodings to AppParams AppParams.recordings = Records.recordList; @@ -1920,19 +1852,17 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ @Override public void onConnectionReplyReceived(TCPEvent event) { - + } @Override public void onContactsListReceived(TCPEvent event) { // TODO Auto-generated method stub - } @Override public void onTextMessagesListReceived(TCPEvent event) { // TODO Auto-generated method stub - } @Override @@ -1942,7 +1872,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // send a broadcast notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + ""); - } @Override @@ -1959,31 +1888,17 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void onPONGReceived() { } - }); } - - // Create runnable for posting - public final Runnable showPopUpRUN = new Runnable() { - public void run() { - updateResultsInUi("realpha"); - } - }; // Create runnable for posting - final Runnable UpdateResultsAlarm = new Runnable() { - public void run() { - updateResultsAlarmInUi("realpha"); - } - }; + final Runnable UpdateResultsAlarm = () -> updateResultsAlarmInUi("realpha"); public void updateResultsAlarmInUi(String animation) { // Back in the UI thread // set TextViews - if(tcp!=null && !AppParams.DEMO) - { - try - { + if(tcp!=null && !AppParams.DEMO) { + try { activePopupType= MsgType.ALARM; imageViewPopUp.setImageResource(R.drawable.siren_on); slideTabsText.setText(getString(R.string.newAlarm)); @@ -2003,35 +1918,25 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // create Notification createNotification(AppParams.alertNotif); + } catch (Exception ex) { + SM.Debug("Erorr on update alarm:"+ ex); } - catch (Exception ex) - { - SM.Debug("Erorr on update alarm:"+ex.toString()); - } - - } } // Create runnable for posting - final Runnable UpdateResultsPoll = new Runnable() { - public void run() { - - updateResultsPollInUi("realpha"); - } - }; + final Runnable UpdateResultsPoll = () -> updateResultsPollInUi("realpha"); public void updateResultsPollInUi(String animation) { // Back in the UI thread // set TextViews String from = ""; - Vehicle fromVehicle = null; - if((fromVehicle = getVehicle4Imei(getImei())) != null) + Vehicle fromVehicle; + if ((fromVehicle = getVehicle4Imei(getImei())) != null) from = fromVehicle.name; - if(tcp!=null && !AppParams.DEMO) - { + if (tcp!=null && !AppParams.DEMO) { activePopupType =MsgType.POLL; imageViewPopUp.setImageResource(R.drawable.poll); slideTabsText.setText("Poll Reply"); @@ -2046,9 +1951,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ anim.reset(); layoutNewMessage.clearAnimation(); layoutNewMessage.startAnimation(anim); - } - else if (AppParams.DEMO) - { + } else if (AppParams.DEMO) { activePopupType =MsgType.POLL; imageViewPopUp.setImageResource(R.drawable.poll); slideTabsText.setText("Poll Reply"); @@ -2056,14 +1959,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ textViewNMMessage.setText(getMess()); // show layout layoutNewMessage.setVisibility(View.VISIBLE); - /* - Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); - if(animation.equals("realpha")) - anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - anim.reset(); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - */ } // create Notification @@ -2071,17 +1966,12 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } // Create runnable for posting - final Runnable UpdateResults = new Runnable() { - public void run() { - updateResultsInUi("realpha"); - } - }; + final Runnable UpdateResults = () -> updateResultsInUi("realpha"); public void updateResultsInUi(String animation) { // Back in the UI thread // set TextViews - if(tcp!=null && !AppParams.DEMO) - { + if(tcp!=null && !AppParams.DEMO) { activePopupType = MsgType.SMS; imageViewPopUp.setImageResource(R.drawable.message); slideTabsText.setText("New Message"); @@ -2096,9 +1986,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ anim.reset(); layoutNewMessage.clearAnimation(); layoutNewMessage.startAnimation(anim); - } - else if(AppParams.DEMO) - { + } else if(AppParams.DEMO) { setMess("i got your sms"); activePopupType = MsgType.SMS; imageViewPopUp.setImageResource(R.drawable.message); @@ -2110,11 +1998,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // create Notification createNotification(AppParams.messageNotif); - /* - Animation anim = AnimationUtils.loadAnimation(this, R.anim.realpha); - layoutNewMessage.clearAnimation(); - layoutNewMessage.startAnimation(anim); - */ } // create Notification @@ -2130,8 +2013,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ Vehicle veh = getVehicle4Imei(getImei()); int icon_value = icon; - switch(icon) - { + switch(icon) { case AppParams.messageNotif: contentText = "\"" + getMess() + "\""; contentTitle = "New Message from " + getImei(); @@ -2179,11 +2061,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // return vehicle according to imei - private Vehicle getVehicle4Imei(String imei) - { + private Vehicle getVehicle4Imei(String imei) { Vehicle veh = null; for(Vehicle vehicle: getAllVehicle()) - //SM.Debug("Vehicle name:"+vehicle.name+" IMEI:"+vehicle.imei); if(vehicle.imei.equals(imei)) veh = vehicle; return veh; @@ -2191,10 +2071,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ @Override - public void enableMenuButtons(boolean enable) - { - if(enable) - { + public void enableMenuButtons(boolean enable) { + if (enable) { buttonAlarms.setEnabled(true); buttonHistory.setEnabled(true); buttonLive.setEnabled(true); @@ -2202,9 +2080,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ buttonText.setEnabled(true); buttonRadio.setEnabled(true); buttonSetup.setEnabled(true); - } - else - { + } else { // disable all buttons buttonAlarms.setEnabled(false); buttonHistory.setEnabled(false); @@ -2217,10 +2093,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } // load settings - public void loadSettings() - { - try - { + public void loadSettings() { + try { // get Preferences for SafeDispatch AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); // get default IP @@ -2231,24 +2105,19 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ AppParams.LANGUAGE = AppParams.prefs.getString("language", "en"); SM.Debug("PORT: " + AppParams.PORT + " | IP: " + AppParams.IP); - } - catch(Exception ex) - { + } catch(Exception ex) { Log.e("Exception", "loadSettings exception"); } } @Override - public double best_zoom(double latMax, double latMin, double lngMax, double lngMin) - { + public double best_zoom(double latMax, double latMin, double lngMax, double lngMin) { double height =400; double width =400; double dlat = Math.abs(latMax - latMin); double dlon = Math.abs(lngMax - lngMin); - if(dlat == 0 && dlon == 0) - { + if(dlat == 0 && dlon == 0) { if ((latMax == latMin)&&(latMax ==0)&&(lngMax == lngMin)&&(lngMax ==0)) return 2; - //return 17; } // Center latitude in radians @@ -2260,173 +2129,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ return (z1 > z0) ? (17-z1) : (17-z0); } - - /* - public void getVehs() - { - boolean res = tcp.Write("0.0", "#21#"+AppParams.USERID+"#"); - if(res){ - SM.Debug("Message (getVehs) sent to app server"); - }else{ - SM.Debug("Could not send message(getVehs)!!"); - } - } - - public void getLastPos() - { - boolean res = tcp.Write("0.0", "#25#"); - if(res){ - SM.Debug("Message (getLastPOS) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void optionForUnit(int radioCode, int opCode, int sc_id, int value) - { - boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + sc_id+"#" +value + "#"); - if(res){ - SM.Debug("Message (optionForUnit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " sc_id:"+sc_id+ " value:"+value); - }else{ - SM.Debug("Could not send message(optionForUnit)!!"); - } - } - - public void getSMS4unit(int sc_id, long timeGMT) - { - boolean res = tcp.Write("0.0", "#22#"+sc_id+"#" +timeGMT+"#"); - if(res){ - SM.Debug("Message (getLastSMS) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void getLastSMS() - { - boolean res = tcp.Write("0.0", "#23#"); - if(res){ - SM.Debug("Message (getLastSMS) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void SendSMS(String seqID,int sc_id, String txt) - { - boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + sc_id + "#" + txt + "#"); - if(res){ - SM.Debug("Message (SendSMS) sent to app server sc_id:"+sc_id+ " txt:"+txt); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void SendAlarmACK(int alarm_id, int type) - { - boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#"); - if(res){ - SM.Debug("Message (SendAlarmACK) sent to app server alarm_id:"+alarm_id+ " type:"+type); - }else{ - SM.Debug("Could not send message(SendAlarmACK)!!"); - } - } - - public void SendPlayRequest(long record_id) - { - boolean res = tcp.Write("0.0", "#18#" + record_id + "#"); - if(res){ - SM.Debug("Message (SendPlayRequest) sent to app server record_id:"+record_id); - }else{ - SM.Debug("Could not send message(SendPlayRequest)!!"); - } - } - - public void SendDekey() - { - boolean res = tcp.Write("0.0", "#30#160#" +crtRadio.GW_ID+"."+crtRadio.ID+ "#"); - if(res){ - SM.Debug("Message (SendDekey) sent to app server record_id"); - }else{ - SM.Debug("Could not send message(SendPlayRequest)!!"); - } - } - - public void getHistoryPos(int sc_id, long timeGMTStart, long timeGMTStop) - { - HistSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); - boolean res = tcp.Write(HistSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#"); - if(res){ - SM.Debug("Message (getHistoryPos) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - - public void RadioGetRadioList() - { - boolean res = tcp.Write("0.0", "#30#100#"); - if(res){ - SM.Debug("Message (RadioGetRadioList) sent to app server"); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - // if zoneNr=0 and channelNR =0 then function acts as GET - public void getSetZoneAndChannel(int gwID, int rgwID, int zoneNR, int channelNR) - { - boolean res = tcp.Write("0.0", "#30#104#" + gwID + "#" + rgwID + "#" + zoneNR + "#" +channelNR +"#"); - if(res){ - SM.Debug("Message (GetSetZoneAndChannel) sent to app server zoneNR:"+zoneNR+ " channelNR:"+channelNR); - }else{ - SM.Debug("Could not send message(GetSetZoneAndChannel)!!"); - } - } - - // send radioCode=30 - //Enable/Disable opcode=150 value(1/0) - //Remote monitor = 161 - //Poll = 154 - - - public void getRadioStatus(int gwID, int rgwID) - { - boolean res = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#"); - if(res){ - SM.Debug("Message (RadioGetRadioList) sent to app server || gwID: " + gwID + " | rgwID: " + rgwID); - }else{ - SM.Debug("Could not send message(getLastSMS)!!"); - } - } - - public void getAlarms() - { - boolean res = tcp.Write("0.0", "#27#"); // = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#"); - if(res){ - SM.Debug("Message (GetAlarms) sent to app server"); - }else{ - SM.Debug("Could not send message(GetAlarms)!!"); - } - } - - - public void getRecordings() - { - boolean res = tcp.Write("0.0", "#29#"+AppParams.USERID+"#"+crtRadio.GW_ID+"#"+crtRadio.ID+"#"); - if(res){ - SM.Debug("Message (GetRecordings) sent to app server"); - }else{ - SM.Debug("Could not send message(GetRecordings)!!"); - } - } - */ - - - - - //callType: //101 -allcall init @@ -2435,10 +2137,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ //112 -prvcall stop //103 -grpcall init //113 -grpcall stop - public void SendPTT(int callType, int id, int gwID, int rgwid, long userID) - { - if(tcp!= null) - { + public void SendPTT(int callType, int id, int gwID, int rgwid, long userID) { + if(tcp!= null) { try { Thread.sleep(300); } catch (InterruptedException e) { @@ -2447,86 +2147,80 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ boolean res = tcp.Write("0.0", "#30#"+callType+"#"+gwID+"."+rgwid+"." + id+"#"+userID+"#"); if(res){ SM.Debug("Message (SendPTT) sent to app server"); - } - else{ + } else { SM.Debug("Could not send message(SendPTT)!!"); } } } - protected class ConnectTask extends AsyncTask - { + protected class ConnectTask extends AsyncTask { @Override protected TCPhandler doInBackground(String... params) { - switch(Integer.parseInt(params[0])) - { - case OperationCodes.TCP_CONNECTION_REQ: - - SM.Exception("TCP CONNECTION REQ!!!"); - if(myService!= null) { - tcp = myService.getTCPConnection(); - SM.Exception("TCP is not null!!!"); - } - break; - - case OperationCodes.GetVehicles: - getVehicles(Integer.parseInt(params[1])); - break; - - case OperationCodes.GetRadiosList: - getRadiosList(); - break; - - case OperationCodes.GetLastPositions: - getLastPositions(Integer.parseInt(params[1])); - break; - - case OperationCodes.GetLastSMS: - getLastSMSs(Integer.parseInt(params[1])); - break; - - case OperationCodes.GetRecentSMSs: - try - { - Long.parseLong(params[2]); - } - catch (Exception ignored) { - - } - getRecentSMSs(Integer.parseInt(params[1]), Long.parseLong(params[2])); - break; - - case OperationCodes.SEND_TM: - sendSMS(params[1], Integer.parseInt(params[2]), params[3]); - - case OperationCodes.Option4Unit: - try { - SM.Debug(params[1] + " | " + params[2] + " | " + params[3] + " | " + params[4]); - - setVehicleStatus(Integer.parseInt(params[1]), Integer.parseInt(params[2]), Integer.parseInt(params[3]), Integer.parseInt(params[4])); - } - catch(Exception ex) { SM.Exception("Paramas -> setVehicleStatus","EXCeption ex " + ex.toString()); } - break; - - case OperationCodes.GetAlarms: - getAlarms(Integer.parseInt(params[1])); - break; - - case OperationCodes.SendAlarmAcknoledge: - sendAlarmAcknowledge(Integer.parseInt(params[1]), Integer.parseInt(params[2])); - break; - - case OperationCodes.GetHistoryPositions: - getHistoryPositions(Integer.parseInt(params[1]), Long.parseLong(params[2]), Long.parseLong(params[3])); - break; - - } + switch(Integer.parseInt(params[0])) { + case OperationCodes.TCP_CONNECTION_REQ: + SM.Exception("TCP CONNECTION REQ!!!"); + if(myService!= null) { + tcp = myService.getTCPConnection(); + SM.Exception("TCP is not null!!!"); + } + break; + + case OperationCodes.GetVehicles: + getVehicles(Integer.parseInt(params[1])); + break; + + case OperationCodes.GetRadiosList: + getRadiosList(); + break; + + case OperationCodes.GetLastPositions: + getLastPositions(Integer.parseInt(params[1])); + break; + + case OperationCodes.GetLastSMS: + getLastSMSs(Integer.parseInt(params[1])); + break; + + case OperationCodes.GetRecentSMSs: + try + { + Long.parseLong(params[2]); + } + catch (Exception ignored) { + + } + getRecentSMSs(Integer.parseInt(params[1]), Long.parseLong(params[2])); + break; + + case OperationCodes.SEND_TM: + sendSMS(params[1], Integer.parseInt(params[2]), params[3]); + + case OperationCodes.Option4Unit: + try { + SM.Debug(params[1] + " | " + params[2] + " | " + params[3] + " | " + params[4]); + + setVehicleStatus(Integer.parseInt(params[1]), Integer.parseInt(params[2]), Integer.parseInt(params[3]), Integer.parseInt(params[4])); + } + catch(Exception ex) { SM.Exception("Paramas -> setVehicleStatus","EXCeption ex " + ex.toString()); } + break; + + case OperationCodes.GetAlarms: + getAlarms(Integer.parseInt(params[1])); + break; + + case OperationCodes.SendAlarmAcknoledge: + sendAlarmAcknowledge(Integer.parseInt(params[1]), Integer.parseInt(params[2])); + break; + + case OperationCodes.GetHistoryPositions: + getHistoryPositions(Integer.parseInt(params[1]), Long.parseLong(params[2]), Long.parseLong(params[3])); + break; + } return null; } - } @@ -2555,8 +2249,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ /* Display Toast messages*/ @Override - public void displayToast(final String msg) - { + public void displayToast(final String msg) { myHandler.post(() -> Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()); } @@ -2607,37 +2300,22 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } @Override - public void recreateTCPConnection() - { - if(!AppParams.DEMO) - { + public void recreateTCPConnection() { + if(!AppParams.DEMO) { if(tcpParser!=null) tcpParser.clearMsgList(); - //showLoadingDialog("Getting users from database..."); - myHandler.post(new Runnable() { - @Override - public void run() { - if(myService != null) - { - myService.stopTCPConnection(); - myService.recreateTCPConnection(); - new ConnectTask().execute(new String[] {OperationCodes.TCP_CONNECTION_REQ + ""}); - - // add a new ITCPListener - tcpParser(); + myHandler.post(() -> { + if(myService != null) { + myService.stopTCPConnection(); + myService.recreateTCPConnection(); + new ConnectTask().execute(new String[] {OperationCodes.TCP_CONNECTION_REQ + ""}); - //tcp.updateTCPparameters(AppParams.IP, AppParams.PORT); - } - // recreate tcp - //myService.updateTCPparameters(AppParams.IP, AppParams.PORT); - //myService.recreateTCPConnection(); - //tcpInit(); - - SM.Debug("RECREATE TCP","IP: " + AppParams.IP + " | Port: " + AppParams.PORT); + // add a new ITCPListener + tcpParser(); } + SM.Debug("RECREATE TCP","IP: " + AppParams.IP + " | Port: " + AppParams.PORT); }); - } } @@ -2645,7 +2323,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void removeITCPListener() { if(tcpParser != null) tcpParser.clearITCPListeners(); - //tcpParser.removeTCPListener(itcpListener); } @@ -2654,25 +2331,23 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ * @param action The type of action which will be notified * @param object The object which will be passed through the intent */ - private void notifyBroadcast(String action) { - Intent intent = new Intent(); - intent.setAction(action); - //intent.putExtra("extra", extra); - getBaseContext().sendBroadcast(intent); - } + private void notifyBroadcast(String action) { + Intent intent = new Intent(); + intent.setAction(action); + getBaseContext().sendBroadcast(intent); + } // send a message to be broadcasted when a specific event happens // every listener that is registered to the broadcast will be notified of these event private void notifyBroadcast(String action, Object object) { Intent intent = new Intent(); intent.setAction(action); - if(action == OperationCodes.UNIT_STATUS_UPDATE+"") + if(action.equals(OperationCodes.UNIT_STATUS_UPDATE + "")) intent.putExtra("unitStatus", (String)object); - else if(action == OperationCodes.BLUETOOTH_TETHER+"") + else if(action.equals(OperationCodes.BLUETOOTH_TETHER + "")) intent.putExtra("tether", Boolean.parseBoolean((String)object)); else intent.putExtra("extra", new SerializedObject(object, action)); getBaseContext().sendBroadcast(intent); } - -} +} \ No newline at end of file From 89f8cbfcae30366c8221ed73f3b851d37b3ec59a Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Fri, 18 Mar 2022 23:12:20 +0200 Subject: [PATCH 05/11] WIP --- .../safemobile/dispatch/HistoryActivity.java | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index afb3de2..f75c69d 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -3,7 +3,10 @@ package com.safemobile.dispatch; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; +import android.os.Handler; +import android.util.Log; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Spinner; @@ -39,7 +42,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private Spinner spinnerVehicle; private ImageView changeMapType, checkTraffic, slideLayoutImage; private LinearLayout layoutTraffic, slidelayout, layoutVehicles; + private Button displayButton; private Date startDate, endDate; + private final Handler myHandler = new Handler(); private ArrayList allVehicle = new ArrayList<>(); private ArrayList allVehicleNames = new ArrayList<>(); @@ -76,6 +81,23 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall slidelayout = findViewById(R.id.slidelayout); slideLayoutImage = findViewById(R.id.slideLayoutImage); layoutVehicles = findViewById(R.id.layoutBig); + displayButton = findViewById(R.id.buttonDisplay); + displayButton.setOnClickListener(view -> { + googleMap.clear(); + if (!AppParams.DEMO) { + parentTab.dropAllData =false; + parentTab.firstHistData = true; + parentTab.HistMsgList.clear(); + parentTab.HistPosList.clear(); + +// request history + parentTab.executeNetworkStuff(new String[] {OperationCodes.GetHistoryPositions + "", allVehicle.get(spinnerVehicle.getSelectedItemPosition()).sc_id + "", + (startDate.getTime()/ 1000L) + "", (endDate.getTime()/ 1000L) + ""}); + } else { + parentTab.demoPositionsList(); + displayHistory(parentTab.demoPositions); + } + }); // slidelayout.setOnTouchListener((v, event) -> { // if (showVehicle) { // layoutVehicles.setVisibility(View.GONE); @@ -90,17 +112,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall // }); setDate(); - - parentTab.executeNetworkStuff(new String[] {OperationCodes.GetHistoryPositions + "", allVehicle.get(spinnerVehicle.getSelectedItemPosition()).sc_id + "", - (startDate.getTime()/ 1000L) + "", (endDate.getTime()/ 1000L) + ""}); } - private void displayHistory(ArrayList demoPositions) { - LatLng latLng = new LatLng(demoPositions.get(0).lat, demoPositions.get(0).lng); + private void displayHistory(ArrayList positions) { + LatLng latLng = null; PolylineOptions polylineOptions = new PolylineOptions(); BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.bus); - - for (HistPos pos : demoPositions) { + for (HistPos pos : positions) { latLng = new LatLng(pos.lat, pos.lng); polylineOptions.add(latLng); @@ -110,7 +128,8 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall } Polyline polyline1 = googleMap.addPolyline(polylineOptions); - googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14)); + if (latLng != null) + googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14)); } private void setDate() { @@ -176,7 +195,16 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall } + final Runnable UpdateMapResults = new Runnable() { + public void run() { + Log.v("updateMap", parentTab.HistPosList.toString()); + SM.Debug("Do the Display"); + displayHistory(parentTab.HistPosList); + } + }; + public void UpdateMap() { + myHandler.post(UpdateMapResults); SM.Debug("Do the updateMAP post"); } @@ -196,8 +224,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall public void onMapReady(@NonNull GoogleMap googleMap) { this.googleMap = googleMap; -// replace this with parentTab.HistPosList parentTab.demoPositionsList(); - displayHistory(parentTab.demoPositions); + displayButton.performClick(); } } \ No newline at end of file From db360c4d45668b9577c75dee3941914d7b44d3ce Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Mon, 21 Mar 2022 11:50:52 +0200 Subject: [PATCH 06/11] speed limit --- .../dispatch/GoogleMapsInfoBubble.java | 71 ++++++++++++---- .../safemobile/dispatch/HistoryActivity.java | 83 ++++++++++++------- .../src/main/res/layout/tabhistory.xml | 5 +- 3 files changed, 107 insertions(+), 52 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/GoogleMapsInfoBubble.java b/safeDispatch/src/main/java/com/safemobile/dispatch/GoogleMapsInfoBubble.java index 4aea17d..c3ac8cb 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/GoogleMapsInfoBubble.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/GoogleMapsInfoBubble.java @@ -12,10 +12,12 @@ import androidx.annotation.NonNull; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.model.Marker; +import com.safemobile.lib.HistPos; import com.safemobile.lib.SuperVehicle; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.Hashtable; import java.util.Locale; @@ -25,8 +27,10 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter { private final String TAG = GoogleMapsInfoBubble.class.getName(); private final View mWindow; - private final Hashtable superVehHash; + private Hashtable superVehHash; private final Context context; + private ArrayList histPosList; + private boolean isLiveTab = true; public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context, Hashtable vehicles) { @@ -35,6 +39,17 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter { mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null); } + public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context) { + isLiveTab = false; + this.context = context; +// this.superVehHash = vehicles; + mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null); + } + + public void setHistoryPositions(ArrayList positions) { + this.histPosList = positions; + } + @Override public View getInfoWindow(@NonNull Marker marker) { render(marker, mWindow); @@ -49,13 +64,21 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter { private void render(Marker marker, View view) { long key = 0; - - try { - key = Long.parseLong(marker.getTitle()); - } catch (Exception ex) { - Log.v(TAG, "Unable to parse Google Maps Info Bubble title"); + int position = 0; + if (isLiveTab) { + try { + key = Long.parseLong(marker.getTitle()); + } catch (Exception ex) { + Log.v(TAG, "Unable to parse Google Maps Info Bubble title"); + } + } else { + try { + position = Integer.getInteger(marker.getTitle()); + } catch (Exception e) { + Log.v(TAG, "Unable to parse Google Maps Info Bubble title on History"); + } } - SuperVehicle vehicle = superVehHash.get(key); + RelativeLayout rlMapInfoBubbleInfo = view.findViewById(R.id.rlMapInfoBubbleInfo); TextView tvUnitName = view.findViewById(R.id.tvUnitName); @@ -67,27 +90,39 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter { rlMapInfoBubbleInfo.setVisibility(View.VISIBLE); boolean isMilitaryTime = false; - Date positionTime = new Date(vehicle.timeGMT); - + Date positionTime; + String speed, address, gpsLocation, name = ""; + if (isLiveTab) { + SuperVehicle vehicle = superVehHash.get(key); + positionTime = new Date(vehicle.timeGMT); + address = vehicle.Address != null ? vehicle.Address : ""; + name = vehicle.name; + speed = String.format(context.getResources().getString(R.string.speedMph), vehicle.speed); + gpsLocation = "[" + String.format("%.4f", vehicle.lat) + "," + String.format("%.4f",vehicle.lng) + "]"; + } else { + HistPos histPos = histPosList.get(position); + positionTime = new Date(histPos.timeGMT); + address = histPos.Address != null ? histPos.Address : ""; + speed = String.format(context.getResources().getString(R.string.speedMph), 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"; DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH); - tvTimeAgo.setText(format.format(positionTime)); - - tvSpeed.setText(String.format(context.getResources().getString(R.string.speedMph), vehicle.speed)); - - String address = vehicle.Address != null ? vehicle.Address : ""; - tvStreetView.setText(address); streetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE); tvStreetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE); - tvUnitName.setText(vehicle.name); - tvGPSLocation.setText("[" + String.format("%.4f", vehicle.lat) - + "," + String.format("%.4f",vehicle.lng) + "]"); + if (!isLiveTab) + tvUnitName.setVisibility(View.GONE); + else + tvUnitName.setText(name); + + tvSpeed.setText(speed); + tvGPSLocation.setText(gpsLocation); } } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index f75c69d..28fd336 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -2,11 +2,18 @@ package com.safemobile.dispatch; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.os.Handler; import android.util.Log; +import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.DatePicker; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.Spinner; @@ -45,11 +52,14 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private Button displayButton; private Date startDate, endDate; private final Handler myHandler = new Handler(); + private GoogleMapsInfoBubble infoBubble; private ArrayList allVehicle = new ArrayList<>(); private ArrayList allVehicleNames = new ArrayList<>(); private ArrayAdapter adapter; private boolean showVehicle = true; + private SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy"); + @Override protected void onCreate(Bundle savedInstanceState) { @@ -98,18 +108,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall displayHistory(parentTab.demoPositions); } }); -// slidelayout.setOnTouchListener((v, event) -> { -// if (showVehicle) { -// layoutVehicles.setVisibility(View.GONE); -// slideLayoutImage.setImageResource(R.drawable.arrow_right); -// showVehicle = false; -// } else { -// layoutVehicles.setVisibility(View.VISIBLE); -// slideLayoutImage.setImageResource(R.drawable.arrow_left); -// showVehicle = true; -// } -// return false; -// }); setDate(); } @@ -117,14 +115,16 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private void displayHistory(ArrayList positions) { LatLng latLng = null; PolylineOptions polylineOptions = new PolylineOptions(); - BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.bus); - for (HistPos pos : positions) { - latLng = new LatLng(pos.lat, pos.lng); - polylineOptions.add(latLng); + for (int i = 0; i < positions.size(); i++) { + HistPos pos = positions.get(i); + if (pos.speed > 0) { + latLng = new LatLng(pos.lat, pos.lng); + polylineOptions.add(latLng); - googleMap.addMarker(new MarkerOptions() - .position(latLng) - .icon(markerIcon)); + googleMap.addMarker(new MarkerOptions() + .position(latLng) + .title(String.valueOf(i))); + } } Polyline polyline1 = googleMap.addPolyline(polylineOptions); @@ -139,23 +139,38 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall startDate = calendar.getTime(); LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker); - TextView textViewDate = findViewById(R.id.textViewStartDate); + TextView textViewStartDate = findViewById(R.id.textViewStartDate); + TextView textViewEndDate = findViewById(R.id.textViewEndDate); - textViewDate.setText(new SimpleDateFormat("HH:mm, dd.MM.yyyy").format(startDate)); -// layoutStartPicker.setOnTouchListener((v, event) -> { -// showDialog(layoutStartPicker); -// return false; -// }); + textViewStartDate.setText(sdf.format(startDate)); + textViewEndDate.setText(sdf.format(endDate)); -// layoutEndPicker.setOnTouchListener(new OnTouchListener() { -// @Override -// public boolean onTouch(View v, MotionEvent event) { -// showDialog(layoutEndPicker); -// return false; -// } -// }); + textViewStartDate.setOnClickListener(view -> openDialog(textViewStartDate, true)); + textViewEndDate.setOnClickListener(view -> openDialog(textViewEndDate, false)); + } + private void openDialog(TextView textView, Boolean isStartDate) { + Date date = startDate; + if (!isStartDate) + date = endDate; + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + DatePickerDialog.OnDateSetListener setListener = (datePicker, y, m, d) -> { + calendar.set(y, m, d); + String dateString = sdf.format(calendar.getTime()); + textView.setText(dateString); + if (isStartDate) + startDate = calendar.getTime(); + else + endDate = calendar.getTime(); + }; + + Dialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, setListener, + calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); + dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + dialog.show(); } private void changeTraffic() { @@ -199,6 +214,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall public void run() { Log.v("updateMap", parentTab.HistPosList.toString()); SM.Debug("Do the Display"); + infoBubble.setHistoryPositions(parentTab.HistPosList); displayHistory(parentTab.HistPosList); } }; @@ -224,6 +240,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall public void onMapReady(@NonNull GoogleMap googleMap) { this.googleMap = googleMap; + infoBubble = new GoogleMapsInfoBubble(getLayoutInflater(), this); + this.googleMap.setInfoWindowAdapter(infoBubble); + parentTab.demoPositionsList(); displayButton.performClick(); } diff --git a/safeDispatch/src/main/res/layout/tabhistory.xml b/safeDispatch/src/main/res/layout/tabhistory.xml index 8c11b21..d322f9e 100644 --- a/safeDispatch/src/main/res/layout/tabhistory.xml +++ b/safeDispatch/src/main/res/layout/tabhistory.xml @@ -162,10 +162,11 @@ android:text="@string/startDate" android:textSize="22dp" android:paddingLeft="5dp" + android:layout_marginTop="15sp" android:textColor="#000000" android:gravity="left" android:id="@+id/labelStartDate" - android:visibility="gone"/> + /> + /> Date: Mon, 21 Mar 2022 11:58:34 +0200 Subject: [PATCH 07/11] clean history activity --- .../safemobile/dispatch/HistoryActivity.java | 38 +++++++------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index 28fd336..46276d2 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -10,12 +10,9 @@ import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.os.Handler; import android.util.Log; -import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; -import android.widget.DatePicker; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; @@ -23,11 +20,8 @@ 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.BitmapDescriptor; -import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; -import com.google.android.gms.maps.model.Polyline; import com.google.android.gms.maps.model.PolylineOptions; import com.safemobile.lib.AppParams; import com.safemobile.lib.HistPos; @@ -47,18 +41,14 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private TabLayoutActivity parentTab; private GoogleMap googleMap; private Spinner spinnerVehicle; - private ImageView changeMapType, checkTraffic, slideLayoutImage; - private LinearLayout layoutTraffic, slidelayout, layoutVehicles; private Button displayButton; private Date startDate, endDate; private final Handler myHandler = new Handler(); private GoogleMapsInfoBubble infoBubble; - private ArrayList allVehicle = new ArrayList<>(); - private ArrayList allVehicleNames = new ArrayList<>(); - private ArrayAdapter adapter; - private boolean showVehicle = true; - private SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy"); + private final ArrayList allVehicle = new ArrayList<>(); + private final ArrayList allVehicleNames = new ArrayList<>(); + private final SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy"); @Override @@ -75,12 +65,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); - mapFragment.getMapAsync(this); + if (mapFragment != null) + mapFragment.getMapAsync(this); spinnerVehicle = findViewById(R.id.spinnerVehicle); getVehicles(); - adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames); + ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames); adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); spinnerVehicle.setAdapter(adapter); spinnerVehicle.setSelection(0); @@ -88,9 +79,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall changeMapType(); changeTraffic(); - slidelayout = findViewById(R.id.slidelayout); - slideLayoutImage = findViewById(R.id.slideLayoutImage); - layoutVehicles = findViewById(R.id.layoutBig); displayButton = findViewById(R.id.buttonDisplay); displayButton.setOnClickListener(view -> { googleMap.clear(); @@ -127,7 +115,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall } } - Polyline polyline1 = googleMap.addPolyline(polylineOptions); + googleMap.addPolyline(polylineOptions); if (latLng != null) googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14)); } @@ -138,7 +126,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall calendar.add(Calendar.DATE, -1); startDate = calendar.getTime(); - LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker); TextView textViewStartDate = findViewById(R.id.textViewStartDate); TextView textViewEndDate = findViewById(R.id.textViewEndDate); @@ -187,14 +174,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall } private void changeMapType() { - changeMapType = findViewById(R.id.changeMapType); - ImageView changeMapTypeImageView = findViewById(R.id.changeMapType); + ImageView changeMapType = findViewById(R.id.changeMapType); changeMapType.setOnClickListener(view -> { if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) { - changeMapTypeImageView.setImageResource(R.drawable.satellite); + changeMapType.setImageResource(R.drawable.satellite); googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); } else { - changeMapTypeImageView.setImageResource(R.drawable.map); + changeMapType.setImageResource(R.drawable.map); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); } }); @@ -202,11 +188,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall public void getVehicles() { try { + allVehicle.clear(); + allVehicleNames.clear(); for (Vehicle vehicle : parentTab.getAllVehicle()) { allVehicleNames.add(vehicle.name); allVehicle.add(vehicle); } - } catch (Exception ex) { } + } catch (Exception ignored) { } } From 0b887deb99c248e79d9a02d9f52ed615cd7d3a26 Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Mon, 21 Mar 2022 12:19:23 +0200 Subject: [PATCH 08/11] remove marker icon --- .../java/com/safemobile/dispatch/HistoryActivity.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index 46276d2..be33cae 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -20,6 +20,8 @@ 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.BitmapDescriptor; +import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.PolylineOptions; @@ -103,15 +105,17 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private void displayHistory(ArrayList positions) { LatLng latLng = null; PolylineOptions polylineOptions = new PolylineOptions(); +// BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.arrow_right); for (int i = 0; i < positions.size(); i++) { HistPos pos = positions.get(i); if (pos.speed > 0) { latLng = new LatLng(pos.lat, pos.lng); polylineOptions.add(latLng); - googleMap.addMarker(new MarkerOptions() - .position(latLng) - .title(String.valueOf(i))); +// googleMap.addMarker(new MarkerOptions() +// .position(latLng) +// .icon(markerIcon) +// .title(String.valueOf(i))); } } From bca16caf94b525ec498568f4a48fb6a1bfea9cf9 Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Mon, 21 Mar 2022 13:01:04 +0200 Subject: [PATCH 09/11] new marker icon --- .../com/safemobile/dispatch/HistoryActivity.java | 10 +++++----- .../src/main/res/drawable-mdpi/history_pin.png | Bin 0 -> 1487 bytes 2 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 safeDispatch/src/main/res/drawable-mdpi/history_pin.png diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java index be33cae..e205be8 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/HistoryActivity.java @@ -105,17 +105,17 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall private void displayHistory(ArrayList positions) { LatLng latLng = null; PolylineOptions polylineOptions = new PolylineOptions(); -// BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.arrow_right); + BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.history_pin); for (int i = 0; i < positions.size(); i++) { HistPos pos = positions.get(i); if (pos.speed > 0) { latLng = new LatLng(pos.lat, pos.lng); polylineOptions.add(latLng); -// googleMap.addMarker(new MarkerOptions() -// .position(latLng) -// .icon(markerIcon) -// .title(String.valueOf(i))); + googleMap.addMarker(new MarkerOptions() + .position(latLng) + .icon(markerIcon) + .title(String.valueOf(i))); } } diff --git a/safeDispatch/src/main/res/drawable-mdpi/history_pin.png b/safeDispatch/src/main/res/drawable-mdpi/history_pin.png new file mode 100644 index 0000000000000000000000000000000000000000..646ee648591cd445e5b995b863902cd2127b862b GIT binary patch literal 1487 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|T2doC(|mmy zw18|523AHP24;{FAY@>aVqgWc85q16rQz%#Mh&PMCI*J~Oa>OHnkXO*0vxV%QuQiw3qZOUY$~jP%-qzHM1_jnoV;SI3R@+x3M(KRB&@Hb09I0xZL1XF8=&Bv zUzDm~re~mMpk&9TprBw=l#*r@P?Wt5Z@Sn2DRmzV368|&p4rRy77T3YHG z80i}s=>k>g7FXt#Bv$C=6)QswftllyTAW;zSx}OhpQivaH!&%{w8U0P31kr*K-^i9 znTD__uNdkrpa=CqGWv#k2KsQbfm&@qqE`MznW;dVLFU^T+JIG}h(YbK(Fa+MJ#~w{jl|tQ}myp%C60q?rFAFMrFmj)q(|5?VHmtUfshlo2f9JMaV=m z$i|X=&na<(AEgs^O+T5u(YLgqe#(J{=M1lqYft2vi#xNY zZ#13UA}w>c`)2!*A1&NdcojtwUW$FTY5jaVZ^81d9v@6(1phbZMCl8t&(%n}=AHcD ztFeu4=|!(uM<#8OD3G?jS$yO4r}IDi;+Ap!|HvV+Ah~tM*UJ&lrxli5u8aDzN|agr zf7`CYj=Ps0RLpq(bge=~vImd%X^Z!_Z`|X^DfC;_v$fNx!-PLe+wJZqsUIhzCfKNK zxW;HzJoitQfaBKYvNg%`kH1y55A$_Q$X3%``E^TbeYo|BTkEdv4cZj?cy;5GcM(3# zHz#OGK55RJV&Oeic;fm#ow#jZ{O)Ogh!lC8wPU)~RHKFeC%4|X5q7|l<(T*TA77P= z0(PDg+%re>#gE(5*0fHY>=Wd`zwYfr>+&lF{~Dz>?_Om*fWgb$A#CK*@89DMsx$t#X6TPStzg^Y8d`=2?lQJs;qsiVBo-~{75 zkIpGtk}man$ve#NwzJ1uzUXl~7Jsc_$^JP!8_xJ{jy`ZaNi6&xU*KB%u&E22H@|7< z?vCtv73Nb|Sh^%uwtm-zt)i=x+YX&B(dmyo_j!A_`A-qOy^@E_nW)LeE#Pg}4!QB@ZY59NqB%$Y>f5cW+tG9L0nc03n5JoIp+;NH z?|-^>n>yQ68(S@@oOTWq?uk#CZQ&Y6TYU*!6?Mz0G#ekFz}hNa&yYoE^D=iaW_ zKXy*M?pb#(f5S=z#lueTlR%}Kr>mdKI;Vst0G@J0 A)&Kwi literal 0 HcmV?d00001 From bbed107c427a8e8bbf1d8802c94d1e296369bcde Mon Sep 17 00:00:00 2001 From: CiufudeanDani Date: Tue, 22 Mar 2022 12:11:08 +0200 Subject: [PATCH 10/11] get versionCode & name from tag --- safeDispatch/build.gradle | 16 ++++++++++++++++ safeDispatch/src/main/AndroidManifest.xml | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/safeDispatch/build.gradle b/safeDispatch/build.gradle index 216ff1d..fe3e81a 100644 --- a/safeDispatch/build.gradle +++ b/safeDispatch/build.gradle @@ -1,5 +1,19 @@ apply plugin: 'com.android.application' apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' +apply plugin: "com.gladed.androidgitversion" + +buildscript { + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + mavenCentral() + } + dependencies { + classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.3" + } +} + android { compileSdkVersion 31 @@ -9,6 +23,8 @@ android { applicationId "com.safemobile.dispatch" minSdkVersion 21 targetSdkVersion 31 + versionName androidGitVersion.name() + versionCode androidGitVersion.code() } buildTypes { diff --git a/safeDispatch/src/main/AndroidManifest.xml b/safeDispatch/src/main/AndroidManifest.xml index 6489df7..7e09470 100644 --- a/safeDispatch/src/main/AndroidManifest.xml +++ b/safeDispatch/src/main/AndroidManifest.xml @@ -1,9 +1,7 @@ + package="com.safemobile.dispatch"> Date: Tue, 22 Mar 2022 15:10:29 +0200 Subject: [PATCH 11/11] edit apk name --- gradlew | 0 safeDispatch/build.gradle | 6 ++++++ 2 files changed, 6 insertions(+) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/safeDispatch/build.gradle b/safeDispatch/build.gradle index fe3e81a..1df4422 100644 --- a/safeDispatch/build.gradle +++ b/safeDispatch/build.gradle @@ -14,6 +14,11 @@ buildscript { } } +androidGitVersion { + codeFormat 'MNNBBBB' + format '%tag%%.count%' + hideBranches = ['develop'] +} android { compileSdkVersion 31 @@ -25,6 +30,7 @@ android { targetSdkVersion 31 versionName androidGitVersion.name() versionCode androidGitVersion.code() + archivesBaseName = "SafeDispatchMobile_v.$versionName" } buildTypes {