diff --git a/libSafeMobile/src/main/java/com/safemobile/activities/AbstractLiveActivity.java b/libSafeMobile/src/main/java/com/safemobile/activities/AbstractLiveActivity.java
index 236b078..6ce3a62 100644
--- a/libSafeMobile/src/main/java/com/safemobile/activities/AbstractLiveActivity.java
+++ b/libSafeMobile/src/main/java/com/safemobile/activities/AbstractLiveActivity.java
@@ -25,6 +25,7 @@ public abstract class AbstractLiveActivity extends AppCompatActivity {
public abstract void vehicleStatusReceived(long imei, int opCode, int status); // --> UpdateOptions
public abstract void emergencyAlarmReceived(int position, double lat, double lng); // --> UpdateEmergencyAlarm
public abstract GoogleMap getMap(); // --> UpdateEmergencyAlarm
+ public abstract void setLanguage();
/** Misc */
public AbstractSDParentActivity getParentTab() {
diff --git a/libSafeMobile/src/main/java/com/safemobile/services/TCPService.java b/libSafeMobile/src/main/java/com/safemobile/services/TCPService.java
index e19c89d..52080cd 100644
--- a/libSafeMobile/src/main/java/com/safemobile/services/TCPService.java
+++ b/libSafeMobile/src/main/java/com/safemobile/services/TCPService.java
@@ -102,10 +102,8 @@ public class TCPService extends Service {
/** Stop TCP Connection */
- public void stopTCPConnection()
- {
- if(tcp != null)
- {
+ public void stopTCPConnection() {
+ if(tcp != null) {
tcp.Stop();
tcp = null;
}
diff --git a/libSafeMobile/src/main/java/com/safemobile/services/TCPhandler.java b/libSafeMobile/src/main/java/com/safemobile/services/TCPhandler.java
index 072dd7a..2d1e678 100644
--- a/libSafeMobile/src/main/java/com/safemobile/services/TCPhandler.java
+++ b/libSafeMobile/src/main/java/com/safemobile/services/TCPhandler.java
@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
+import android.util.Log;
import com.safemobile.lib.AppParams;
import com.safemobile.lib.SM;
@@ -24,6 +25,7 @@ import java.util.TimerTask;
public class TCPhandler implements Runnable {
+ private final String TAG = "TCPhandler";
private boolean alive = true;
public String serverHostname;
@@ -56,18 +58,22 @@ public class TCPhandler implements Runnable {
// create timer to check socket status
Timer timer = new Timer();
- timer.scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- try {
- previousConnectionWasUP = isConnectionUP;
- // try to send something
- TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
- } catch (Exception e) {
- SM.Exception("TIMERException", e.toString());
+ try {
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ previousConnectionWasUP = isConnectionUP;
+ // try to send something
+ TCPmsgParser._fireonTCPConnectionStatusEvent(isConnectionUP, previousConnectionWasUP);
+ } catch (Exception e) {
+ SM.Exception("TIMERException", e.toString());
+ }
}
- }
- }, 0, 3000);
+ }, 0, 3000);
+ } catch(Exception e) {
+ Log.v("Exception", e.getMessage());
+ }
// get WiFi state
isWiFiOn = isNetworkConnected();
@@ -104,6 +110,8 @@ public class TCPhandler implements Runnable {
SM.Debug("IllegalArgumentException", "TCPhandler break:"+ e);
} catch (IOException e) {
SM.Debug("IOException", "TCPhandler break:"+ e);
+ } catch (Exception e) {
+ Log.v("Exception", e.getMessage());
}
while (alive) {
@@ -111,6 +119,8 @@ public class TCPhandler implements Runnable {
Thread.sleep(3000);
} catch (InterruptedException e) {
SM.Debug("TCPhandler Crash1 on sleep:"+ e);
+ } catch (Exception e) {
+ Log.v("Exception", e.getMessage());
}
while (Boolean.TRUE.equals(isConnectionUP)) {
@@ -242,6 +252,8 @@ public class TCPhandler implements Runnable {
Thread.sleep(1000);
} catch (InterruptedException e) {
SM.Debug("TCPhandler Crash2 on sleep:"+ e);
+ } catch (Exception e) {
+ Log.v("Exception", e.getMessage());
}
//try to restart connection
if (alive && isWiFiOn)
@@ -350,6 +362,7 @@ public class TCPhandler implements Runnable {
if (soc != null)
soc.close();
} catch (IOException e1) {
+ Log.v("IOException", e1.getMessage());
e1.printStackTrace();
}
@@ -371,14 +384,15 @@ public class TCPhandler implements Runnable {
private void restartTCP() {
try {
+ Log.v(TAG, "restartTCP");
isConnectionUP = false;
previousConnectionWasUP = false;
SM.Debug("Restarting TCP...ip:" + serverHostname + ":" + port);
soc = new Socket();
- soc.connect(new InetSocketAddress(serverHostname, port), 5000);
-
+ soc.connect(new InetSocketAddress(serverHostname, port), 50000);
input = new DataInputStream(soc.getInputStream());
+
//output stream
output = new DataOutputStream(soc.getOutputStream());
@@ -386,17 +400,11 @@ public class TCPhandler implements Runnable {
isConnectionUP = true;
}
- } catch (UnknownHostException e) {
- SM.Exception("restartTCP break:" + e.toString());
+ } catch (NullPointerException | IOException e) {
+ SM.Exception("restartTCP break:" + e);
isConnectionUP = false;
} catch (IllegalArgumentException e) {
- SM.Debug("IllegalArgumentException", "restartTCP break:" + e.toString());
- } catch (IOException e) {
- SM.Exception("restartTCP break:" + e.toString());
- isConnectionUP = false;
- } catch (NullPointerException e) {
- SM.Exception("restartTCP break:" + e.toString());
- isConnectionUP = false;
+ SM.Debug("IllegalArgumentException", "restartTCP break:" + e);
}
triggerTCPConnectionStateEvent();
}
@@ -410,6 +418,7 @@ public class TCPhandler implements Runnable {
soc.close();
soc = null;
} catch (IOException e) {
+ Log.v("IOException", e.getMessage());
e.printStackTrace();
}
}
diff --git a/safeDispatch/src/main/AndroidManifest.xml b/safeDispatch/src/main/AndroidManifest.xml
index 23f0048..d91b7ed 100644
--- a/safeDispatch/src/main/AndroidManifest.xml
+++ b/safeDispatch/src/main/AndroidManifest.xml
@@ -7,6 +7,7 @@
android:glEsVersion="0x00020000"
android:required="true" />
+
diff --git a/safeDispatch/src/main/java/com/safemobile/lib/sound/TcpAudioClient.java b/safeDispatch/src/main/java/com/safemobile/lib/sound/TcpAudioClient.java
index 81d09f0..8344c36 100644
--- a/safeDispatch/src/main/java/com/safemobile/lib/sound/TcpAudioClient.java
+++ b/safeDispatch/src/main/java/com/safemobile/lib/sound/TcpAudioClient.java
@@ -107,7 +107,6 @@ public class TcpAudioClient implements Runnable {
recv = soc.getInputStream();
writer = soc.getOutputStream();
setConnOK(true);
-
} catch (IOException e) {
SM.Debug("break:" + e);
}
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/AlarmActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/AlarmActivity.java
index 4585b00..b40f29f 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/AlarmActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/AlarmActivity.java
@@ -66,6 +66,7 @@ public class AlarmActivity extends Activity {
setContentView(R.layout.tabalarm);
gridView = findViewById(R.id.gridViewAlarms);
+ gridView.setNestedScrollingEnabled(true);
adapter = new AlertGridViewAdapter(this, getAllAlarms(), context, acknowledged);
gridView.setAdapter(adapter);
@@ -171,7 +172,10 @@ public class AlarmActivity extends Activity {
if (param.equals(ALARM)) {
// set adapter
adapter = new AlertGridViewAdapter(this, getAllAlarms(), context, acknowledged);
+ int position = gridView.getFirstVisiblePosition();
+
gridView.setAdapter(adapter);
+ gridView.setSelection(position);
} else {
adapter.changeACK(ackPosition);
SM.Debug("Set ACK: " + ackPosition + " | " + (Boolean.TRUE.equals(acknowledged.get(ackPosition)) ? "true" : "false"));
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/HistoryActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/HistoryActivity.java
index e3b786a..c78c949 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/HistoryActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/HistoryActivity.java
@@ -132,6 +132,17 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
setDate();
}
+ public void setLanguage() {
+ TextView labelVehicle = findViewById(R.id.labelVehicle);
+ TextView labelStartDate = findViewById(R.id.labelStartDate);
+ TextView labelEndDate = findViewById(R.id.labelEndDate);
+
+ labelVehicle.setText(R.string.vehicle);
+ labelStartDate.setText(R.string.startDate);
+ labelEndDate.setText(R.string.endDate);
+ displayButton.setText(R.string.display);
+ }
+
private void displayHistory(ArrayList positions) {
LatLng latLng = null;
PolylineOptions polylineOptions = new PolylineOptions();
@@ -168,8 +179,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
private void setDate() {
Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.DATE, 1);
endDate = calendar.getTime();
- calendar.add(Calendar.DATE, -1);
+ calendar.add(Calendar.DATE, -2);
startDate = calendar.getTime();
TextView textViewStartDate = findViewById(R.id.textViewStartDate);
@@ -279,6 +291,5 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
this.googleMap.getUiSettings().setMapToolbarEnabled(false);
parentTab.demoPositionsList();
- displayButton.performClick();
}
}
\ No newline at end of file
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/LiveActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/LiveActivity.java
index 0daa7c7..111066a 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/LiveActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/LiveActivity.java
@@ -296,6 +296,11 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
registerBroadcastIntents();
}
+ public void setLanguage() {
+ TextView textView = findViewById(R.id.unit_name);
+ textView.setText(R.string.unitName);
+ }
+
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
@@ -444,12 +449,6 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
public void displayVehicle(double latZoom, double lngZoom) {
if (googleMap != null) {
- String openWindow = "";
- for (Marker marker : markers) {
- if (marker.isInfoWindowShown()) {
- openWindow = marker.getTitle();
- }
- }
googleMap.clear();
for (int i = 0; i < displayedVehicles.size(); i++) {
@@ -464,7 +463,8 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
markerOptions.icon(markerIcon);
Marker marker = this.googleMap.addMarker(markerOptions);
- if (openWindow.equals(marker.getTitle()) || i == lastItemClicked) {
+
+ if (i == lastItemClicked) {
marker.showInfoWindow();
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newLocation, 14));
}
@@ -474,7 +474,6 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
}
}
}
- lastItemClicked = 0;
}
private BitmapDescriptor getProperBitmap(int largeIcon, String text) {
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/MessagesActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/MessagesActivity.java
index 952c7e6..b4331b3 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/MessagesActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/MessagesActivity.java
@@ -10,6 +10,7 @@ import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
@@ -45,6 +46,7 @@ public class MessagesActivity extends Activity {
/**
* Called when the activity is first created.
*/
+ private final String TAG = "MessagesActivity";
private MessagesGridViewAdapter mAdapter;
private ConversationGridViewAdapter convAdapter;
@@ -138,6 +140,7 @@ public class MessagesActivity extends Activity {
// Implement On Item click listener
gridView.setOnItemClickListener((arg0, arg1, position, arg3) -> {
+ Log.v(TAG, "onItemClick " + LASTMESSAGES);
if (LASTMESSAGES) {
// get position
Msg item = mAdapter.getItem(position);
@@ -196,6 +199,7 @@ public class MessagesActivity extends Activity {
imageButtonBack.setOnClickListener(v -> {
// set LastMessage conversation type
LASTMESSAGES = true;
+ Log.v(TAG, "lastmessages: true");
// refresh Grid
getLastSMS();
if (AppParams.DEMO)
@@ -388,6 +392,7 @@ public class MessagesActivity extends Activity {
listLastMessages.add(new Msg(sentVehicle, txt, Calendar.getInstance().getTime(), sendSMSSeqID));
}
SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime());
+ Log.v(TAG, "lastmessages: false");
LASTMESSAGES = false;
updateResultsInUi();
@@ -627,6 +632,7 @@ public class MessagesActivity extends Activity {
setScId(item.sc_id);
SM.Debug("Selected scId: " + getScId());
// set Conversation type
+ Log.v(TAG, "lastmessages: false");
LASTMESSAGES = false;
// call get SMS
getSMS4unit(getScId());
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java
index 8dcf236..e30077c 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/RadioActivity.java
@@ -2,10 +2,8 @@ package com.safemobile.safedispatch;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
@@ -34,7 +32,6 @@ import com.safemobile.lib.radio.Zone_and_channel;
import com.safemobile.lib.sound.AudioHandle;
import java.util.ArrayList;
-import java.util.Hashtable;
import java.util.Locale;
/**
@@ -64,16 +61,15 @@ public class RadioActivity extends Activity {
private int callstatus = 0;
/* Lists */
- private ArrayList allVehicleNames = new ArrayList();
- public ArrayList allVehicle = new ArrayList();
+ private ArrayList allVehicleNames = new ArrayList<>();
+ public ArrayList allVehicle = new ArrayList<>();
- private ArrayList allContactsIDs = new ArrayList();
- private ArrayList allGroupsIDs = new ArrayList();
- private ArrayList allGroupsNames = new ArrayList();
+ private final ArrayList allGroupsIDs = new ArrayList<>();
+ private final ArrayList allGroupsNames = new ArrayList<>();
- private ArrayList crtZones = new ArrayList();
- private ArrayList crtChannels = new ArrayList();
- private ArrayList allGWsIP = new ArrayList();
+ private ArrayList crtZones = new ArrayList<>();
+ private ArrayList crtChannels = new ArrayList<>();
+ private final ArrayList allGWsIP = new ArrayList<>();
private ArrayAdapter adapter;
// Need handler for callbacks to the UI thread
@@ -85,10 +81,10 @@ public class RadioActivity extends Activity {
private AudioHandle audioH = null;
private final int ALLCall = 101, PRIVATECall = 102, GROUPCall = 103;
private int selectedID=0, selectedCallType = 101;
- private Boolean pttONoff = false, FIRST = true;
+ private Boolean pttONoff = false;
private final int inCall = 1, hangTime = 2, callEnd = 3;
- public Bundle savedInstanceState;
+ private Bundle savedInstanceState;
/** Called when the activity is first created. */
@@ -116,56 +112,55 @@ public class RadioActivity extends Activity {
allGroupsIDs.add(1);
allGroupsIDs.add(2);
-
//====================
// get visual elements
//====================
// get buttons
- buttonPTT = (Button) findViewById(R.id.buttonPTT);
- buttonDKey = (Button) findViewById(R.id.buttonDKey);
+ buttonPTT = findViewById(R.id.buttonPTT);
+ buttonDKey = findViewById(R.id.buttonDKey);
// get CallType Spinner
- layoutSpinnerCallType = (LinearLayout) findViewById(R.id.layoutSpinnerCallType);
+ layoutSpinnerCallType = findViewById(R.id.layoutSpinnerCallType);
layoutSpinnerCallType.setOnClickListener(CallTypeListener);
- textViewCallType = (TextView) findViewById(R.id.textViewCallType);
+ textViewCallType = findViewById(R.id.textViewCallType);
// get status dot
- imageViewStatus = (ImageView) findViewById(R.id.imageViewStatus);
+ imageViewStatus = findViewById(R.id.imageViewStatus);
- layoutSpinnerChannel = (LinearLayout) findViewById(R.id.layoutSpinnerChannel);
+ layoutSpinnerChannel = findViewById(R.id.layoutSpinnerChannel);
layoutSpinnerChannel.setOnClickListener(ChannelChangeListener);
- layoutSpinnerZone = (LinearLayout) findViewById(R.id.layoutSpinnerZone);
+ layoutSpinnerZone = findViewById(R.id.layoutSpinnerZone);
layoutSpinnerZone.setOnClickListener(ZoneChangeListener);
// get TextView from Spinner
- textViewChannel = (TextView) findViewById(R.id.textViewChannel);
- textViewZone = (TextView) findViewById(R.id.textViewZone);
+ textViewChannel = findViewById(R.id.textViewChannel);
+ textViewZone = findViewById(R.id.textViewZone);
// get IP
- textViewIP = (TextView) findViewById(R.id.textViewIP);
+ textViewIP = findViewById(R.id.textViewIP);
textViewIP.setText(AppParams.IP);
// get CallType
- radioGroupCallType = (RadioGroup) findViewById(R.id.radioGroupCallType);
+ radioGroupCallType = findViewById(R.id.radioGroupCallType);
radioGroupCallType.setOnCheckedChangeListener(CallTypeChanged);
// get radio buttons
- radioAll = (RadioButton) findViewById(R.id.radioAll);
- radioGroup = (RadioButton) findViewById(R.id.radioGroup);
- radioPrivate = (RadioButton) findViewById(R.id.radioPrivate);
+ radioAll = findViewById(R.id.radioAll);
+ radioGroup = findViewById(R.id.radioGroup);
+ radioPrivate = findViewById(R.id.radioPrivate);
// get channel
- textViewMessageChannel = (TextView) findViewById(R.id.textViewMessageChannel);
+ textViewMessageChannel = findViewById(R.id.textViewMessageChannel);
// get gateway
- textViewGateway = (TextView) findViewById(R.id.textViewGateway);
+ textViewGateway = findViewById(R.id.textViewGateway);
textViewGateway.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
textViewGateway.setTextSize(24);
// get status
- textViewMessageStatus = (TextView) findViewById(R.id.textViewMessageStatus);
- layoutGateway = (LinearLayout) findViewById(R.id.layoutGateway);
+ textViewMessageStatus = findViewById(R.id.textViewMessageStatus);
+ layoutGateway = findViewById(R.id.layoutGateway);
layoutGateway.setOnClickListener(GatwayListener);
// set button ptt listener
@@ -173,7 +168,6 @@ public class RadioActivity extends Activity {
// set button DKey listener
buttonDKey.setOnClickListener(DKeyClickListener);
-
startAudioThread();
if(!AppParams.DEMO)
@@ -187,128 +181,87 @@ public class RadioActivity extends Activity {
registerBroadcastIntents();
}
- private void startAudioThread()
- {
- audioThread = new Thread(new Runnable() {
+ public Bundle getSavedInstanceState() {
+ return savedInstanceState;
+ }
- @Override
- public void run() {
- //start audio
- try{
- if(audioH == null && !AppParams.IP.equalsIgnoreCase("n/a"))
- audioH = new AudioHandle(AppParams.IP,0);
- }
- catch(Exception ex)
- {
- SM.Exception("#### audioH exception! ####");
- SM.Exception(ex.toString());
- }
+ private void startAudioThread() {
+ audioThread = new Thread(() -> {
+ //start audio
+ try {
+ if (audioH == null && !AppParams.IP.equalsIgnoreCase("n/a"))
+ audioH = new AudioHandle(AppParams.IP,0);
+ } catch(Exception ex) {
+ SM.Exception("#### audioH exception! ####");
+ SM.Exception(ex.toString());
}
});
audioThread.start();
-
}
@Override
- public void onBackPressed()
- {
+ public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.exit))
.setCancelable(false)
- .setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- parentTab.whenBackPressed(AppParams.ActivityResult.logout);
- }
- })
- .setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- parentTab.whenBackPressed(AppParams.ActivityResult.exit);
- }
- })
- .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
+ .setNeutralButton(getString(R.string.logout), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.logout))
+ .setPositiveButton(getString(R.string.ext), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.exit))
+ .setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
AlertDialog alert = builder.create();
alert.show();
}
-
@Override
- public void onPause()
- {
+ public void onPause() {
super.onPause();
SM.Debug("onPause");
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
// get all vehicles from TabLayoutActivity
- if(!allVehicle.equals(parentTab.getAllVehicle()))
- {
+ if (!allVehicle.equals(parentTab.getAllVehicle())) {
allVehicle = parentTab.getAllVehicle();
UpdateVehicle();
-
}
- if(AppParams.listRadios.size() == 0)
+ if (AppParams.listRadios.size() == 0)
GetGWRadios();
SM.Debug("onResume");
}
- private OnClickListener GatwayListener = new OnClickListener() {
-
+ private final OnClickListener GatwayListener = new OnClickListener() {
@Override
public void onClick(View v) {
- adapter = new ArrayAdapter(
+ adapter = new ArrayAdapter<>(
context, R.layout.template_simple_list_item,
allGWsIP);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select RadioGW");
builder.setAdapter(adapter,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // change gateway
- //textViewGateway.setText(allGWsIP.get(which));
- // change visual if selected another radioGW
+ (dialog, which) -> {
+ // change gateway
+ //textViewGateway.setText(allGWsIP.get(which));
+ // change visual if selected another radioGW
- radioGWChanged(allGWsIP.get(which));
-
- }
+ radioGWChanged(allGWsIP.get(which));
});
AlertDialog alert = builder.create();
alert.show();
}
};
-
- private OnClickListener PTTClickListener = new OnClickListener() {
- @Override
-
- public void onClick(View v) {
-
- if (pttONoff)
- pttOffClick();
- else
- pttOnClick();
- }
+ private final OnClickListener PTTClickListener = v -> {
+ if (pttONoff)
+ pttOffClick();
+ else
+ pttOnClick();
};
- final Runnable UpdatepttOffClickRUN = new Runnable() {
- public void run() {
- pttOffClick();
- }
- };
-
-
- private void pttOnClick()
- {
+ private void pttOnClick() {
//================
// get selectedID
//================
@@ -352,12 +305,10 @@ public class RadioActivity extends Activity {
//===================
UpdateEnableDisableButtons("disablePTT");
parentTab.enableMenuButtons(false);
-
}
- private void pttOffClick()
- {
- String chanMsg = "", statMsg = "";
+ private void pttOffClick() {
+ String chanMsg, statMsg = "";
// send stop the call
if(parentTab.getCrtRadio() != null)
@@ -368,11 +319,9 @@ public class RadioActivity extends Activity {
if(audioH != null)
audioH.soundNeeded = false;
-
buttonPTT.setText(getString(R.string.PTT));
buttonPTT.setBackgroundResource(R.drawable.style_buttonptt);
-
chanMsg = textViewChannel.getText().toString();
textViewMessageChannel.setText(chanMsg);
textViewMessageStatus.setText(statMsg);
@@ -383,45 +332,32 @@ public class RadioActivity extends Activity {
// enable buttons
UpdateEnableDisableButtons("enable");
parentTab.enableMenuButtons(true);
-
}
- private OnClickListener DKeyClickListener = new OnClickListener() {
- @Override
- public void onClick(View v)
- {
- SendDekey();
- }
- };
-
- private OnClickListener ChannelChangeListener = new OnClickListener() {
+ private final OnClickListener DKeyClickListener = v -> SendDekey();
+ private final OnClickListener ChannelChangeListener = new OnClickListener() {
@Override
public void onClick(View v) {
-
- if(parentTab.getCrtRadio() != null)
- {
+ if (parentTab.getCrtRadio() != null) {
// display dialog with adapter
- ArrayList tmp = new ArrayList();
+ ArrayList tmp = new ArrayList<>();
for(Channel ch: crtChannels)
tmp.add(ch.chName);
- ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp);
+ ArrayAdapter adapter = new ArrayAdapter<>(activity, R.layout.template_simple_list_item, tmp);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(getString(R.string.selChannel));
- builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // change Channel in Display
- //textViewMessageChannel.setText(crtChannels.get(which).chName);
+ builder.setAdapter(adapter , (dialog, which) -> {
+ // change Channel in Display
+ //textViewMessageChannel.setText(crtChannels.get(which).chName);
- // set channel name
- //textViewChannel.setText(crtChannels.get(which).chName);
+ // set channel name
+ //textViewChannel.setText(crtChannels.get(which).chName);
- // send change to App
- onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(textViewZone.getText().toString()), getNR4CH(crtChannels.get(which).chName));
- }
+ // send change to App
+ onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(textViewZone.getText().toString()), getNR4CH(crtChannels.get(which).chName));
});
AlertDialog alert = builder.create();
@@ -430,70 +366,51 @@ public class RadioActivity extends Activity {
}
};
- private OnClickListener ZoneChangeListener = new OnClickListener() {
-
+ private final OnClickListener ZoneChangeListener = new OnClickListener() {
@Override
public void onClick(View v) {
-
- if(parentTab.getCrtRadio() !=null)
- {
+ if (parentTab.getCrtRadio() !=null) {
// display dialog with adapter
- ArrayList tmp = new ArrayList();
+ ArrayList tmp = new ArrayList<>();
for(Zone zone: crtZones)
tmp.add(zone.ZoneName);
- ArrayAdapter adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, tmp);
+ ArrayAdapter adapter = new ArrayAdapter<>(activity, R.layout.template_simple_list_item, tmp);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(getString(R.string.selZone));
- builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // set zone name
- //textViewZone.setText(crtZones.get(which).ZoneName);
-
- // send change to App
- //onZoneCHChange(parentTab.crtRadio.ID, parentTab.crtRadio.GW_ID, getNR4Zone(crtZones.get(which).ZoneName), getNR4CH(textViewChannel.getText().toString()));
- onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1);
- }
+ builder.setAdapter(adapter , (dialog, which) -> {
+ // send change to App
+ onZoneCHChange(parentTab.getCrtRadio().ID, parentTab.getCrtRadio().GW_ID, getNR4Zone(crtZones.get(which).ZoneName), 1);
});
AlertDialog alert = builder.create();
alert.show();
}
-
}
};
- private OnClickListener CallTypeListener = new OnClickListener() {
-
+ private final OnClickListener CallTypeListener = new OnClickListener() {
@Override
public void onClick(View v) {
-
-
- if(parentTab.getCrtRadio() != null)
- {
+ if (parentTab.getCrtRadio() != null) {
// create spinner selected
AlertDialog.Builder builder = new AlertDialog.Builder(context);
- switch(radioGroupCallType.getCheckedRadioButtonId())
- {
- case R.id.radioGroup :
- // set adapter and title
- adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allGroupsNames);
- builder.setTitle(getString(R.string.selectGroup));
- break;
- case R.id.radioPrivate :
- // set adapter and title
- adapter = new ArrayAdapter(activity, R.layout.template_simple_list_item, allVehicleNames);
- builder.setTitle(getString(R.string.selectVehicle));
- break;
+ switch(radioGroupCallType.getCheckedRadioButtonId()) {
+ case R.id.radioGroup :
+ // set adapter and title
+ adapter = new ArrayAdapter<>(activity, R.layout.template_simple_list_item, allGroupsNames);
+ builder.setTitle(getString(R.string.selectGroup));
+ break;
+ case R.id.radioPrivate :
+ // set adapter and title
+ adapter = new ArrayAdapter<>(activity, R.layout.template_simple_list_item, allVehicleNames);
+ builder.setTitle(getString(R.string.selectVehicle));
+ break;
}
- builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch(radioGroupCallType.getCheckedRadioButtonId())
- {
+ builder.setAdapter(adapter , (dialog, which) -> {
+ switch(radioGroupCallType.getCheckedRadioButtonId()) {
case R.id.radioGroup :
// set adapter and title
textViewCallType.setText(allGroupsNames.get(which));
@@ -501,66 +418,43 @@ public class RadioActivity extends Activity {
case R.id.radioPrivate :
textViewCallType.setText(allVehicleNames.get(which));
break;
- }
}
});
AlertDialog alert = builder.create();
alert.show();
}
-
}
};
- private OnCheckedChangeListener CallTypeChanged = new OnCheckedChangeListener() {
-
+ private final OnCheckedChangeListener CallTypeChanged = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
- switch(radioGroupCallType.getCheckedRadioButtonId())
- {
- case R.id.radioAll :
- layoutSpinnerCallType.setVisibility(View.INVISIBLE);
- selectedCallType = ALLCall;
- break;
- case R.id.radioGroup :
- layoutSpinnerCallType.setVisibility(View.VISIBLE);
- textViewCallType.setText(allGroupsNames.get(0));
- selectedCallType = GROUPCall;
- break;
- case R.id.radioPrivate :
+ switch(radioGroupCallType.getCheckedRadioButtonId()) {
+ case R.id.radioAll :
+ layoutSpinnerCallType.setVisibility(View.INVISIBLE);
+ selectedCallType = ALLCall;
+ break;
+ case R.id.radioGroup :
+ layoutSpinnerCallType.setVisibility(View.VISIBLE);
+ textViewCallType.setText(allGroupsNames.get(0));
+ selectedCallType = GROUPCall;
+ break;
+ case R.id.radioPrivate :
+ layoutSpinnerCallType.setVisibility(View.VISIBLE);
+ if (allVehicleNames.size() > 0)
+ textViewCallType.setText(allVehicleNames.get(0));
+ else
+ textViewCallType.setText("");
- layoutSpinnerCallType.setVisibility(View.VISIBLE);
- if(allVehicleNames.size() > 0)
- textViewCallType.setText(allVehicleNames.get(0));
- else
- textViewCallType.setText("");
-
- selectedCallType = PRIVATECall;
- break;
+ selectedCallType = PRIVATECall;
+ break;
}
}
};
-
- public void showDialog(String errorMsg)
- {
- Dialog dialog = new Dialog(context);
- dialog.setContentView(R.layout.dialog);
- dialog.setTitle(getString(R.string.message));
- dialog.setCancelable(true);
- dialog.setCanceledOnTouchOutside(true);
-
- TextView text = dialog.findViewById(R.id.text);
- ImageView image = dialog.findViewById(R.id.image);
-
- image.setImageResource(R.mipmap.ic_launcher);
- text.setText(errorMsg);
- dialog.show();
- }
-
// called from ParentTabActivity
- public void UpdateRadios(ArrayList radios)
- {
+ public void UpdateRadios(ArrayList radios) {
// save radios
AppParams.listRadios = radios;
if(parentTab.getCrtRadio() == null)
@@ -583,18 +477,13 @@ public class RadioActivity extends Activity {
// Create runnable for posting
- final Runnable updateGatewaysRUN = new Runnable() {
- public void run() {
- updateGateways();
- }
- };
+ final Runnable updateGatewaysRUN = this::updateGateways;
- public void updateGateways()
- {
+ public void updateGateways() {
// get all radio IP
allGWsIP.clear();
- for(RadioGW radio: AppParams.listRadios)
+ for (RadioGW radio: AppParams.listRadios)
allGWsIP.add(radio.IP);
textViewGateway.setText(parentTab.getCrtRadio().IP);
@@ -602,19 +491,15 @@ public class RadioActivity extends Activity {
// modify privateCall Adapter after resume if Vehicle List Modified
- public void UpdateVehicle()
- {
-
- allVehicleNames = new ArrayList();
- if( allVehicle!=null )
+ public void UpdateVehicle() {
+ allVehicleNames = new ArrayList<>();
+ if (allVehicle!=null)
for(Vehicle vehicle: allVehicle)
allVehicleNames.add(vehicle.name);
-
}
- private RadioGW getRadioGW(int _radioID, int _gwID)
- {
- for(RadioGW radio: AppParams.listRadios) {
+ private RadioGW getRadioGW(int _radioID, int _gwID) {
+ for (RadioGW radio: AppParams.listRadios) {
if (radio.GW_ID == _gwID && radio.ID == _radioID)
return radio;
}
@@ -622,20 +507,17 @@ public class RadioActivity extends Activity {
return null;
}
- private ArrayList getChannels(int zoneNR)
- {
+ private ArrayList getChannels(int zoneNR) {
for(Zone zone : parentTab.getCrtRadio().zoneList) {
if (zone.id == zoneNR)
return zone.channelList;
}
- return new ArrayList();
+ return new ArrayList<>();
}
// called from ParentTabActivity to set radioID, GWID, zoneNR and chNR
- public void UpdateZoneCH(int _radioID, int _gwID, int _zoneNR, int _chNR)
- {
- boolean cmdForMe =false;
+ public void UpdateZoneCH(int _radioID, int _gwID, int _zoneNR, int _chNR) {
// save received id's zoneNr and CHNR
this.radioID = _radioID;
this.GWID = _gwID;
@@ -646,9 +528,8 @@ public class RadioActivity extends Activity {
// get RadioGw
RadioGW radioGW = getRadioGW(_radioID, _gwID);
- if( radioGW == null) {
+ if (radioGW == null)
return;
- }
// set current radio
parentTab.setCrtRadio(radioGW);
@@ -658,93 +539,74 @@ public class RadioActivity extends Activity {
crtChannels = getChannels(_zoneNR);
myHandler.post(UpdateResultsZoneChannelRUN);
-
}
// Create runnable for posting
- final Runnable UpdateResultsZoneChannelRUN = new Runnable() {
- public void run() {
- updateResultsInUi();
- }
- };
+ final Runnable UpdateResultsZoneChannelRUN = this::updateResultsInUi;
- private void updateResultsInUi()
- {
-
- if(AppParams.listRadios.size() > 0)
- {
+ private void updateResultsInUi() {
+ if (AppParams.listRadios.size() > 0) {
textViewGateway.setText(parentTab.getCrtRadio().IP);
// get all radio IP
allGWsIP.clear();
- for(RadioGW radio: AppParams.listRadios)
+ for (RadioGW radio: AppParams.listRadios)
allGWsIP.add(radio.IP);
// set spinners and text
- if(parentTab.getCrtRadio() == null)
- {
+ if (parentTab.getCrtRadio() == null) {
parentTab.setCrtRadio(AppParams.listRadios.get(0));
textViewGateway.setText(allGWsIP.get(0));
// set zone
- ArrayList zones = new ArrayList();
+ ArrayList zones = new ArrayList<>();
crtZones = parentTab.getCrtRadio().zoneList;
for(Zone zone: crtZones)
zones.add(zone.ZoneName);
- textViewZone.setText(zones.get(0).toString());
- //spinnerZone.setAdapter(new ArrayAdapter(context, R.layout.template_simple_list_item, zones));
- //spinnerZone.setSelection(0);
+ textViewZone.setText(zones.get(0));
// set channel
- ArrayList channel = new ArrayList();
+ ArrayList channel = new ArrayList<>();
crtChannels = parentTab.getCrtRadio().zoneList.get(0).channelList;
for(Channel ch: crtChannels)
channel.add(ch.chName);
- textViewChannel.setText(channel.get(0).toString());
-
- //spinnerChannel.setAdapter(new ArrayAdapter(context, R.layout.template_simple_list_item, channel));
- //if(spinnerChannel.getSelectedItemPosition() !=0)
- // spinnerChannel.setSelection(0);
- }
- else
- {
- for(RadioGW radio: AppParams.listRadios)
- if(radio.ID == radioID && radio.GW_ID == GWID)
+ textViewChannel.setText(channel.get(0));
+ } else {
+ for (RadioGW radio: AppParams.listRadios)
+ if (radio.ID == radioID && radio.GW_ID == GWID)
parentTab.setCrtRadio(radio);
// get zones for adapter
- ArrayList zones = new ArrayList();
+ ArrayList zones = new ArrayList<>();
crtZones = parentTab.getCrtRadio().zoneList;
int position = 0;
// get selected Zone
- for(int i=0; i< crtZones.size(); i++)
- {
+ for (int i=0; i< crtZones.size(); i++) {
Zone zone = crtZones.get(i);
zones.add(zone.ZoneName);
- if(zone.id == zoneNR)
+ if (zone.id == zoneNR)
position = i; // save crt position in array
}
- textViewZone.setText(zones.get(position).toString());
+ textViewZone.setText(zones.get(position));
// set channel
- ArrayList channel = new ArrayList();
+ ArrayList channel = new ArrayList<>();
crtChannels = parentTab.getCrtRadio().zoneList.get(position).channelList;
// get current channel
position = 0;
- for(int i=0; i< crtChannels.size(); i++)
- {
+ for (int i=0; i< crtChannels.size(); i++) {
Channel ch = crtChannels.get(i);
channel.add(ch.chName);
if(ch.id == chNR)
position = i;
}
- textViewChannel.setText(channel.get(position).toString());
- textViewMessageChannel.setText(channel.get(position).toString());
+ textViewChannel.setText(channel.get(position));
+ textViewMessageChannel.setText(channel.get(position));
}
UpdateEnableDisableButtons("online");
imageViewStatus.setImageResource(R.drawable.status_online);
@@ -752,13 +614,10 @@ public class RadioActivity extends Activity {
}
// Radio Gateway changed from UI
- private void radioGWChanged(String newIP)
- {
-
+ private void radioGWChanged(String newIP) {
// get gateway id
- for(RadioGW radio:AppParams.listRadios)
- if(radio.IP.equals(newIP))
- {
+ for (RadioGW radio:AppParams.listRadios)
+ if (radio.IP.equals(newIP)) {
UpdateEnableDisableButtons("offline");
onZoneCHChange(radio.ID, radio.GW_ID,0,0); // get zone and channel for crt radio
parentTab.setCrtRadio(radio);
@@ -771,90 +630,68 @@ public class RadioActivity extends Activity {
ClearSpinners();
// reset adapter for spinners
ResetAdaptersForSpinners();
-
}
- private void ClearSpinners()
- {
+ private void ClearSpinners() {
textViewZone.setText("");
textViewChannel.setText("");
textViewMessageChannel.setText("");
}
- private void ResetAdaptersForSpinners()
- {
- crtChannels = new ArrayList();
- crtZones = new ArrayList();
+ private void ResetAdaptersForSpinners() {
+ crtChannels = new ArrayList<>();
+ crtZones = new ArrayList<>();
}
- private void SetCheck(RadioButton radioButton)
- {
+ private void SetCheck(RadioButton radioButton) {
radioPrivate.setChecked(radioPrivate == radioButton );
radioGroup.setChecked(radioGroup == radioButton );
radioAll.setChecked(radioAll == radioButton );
-
}
// broadcastCall from ParentTabActivity to set radio status
- public void UpdateBroadcastCall(long Imei,int Calltype,int GroupID,int CallStatus)
- {
- // save received id's zoneNr and CHNR
- SM.Debug("Status: Imei: " + Imei+ " Calltype: "+Calltype+ " GroupID: "+GroupID+" CallStatus:"+CallStatus);
- this.imei = Imei;
- this.calltype = Calltype;
- this.groupid = GroupID;
- this.callstatus = CallStatus;
+ public void UpdateBroadcastCall(long Imei,int Calltype,int GroupID,int CallStatus) {
+ // save received id's zoneNr and CHNR
+ SM.Debug("Status: Imei: " + Imei+ " Calltype: "+Calltype+ " GroupID: "+GroupID+" CallStatus:"+CallStatus);
+ this.imei = Imei;
+ this.calltype = Calltype;
+ this.groupid = GroupID;
+ this.callstatus = CallStatus;
- myHandler.post(UpdateB);
- }
+ myHandler.post(UpdateB);
+ }
- final Runnable UpdateB = new Runnable() {
- public void run() {
- UpdateResultsBroadcastCall();
- }
- };
+ final Runnable UpdateB = this::UpdateResultsBroadcastCall;
- private void UpdateResultsBroadcastCall()
- {
+ private void UpdateResultsBroadcastCall() {
SM.Debug("UpdateResultsBroadcastCall with Imei: " +imei+ " CallType:"+calltype+ " GroupID:"+groupid+" CallStatus:"+callstatus);
- if ((callstatus == inCall) || (callstatus== hangTime))
- {
+ if ((callstatus == inCall) || (callstatus== hangTime)) {
// modify UI only when call is received, not in hangtime
- if(callstatus == inCall)
- {
+ if (callstatus == inCall) {
layoutGateway.setEnabled(false);
String CallType = getString(R.string.AllCall);
- if (calltype == PRIVATECall )
- {
+ if (calltype == PRIVATECall) {
CallType = getString(R.string.PrivateCall);
SetCheck(radioPrivate);
selectedCallType = PRIVATECall;
-
- }
- else if (calltype == GROUPCall)
- {
+ } else if (calltype == GROUPCall) {
CallType = getString(R.string.GroupCall) + "("+groupid+")";
SetCheck(radioGroup);
selectedCallType = GROUPCall;
textViewCallType.setText(groupid + "");
-
- }
- else
- {
+ } else {
SetCheck(radioAll);
selectedCallType = ALLCall;
-
}
layoutSpinnerCallType.setVisibility( calltype != ALLCall ? View.VISIBLE : View.INVISIBLE);
textViewMessageChannel.setText(CallType);
-
- if ( parentTab.getSuperVehHash() != null) {
- if (parentTab.getSuperVehHash().containsKey((long) imei))
- textViewMessageStatus.setText(parentTab.getSuperVehHash().get((long) imei).name);
+ if (parentTab.getSuperVehHash() != null) {
+ if (parentTab.getSuperVehHash().containsKey(imei))
+ textViewMessageStatus.setText(parentTab.getSuperVehHash().get(imei).name);
else
- textViewMessageStatus.setText("Imei: " + Long.toString(imei));
+ textViewMessageStatus.setText("Imei: " + imei);
}
}
@@ -865,52 +702,31 @@ public class RadioActivity extends Activity {
buttonDKey.setEnabled(false);
}
- // change UI only if call types equals
-// if(selectedCallType == calltype)
-// {
-// imageViewStatus.setImageResource(R.drawable.status_idle);
-// // disable buttons
-// UpdateEnableDisableButtons("disableIncCall");
-// }
-
- // enable PTT button and disable DKey when HangTime
-// if(callstatus == hangTime && selectedCallType == calltype)
-// {
-// buttonPTT.setEnabled(true);
-// buttonDKey.setEnabled(false);
-// }
-
- if(parentTab.getCrtActivity() == parentTab.RADIO_TAB_ID && selectedCallType == calltype)
+ if (parentTab.getCrtActivity() == parentTab.RADIO_TAB_ID && selectedCallType == calltype)
parentTab.enableMenuButtons(false);
- if(selectedCallType == calltype)
+ if (selectedCallType == calltype)
parentTab.setInCall(true);
-
- }
- else if (callstatus == callEnd )
- {
- if((calltype == 0 && pttONoff == true) || selectedCallType == calltype)
- {
+ } else if (callstatus == callEnd ) {
+ if ((calltype == 0 && pttONoff) || selectedCallType == calltype) {
layoutGateway.setEnabled(true);
textViewMessageChannel.setText(textViewChannel.getText());
textViewMessageStatus.setText(" ");
imageViewStatus.setImageResource(R.drawable.status_online);
// stop sound
- if(audioH!=null)
+ if (audioH!=null)
audioH.StopSound();
// disable buttons
UpdateEnableDisableButtons("enable");
- if(pttONoff)
- {
+ if (pttONoff) {
pttONoff= false;
- if(audioH!=null)
+ if (audioH!=null)
audioH.soundNeeded = false;
-
buttonPTT.setText(getString(R.string.PTT));
buttonPTT.setBackgroundResource(R.drawable.style_buttonptt);
}
@@ -921,8 +737,7 @@ public class RadioActivity extends Activity {
}
// called from ParentTabActivity to set radio status
- public void UpdateRadioStatus (int status)
- {
+ public void UpdateRadioStatus (int status) {
// save received id's zoneNr and CHNR
this.rStatus = status;
@@ -930,14 +745,9 @@ public class RadioActivity extends Activity {
myHandler.post(UpdateRadioS);
}
- final Runnable UpdateRadioS = new Runnable() {
- public void run() {
- updateResultsStatus();
- }
- };
+ final Runnable UpdateRadioS = this::updateResultsStatus;
- private void updateResultsStatus()
- {
+ private void updateResultsStatus() {
SM.Debug("updateResultsStatusUI with Status: " + (rStatus == 1? "ONLINE" : "OFFLINE"));
imageViewStatus.setImageResource( (rStatus == 1 ) ? R.drawable.status_online : R.drawable.status_offline);
@@ -945,25 +755,21 @@ public class RadioActivity extends Activity {
}
- private void enableDisableRadioCallType(boolean enabled)
- {
+ private void enableDisableRadioCallType(boolean enabled) {
radioGroupCallType.setEnabled(enabled);
radioAll.setEnabled(enabled);
radioGroup.setEnabled(enabled);
radioPrivate.setEnabled(enabled);
}
- private void enableDisableSpinners(boolean enabled)
- {
+ private void enableDisableSpinners(boolean enabled) {
layoutSpinnerZone.setEnabled(enabled);
layoutSpinnerChannel.setEnabled(enabled);
layoutSpinnerCallType.setEnabled(enabled);
}
- public void UpdateEnableDisableButtons(String type)
- {
- if(type.equals("disableIncCall"))
- {
+ public void UpdateEnableDisableButtons(String type) {
+ if (type.equals("disableIncCall")) {
enableDisableRadioCallType(false);
enableDisableSpinners(false);
@@ -971,27 +777,20 @@ public class RadioActivity extends Activity {
buttonDKey.setEnabled(true);
// disable PTT
buttonPTT.setEnabled(false);
- }
- else if (type.equals("disablePTT"))
- {
-
+ } else if (type.equals("disablePTT")) {
enableDisableRadioCallType(false);
enableDisableSpinners(false);
// disable Dkey button
buttonDKey.setEnabled(false);
- }
- else if (type.equals("enable"))
- {
+ } else if (type.equals("enable")) {
enableDisableRadioCallType(true);
enableDisableSpinners(true);
// disable Dkey button and enable PTT
buttonDKey.setEnabled(false);
buttonPTT.setEnabled(true);
- }
- else if(type.equals("online"))
- {
+ } else if(type.equals("online")) {
enableDisableRadioCallType(true);
enableDisableSpinners(true);
@@ -1000,13 +799,10 @@ public class RadioActivity extends Activity {
buttonPTT.setEnabled(true);
textViewMessageStatus.setText("");
parentTab.enableMenuButtons(true);
- }
- else if (type.equals("offline"))
- {
+ } else if (type.equals("offline")) {
enableDisableRadioCallType(false);
enableDisableSpinners(false);
-
// disable Dkey button
buttonDKey.setEnabled(false);
// disable PTT button
@@ -1027,16 +823,12 @@ public class RadioActivity extends Activity {
}
}
-
// get Group Contact ID from Name
- private int getGroupID4Name(String name)
- {
+ private int getGroupID4Name(String name) {
int i = 0;
-
- for (String groupName: allGroupsNames)
- {
+ for (String groupName: allGroupsNames) {
// if searched name - return corresponding id
- if(groupName.equals(name))
+ if (groupName.equals(name))
return allGroupsIDs.get(i);
i++;
}
@@ -1045,11 +837,9 @@ public class RadioActivity extends Activity {
}
// get Private Contact ID from Name
- private int getPrivateImei4Name(String name)
- {
- for(Vehicle vehicle: allVehicle)
- {
- if(vehicle.name.equals(name))
+ private int getPrivateImei4Name(String name) {
+ for (Vehicle vehicle: allVehicle) {
+ if (vehicle.name.equals(name))
return Integer.parseInt(vehicle.imei);
}
@@ -1057,46 +847,40 @@ public class RadioActivity extends Activity {
}
// get zone number from spinner zoneName
- private int getNR4Zone(String zoneName)
- {
- for(Zone zone: crtZones)
- if(zone.ZoneName.equals(zoneName))
+ private int getNR4Zone(String zoneName) {
+ for (Zone zone: crtZones)
+ if (zone.ZoneName.equals(zoneName))
return zone.id;
return -1;
}
// get channel number from spinner chName
- private int getNR4CH(String chName)
- {
- for(Channel ch: crtChannels)
- if(ch.chName.equals(chName))
+ private int getNR4CH(String chName) {
+ for (Channel ch: crtChannels)
+ if (ch.chName.equals(chName))
return ch.id;
return -1;
}
// send GetGWRadios to AppServer
- private void GetGWRadios()
- {
+ private void GetGWRadios() {
parentTab.getRadiosList();
}
// send Dekey to AppServer
- private void SendDekey()
- {
- if(parentTab.getCrtRadio() != null)
+ private void SendDekey() {
+ if (parentTab.getCrtRadio() != null)
parentTab.sendDekey(parentTab.getCrtRadio().GW_ID, parentTab.getCrtRadio().ID);
}
// send change Channel and Zone message to AppServer
- private void onZoneCHChange(int RadioID, int GWID, int zone, int ch)
- {
+ private void onZoneCHChange(int RadioID, int GWID, int zone, int ch) {
SM.Debug("Changed Z: " + zone + " | Channel: " + ch);
parentTab.getSetZoneAndChannel(GWID,RadioID,zone,ch);
}
// request radio status
- private void ReqRadioStatus(int RadioID, int GWID)
- {
+ private void ReqRadioStatus(int RadioID, int GWID) {
SM.Debug("Request radio status 4 radioId: " + RadioID + " | GW_ID:" + GWID);
parentTab.getRadioStatus(GWID,RadioID);
try {
@@ -1114,14 +898,11 @@ public class RadioActivity extends Activity {
//112 -prvcall stop
//103 -grpcall init
//113 -grpcall stop
- public void SendPTT(int callType, int id,int gwid, int rgwid,long userID)
- {
+ public void SendPTT(int callType, int id,int gwid, int rgwid,long userID) {
SM.Debug("sendPTT callType:"+callType);
parentTab.sendPTT(callType, id,gwid,rgwid,userID);
}
-
-
/** Register for broadcasts */
private void registerBroadcastIntents() {
IntentFilter intentFilter = new IntentFilter(OperationCodes.CHANNEL_BRDCST + "");
@@ -1135,20 +916,17 @@ public class RadioActivity extends Activity {
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- //SM.Debug("### NOTIFICATION ###", "Radio: " + intent.getAction());
final String action = intent.getAction();
// CHANNEL_BRDCST
if (action.equals(OperationCodes.CHANNEL_BRDCST + "")) {
-
Zone_and_channel zc = AppParams.crtZoneAndChannel;
UpdateZoneCH(zc.rgwID, zc.gwID, zc.zoneNr, zc.channelNr);
}
// RADIOID_CHANGED
if (action.equals(OperationCodes.RADIOID_CHANGED + "")) {
-
textViewGateway.setText(parentTab.getCrtRadio().IP);
textViewChannel.setText(parentTab.getCrtRadio().getChannelName());
textViewZone.setText(parentTab.getCrtRadio().getZoneName());
@@ -1159,5 +937,4 @@ public class RadioActivity extends Activity {
}
}
};
-
}
\ No newline at end of file
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/RecordingsActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/RecordingsActivity.java
index acdc9ca..65b86ca 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/RecordingsActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/RecordingsActivity.java
@@ -26,6 +26,7 @@ import com.safemobile.lib.AppParams;
import com.safemobile.lib.OperationCodes;
import com.safemobile.lib.Recording;
import com.safemobile.lib.SM;
+import com.safemobile.lib.Vehicle;
import com.safemobile.lib.radio.RadioGW;
import com.safemobile.lib.sound.RecordingHandle;
@@ -295,9 +296,27 @@ public class RecordingsActivity extends Activity {
private void updateResultsInUi() {
// clear played items
playingPositions = new ArrayList<>();
+
+ ArrayList recordings = getAllRecordings();
+ ArrayList filteredList = new ArrayList<>();
+ ArrayList vehicles = getParentTab().getAllVehicle();
+ for (Recording recording : recordings) {
+ if (recording.callType == 0 || recording.callType == 4) {
+ for (Vehicle vehicle : vehicles)
+ if (vehicle.imei.equals(String.valueOf(recording.subID))) {
+ filteredList.add(recording);
+ break;
+ }
+ } else {
+ filteredList.add(recording);
+ }
+ }
+
+ setAllRecordings(filteredList);
+
for (int i = 0; i < getAllRecordings().size(); i++)
playingPositions.add(true);
- // set adapter - where playingPositions stores exists values
+
adapter = new RecordingsGridViewAdapter(activity, getAllRecordings(), playingPositions);
// playing positions need to be false because no recording is played
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java
index 478f8da..d941432 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/SDMobileActivity.java
@@ -10,13 +10,19 @@ import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
+import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.net.NetworkRequest;
import android.os.AsyncTask;
+import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.text.Editable;
import android.text.InputType;
+import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
@@ -114,6 +120,17 @@ public class SDMobileActivity extends Activity {
super.onCreate(savedInstanceState);
SM.Debug("##### onCREATE ##### with LANGUAGE " + AppParams.LANGUAGETMP);
+ ConnectivityManager connectivityManager =
+ (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ connectivityManager.registerDefaultNetworkCallback(networkCallback);
+ else {
+ NetworkRequest request = new NetworkRequest.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
+ connectivityManager.registerNetworkCallback(request, networkCallback);
+ }
+
AppParams.theme = AppParams.Theme.SAFEDISPATCH;
if (AppParams.theme == AppParams.Theme.SAFENET)
this.setTheme(R.style.Theme_Safenet);
@@ -532,6 +549,21 @@ public class SDMobileActivity extends Activity {
SM.Debug("##### onRESUME #####");
}
+ private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
+ @Override
+ public void onAvailable(Network network) {
+ // network available
+ Log.v("NetworkAvailability", "available");
+ if (tcp != null && !tcp.isConnectionUP)
+ saveIPandRestartTCP(AppParams.IP, AppParams.PORT);
+ }
+
+ @Override
+ public void onLost(Network network) {
+ // network unavailable
+ Log.v("NetworkAvailability", "unavailable");
+ }
+ };
private void startTabActivity(long userID) {
// good login - load activity
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/SetupActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/SetupActivity.java
index 6be79a5..1a9c92b 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/SetupActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/SetupActivity.java
@@ -2,16 +2,13 @@ package com.safemobile.safedispatch;
import java.util.Locale;
-/** fix import */
import com.safemobile.adapters.LanguageSpinnerAdapter;
import com.safemobile.lib.AppParams;
import com.safemobile.lib.SM;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Dialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
@@ -73,52 +70,49 @@ public class SetupActivity extends Activity {
setContentView(R.layout.tabsetup);
- layoutSpinnerLanguage = (LinearLayout) findViewById(R.id.layoutSpinnerLanguage);
+ layoutSpinnerLanguage = findViewById(R.id.layoutSpinnerLanguage);
layoutSpinnerLanguage.setOnClickListener(LanguageListener);
- imageLanguage = (ImageView) findViewById(R.id.imageLanguage);
- textViewSpinnerLanguage = (TextView) findViewById(R.id.textViewSpinnerLanguage);
+ imageLanguage = findViewById(R.id.imageLanguage);
+ textViewSpinnerLanguage = findViewById(R.id.textViewSpinnerLanguage);
// change spinner icon and selected language according to tmpLanguage
- if (AppParams.LANGUAGETMP.equals("en")){
- imageLanguage.setImageResource(R.drawable.en);
- textViewSpinnerLanguage.setText(getString(R.string.en));
- }
- else if (AppParams.LANGUAGETMP.equals("de")){
- imageLanguage.setImageResource(R.drawable.de);
- textViewSpinnerLanguage.setText(getString(R.string.de));
- }
- else if (AppParams.LANGUAGETMP.equals("tr")){
- imageLanguage.setImageResource(R.drawable.tr);
- textViewSpinnerLanguage.setText(getString(R.string.tr));
- }
- else if (AppParams.LANGUAGETMP.equals("ro")){
- imageLanguage.setImageResource(R.drawable.ro);
- textViewSpinnerLanguage.setText(getString(R.string.ro));
- }
- else if(AppParams.LANGUAGETMP.equals("es")){
- imageLanguage.setImageResource(R.drawable.es);
- textViewSpinnerLanguage.setText(getString(R.string.es));
- }
- else if(AppParams.LANGUAGETMP.equals("ru")){
- imageLanguage.setImageResource(R.drawable.ru);
- textViewSpinnerLanguage.setText(getString(R.string.ru));
+ switch (AppParams.LANGUAGETMP) {
+ case "en":
+ imageLanguage.setImageResource(R.drawable.en);
+ textViewSpinnerLanguage.setText(getString(R.string.en));
+ break;
+ case "de":
+ imageLanguage.setImageResource(R.drawable.de);
+ textViewSpinnerLanguage.setText(getString(R.string.de));
+ break;
+ case "tr":
+ imageLanguage.setImageResource(R.drawable.tr);
+ textViewSpinnerLanguage.setText(getString(R.string.tr));
+ break;
+ case "ro":
+ imageLanguage.setImageResource(R.drawable.ro);
+ textViewSpinnerLanguage.setText(getString(R.string.ro));
+ break;
+ case "es":
+ imageLanguage.setImageResource(R.drawable.es);
+ textViewSpinnerLanguage.setText(getString(R.string.es));
+ break;
+ case "ru":
+ imageLanguage.setImageResource(R.drawable.ru);
+ textViewSpinnerLanguage.setText(getString(R.string.ru));
+ break;
}
// get visual elements
- appServerIP = (EditText) findViewById(R.id.appServerIP);
- appServerPort = (EditText) findViewById(R.id.appServerPort);
+ appServerIP = findViewById(R.id.appServerIP);
+ appServerPort = findViewById(R.id.appServerPort);
// hide path layout used only on Pad/Pod
- layoutPath = (LinearLayout) findViewById(R.id.layoutPath);
+ layoutPath = findViewById(R.id.layoutPath);
layoutPath.setVisibility(View.GONE);
- btn_save = (Button) findViewById(R.id.btn_save);
+ btn_save = findViewById(R.id.btn_save);
- btn_save.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- saveSettings();
- }
- });
+ btn_save.setOnClickListener(v -> saveSettings());
// set values
if(!AppParams.IP.equals("n/a"))
@@ -134,46 +128,31 @@ public class SetupActivity extends Activity {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.exit))
.setCancelable(false)
- .setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- parentTab.whenBackPressed(AppParams.ActivityResult.logout);
- }
- })
- .setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- parentTab.whenBackPressed(AppParams.ActivityResult.exit);
- }
- })
- .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
+ .setNeutralButton(getString(R.string.logout), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.logout))
+ .setPositiveButton(getString(R.string.ext), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.exit))
+ .setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
AlertDialog alert = builder.create();
alert.show();
}
// listener when select language pressed
- private OnClickListener LanguageListener = new OnClickListener() {
+ private final OnClickListener LanguageListener = new OnClickListener() {
@Override
public void onClick(View v) {
final LanguageSpinnerAdapter adapter = new LanguageSpinnerAdapter(context, android.R.layout.simple_spinner_item, Languages, getLayoutInflater());
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(getString(R.string.selLanguage));
- builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- textViewSpinnerLanguage.setText(adapter.getItem(which));
- switch(which)
- {
- case 0: imageLanguage.setImageResource(R.drawable.en); AppParams.LANGUAGETMP = "en"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
- case 1: imageLanguage.setImageResource(R.drawable.de); AppParams.LANGUAGETMP = "de"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
- case 2: imageLanguage.setImageResource(R.drawable.tr); AppParams.LANGUAGETMP = "tr"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
- case 3: imageLanguage.setImageResource(R.drawable.ro); AppParams.LANGUAGETMP = "ro"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
- case 4: imageLanguage.setImageResource(R.drawable.ru); AppParams.LANGUAGETMP = "ru"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
- case 5: imageLanguage.setImageResource(R.drawable.es); AppParams.LANGUAGETMP = "es"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
- }
+ builder.setAdapter(adapter , (dialog, which) -> {
+ textViewSpinnerLanguage.setText(adapter.getItem(which));
+ switch(which)
+ {
+ case 0: imageLanguage.setImageResource(R.drawable.en); AppParams.LANGUAGETMP = "en"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
+ case 1: imageLanguage.setImageResource(R.drawable.de); AppParams.LANGUAGETMP = "de"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
+ case 2: imageLanguage.setImageResource(R.drawable.tr); AppParams.LANGUAGETMP = "tr"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
+ case 3: imageLanguage.setImageResource(R.drawable.ro); AppParams.LANGUAGETMP = "ro"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
+ case 4: imageLanguage.setImageResource(R.drawable.ru); AppParams.LANGUAGETMP = "ru"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
+ case 5: imageLanguage.setImageResource(R.drawable.es); AppParams.LANGUAGETMP = "es"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
}
});
@@ -215,12 +194,12 @@ public class SetupActivity extends Activity {
String oldIP = AppParams.IP;
String oldPort = AppParams.PORT;
- editor.putString("ip", appServerIP.getText().toString());
- editor.putString("port", appServerPort.getText().toString());
- editor.putString("language", AppParams.LANGUAGETMP);
- Boolean result = editor.commit();
+ editor.putString("ip", appServerIP.getText().toString());
+ editor.putString("port", appServerPort.getText().toString());
+ editor.putString("language", AppParams.LANGUAGETMP);
+ boolean result = editor.commit();
// saved completed
- if(result)
+ if (result)
Toast.makeText(context, "Settings saved successfully.", Toast.LENGTH_LONG).show();
else
Toast.makeText(context, "Settings failed to complete!", Toast.LENGTH_LONG).show();
@@ -265,31 +244,4 @@ public class SetupActivity extends Activity {
//showDialog(result);
}
- public void showDialog(Boolean result)
- {
- Dialog dialog = new Dialog(context);
- if(result)
- dialog.setTitle("Save Completed");
- else
- dialog.setTitle("Save Failed");
- dialog.setContentView(R.layout.dialog);
- dialog.setCancelable(true);
- dialog.setCanceledOnTouchOutside(true);
-
- TextView text = (TextView) dialog.findViewById(R.id.text);
- ImageView image = (ImageView) dialog.findViewById(R.id.image);
- if(result)
- {
- image.setImageResource(R.drawable.error);
- text.setText("Settings saved successfully.");
- }
- else
- {
- image.setImageResource(R.drawable.error);
- text.setText("Settings failed to complete!");
- }
-
- dialog.show();
- }
-
}
diff --git a/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java
index 6686bee..2acf71b 100644
--- a/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java
+++ b/safeDispatch/src/main/java/com/safemobile/safedispatch/TabLayoutActivity.java
@@ -73,6 +73,10 @@ import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.net.NetworkRequest;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@@ -101,6 +105,7 @@ import androidx.core.app.NotificationManagerCompat;
public class TabLayoutActivity extends AbstractSDParentActivity {
+ private final String TAG = "TabLayoutActivity";
/* Misc */
private Resources res;
private Context context;
@@ -179,6 +184,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
private static final String SETTINGS = "Setup";
private static final String ABOUT = "SafeMobile";
+ private final Handler uiHandler = new Handler(Looper.getMainLooper());
+
+
// default app language
public static final String DATABASE_LANGUAGE = "en"; // database language : en, de, tr, ro or empty
@@ -566,8 +574,59 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
/* Create Service and bind to it */
getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
+
+
+ ConnectivityManager connectivityManager =
+ (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ connectivityManager.registerDefaultNetworkCallback(networkCallback);
+ else {
+ NetworkRequest request = new NetworkRequest.Builder()
+ .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
+ connectivityManager.registerNetworkCallback(request, networkCallback);
+ }
}
+ private final ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
+ @Override
+ public void onAvailable(Network network) {
+ // network available
+ Log.v(TAG, "network available");
+ Log.v(TAG, "tcp: " + (tcp != null));
+
+ if (tcp != null) {
+ if (tcp.isConnectionUP)
+ tcp.isConnectionUP = false;
+
+ uiHandler.post(() -> {
+ Log.v(TAG, "myService: " + (myService != null));
+ if (myService != null) {
+ myService.stopTCPConnection();
+ myService.recreateTCPConnection();
+
+ getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
+ if (getRadioActivity() != null)
+ getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
+ if (getMessageActivity() != null)
+ getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
+ if (getRecordingsActivity() != null)
+ getRecordingsActivity().onCreate(getRecordingsActivity().getSavedInstanceState());
+ if (getAlarmActivity() != null)
+ getAlarmActivity().onCreate(getAlarmActivity().getSavedInstanceState());
+
+ uiHandler.post(initTCPRUN);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onLost(Network network) {
+ // network unavailable
+ Log.v(TAG, "network unavailable");
+ }
+ };
+
/**
* Broadcast Received for notifications
*/
@@ -602,6 +661,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
Vehicle vehicle = getVehicle4Imei(getImei());
if (vehicle != null)
getMessageActivity().setScId(vehicle.sc_id);
+ Log.v(TAG, "lastmessages: false");
getMessageActivity().LASTMESSAGES = false;
getMessageActivity().getLastSMS();
@@ -694,13 +754,26 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
@Override
public void whenBackPressed(AppParams.ActivityResult result) {
+ try {
+ prepareForLogOut(result);
+
+ finish();
+ android.os.Process.killProcess(android.os.Process.myPid());
+ System.exit(0);
+ } catch (Exception e) {
+ Log.v(TAG, e.getMessage());
+ }
+ }
+
+ private void prepareForLogOut(AppParams.ActivityResult result) {
+ Log.v(TAG, "prepareForLogOut");
if (tcpTimer != null) {
tcpTimer.cancel();
tcpTimer.purge();
tcpTimer = null;
}
- if (getRadioActivity().audioThread != null) {
+ if (getRadioActivity() != null && getRadioActivity().audioThread != null) {
Thread moribund = getRadioActivity().audioThread;
getRadioActivity().audioThread = null;
moribund.interrupt();
@@ -721,10 +794,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
getIntent().putExtra("result", result);
setResult(RESULT_OK, getIntent()); //-> used for exit
-
- finish();
- android.os.Process.killProcess(android.os.Process.myPid());
- System.exit(0);
}
@Override
@@ -732,16 +801,15 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
// recreate UI
Locale locale = new Locale(AppParams.LANGUAGETMP);
Locale.setDefault(locale);
- android.content.res.Configuration configuration = new android.content.res.Configuration();
- configuration.locale = locale;
- getBaseContext().getResources().updateConfiguration(configuration,
- getBaseContext().getResources().getDisplayMetrics());
+ setLocale(getLiveActivity(), locale);
- if (getHistoryActivity() != null)
- getHistoryActivity().onCreate(getHistoryActivity().savedInstanceState);
// change UI for RadioActivity and MessageActivity
+ if (getLiveActivity() != null)
+ getLiveActivity().setLanguage();
+ if (getHistoryActivity() != null)
+ getHistoryActivity().setLanguage();
if (getRadioActivity() != null)
- getRadioActivity().onCreate(getRadioActivity().savedInstanceState);
+ getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
if (getMessageActivity() != null)
getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
if (getRecordingsActivity() != null)
@@ -750,6 +818,13 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
getAlarmActivity().onCreate(getAlarmActivity().getSavedInstanceState());
}
+ public static void setLocale(Activity activity, Locale locale) {
+ Resources resources = activity.getResources();
+ Configuration config = resources.getConfiguration();
+ config.setLocale(locale);
+ resources.updateConfiguration(config, resources.getDisplayMetrics());
+ }
+
//timer stuff
private void timerMethod() {
if (!AppParams.DEMO)
@@ -2031,11 +2106,53 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
@Override
public void onTCPConnectionDown(boolean previousWasConnectionUp) {
+ Timer timer = new Timer();
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ boolean isNetworkConnected = isNetworkConnected();
+ Log.v(TAG, "isNetworkConnected: " + isNetworkConnected);
+ if (isNetworkConnected) {
+ if (tcp != null && !tcp.isConnectionUP) {
+ tcp.Stop();
+// if (tcpParser != null)
+// tcpParser.clearMsgList();
+ tcp = null;
+
+ uiHandler.post(() -> {
+ if (myService != null) {
+ myService.stopTCPConnection();
+
+
+ myService.recreateTCPConnection();
+
+ getApplicationContext().bindService(new Intent(context, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE);
+ if (getRadioActivity() != null)
+ getRadioActivity().onCreate(getRadioActivity().getSavedInstanceState());
+ if (getMessageActivity() != null)
+ getMessageActivity().onCreate(getMessageActivity().getSavedInstanceState());
+ if (getRecordingsActivity() != null)
+ getRecordingsActivity().onCreate(getRecordingsActivity().getSavedInstanceState());
+ if (getAlarmActivity() != null)
+ getAlarmActivity().onCreate(getAlarmActivity().getSavedInstanceState());
+
+ uiHandler.post(initTCPRUN);
+ }
+ SM.Debug("RECREATE TCP", "IP: " + AppParams.IP + " | Port: " + AppParams.PORT);
+ });
+ }
+
+ this.cancel();
+ }
+ }
+ }, 0, 100);
+
+ prepareForLogOut(AppParams.ActivityResult.tcpDown);
// execute logout
- whenBackPressed(AppParams.ActivityResult.tcpDown);
+// whenBackPressed(AppParams.ActivityResult.tcpDown);
// send a broadcast
- notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + "");
+// notifyBroadcast(OperationCodes.TCP_CONNECTION_DOWN + "");
}
@Override
@@ -2056,6 +2173,19 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
});
}
+ // Create runnable for posting
+ final Runnable initTCPRUN = () -> {
+ // start thread to add listener
+ SM.Debug("##### initTCPRUN");
+ if (!AppParams.DEMO)
+ tcpInit();
+ };
+
+ private boolean isNetworkConnected() {
+ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
+ }
+
// Create runnable for posting
final Runnable updateResultsAlarm = () -> updateResultsAlarmInUi("realpha");
diff --git a/safeDispatch/src/main/res/layout/style_header_units.xml b/safeDispatch/src/main/res/layout/style_header_units.xml
index 9620ef3..7636db1 100644
--- a/safeDispatch/src/main/res/layout/style_header_units.xml
+++ b/safeDispatch/src/main/res/layout/style_header_units.xml
@@ -10,6 +10,7 @@
android:gravity="center_vertical" >