diff --git a/.gitignore b/.gitignore index bc21e6d..2389820 100644 --- a/.gitignore +++ b/.gitignore @@ -184,5 +184,3 @@ $RECYCLE.BIN/ /.idea/misc.xml /.idea /.idea/modules.xml -/.idea/gradle.xml -/.idea/misc.xml diff --git a/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java b/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java index 3feaf95..1564341 100644 --- a/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java +++ b/libSafeMobile/src/main/java/com/safemobile/activities/AbstractSDParentActivity.java @@ -1,9 +1,8 @@ package com.safemobile.activities; -import java.util.ArrayList; -import java.util.Hashtable; +import android.app.TabActivity; +import android.content.BroadcastReceiver; -import com.safemobile.bluetooth.BluetoothTether; import com.safemobile.lib.AppParams; import com.safemobile.lib.SM; import com.safemobile.lib.SuperVehicle; @@ -11,43 +10,21 @@ import com.safemobile.lib.Vehicle; import com.safemobile.services.TCPhandler; import com.safemobile.services.TCPmsgParser; -import android.app.Activity; -import android.app.NotificationManager; -import android.app.TabActivity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.os.Handler; -import android.widget.ImageView; -import android.widget.RelativeLayout; +import java.util.ArrayList; +import java.util.Hashtable; @SuppressWarnings("deprecation") public abstract class AbstractSDParentActivity extends TabActivity { - - /** UI Elements */ - public RelativeLayout layoutLoading; - public ImageView imageViewLoading; - + /** Misc */ - public Activity activity; - public Context context; - public NotificationManager mNotificationManager; - public boolean displayLogCat = true; // show logCat messages when TCP send was successful - public String imei, mess; + private static final boolean SHOULD_DISPLAY_LOGCAT = true; // show logCat messages when TCP send was successful + private String imei; + private String mess; public int demoPosition = 0; - /** Lists */ - public ArrayList allVehicle = new ArrayList(); - public Hashtable SuperVehHash = new Hashtable(); - public Hashtable VehHashbySc_id = new Hashtable(); - - /** Handler */ - public Handler myHandler = new Handler(); - - /** BlueTooth Tether */ - public BluetoothTether bluetoothTether = null; - - /** Broadcast Receiver */ - public BroadcastReceiver mReceiver = null; + private ArrayList allVehicle = new ArrayList<>(); + private Hashtable superVehHash = new Hashtable<>(); + private Hashtable vehHashByScId = new Hashtable<>(); /** TCP */ protected TCPhandler tcp = null; @@ -66,9 +43,9 @@ public abstract class AbstractSDParentActivity extends TabActivity { public Object getTCPState() { // return true if tcp connection is on, false if not connected and null - if(tcp!=null && tcp.isConnectionUP) + if (tcp != null && tcp.isConnectionUP) return "true"; - else if(tcp!=null && !tcp.isConnectionUP) + else if (tcp != null) return "false"; return null; } @@ -84,83 +61,78 @@ public abstract class AbstractSDParentActivity extends TabActivity { public abstract void updateDemoPosition(); public abstract void updateResultsPollInUi(String type); - public abstract double best_zoom(double LATMAX,double LATmin,double LNGMAX,double LNGmin); + public abstract double best_zoom(double latMax,double latMin,double lngMax,double lngMin); /* SafeDispatch Mobile functions */ /** get Vehicles for an user id */ - public boolean getVehicles(int userID) - { - if(tcp == null) + public boolean getVehicles(int userID) { + if (tcp == null) return false; - - boolean res = tcp.Write("0.0", "#21#" + AppParams.USERID + "#"); - if(res && displayLogCat) + + boolean res = tcp.Write("0.0", "#21#" + userID + "#"); + if (res && SHOULD_DISPLAY_LOGCAT) SM.Debug("Message (getVehs) sent to app server"); else SM.Debug("Could not send message(getVehs)!!"); - + return res; } /** get vehicles Last Positions for an user id */ - public boolean getLastPositions(int userID) - { - if(tcp == null) + public boolean getLastPositions(int userID) { + if (tcp == null) return false; - + boolean res = tcp.Write("0.0", "#25#" + userID + "#"); - if(res && displayLogCat) + if (res && SHOULD_DISPLAY_LOGCAT) SM.Debug("Message (getLastPOS) sent to app server"); else SM.Debug("Could not send message(getLastSMS)!!"); - + return res; } /** set Enable/Disable a vehicle */ - public boolean setVehicleStatus(int radioCode, int opCode, int sc_id, int enable) - { - if(tcp == null) + public boolean setVehicleStatus(int radioCode, int opCode, int sc_id, int enable) { + if (tcp == null) return false; - - boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + sc_id+"#" + enable + "#"); - if(res && displayLogCat) - SM.Debug("Message (Option4Unit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " sc_id:"+sc_id+ " value:" + enable); + + boolean res = tcp.Write("0.0", "#" + radioCode + "#" + opCode + "#" + sc_id + "#" + enable + "#"); + if (res && SHOULD_DISPLAY_LOGCAT) + SM.Debug("Message (Option4Unit) sent to app server radioCode:" + radioCode + " opCode:" + opCode + " sc_id:" + sc_id + " value:" + enable); else SM.Debug("Could not send message(Option4Unit)!!"); - + return res; } /** get Last SMSs for an user */ - public boolean getLastSMSs(int userID) - { - if(tcp == null) + public boolean getLastSMSs(int userID) { + if (tcp == null) return false; - + boolean res = tcp.Write("0.0", "#23#" + userID + "#"); - if(res && displayLogCat) + if (res && SHOULD_DISPLAY_LOGCAT) SM.Debug("#Send Request#", "Message [getLastSMSs] sent to app server"); else SM.Debug("#Send Request#", "Could not send message [getLastSMSs]!!"); - + return res; } /** get SMSs for an user that are recent than timeGMT * @param sc_id the vehicle imei for which we want the SMSs * @param timeGMT the unix time for the last message in the grid or messages that are newer than this time */ - public boolean getRecentSMSs(int sc_id, long timeGMT) - { - if(tcp == null) + public boolean getRecentSMSs(int sc_id, long timeGMT) { + if (tcp == null) return false; - - boolean res = tcp.Write("0.0", "#22#"+sc_id+"#" +timeGMT+"#"); - if(res && displayLogCat) + + boolean res = tcp.Write("0.0", "#22#" + sc_id + "#" + timeGMT + "#"); + if (res && SHOULD_DISPLAY_LOGCAT) SM.Debug("#Send Request#", "Message [getRecentSMSs] sent to app server"); else SM.Debug("#Send Request#", "Could not send message [getRecentSMSs]!!"); - + return res; } @@ -174,7 +146,7 @@ public abstract class AbstractSDParentActivity extends TabActivity { return false; boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + sc_id + "#" + txt + "#"); - if(res && displayLogCat) + if(res && SHOULD_DISPLAY_LOGCAT) SM.Debug("Message [sendSMS] sent to app server sc_id:"+sc_id+ " txt:"+txt); else SM.Debug("Could not send message [sendSMS]!!"); @@ -183,16 +155,16 @@ public abstract class AbstractSDParentActivity extends TabActivity { } - public boolean sendAlarmAcknoledge(int alarm_id, int type) + public boolean sendAlarmAcknowledge(int alarm_id, int type) { if(tcp == null) return false; boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#"); if(res) - SM.Debug("Message [sendAlarmAcknoledge] sent to app server alarm_id:" + alarm_id + " type:" + type); + SM.Debug("Message [sendAlarmAcknowledge] sent to app server alarm_id:" + alarm_id + " type:" + type); else - SM.Debug("Could not send message [sendAlarmAcknoledge]!!"); + SM.Debug("Could not send message [sendAlarmAcknowledge]!!"); return res; } @@ -290,7 +262,7 @@ public abstract class AbstractSDParentActivity extends TabActivity { if(tcp == null) return false; - boolean res = tcp.Write("0.0", "#27#" + userID + "#"); // = tcp.Write("0.0", "#30#99#" + gwID + "#" + rgwID + "#"); + boolean res = tcp.Write("0.0", "#27#" + userID + "#"); if(res) SM.Debug("Message [GetAlarms] sent to app server"); else @@ -313,11 +285,45 @@ public abstract class AbstractSDParentActivity extends TabActivity { return res; } - - //public abstract void getVehiclePosition(long imei); - /* - public abstract void onResume(); - public abstract void onStart(); - public abstract void onPause(); - */ + + public String getImei() { + return imei; + } + + public void setImei(String imei) { + this.imei = imei; + } + + public String getMess() { + return mess; + } + + public void setMess(String mess) { + this.mess = mess; + } + + /** Lists */ + public ArrayList getAllVehicle() { + return allVehicle; + } + + public void setAllVehicle(ArrayList allVehicle) { + this.allVehicle = allVehicle; + } + + public Hashtable getSuperVehHash() { + return superVehHash; + } + + public void setSuperVehHash(Hashtable superVehHash) { + this.superVehHash = superVehHash; + } + + public Hashtable getVehHashByScId() { + return vehHashByScId; + } + + public void setVehHashByScId(Hashtable vehHashByScId) { + this.vehHashByScId = vehHashByScId; + } } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java index d33dc87..ac6e7de 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/AlarmActivity.java @@ -167,11 +167,11 @@ public class AlarmActivity extends Activity { { acknowledged.add((alarm.ack == 1)? true: false); SM.Debug("ALARM", "SC_ID> " + alarm.sc_id + " | " - + (parentTab.VehHashbySc_id.get(alarm.sc_id) == null ? "null" : parentTab.VehHashbySc_id.get(alarm.sc_id).name )); + + (parentTab.getVehHashByScId().get(alarm.sc_id) == null ? "null" : parentTab.getVehHashByScId().get(alarm.sc_id).name )); - if (parentTab.VehHashbySc_id.get(alarm.sc_id)!=null) - alarm.unitName = parentTab.VehHashbySc_id.get(alarm.sc_id).name; + if (parentTab.getVehHashByScId().get(alarm.sc_id)!=null) + alarm.unitName = parentTab.getVehHashByScId().get(alarm.sc_id).name; @@ -254,6 +254,6 @@ public class AlarmActivity extends Activity { private void setACK(int idx, int type) { parentTab.executeNetworkStuff(new String[]{OperationCodes.SendAlarmAcknoledge +"", idx + "", type + ""}); - //parentTab.sendAlarmAcknoledge(idx, type); + //parentTab.sendAlarmAcknowledge(idx, type); } } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java index ebbfdc1..e8e3ca6 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/LiveActivity.java @@ -167,12 +167,12 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall if (AppParams.DEMO) { disabledVehicles = new ArrayList<>(); - for (Vehicle veh : getParentTab().allVehicle) + for (Vehicle veh : getParentTab().getAllVehicle()) disabledVehicles.add(!veh.status); } - adapter = new VehiclesGridViewAdapter(activity, context, getParentTab().allVehicle, disabledVehicles); + adapter = new VehiclesGridViewAdapter(activity, context, getParentTab().getAllVehicle(), disabledVehicles); adapter.notifyDataSetChanged(); gridVehicle.setAdapter(adapter); @@ -221,9 +221,9 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall else viewLive.imgViewChecked.setImageResource(R.drawable.unchecked); - Enumeration keyList = getParentTab().SuperVehHash.keys(); + Enumeration keyList = getParentTab().getSuperVehHash().keys(); while (keyList.hasMoreElements()) { - (Objects.requireNonNull(getParentTab().SuperVehHash.get((long) keyList.nextElement()))).needUpdate = true; + (Objects.requireNonNull(getParentTab().getSuperVehHash().get((long) keyList.nextElement()))).needUpdate = true; } // change button title @@ -257,9 +257,9 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall for (int i = 0; i < displayedVehicles.size(); i++) displayedVehicles.set(i, true); - Enumeration keyList = getParentTab().SuperVehHash.keys(); + Enumeration keyList = getParentTab().getSuperVehHash().keys(); while (keyList.hasMoreElements()) - (Objects.requireNonNull(getParentTab().SuperVehHash.get((long) keyList.nextElement()))).needUpdate = true; + (Objects.requireNonNull(getParentTab().getSuperVehHash().get((long) keyList.nextElement()))).needUpdate = true; // change button title if (displayButton.getText().toString().equals(getString(R.string.displayAll))) { @@ -419,7 +419,7 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall // send change to AppServer optionForUnit(radioCode, MENU_POLL, liveVehicle.get(contextMenuPosition).id + ""); if (AppParams.DEMO) { - getParentTab().imei = liveVehicle.get(contextMenuPosition).sc_id + ""; + getParentTab().setImei(liveVehicle.get(contextMenuPosition).sc_id + ""); getParentTab().updateDemoPosition(); getParentTab().updateResultsPollInUi("realpha"); } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java index 23dd2b1..9f1dd26 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java @@ -273,7 +273,7 @@ public class MessagesActivity extends Activity { // Create runnable for posting final Runnable demoReceveidSMSRUN = new Runnable() { public void run() { - parentTab.imei = sc_id + ""; + parentTab.setImei(sc_id + ""); parentTab.updateResultsInUi("realpha"); int timeGMT = (int) (System.currentTimeMillis() / 1000L); @@ -354,7 +354,7 @@ public class MessagesActivity extends Activity { if(parentTab.getTCPState() != null){ if(FIRST) { - UpdateVehs(parentTab.allVehicle); + UpdateVehs(parentTab.getAllVehicle()); FIRST = false; if(LASTMESSAGES) parentTab.executeNetworkStuff(new String[] {OperationCodes.GetLastSMS + "", AppParams.USERID + ""}); @@ -704,7 +704,7 @@ public class MessagesActivity extends Activity { private void updateResultsInUi() { if(allVehicle == null) - UpdateVehs(parentTab.allVehicle); + UpdateVehs(parentTab.getAllVehicle()); //SM.Debug("updateResultsInUi: " + ACTION); if(ACTION == MSGUpdate) diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java index f0821a1..30f59e5 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/RadioActivity.java @@ -280,9 +280,9 @@ public class RadioActivity extends Activity { { super.onResume(); // get all vehicles from TabLayoutActivity - if(!allVehicle.equals(parentTab.allVehicle)) + if(!allVehicle.equals(parentTab.getAllVehicle())) { - allVehicle = parentTab.allVehicle; + allVehicle = parentTab.getAllVehicle(); UpdateVehicle(); } /* @@ -908,7 +908,7 @@ public class RadioActivity extends Activity { radioAll.setChecked(false); radioGroup.setChecked(false); selectedCallType = PRIVATECall; - textViewCallType.setText(parentTab.SuperVehHash.get((long)imei).name); + textViewCallType.setText(parentTab.getSuperVehHash().get((long)imei).name); layoutSpinnerCallType.setVisibility(View.VISIBLE); } else if (calltype==103) @@ -936,8 +936,8 @@ public class RadioActivity extends Activity { } if (callstatus==1) { - if (parentTab.SuperVehHash.get((long)imei)!=null) - textViewMessageStatus.setText(parentTab.SuperVehHash.get((long)imei).name); + if (parentTab.getSuperVehHash().get((long)imei)!=null) + textViewMessageStatus.setText(parentTab.getSuperVehHash().get((long)imei).name); else textViewMessageStatus.setText("Imei: "+Long.toString(imei)); } diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java index dc0f5ea..20484f1 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/SDMobileActivity.java @@ -1,12 +1,36 @@ package com.safemobile.dispatch; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Locale; -import java.util.Timer; -import java.util.TimerTask; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.graphics.Color; +import android.os.AsyncTask; +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.view.Gravity; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; +import android.widget.Toast; -//to fix R import import com.safemobile.adapters.LanguageSpinnerAdapter; import com.safemobile.interfaces.ITCPListener; import com.safemobile.interfaces.TCPEvent; @@ -29,507 +53,397 @@ import com.safemobile.services.TCPService.TCPBinder; import com.safemobile.services.TCPhandler; import com.safemobile.services.TCPmsgParser; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.ComponentName; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.ServiceConnection; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.graphics.Color; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Handler; -import android.os.IBinder; -import android.text.Editable; -import android.text.InputType; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.Window; -import android.view.WindowManager; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; +import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; public class SDMobileActivity extends Activity { - + /* Visual Elements */ - private Button btLogin; //buttonChangeIP, - private EditText etPassword, etUsername; + private Button btLogin; + private EditText etPassword; + private EditText etUsername; private CheckBox checkBoxSaveDefault; private RelativeLayout layoutTCP; - private LinearLayout llUsername, llPassword; - private ImageView imageLanguage, imageLoading, imageSettings, ivLogo; - + private LinearLayout llUsername; + private LinearLayout llPassword; + private ImageView imageLanguage; + /* Preferences */ private SharedPreferences.Editor editor; - //private String LANGUAGE, USERNAME, PASSWORD, IP, PORT, DEFAULT; - + /* Misc */ - //private boolean DEMO = false; - private String[] Languages = {"English", "German", "Turkish", "Romanian", "Russian", "Spanish"}; - //private String LANGUAGETMP = null; + private String[] languages = {"English", "German", "Turkish", "Romanian", "Russian", "Spanish"}; private Context context; private Activity activity; - - /* Dialog */ - private Dialog dialogInfo, loadingDialog; - - + private Dialog loadingDialog; + /* Handler for callbacks to the UI thread */ - private final Handler myHandler = new Handler(); - + private final Handler uiHandler = new Handler(Looper.getMainLooper()); + /* TCP */ - protected TCPhandler tcp ; + protected TCPhandler tcp; protected TCPmsgParser tcpParser; protected ITCPListener itcpListener; protected Timer timerLogin;//timer to check connection!!! - - /** TCP Service */ + + /** + * TCP Service + */ private TCPService myService; private boolean isBound = false; - + /* User details */ - protected int userID;// ID of loged in user - - - //private String oldUsername = null, oldPassword = null; - private String crtFirmwareVersion = ""; - //private Boolean oldCheck = null; + protected int userID;// ID of logged in user + private Boolean prevTCPState = false; - - // default app language - public String databaseLanguage = "en"; // database language : en, de, tr, ro or empty - - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - SM.Debug("##### onCREATE ##### with Language " + AppParams.LANGUAGETMP); - AppParams.theme = AppParams.Theme.SAFEDISPATCH; - if(AppParams.theme == AppParams.Theme.SAFENET) - this.setTheme(R.style.Theme_Safenet); - else if(AppParams.theme == AppParams.Theme.VISION) - this.setTheme(R.style.Theme_Vision); - else if(AppParams.theme == AppParams.Theme.HYTERA) - this.setTheme(R.style.Theme_Hytera); - else - this.setTheme(R.style.AppTheme); - - - // get Context - context = this; - activity = this; - - // get settings - loadSettings(); - - // if package is demo set DEMO to true - AppParams.DEMO = (context.getPackageName().contains("demo")); - - - if(savedInstanceState != null && savedInstanceState.getString("language") != null) - // set language which will be used for displaying UI - AppParams.LANGUAGETMP = savedInstanceState.getString("language"); - else - AppParams.LANGUAGETMP = AppParams.LANGUAGE; + /* Constants */ + private static final String DATABASE_LANGUAGE = "en"; // database language : en, de, tr, ro or empty + private static final String LANGUAGE = "language"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String LOGIN = "login"; + private static final String DEFAULT = "default"; - Locale locale = new Locale(AppParams.LANGUAGETMP); - Locale.setDefault(locale); - Configuration config = new Configuration(); - config.locale = locale; - getBaseContext().getResources().updateConfiguration(config, - getBaseContext().getResources().getDisplayMetrics()); - - Languages = new String[] {getString(R.string.en), getString(R.string.de), getString(R.string.tr), getString(R.string.ro), getString(R.string.ru), getString(R.string.es)}; - - setContentView(R.layout.login_h); - - - /* - RelativeLayout rlBackground = (RelativeLayout) findViewById(R.id.rlBackground); - int h = rlBackground.getHeight(); - ShapeDrawable mDrawable = new ShapeDrawable(new RectShape()); - mDrawable.getPaint().setShader(new LinearGradient(0, 0, 0, h, Color.parseColor("#330000FF"), Color.parseColor("#110000FF"), Shader.TileMode.REPEAT)); - rlBackground.setBackground(mDrawable); - */ - - - /* - try - { - // FIX Network in main thread - StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); - StrictMode.setThreadPolicy(policy); - } - catch(Exception ex) - { - ; - } - */ - - // do not dim the display - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - // hide keyboard when opening app + /** + * Called when the activity is first created. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + SM.Debug("##### onCREATE ##### with LANGUAGE " + AppParams.LANGUAGETMP); + + AppParams.theme = AppParams.Theme.SAFEDISPATCH; + if (AppParams.theme == AppParams.Theme.SAFENET) + this.setTheme(R.style.Theme_Safenet); + else if (AppParams.theme == AppParams.Theme.VISION) + this.setTheme(R.style.Theme_Vision); + else if (AppParams.theme == AppParams.Theme.HYTERA) + this.setTheme(R.style.Theme_Hytera); + else + this.setTheme(R.style.AppTheme); + + // get Context + context = this; + activity = this; + + // get settings + loadSettings(); + + // if package is demo set DEMO to true + AppParams.DEMO = (context.getPackageName().contains("demo")); + + + if (savedInstanceState != null && savedInstanceState.getString(LANGUAGE) != null) + // set language which will be used for displaying UI + AppParams.LANGUAGETMP = savedInstanceState.getString(LANGUAGE); + else + AppParams.LANGUAGETMP = AppParams.LANGUAGE; + + Locale locale = new Locale(AppParams.LANGUAGETMP); + Locale.setDefault(locale); + Configuration config = new Configuration(); + config.locale = locale; + getBaseContext().getResources().updateConfiguration(config, + getBaseContext().getResources().getDisplayMetrics()); + + languages = new String[]{getString(R.string.en), getString(R.string.de), getString(R.string.tr), getString(R.string.ro), getString(R.string.ru), getString(R.string.es)}; + + setContentView(R.layout.login_h); + + // do not dim the display + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + // hide keyboard when opening app getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); - - checkBoxSaveDefault = (CheckBox) findViewById(R.id.checkBoxSaveDefault); - // if username and password not equal N/A => save as default was checked - if(!AppParams.USERNAME.equals("n/a") && !AppParams.PASSWORD.equals("n/a")) - checkBoxSaveDefault.setChecked(true); - - ivLogo = (ImageView) findViewById(R.id.ivLogo); - - imageLoading = (ImageView) findViewById(R.id.imageLoading); - imageLoading.setBackgroundResource(R.drawable.loading); - - - - imageLanguage = (ImageView) findViewById(R.id.imageLanguage); - - // change spinner icon and selected language according to tmpLanguage - if (AppParams.LANGUAGETMP.equals("en")) - imageLanguage.setImageResource(R.drawable.en); - else if (AppParams.LANGUAGETMP.equals("de")) - imageLanguage.setImageResource(R.drawable.de); - else if (AppParams.LANGUAGETMP.equals("tr")) - imageLanguage.setImageResource(R.drawable.tr); - else if (AppParams.LANGUAGETMP.equals("ro")) - imageLanguage.setImageResource(R.drawable.ro); - else if(AppParams.LANGUAGETMP.equals("es")) - imageLanguage.setImageResource(R.drawable.es); - else if(AppParams.LANGUAGETMP.equals("ru")) - imageLanguage.setImageResource(R.drawable.ru); - - imageLanguage.setOnClickListener(LanguageListener); - - - etUsername = (EditText) findViewById(R.id.etUsername); - etPassword = (EditText) findViewById(R.id.etPassword); - - btLogin = (Button) findViewById(R.id.btLogin); - btLogin.setOnClickListener(new OnClickListener(){ - @Override - public void onClick(View arg0) { - - if(AppParams.DEMO) - startTabActivity(0); - else - { - if(etPassword.getText().toString().length()<1 || etUsername.getText().toString().length()<1) - showInfoDialog(getResources().getString(R.string.password)); - //showDialog("Password or Username are empty!"); - else { - // if save username and password - if(checkBoxSaveDefault.isChecked()) - saveSettings(true); // save settings - else - saveSettings(false); // reset username and password - if(!loadingDialog.isShowing()) - loadingDialog.show(); - - // TODO get users list - new connectTask().execute("login"); - } + checkBoxSaveDefault = (CheckBox) findViewById(R.id.checkBoxSaveDefault); + // if username and password not equal N/A => save as default was checked + if (!AppParams.USERNAME.equals("n/a") && !AppParams.PASSWORD.equals("n/a")) + checkBoxSaveDefault.setChecked(true); + + ImageView imageLoading = (ImageView) findViewById(R.id.imageLoading); + imageLoading.setBackgroundResource(R.drawable.loading); + + imageLanguage = (ImageView) findViewById(R.id.imageLanguage); + + // change spinner icon and selected language according to tmpLanguage + switch (AppParams.LANGUAGETMP) { + case "en": + imageLanguage.setImageResource(R.drawable.en); + break; + case "de": + imageLanguage.setImageResource(R.drawable.de); + break; + case "tr": + imageLanguage.setImageResource(R.drawable.tr); + break; + case "ro": + imageLanguage.setImageResource(R.drawable.ro); + break; + case "es": + imageLanguage.setImageResource(R.drawable.es); + break; + case "ru": + imageLanguage.setImageResource(R.drawable.ru); + break; + default: + throw new IllegalStateException("Unexpected value: " + AppParams.LANGUAGETMP); + } + + imageLanguage.setOnClickListener(LanguageListener); + + etUsername = (EditText) findViewById(R.id.etUsername); + etPassword = (EditText) findViewById(R.id.etPassword); + + btLogin = (Button) findViewById(R.id.btLogin); + btLogin.setOnClickListener(arg0 -> { + + if (AppParams.DEMO) + startTabActivity(0); + else { + if (etPassword.getText().toString().length() < 1 || etUsername.getText().toString().length() < 1) + showInfoDialog(getResources().getString(R.string.password)); + else { + // if save username and password + // reset username and password + saveSettings(checkBoxSaveDefault.isChecked()); // save settings + + if (!loadingDialog.isShowing()) + loadingDialog.show(); + + // TODO get users list + new connectTask().execute(LOGIN); } - } - }); - - - imageSettings = (ImageView) findViewById(R.id.imageSettings); - //buttonChangeIP = (Button) findViewById(R.id.buttonChangeIP); - imageSettings.setOnClickListener(changeIPListener); - //layoutTCP.setVisibility(View.INVISIBLE); - - // reset values before changing language - if(savedInstanceState != null && savedInstanceState.getString("username") != null) { - etUsername.setText(savedInstanceState.getString("username")); - etPassword.setText(savedInstanceState.getString("password")); - checkBoxSaveDefault.setChecked(savedInstanceState.getBoolean("checked")); - } - else - { - // set values stored in Shared Preferences - etUsername.setText(AppParams.USERNAME.equalsIgnoreCase("n/a") ? "" : AppParams.USERNAME); - etPassword.setText(AppParams.PASSWORD.equalsIgnoreCase("n/a") ? "" : AppParams.PASSWORD); - } - - layoutTCP = (RelativeLayout) findViewById(R.id.layoutTCP); - - llUsername = (LinearLayout) findViewById(R.id.llUsername); - llPassword = (LinearLayout) findViewById(R.id.llPassword); - - // enable ui after the language is changed and tcp connection is on - if(tcp!=null && tcp.isConnectionUP) { - layoutTCP.setVisibility(View.INVISIBLE); - enableUI(true); - } - // enable UI if application is demo - else if(AppParams.DEMO) { - enableUI(true); - layoutTCP.setVisibility(View.INVISIBLE); - } - else - enableUI(false); - - if(!AppParams.DEMO) - { - /** Create Service and bind on it */ - getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE); - } - - createLoadingDialog(getString(R.string.checkingUser)); - - timerLogin = new Timer(); - timerLogin.scheduleAtFixedRate(new TimerTask() { + }); + + ImageView imageSettings = (ImageView) findViewById(R.id.imageSettings); + imageSettings.setOnClickListener(changeIPListener); + + // reset values before changing language + if (savedInstanceState != null && savedInstanceState.getString(USERNAME) != null) { + etUsername.setText(savedInstanceState.getString(USERNAME)); + etPassword.setText(savedInstanceState.getString(PASSWORD)); + checkBoxSaveDefault.setChecked(savedInstanceState.getBoolean("checked")); + } else { + // set values stored in Shared Preferences + etUsername.setText(AppParams.USERNAME.equalsIgnoreCase("n/a") ? "" : AppParams.USERNAME); + etPassword.setText(AppParams.PASSWORD.equalsIgnoreCase("n/a") ? "" : AppParams.PASSWORD); + } + + layoutTCP = (RelativeLayout) findViewById(R.id.layoutTCP); + + llUsername = (LinearLayout) findViewById(R.id.llUsername); + llPassword = (LinearLayout) findViewById(R.id.llPassword); + + // enable ui after the language is changed and tcp connection is on + if (tcp != null && tcp.isConnectionUP) { + layoutTCP.setVisibility(View.INVISIBLE); + enableUI(true); + } + // enable UI if application is demo + else if (AppParams.DEMO) { + enableUI(true); + layoutTCP.setVisibility(View.INVISIBLE); + } else + enableUI(false); + + if (!AppParams.DEMO) { + /** Create Service and bind on it */ + getApplicationContext().bindService(new Intent(this, TCPService.class), serviceConnection, Context.BIND_AUTO_CREATE); + } + + createLoadingDialog(getString(R.string.checkingUser)); + + timerLogin = new Timer(); + timerLogin.scheduleAtFixedRate(new TimerTask() { @Override public void run() { // request to trigger the event because the first time when // it was triggered, the listener wasn't created - if(tcp!=null) { + if (tcp != null) { tcp.triggerTCPConnectionStateEvent(); } } }, 1000, 500); - - } - - - - /* Enable and disable UI elements */ - private void enableUI(boolean isEnabled) { - checkBoxSaveDefault.setEnabled(isEnabled); - btLogin.setEnabled(isEnabled); - etPassword.setEnabled(isEnabled); - etUsername.setEnabled(isEnabled); - - // change username and password layout background to gray or white - if(isEnabled) { - llUsername.setBackgroundResource(R.drawable.textboxx); - llPassword.setBackgroundResource(R.drawable.textboxx); - } - else { - llUsername.setBackgroundResource(R.drawable.textboxx); - llPassword.setBackgroundResource(R.drawable.textboxx); - } - - } - - - @Override - public void onBackPressed() - { + } + + /* Enable and disable UI elements */ + private void enableUI(boolean isEnabled) { + checkBoxSaveDefault.setEnabled(isEnabled); + btLogin.setEnabled(isEnabled); + etPassword.setEnabled(isEnabled); + etUsername.setEnabled(isEnabled); + + // change username and password layout background to gray or white + if (isEnabled) { + llUsername.setBackgroundResource(R.drawable.textboxx); + llPassword.setBackgroundResource(R.drawable.textboxx); + } else { + llUsername.setBackgroundResource(R.drawable.textboxx); + llPassword.setBackgroundResource(R.drawable.textboxx); + } + } + + @Override + public void onBackPressed() { + if (loadingDialog.isShowing()) + cancelLoadingDialog(); + else { + + // show dialog that allows to select the close of the app + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(getString(R.string.exit)) + .setCancelable(false) + .setPositiveButton(getString(R.string.yes), (dialog, id) -> whenBackPressed()) + .setNegativeButton(getString(R.string.no), (dialog, id) -> dialog.cancel()); + AlertDialog alert = builder.create(); + alert.show(); + } + } + + /* Callback for connecting/disconnecting from the service that controls TCP Connections */ + ServiceConnection serviceConnection = new ServiceConnection() { - if(loadingDialog.isShowing()) - CancelLoadingDialog(); - else - { - - // show dialog that allows to select the close of the app - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(getString(R.string.exit)) - .setCancelable(false) - .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - whenBackPressed(); - } - }) - .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - } - - } - - /* Callback for connecting/disconnecting from the service that controls TCP Connections */ - ServiceConnection serviceConnection = new ServiceConnection() { - @Override public void onServiceDisconnected(ComponentName name) { - Toast.makeText(context, getString(R.string.serviceDisconnected), 1000).show(); - //SM.Debug("Service is disconnected"); - isBound = false; + Toast.makeText(context, getString(R.string.serviceDisconnected), Toast.LENGTH_SHORT).show(); + isBound = false; } - + @Override public void onServiceConnected(ComponentName name, IBinder service) { - //Toast.makeText(context, getString(R.string.serviceConnected), 1000).show(); - //SM.Debug("Service is connected"); - TCPBinder binder = (TCPBinder) service; - myService = binder.getService(); - isBound = true; + TCPBinder binder = (TCPBinder) service; + myService = binder.getService(); + isBound = true; } }; - + @Override - public void onStop() - { + public void onStop() { super.onStop(); SM.Debug("##### onSTOP #####"); // Unbind from the service - if (isBound) { - getApplicationContext().unbindService(serviceConnection); - isBound = false; - } - + if (isBound) { + getApplicationContext().unbindService(serviceConnection); + isBound = false; + } } - - @Override - public void onStart() - { - super.onStart(); - SM.Debug("##### onSTART #####"); - - if(AppParams.DEMO) - { + + @Override + public void onStart() { + super.onStart(); + SM.Debug("##### onSTART #####"); + + if (AppParams.DEMO) { etPassword.setText("demo"); etUsername.setText("demo"); } - - if(loadingDialog!=null) - loadingDialog.cancel(); - - - // get Users only if IP and PORT are completed - if(!AppParams.IP.equals("n/a") && !AppParams.PORT.equals("n/a") && !AppParams.DEMO) - { - if(tcp == null) - { - new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(300); - } catch (InterruptedException e) { - e.printStackTrace(); - } - myHandler.post(initTCPRUN); - } - }).start(); - } - } - } - - @Override - // this will be called when the user selects logout or exit - public void onActivityResult(int requestCode, int resultCode, Intent intent) { - - if (requestCode == 0) { - - if (resultCode == RESULT_OK) { - AppParams.ActivityResult result = (ActivityResult) intent.getSerializableExtra("result"); - - if(result == AppParams.ActivityResult.logout) { - SM.Debug("### RESULT ###", "LOGOUT"); - updateUIwithTCPStatus(true); - } - else if(result == AppParams.ActivityResult.restart) { - // check tcp status and set UI - if(myService!= null) - tcp = myService.getTCPConnection(); - - SM.Debug("### RESULT ###", "RESTART"); - - /* authenticate again if tcp is ok */ - Timer t = new Timer(); - t.schedule(new TimerTask() { - @Override - public void run() { - myHandler.post(new Runnable() { - @Override - public void run() { - - if(tcp!=null && tcp.isConnectionUP) { - if(!loadingDialog.isShowing()) - loadingDialog.show(); - - enableUI(true); - layoutTCP.setVisibility(View.INVISIBLE); - new connectTask().execute("login"); - } - } - }); - } - }, 1000); - } - else if(result == AppParams.ActivityResult.tcpDown) { - SM.Debug("### RESULT ###", "TCP DOWN"); - updateUIwithTCPStatus(false); - } - else if(result == AppParams.ActivityResult.exit) { - SM.Debug("### RESULT ###", "EXIT"); - whenBackPressed(); - } - } else if (resultCode == RESULT_CANCELED) { - //SM.Debug("LogOut","CANCeled " + (intent==null ? "null" : "not null")); - } - } - - resetAppLists(); - } - - private void resetAppLists() { - SM.Exception("################ RESET ##############"); - - AppParams.listContacts.clear(); - AppParams.listRecordings.clear(); - AppParams.hashTextMessagesByRadioID.clear(); - AppParams.listZones.clear(); - AppParams.crtAckedTextMessage = new PadTextMessage(); - AppParams.crtChannel = new Channel(); - AppParams.crtContact = new Contact(); - AppParams.crtEmergencyState = new Emerg(); - AppParams.crtIncCall = new IncCall(); - AppParams.crtRadio = new Radio(); - AppParams.crtRadioStatus = new RadioStatus(); - AppParams.crtReceivedTextMessage = new PadTextMessage(); - AppParams.crtRecording = new PadRecording(); - AppParams.crtSentTextMessage = new PadTextMessage(); - - } - - - private OnClickListener changeIPListener = new OnClickListener() { + if (loadingDialog != null) + loadingDialog.cancel(); + + // get Users only if IP and PORT are completed + if (tcp == null && !AppParams.IP.equals("n/a") && !AppParams.PORT.equals("n/a") && !AppParams.DEMO) { + new Thread(() -> { + try { + Thread.sleep(300); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + uiHandler.post(initTCPRUN); + }).start(); + } + } + + @Override + // this will be called when the user selects logout or exit + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + final String TAG = "### RESULT ###"; + if (requestCode == 0 && resultCode == RESULT_OK) { + ActivityResult result = (ActivityResult) intent.getSerializableExtra("result"); + if (result == ActivityResult.logout) { + SM.Debug(TAG, "LOGOUT"); + updateUIwithTCPStatus(true); + } else if (result == ActivityResult.restart) { + // check tcp status and set UI + if (myService != null) + tcp = myService.getTCPConnection(); + + SM.Debug(TAG, "RESTART"); + + /* authenticate again if tcp is ok */ + Timer t = new Timer(); + t.schedule(new TimerTask() { + @Override + public void run() { + uiHandler.post(() -> { + + if (tcp != null && tcp.isConnectionUP) { + if (!loadingDialog.isShowing()) + loadingDialog.show(); + + enableUI(true); + layoutTCP.setVisibility(View.INVISIBLE); + new connectTask().execute(LOGIN); + } + }); + } + }, 1000); + } else if (result == ActivityResult.tcpDown) { + SM.Debug(TAG, "TCP DOWN"); + updateUIwithTCPStatus(false); + } else if (result == ActivityResult.exit) { + SM.Debug(TAG, "EXIT"); + whenBackPressed(); + } + } + resetAppLists(); + } + + private void resetAppLists() { + SM.Exception("################ RESET ##############"); + AppParams.listContacts.clear(); + AppParams.listRecordings.clear(); + AppParams.hashTextMessagesByRadioID.clear(); + AppParams.listZones.clear(); + AppParams.crtAckedTextMessage = new PadTextMessage(); + AppParams.crtChannel = new Channel(); + AppParams.crtContact = new Contact(); + AppParams.crtEmergencyState = new Emerg(); + AppParams.crtIncCall = new IncCall(); + AppParams.crtRadio = new Radio(); + AppParams.crtRadioStatus = new RadioStatus(); + AppParams.crtReceivedTextMessage = new PadTextMessage(); + AppParams.crtRecording = new PadRecording(); + AppParams.crtSentTextMessage = new PadTextMessage(); + } + + + private OnClickListener changeIPListener = new OnClickListener() { @Override public void onClick(View v) { // show dialog - //changeIP(); LinearLayout ll = new LinearLayout(context); ll.setOrientation(LinearLayout.HORIZONTAL); - + final EditText input = new EditText(activity); input.setSelectAllOnFocus(true); input.setText(AppParams.IP); input.setMinWidth(190); input.setHint(getString(R.string.hintIP)); input.setGravity(Gravity.CENTER); - + ll.addView(input, 0); - + final TextView tv = new TextView(context); tv.setText(":"); tv.setTextColor(Color.WHITE); ll.addView(tv, 1); - + final EditText inputPort = new EditText(activity); inputPort.setSelectAllOnFocus(true); inputPort.setText(AppParams.PORT); @@ -538,317 +452,265 @@ public class SDMobileActivity extends Activity { inputPort.setInputType(InputType.TYPE_CLASS_NUMBER); inputPort.setGravity(Gravity.CENTER); ll.addView(inputPort, 2); - + ll.setGravity(Gravity.CENTER); - + new AlertDialog.Builder(activity) - .setTitle(getString(R.string.appServerIP)) - .setMessage(getString(R.string.enterIPPort)) - .setView(ll) - .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - Editable value = input.getText(); - Editable valuePort = inputPort.getText(); - - try { - if(Integer.parseInt(valuePort.toString()) > 0 && Integer.parseInt(valuePort.toString()) < 65535) - saveIPandRestartTCP(value.toString(), valuePort.toString()); - else - Toast.makeText(context, getString(R.string.invalidPort), Toast.LENGTH_SHORT).show(); - } - catch(Exception ex) { - Toast.makeText(context, getString(R.string.invalidPort), Toast.LENGTH_SHORT).show(); - } - - - } - }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - // close dialog - dialog.dismiss(); + .setTitle(getString(R.string.appServerIP)) + .setMessage(getString(R.string.enterIPPort)) + .setView(ll) + .setPositiveButton(getString(R.string.ok), (dialog, whichButton) -> { + Editable value = input.getText(); + Editable valuePort = inputPort.getText(); - // hide keyboard - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + try { + if (Integer.parseInt(valuePort.toString()) > 0 && Integer.parseInt(valuePort.toString()) < 65535) + saveIPandRestartTCP(value.toString(), valuePort.toString()); + else + Toast.makeText(context, getString(R.string.invalidPort), Toast.LENGTH_SHORT).show(); + } catch (Exception ex) { + Toast.makeText(context, getString(R.string.invalidPort), Toast.LENGTH_SHORT).show(); + } - } - }).show(); - + + }).setNegativeButton(getString(R.string.cancel), (dialog, whichButton) -> { + // close dialog + dialog.dismiss(); + + // hide keyboard + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + + }).show(); } }; - - private void whenBackPressed() - { - if(tcp!=null) - { - tcp.Stop(); - if(tcpParser!=null) - tcpParser.Stop(); - } - - CancelTimerLogin(); - - try - { - getApplicationContext().unbindService(serviceConnection); - } - catch(IllegalArgumentException ex) - { - - } - - activity.finish(); - android.os.Process.killProcess(android.os.Process.myPid()); - System.exit(0); - } - - // Create runnable for posting - final Runnable initTCPRUN = new Runnable() { - public void run() { - // start thread to add listener - SM.Debug("##### initTCPRUN"); - if(!AppParams.DEMO) - tcpInit(); - } - }; - - @Override - public void onPause() - { - super.onPause(); + + private void whenBackPressed() { + if (tcp != null) { + tcp.Stop(); + if (tcpParser != null) + tcpParser.Stop(); + } + + cancelTimerLogin(); + + try { + getApplicationContext().unbindService(serviceConnection); + } catch (IllegalArgumentException ignored) { + //ignored + } + + activity.finish(); + android.os.Process.killProcess(android.os.Process.myPid()); + System.exit(0); + } + + // Create runnable for posting + final Runnable initTCPRUN = () -> { + // start thread to add listener + SM.Debug("##### initTCPRUN"); + if (!AppParams.DEMO) + tcpInit(); + }; + + @Override + public void onPause() { + super.onPause(); SM.Debug("##### onPAUSE #####"); - } + } - @Override - public void onResume() - { - super.onResume(); + @Override + public void onResume() { + super.onResume(); SM.Debug("##### onRESUME #####"); - } + } + + + private void startTabActivity(long userID) { + // good login - load activity + Intent intent = new Intent(context, TabLayoutActivity.class); + + // send parameters + intent.putExtra("userID", userID); + intent.putExtra(USERNAME, etUsername.getText().toString()); + intent.putExtra(PASSWORD, etPassword.getText().toString()); - - private void startTabActivity(long userID) { - // good login - load activity - Intent intent=new Intent(context, TabLayoutActivity.class); - - // send parameters - intent.putExtra("userID", userID); - intent.putExtra("username", etUsername.getText().toString()); - intent.putExtra("password", etPassword.getText().toString()); - AppParams.USERNAME = etUsername.getText().toString(); AppParams.PASSWORD = etPassword.getText().toString(); AppParams.USERID = userID; - - if(!AppParams.DEMO) { + + if (!AppParams.DEMO && tcpParser != null && itcpListener != null) { // unregister tcpParser - if(tcpParser!= null && itcpListener != null) - tcpParser.removeTCPListener(itcpListener); + tcpParser.removeTCPListener(itcpListener); } - + // start activity startActivityForResult(intent, 0); - } - - - private void updateUIwithTCPStatus(boolean enable) - { - + } + + private void updateUIwithTCPStatus(boolean enable) { SM.Debug("UPDATE UI :" + enable); - if(enable) + if (enable) layoutTCP.setVisibility(View.INVISIBLE); else layoutTCP.setVisibility(View.VISIBLE); - + enableUI(enable); } - - - final Runnable CancelLoadingDialogRUN = new Runnable() { - @Override - public void run() { - // cancel loading dialog and show sending error message - CancelLoadingDialog(); - } - }; - + // cancel loading dialog and show sending error message - private void CancelLoadingDialog() - { + private void cancelLoadingDialog() { // cancel loading dialog - if(loadingDialog!=null) + if (loadingDialog != null) loadingDialog.cancel(); - //if() - { - // show connection error - //showDialog("Could not load users!! Please check the connection and restart."); + } + + // this will cancel the timer that waits for the authenticating procedure to complete + private void cancelTimerLogin() { + if (timerLogin != null) { + timerLogin.cancel(); + timerLogin = null; } } - - // this will cancel the timer that waits for the autheticating procedure to complete - private void CancelTimerLogin() { - if(timerLogin!=null) { - timerLogin.cancel(); - timerLogin = null; - } - } - - - // listener when select language pressed - private OnClickListener LanguageListener = new OnClickListener() { - + + // listener when select language pressed + 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) { - Bundle saved = new Bundle(); - saved.putString("username", etUsername.getText().toString()); - saved.putString("password", etPassword.getText().toString()); - saved.putBoolean("checked", checkBoxSaveDefault.isChecked()); + 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, (dialog, which) -> { + Bundle saved = new Bundle(); + saved.putString(USERNAME, etUsername.getText().toString()); + saved.putString(PASSWORD, etPassword.getText().toString()); + saved.putBoolean("checked", checkBoxSaveDefault.isChecked()); + switch (which) { + case 0: + imageLanguage.setImageResource(R.drawable.en); + saved.putString(LANGUAGE, "en"); + AppParams.LANGUAGETMP = "en"; + AppParams.LANGUAGE = "en"; + break; + case 1: + imageLanguage.setImageResource(R.drawable.de); + saved.putString(LANGUAGE, "de"); + AppParams.LANGUAGETMP = "de"; + AppParams.LANGUAGE = "de"; + break; + case 2: + imageLanguage.setImageResource(R.drawable.tr); + saved.putString(LANGUAGE, "tr"); + AppParams.LANGUAGETMP = "tr"; + AppParams.LANGUAGE = "tr"; + break; + case 3: + imageLanguage.setImageResource(R.drawable.ro); + saved.putString(LANGUAGE, "ro"); + AppParams.LANGUAGETMP = "ro"; + AppParams.LANGUAGE = "ro"; + break; + case 4: + imageLanguage.setImageResource(R.drawable.ru); + saved.putString(LANGUAGE, "ru"); + AppParams.LANGUAGETMP = "ru"; + AppParams.LANGUAGE = "ru"; + break; + case 5: + imageLanguage.setImageResource(R.drawable.es); + saved.putString(LANGUAGE, "es"); + AppParams.LANGUAGETMP = "es"; + AppParams.LANGUAGE = "es"; + break; + default: + throw new IllegalStateException("Unexpected value: " + which); + } - switch(which) - { - case 0: imageLanguage.setImageResource(R.drawable.en); - saved.putString("language", "en"); - AppParams.LANGUAGETMP = "en"; AppParams.LANGUAGE = "en"; - break; - case 1: imageLanguage.setImageResource(R.drawable.de); - saved.putString("language", "de"); - AppParams.LANGUAGETMP = "de"; AppParams.LANGUAGE = "de"; - break; - case 2: imageLanguage.setImageResource(R.drawable.tr); - saved.putString("language", "tr"); - AppParams.LANGUAGETMP = "tr"; AppParams.LANGUAGE = "tr"; - break; - case 3: imageLanguage.setImageResource(R.drawable.ro); - saved.putString("language", "ro"); - AppParams.LANGUAGETMP = "ro"; AppParams.LANGUAGE = "ro"; - break; - case 4: imageLanguage.setImageResource(R.drawable.ru); - saved.putString("language", "ru"); - AppParams.LANGUAGETMP = "ru"; AppParams.LANGUAGE = "ru"; - break; - case 5: imageLanguage.setImageResource(R.drawable.es); - saved.putString("language", "es"); - AppParams.LANGUAGETMP = "es"; AppParams.LANGUAGE = "es"; - break; - } + // recreate the activity + onCreate(saved); + }); - // recreate the activity - onCreate(saved); - } - }); - - AlertDialog alert = builder.create(); - alert.show(); + AlertDialog alert = builder.create(); + alert.show(); } - }; - - + }; - private void tcpInit() - { + private void tcpInit() { int port = 0; - try - { - port = Integer.valueOf(AppParams.PORT); - } - catch(Exception ex) - { + try { + port = Integer.parseInt(AppParams.PORT); + } catch (Exception ex) { SM.Debug("PORT is not an integer"); } - //create TCP handle + //create TCP handle SM.Debug("new TCP on IP: " + AppParams.IP + " | PORT: " + port); - + // connect to the server - new connectTask().execute("tcp"); - new connectParserTask().execute(""); - //tcp = new TCPhandler(AppParams.IP, port); - - //new TCPhandler().execute(AppParams.IP, port + ""); - - /* - try { - Thread.sleep(1000); - SM.Debug("new $$$ AUDIO $$$ TCP on IP: " + AppParams.IP ); - AudioHandle audioH = new AudioHandle(AppParams.IP, context); - } catch (InterruptedException e) { - e.printStackTrace(); - } - //*/ - } - - // load settings - public void loadSettings() - { - try - { - // get Preferences for SafeDispatch - AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); - // get default language - AppParams.LANGUAGE = AppParams.prefs.getString("language", databaseLanguage); - // get default username - AppParams.USERNAME = AppParams.prefs.getString("username", "n/a"); - // get default password - AppParams.PASSWORD = AppParams.prefs.getString("password", "n/a"); - // get default IP - AppParams.IP = AppParams.prefs.getString("ip", "192.168.2.100"); - - // get Radio ID & IP - AppParams.RADIOID = AppParams.prefs.getInt("radioId", 100); - AppParams.RADIOIP = AppParams.prefs.getString("radioIp", "192.168.10.40"); - - // get default communication port - AppParams.PORT = AppParams.prefs.getString("port", "13589"); - // get default value -> IP,PORT - AppParams.DEFAULT = AppParams.prefs.getString("default", "0#0"); - // get default sound source value - AppParams.SOURCE = AppParams.prefs.getString("source", "TCP"); - - - SM.Debug("LOAD SETTINGS ### UserName: " + AppParams.USERNAME + " |Password: " + AppParams.PASSWORD - + " |IP: " + AppParams.IP + " |PORT: " + AppParams.PORT + " | Language: " + AppParams.LANGUAGE); - } - catch(Exception ex) - { - Log.e("Exception", "loadSettings exception"); - } + new connectTask().execute("tcp"); + new connectParserTask().execute(""); } - - public void saveSettings(Boolean modify) - { + + // load settings + public void loadSettings() { + try { + // get Preferences for SafeDispatch + AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE); + // get default language + AppParams.LANGUAGE = AppParams.prefs.getString(LANGUAGE, DATABASE_LANGUAGE); + // get default username + AppParams.USERNAME = AppParams.prefs.getString(USERNAME, "n/a"); + // get default password + AppParams.PASSWORD = AppParams.prefs.getString(PASSWORD, "n/a"); + // get default IP + AppParams.IP = AppParams.prefs.getString("ip", "192.168.2.100"); + + // get Radio ID & IP + AppParams.RADIOID = AppParams.prefs.getInt("radioId", 100); + AppParams.RADIOIP = AppParams.prefs.getString("radioIp", "192.168.10.40"); + + // get default communication port + AppParams.PORT = AppParams.prefs.getString("port", "13589"); + // get default value -> IP,PORT + AppParams.DEFAULT = AppParams.prefs.getString(DEFAULT, "0#0"); + // get default sound source value + AppParams.SOURCE = AppParams.prefs.getString("source", "TCP"); + + + SM.Debug("LOAD SETTINGS ### UserName: " + AppParams.USERNAME + " |Password: " + AppParams.PASSWORD + + " |IP: " + AppParams.IP + " |PORT: " + AppParams.PORT + " | LANGUAGE: " + AppParams.LANGUAGE); + } catch (Exception ex) { + SM.Exception("Exception", "loadSettings exception"); + } + } + + public void saveSettings(boolean modify) { // get editor editor = AppParams.prefs.edit(); // put new values - editor.putString("language", AppParams.LANGUAGETMP); + editor.putString(LANGUAGE, AppParams.LANGUAGETMP); editor.putString("languagetmp", AppParams.LANGUAGETMP); // save new username and password - if(modify) - { - if(etUsername.getText().toString().length() > 0) - editor.putString("username", etUsername.getText().toString()); + if (modify) { + if (etUsername.getText().toString().length() > 0) + editor.putString(USERNAME, etUsername.getText().toString()); else - editor.putString("username", "n/a"); - - if(etPassword.getText().toString().length() > 0) - editor.putString("password", etPassword.getText().toString()); + editor.putString(USERNAME, "n/a"); + + if (etPassword.getText().toString().length() > 0) + editor.putString(PASSWORD, etPassword.getText().toString()); else - editor.putString("password", "n/a"); - + editor.putString(PASSWORD, "n/a"); + // safe default -> ip#port - editor.putString("default", AppParams.IP + "#" + AppParams.PORT); - } - else // reset username and password + editor.putString(DEFAULT, AppParams.IP + "#" + AppParams.PORT); + } else // reset username and password { - editor.putString("username", "n/a"); - editor.putString("password", "n/a"); - editor.putString("default", "0#0"); + editor.putString(USERNAME, "n/a"); + editor.putString(PASSWORD, "n/a"); + editor.putString(DEFAULT, "0#0"); } - + AppParams.USERNAME = etUsername.getText().toString(); AppParams.PASSWORD = etPassword.getText().toString(); SM.Debug("SAVE SETTINGS ### UserName: " + AppParams.USERNAME + " |Password: " + AppParams.PASSWORD @@ -856,9 +718,8 @@ public class SDMobileActivity extends Activity { editor.commit(); } - - public void createLoadingDialog(String message) - { + + public void createLoadingDialog(String message) { loadingDialog = new Dialog(context); loadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); loadingDialog.setContentView(R.layout.dialogloading); @@ -870,107 +731,53 @@ public class SDMobileActivity extends Activity { TextView textView1 = (TextView) loadingDialog.findViewById(R.id.textView1); textView1.setText(message); } - - - public void showInfoDialog(String message) - { - dialogInfo = new Dialog(context); - dialogInfo.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialogInfo.setContentView(R.layout.dialog_login); - TextView textTitle = (TextView) dialogInfo.findViewById(R.id.textTitle); - TextView text = (TextView) dialogInfo.findViewById(R.id.text); - TextView text2 = (TextView) dialogInfo.findViewById(R.id.text2); - ImageView image = (ImageView) dialogInfo.findViewById(R.id.image); - textTitle.setText(getString(R.string.connectionError)); - image.setImageResource(R.drawable.error); - text.setText(getString(R.string.userPassError)); - text2.setVisibility(View.GONE); + public void showInfoDialog(String message) { + /* Dialog */ + Dialog dialogInfo = new Dialog(context); + dialogInfo.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialogInfo.setContentView(R.layout.dialog_login); + TextView textTitle = (TextView) dialogInfo.findViewById(R.id.textTitle); + TextView text = (TextView) dialogInfo.findViewById(R.id.text); + TextView text2 = (TextView) dialogInfo.findViewById(R.id.text2); + ImageView image = (ImageView) dialogInfo.findViewById(R.id.image); - dialogInfo.setCancelable(true); - dialogInfo.setCanceledOnTouchOutside(true); - try - { - dialogInfo.show(); - } - catch(Exception ex) - { - ex.toString(); - } + textTitle.setText(getString(R.string.connectionError)); + image.setImageResource(R.drawable.error); + text.setText(getString(R.string.userPassError)); + text2.setVisibility(View.GONE); + + dialogInfo.setCancelable(true); + dialogInfo.setCanceledOnTouchOutside(true); + try { + dialogInfo.show(); + } catch (Exception ex) { + ex.toString(); } - - public void showErrorDialog(String title, String errorMsg) - { - Dialog dialog = new Dialog(context); - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialog.setContentView(R.layout.dialog_login); - dialog.setCancelable(true); - dialog.setCanceledOnTouchOutside(true); + } - TextView textTitle = (TextView) dialog.findViewById(R.id.textTitle); - textTitle.setText(title); - TextView text = (TextView) dialog.findViewById(R.id.text); - TextView text2 = (TextView) dialog.findViewById(R.id.text2); - text2.setVisibility(View.GONE); - ImageView image = (ImageView) dialog.findViewById(R.id.image); - - image.setImageResource(R.drawable.error); - text.setText(errorMsg); - dialog.show(); - } - - /* - public void changeIP() - { - final Dialog dialog = new Dialog(context); - dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); - dialog.setContentView(R.layout.dialogip); + public void showErrorDialog(String title, String errorMsg) { + Dialog dialog = new Dialog(context); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setContentView(R.layout.dialog_login); dialog.setCancelable(true); dialog.setCanceledOnTouchOutside(true); - final EditText editTextIP = (EditText) dialog.findViewById(R.id.editTextIP); - final EditText editTextPort = (EditText) dialog.findViewById(R.id.editTextPort); - if(!AppParams.IP.equals("n/a")) - editTextIP.setText(AppParams.IP); - SM.Debug("######## PORT " + AppParams.PORT); - if(!AppParams.PORT.equals("n/a")) - editTextPort.setText(AppParams.PORT); - //editTextPort.setText(PORT); - Button buttonCancel = (Button) dialog.findViewById(R.id.buttonCancelIP); - buttonCancel.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - // close dialog - dialog.dismiss(); - - // hide keyboard - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); - } - }); - - Button buttonApply = (Button) dialog.findViewById(R.id.buttonApplyIP); - buttonApply.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - EditText editTextIP = (EditText) dialog.findViewById(R.id.editTextIP); - EditText editTextPort = (EditText) dialog.findViewById(R.id.editTextPort); - - saveIPandRestartTCP(editTextIP.getText().toString(), editTextPort.getText().toString()); - - // hide keyboard - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); - // close dialog - dialog.dismiss(); - } - }); - - // show dialog + TextView textTitle = (TextView) dialog.findViewById(R.id.textTitle); + textTitle.setText(title); + TextView text = (TextView) dialog.findViewById(R.id.text); + TextView text2 = (TextView) dialog.findViewById(R.id.text2); + text2.setVisibility(View.GONE); + ImageView image = (ImageView) dialog.findViewById(R.id.image); + + image.setImageResource(R.drawable.error); + text.setText(errorMsg); dialog.show(); - }*/ - + } + private void saveIPandRestartTCP(String myIP, String port) { // get IP - if(myIP.length()>1) + if (myIP.length() > 1) AppParams.IP = myIP; // get Preferences for SafeDispatch // save net ip @@ -980,135 +787,74 @@ public class SDMobileActivity extends Activity { // get PORT AppParams.PORT = port; - if(AppParams.PORT.length()<1) + if (AppParams.PORT.length() < 1) AppParams.PORT = "n/a"; // save port editor.putString("port", AppParams.PORT); editor.commit(); - - SM.Exception("TCP CHANGED WITH IP AND PORT " + myIP + " | " + port); - - + + SM.Exception("TCP CHANGED WITH IP AND PORT " + myIP + " | " + port); + // if port or IP changed - //if(!oldIP.equalsIgnoreCase(IP) || !oldPort.equalsIgnoreCase(PORT)) - { - if(!AppParams.DEMO) - { - if(tcp!=null) - { - tcp.Stop(); - if(tcpParser!= null) - tcpParser.clearMsgList(); - tcp = null; - } - - //showLoadingDialog("Getting users from database..."); - myHandler.post(new Runnable() { - @Override - public void run() { - if(myService != null) - { - myService.stopTCPConnection(); - - - myService.recreateTCPConnection(); - - myHandler.post(initTCPRUN); - - /* - new connectTask().execute(""); - new connectParserTask().execute(""); - */ - // start thread to add listener - - //tcp.updateTCPparameters(AppParams.IP, AppParams.PORT); - } - // recreate tcp - //myService.updateTCPparameters(AppParams.IP, AppParams.PORT); - //myService.recreateTCPConnection(); - //tcpInit(); + if (!AppParams.DEMO) { + if (tcp != null) { + tcp.Stop(); + if (tcpParser != null) + tcpParser.clearMsgList(); + tcp = null; + } - SM.Debug("RECREATE TCP","IP: " + AppParams.IP + " | Port: " + AppParams.PORT); - } - }); + uiHandler.post(() -> { + if (myService != null) { + myService.stopTCPConnection(); - } + + myService.recreateTCPConnection(); + + uiHandler.post(initTCPRUN); + } + SM.Debug("RECREATE TCP", "IP: " + AppParams.IP + " | Port: " + AppParams.PORT); + }); } } - - - public static final String md5(final String s) { - try { - // Create MD5 Hash - MessageDigest digest = java.security.MessageDigest - .getInstance("MD5"); - digest.update(s.getBytes()); - byte messageDigest[] = digest.digest(); - // Create Hex String - StringBuffer hexString = new StringBuffer(); - for (int i = 0; i < messageDigest.length; i++) { - String h = Integer.toHexString(0xFF & messageDigest[i]); - while (h.length() < 2) - h = "0" + h; - hexString.append(h); - } - return hexString.toString(); - - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return ""; - } - - //tcp - public boolean getUsers() - { - if(tcp==null) + public boolean getUsers() { + if (tcp == null) return false; - - if(!tcp.isConnectionUP) + + if (Boolean.FALSE.equals(tcp.isConnectionUP)) return false; - + boolean res = tcp.Write("0.0", "#20#"); - if(res){ + if (res) { SM.Debug("Message sent to app server"); - }else{ + } else { SM.Debug("Could not send message!!"); } return res; - } - - public class connectTask extends AsyncTask - { + + public class connectTask extends AsyncTask { @Override protected TCPhandler doInBackground(String... params) { - - if(params[0].equals("tcp")) { - if(myService!= null) { + + if (params[0].equals("tcp")) { + if (myService != null) { tcp = myService.getTCPConnection(); - if(myService!= null) - tcp = myService.getTCPConnection(); } - //tcp = new TCPhandler(AppParams.IP, Integer.parseInt(AppParams.PORT)); - } - else if (params[0].equals("login")) { + } else if (params[0].equals(LOGIN)) { getUsers(); - - // start a timert to display an error message if response isn't received + + // start a timer to display an error message if response isn't received timerLogin = new Timer(); timerLogin.schedule(new TimerTask() { @Override public void run() { - myHandler.post(new Runnable() { - @Override - public void run() { - loadingDialog.cancel(); - showErrorDialog("Login Error", "Could not receive response for login. Check connectivity and try again"); - } + uiHandler.post(() -> { + loadingDialog.cancel(); + showErrorDialog("Login Error", "Could not receive response for login. Check connectivity and try again"); }); } }, 10000); @@ -1116,199 +862,190 @@ public class SDMobileActivity extends Activity { return null; } } - - public class connectParserTask extends AsyncTask - { + public class connectParserTask extends AsyncTask { @Override protected TCPhandler doInBackground(String... params) { - if(myService!= null) + if (myService != null) tcpParser = myService.getTCPmsgParser(); // add TCPParserListener - if(tcpParser!=null) - { + if (tcpParser != null) { tcpParser.clearITCPListeners(); tcpParser.addTCPListener(itcpListener = new ITCPListener() { @Override - public void onLoginReceived(TCPEvent event) { + public void onLoginReceived(TCPEvent event) { SM.Debug("LoginReceived", "LoginReceived"); - TCPmsg msg= event.msg(); + TCPmsg msg = event.msg(); LoginMSG lMSG = new LoginMSG(msg); - - SM.Debug("userList:" +lMSG.userList.size()); - for(User u: lMSG.userList) - { - SM.Debug("$$$$$$ user:"+u.login + " id:" + u.id + " pass:" + u.password); + + SM.Debug("userList:" + lMSG.userList.size()); + for (User u : lMSG.userList) { + SM.Debug("$$$$$$ user:" + u.login + " id:" + u.id + " pass:" + u.password); } - + // save received users AppParams.allUsers = lMSG.userList; - - boolean good = false; // remembers if username and password are good - for(User u: AppParams.allUsers) - if(u.login.equals(etUsername.getText().toString()) && etPassword.getText().toString().equals(u.password)) - { - good = true; // flag good login + + boolean good = false; // remembers if username and password are good + for (User u : AppParams.allUsers) + if (u.login.equals(etUsername.getText().toString()) && etPassword.getText().toString().equals(u.password)) { + good = true; // flag good login userID = u.id; - SM.Debug("Loged userID (LoginActivity):" +userID); + SM.Debug("Loged userID (LoginActivity):" + userID); } - - if(!good){ + + if (!good) { SM.Debug("Invalid username or password"); // invalid username - //Toast.makeText(context, getString(R.string.invalidUser), Toast.LENGTH_SHORT).show(); - myHandler.post(new Runnable() { - @Override - public void run() { - CancelLoadingDialog(); - CancelTimerLogin(); - showErrorDialog("Login Error",getString(R.string.invalidUser)); - } + uiHandler.post(() -> { + cancelLoadingDialog(); + cancelTimerLogin(); + showErrorDialog("Login Error", getString(R.string.invalidUser)); }); - - } - else - { + } else { // clear tcp listener tcpParser.removeTCPListener(itcpListener); - + AppParams.USERNAME = etUsername.getText().toString(); AppParams.USERID = userID; - + // login was successful so I can load Tab Activity startTabActivity(userID); } } - - @Override - public void onGPSReceived(TCPEvent event) { } - - @Override - public void onSMSReceived(TCPEvent event) { } - - @Override - public void onVehiclesReceived(TCPEvent event) { } - - @Override - public void onLastSMSsReceived(TCPEvent event) { } - - @Override - public void onSMSAckReceived(TCPEvent event) { } - - @Override - public void onNewSMSReceived(TCPEvent event) { } - - @Override - public void onLastPositionsReceived(TCPEvent event) { } - - @Override - public void onRadioMsgReceived(TCPEvent event) { } - - @Override - public void onHistoryPositionsReceived(TCPEvent event) { } - - @Override - public void onHistoryPositionsCountReceived(TCPEvent event) { } - - @Override - public void onAlarmsReceived(TCPEvent event) { } - - @Override - public void onAlarmAckReceived(TCPEvent event) { } - - @Override - public void alarmLiveRecv(TCPEvent event) { } - - @Override - public void onRecordingPlayReceived(TCPEvent event) { } - - @Override - public void onPollReceived(TCPEvent event) { } @Override - public void onConnectionReplyReceived(TCPEvent event) { - SM.Debug("Connection Ack Received","##### Connection Ack Received #####"); + public void onGPSReceived(TCPEvent event) { } @Override - public void onContactsListReceived(TCPEvent event) { } + public void onSMSReceived(TCPEvent event) { + } @Override - public void onRecordingsListReceived(TCPEvent event) { } - + public void onVehiclesReceived(TCPEvent event) { + } + @Override - public void onTextMessagesListReceived(TCPEvent event) { } + public void onLastSMSsReceived(TCPEvent event) { + } + + @Override + public void onSMSAckReceived(TCPEvent event) { + } + + @Override + public void onNewSMSReceived(TCPEvent event) { + } + + @Override + public void onLastPositionsReceived(TCPEvent event) { + } + + @Override + public void onRadioMsgReceived(TCPEvent event) { + } + + @Override + public void onHistoryPositionsReceived(TCPEvent event) { + } + + @Override + public void onHistoryPositionsCountReceived(TCPEvent event) { + } + + @Override + public void onAlarmsReceived(TCPEvent event) { + } + + @Override + public void onAlarmAckReceived(TCPEvent event) { + } + + @Override + public void alarmLiveRecv(TCPEvent event) { + } + + @Override + public void onRecordingPlayReceived(TCPEvent event) { + } + + @Override + public void onPollReceived(TCPEvent event) { + } + + @Override + public void onConnectionReplyReceived(TCPEvent event) { + SM.Debug("Connection Ack Received", "##### Connection Ack Received #####"); + } + + @Override + public void onContactsListReceived(TCPEvent event) { + } + + @Override + public void onRecordingsListReceived(TCPEvent event) { + } + + @Override + public void onTextMessagesListReceived(TCPEvent event) { + } @Override public void onTCPConnectionDown(boolean previuosWasConnectionUp) { - - SM.Debug("TCP connection with:"+ (tcp!=null ? tcp.serverHostname : AppParams.RADIOIP) + ":" - + (tcp!=null ? tcp.getPort() : 0) + " is DOWN!!!"); + SM.Debug("TCP connection with:" + (tcp != null ? tcp.serverHostname : AppParams.RADIOIP) + ":" + + (tcp != null ? tcp.getPort() : 0) + " is DOWN!!!"); // update ui only when a change happens with tcp connection - if(tcp!= null && prevTCPState != tcp.isConnectionUP) - myHandler.post(new Runnable() { - @Override - public void run() { - updateUIwithTCPStatus(false); + if (tcp != null && prevTCPState.equals(tcp.isConnectionUP)) + uiHandler.post(() -> { + updateUIwithTCPStatus(false); - // cancel loading dialog if an authenticating procedure is going on - if(loadingDialog.isShowing()) { - CancelLoadingDialog(); - CancelTimerLogin(); - } + // cancel loading dialog if an authenticating procedure is going on + if (loadingDialog.isShowing()) { + cancelLoadingDialog(); + cancelTimerLogin(); } }); - if(tcp != null) + if (tcp != null) prevTCPState = tcp.isConnectionUP; - + // I can cancel the timer because I don't need for it to request the TCP status - // the listener is now created and it will handle all the events broadcasted - CancelTimerLogin(); + // the listener is now created and it will handle all the events broadcast + cancelTimerLogin(); } @Override - public void onTCPConnectionUp(boolean previuosWasConnectionUp) { - SM.Debug("TCP connection with:"+ (tcp!=null ? tcp.serverHostname : AppParams.RADIOIP) + " is UP!!!"); + public void onTCPConnectionUp(boolean previousWasConnectionUp) { + SM.Debug("TCP connection with:" + (tcp != null ? tcp.serverHostname : AppParams.RADIOIP) + " is UP!!!"); // update state only if previous was offline - if(!prevTCPState || layoutTCP.getVisibility()==View.VISIBLE) - { - //SM.Debug("TCP connection with:"+tcp.serverHostname + " is OKKKKK!!!"); - myHandler.post(new Runnable() { - @Override - public void run() { - updateUIwithTCPStatus(true); - } - }); + if (Boolean.TRUE.equals(!prevTCPState) || layoutTCP.getVisibility() == View.VISIBLE) { + uiHandler.post(() -> updateUIwithTCPStatus(true)); } - if(tcp != null) + if (tcp != null) prevTCPState = tcp.isConnectionUP; - + // I can cancel the timer because I don't need for it to request the TCP status // the listener is now created and it will handle all the events broadcasted - CancelTimerLogin(); + cancelTimerLogin(); } - - + @Override public void onTCPConnectionStatusReceived(boolean isConnectionUp, boolean previuosWasConnectionUp) { - + } @Override public void onPONGReceived() { // TODO Auto-generated method stub - } }); - + } return null; } } - - } \ 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 fe01c66..5abc586 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -12,7 +12,6 @@ import java.util.Locale; import java.util.Timer; import java.util.TimerTask; -/** fix import */ import com.safemobile.activities.AbstractEmptyActivity; import com.safemobile.activities.AbstractLiveActivity; import com.safemobile.activities.AbstractMessagesActivity; @@ -200,16 +199,16 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(AppParams.DEMO) { - allVehicle.add(new Vehicle(101, "101", 101, "101", 101, 101, 101, 0)); - allVehicle.add(new Vehicle(102, "102", 102, "102", 102, 102, 102, 0)); - allVehicle.add(new Vehicle(103, "103", 103, "Ambulance", 78, 103, 103, 0)); - allVehicle.add(new Vehicle(104, "104", 104, "104", 104, 104, 104, 0)); - allVehicle.add(new Vehicle(105, "105", 105, "Police", 105, 105, 105, 0)); - allVehicle.add(new Vehicle(106, "106", 106, "Mike", 106, 106, 106, 0)); - allVehicle.add(new Vehicle(107, "107", 107, "Rob", 107, 107, 107, 0)); - allVehicle.add(new Vehicle(108, "108", 108, "Ben", 108, 108, 108, 0)); - allVehicle.add(new Vehicle(109, "109", 109, "Taxi_3", 109, 109, 109, 0)); - allVehicle.add(new Vehicle(110, "110", 110, "Pam", 110, 110, 110, 0)); + getAllVehicle().add(new Vehicle(101, "101", 101, "101", 101, 101, 101, 0)); + getAllVehicle().add(new Vehicle(102, "102", 102, "102", 102, 102, 102, 0)); + getAllVehicle().add(new Vehicle(103, "103", 103, "Ambulance", 78, 103, 103, 0)); + getAllVehicle().add(new Vehicle(104, "104", 104, "104", 104, 104, 104, 0)); + getAllVehicle().add(new Vehicle(105, "105", 105, "Police", 105, 105, 105, 0)); + getAllVehicle().add(new Vehicle(106, "106", 106, "Mike", 106, 106, 106, 0)); + getAllVehicle().add(new Vehicle(107, "107", 107, "Rob", 107, 107, 107, 0)); + getAllVehicle().add(new Vehicle(108, "108", 108, "Ben", 108, 108, 108, 0)); + getAllVehicle().add(new Vehicle(109, "109", 109, "Taxi_3", 109, 109, 109, 0)); + getAllVehicle().add(new Vehicle(110, "110", 110, "Pam", 110, 110, 110, 0)); listSMS = new ArrayList(); @@ -219,7 +218,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ listSMS.add(new SMS(3, 1, 1328060100, "i'm at the train station", 0, 102)); listSMS.add(new SMS(4, 1, 1121016818, "I'll be right there", 0, 103)); - for(Vehicle veh:allVehicle) + for(Vehicle veh: getAllVehicle()) { SuperVehicle tmpSuper = new SuperVehicle(veh.sc_id,veh.imei,veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen); if (veh.sc_id == 101) @@ -243,8 +242,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ else if (veh.sc_id == 110) tmpSuper.SetDataFromLastPos(41.748391,-87.933497, Calendar.getInstance().getTimeInMillis(), 47, "Historic U.S. 66, Burr Ridge, IL 60527 , USA", true); - SuperVehHash.put(Long.valueOf(veh.imei), tmpSuper); - VehHashbySc_id.put(veh.sc_id, veh); + getSuperVehHash().put(Long.valueOf(veh.imei), tmpSuper); + getVehHashByScId().put(veh.sc_id, veh); } } @@ -254,7 +253,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // do not dim the display getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - // get NewMessage Visual Element layoutNewMessage = (RelativeLayout) findViewById(R.id.layoutNewMessage); textViewNMMessage = (TextView) findViewById(R.id.textViewNMMessage); @@ -422,7 +420,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(AppParams.DEMO && messageActivity.allVehicle.size()== 0) { - messageActivity.UpdateVehs(allVehicle); + messageActivity.UpdateVehs(getAllVehicle()); messageActivity.UpdateSMS(listSMS); } } @@ -453,7 +451,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(radioActivity!= null && radioActivity.allVehicle!= null && radioActivity.allVehicle.size()==0) { - radioActivity.allVehicle = allVehicle; + radioActivity.allVehicle = getAllVehicle(); radioActivity.UpdateVehicle(); } } @@ -751,7 +749,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(AppParams.DEMO && liveActivity != null) { - liveActivity.vehiclesReceived(allVehicle); + liveActivity.vehiclesReceived(getAllVehicle()); demoPositionsList(); } @@ -826,7 +824,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ tabHost.setCurrentTabByTag("Text"); AppParams.crtTab = AppParams.Tabs.message; - messageActivity.sc_id = getVehicle4Imei(imei).sc_id; + messageActivity.sc_id = getVehicle4Imei(getImei()).sc_id; messageActivity.LASTMESSAGES = false; messageActivity.GetLastSMS(); @@ -1055,14 +1053,14 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void run() { if(AppParams.crtTab == AppParams.Tabs.live) { - if(SuperVehHash.containsKey((long)101)) + if(getSuperVehHash().containsKey((long)101)) { HistPos crtPos = demoPositions.get(demoPosition++ % demoPositions.size()); SM.Debug("########### UPDATE"); int sc_id = demoPosition%3 == 0 ? 101:102; - ((SuperVehicle)SuperVehHash.get((long)sc_id)).SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed); + ((SuperVehicle) getSuperVehHash().get((long)sc_id)).SetNewPosition(crtPos.lat, crtPos.lng, Calendar.getInstance().getTime().getTime(), crtPos.speed); liveActivity.refreshMap(); } } @@ -1075,9 +1073,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ HistPos crtPos = demoPositions.get(demoPosition++ % demoPositions.size()); SM.Debug("########### UPDATE"); - int sc_id = Integer.parseInt(imei); - ((SuperVehicle)SuperVehHash.get((long)sc_id)).SetNewPosition(crtPos.lat + 0.0002, crtPos.lng + 0.0002, Calendar.getInstance().getTime().getTime(), crtPos.speed+2); - mess = "Lat:" + String.format("%5f", crtPos.lat + 0.0002) + ", Lng:" + String.format("%5f", crtPos.lng + 0.0002); + 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); + setMess("Lat:" + String.format("%5f", crtPos.lat + 0.0002) + ", Lng:" + String.format("%5f", crtPos.lng + 0.0002)); liveActivity.refreshMap(); } @@ -1143,7 +1141,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // when connection becomes true after it was false - if(allVehicle.size() == 0) + if(getAllVehicle().size() == 0) //connectTask.doIn(OperationCodes.GetVehicles, new Object[] {AppParams.USERID}); new ConnectTask().execute(new String[] {OperationCodes.GetVehicles + "", AppParams.USERID + ""}); //getVehicles(AppParams.USERID); @@ -1237,11 +1235,11 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ GPSmsg GPSPos= new GPSmsg(msg); //SM.Debug("Got new GPS pos data:" + GPSPos.data); - if(SuperVehHash.get(GPSPos.gpsValue.imei) != null) + if(getSuperVehHash().get(GPSPos.gpsValue.imei) != null) { - ((SuperVehicle)SuperVehHash.get(GPSPos.gpsValue.imei)).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); + ((SuperVehicle) getSuperVehHash().get(GPSPos.gpsValue.imei)).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); - if(SuperVehHash.get(GPSPos.gpsValue.imei).needUpdate) + if(getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { //list for live @@ -1269,23 +1267,23 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("Got POLL GPS message"); TCPmsg msg= event.msg(); GPSmsg GPSPos= new GPSmsg(msg); - imei = Long.toString(GPSPos.gpsValue.imei); - mess = "LAT:"+Double.toString(GPSPos.gpsValue.lat)+" LNG:"+Double.toString(GPSPos.gpsValue.lng); + setImei(Long.toString(GPSPos.gpsValue.imei)); + setMess("LAT:"+Double.toString(GPSPos.gpsValue.lat)+" LNG:"+Double.toString(GPSPos.gpsValue.lng)); SM.Debug("Got new Poll pos data:" + GPSPos.data); - if(SuperVehHash.get(GPSPos.gpsValue.imei) != null) + if(getSuperVehHash().get(GPSPos.gpsValue.imei) != null) { - ((SuperVehicle)SuperVehHash.get(GPSPos.gpsValue.imei)).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); + ((SuperVehicle) getSuperVehHash().get(GPSPos.gpsValue.imei)).SetNewPosition(GPSPos.gpsValue.lat, GPSPos.gpsValue.lng, GPSPos.gpsValue.timeGMT, GPSPos.gpsValue.speed); //if is not check i need to force check to put on the map Boolean forceChecked =false; - if (!SuperVehHash.get(GPSPos.gpsValue.imei).needUpdate) + if (!getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { - SuperVehHash.get(GPSPos.gpsValue.imei).needUpdate =true; + getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate =true; forceChecked =true; } //back to standard procedures to put on the map - if(SuperVehHash.get(GPSPos.gpsValue.imei).needUpdate) + if(getSuperVehHash().get(GPSPos.gpsValue.imei).needUpdate) { //list for live @@ -1298,7 +1296,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ int x = 0; if (forceChecked) { - for (Vehicle veh : allVehicle) + for (Vehicle veh : getAllVehicle()) { if (veh.imei.compareTo(Long.toString(GPSPos.gpsValue.imei))==0) break; x++; @@ -1307,7 +1305,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ else x = -1; if(liveActivity!=null) { - if (x!=allVehicle.size()) + if (x!= getAllVehicle().size()) liveActivity.pollReceived(x ,GPSPos.gpsValue.lat,GPSPos.gpsValue.lng); else liveActivity.pollReceived(-1 ,GPSPos.gpsValue.lat,GPSPos.gpsValue.lng); @@ -1360,10 +1358,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ for(Vehicle veh:vMSG.vehList) { SuperVehicle tmpSuper = new SuperVehicle(veh.sc_id,veh.imei,veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen); - SuperVehHash.put(Long.valueOf(veh.imei), tmpSuper); - VehHashbySc_id.put(veh.sc_id, veh); + getSuperVehHash().put(Long.valueOf(veh.imei), tmpSuper); + getVehHashByScId().put(veh.sc_id, veh); } - SM.Debug(" #$############# " + SuperVehHash.size() + " \nVEH " + vMSG.vehList.size()); + SM.Debug(" #$############# " + getSuperVehHash().size() + " \nVEH " + vMSG.vehList.size()); } catch (Exception ex) { @@ -1386,7 +1384,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(messageActivity != null) messageActivity.UpdateVehs(vMSG.vehList); } - allVehicle = vMSG.vehList; + setAllVehicle(vMSG.vehList); } public void onLastSMSsReceived(TCPEvent event) { @@ -1459,8 +1457,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("Message:" + tempArr[1]); // change Visual Elements - imei = tempArr[0]; - mess = tempArr[1]; + setImei(tempArr[0]); + setMess(tempArr[1]); long time = Calendar.getInstance().getTimeInMillis() / 1000; try { // get time from the last received sms and divide it to 1000 to convert it to seconds @@ -1532,8 +1530,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ //SM.Debug("Got LastPost msg.data:" + msg.data); for(LastPos posMsg: lastPos.PosList) { - if(SuperVehHash.get(posMsg.imei) != null) - ((SuperVehicle)SuperVehHash.get(posMsg.imei)).SetDataFromLastPos(posMsg.lat, posMsg.lng, posMsg.timeGMT, posMsg.speed, posMsg.Address, posMsg.isON); + if(getSuperVehHash().get(posMsg.imei) != null) + ((SuperVehicle) getSuperVehHash().get(posMsg.imei)).SetDataFromLastPos(posMsg.lat, posMsg.lng, posMsg.timeGMT, posMsg.speed, posMsg.Address, posMsg.isON); } } @@ -1890,33 +1888,33 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(tabHost.getCurrentTab() != 5) { // change Visual Elements - imei = UnitIMEI; + setImei(UnitIMEI); switch (msg.opCode) { - case 135: mess = "speed "+tempArr[1]; + case 135: setMess("speed "+tempArr[1]); break; - case 136: mess = "landmark "+tempArr[1]; + case 136: setMess("landmark "+tempArr[1]); break; - case 137: mess = "zone "+tempArr[1]; + case 137: setMess("zone "+tempArr[1]); break; - case 138: mess = "emergency"; + case 138: setMess("emergency"); break; - case 140: mess = "telemetry "+ tempArr[1]; + case 140: setMess("telemetry "+ tempArr[1]); break; default: - mess = "emergency"; + setMess("emergency"); } myHandler.post(UpdateResultsAlarm); if ((msg.opCode==138)&&(AppParams.crtTab == AppParams.Tabs.live)) { - if(SuperVehHash.get(Long.parseLong(UnitIMEI)) != null) + 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 (!SuperVehHash.get(Long.parseLong(UnitIMEI)).needUpdate) + if (!getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate) { - SuperVehHash.get(Long.parseLong(UnitIMEI)).needUpdate =true; + getSuperVehHash().get(Long.parseLong(UnitIMEI)).needUpdate =true; forceChecked =true; } try @@ -1924,7 +1922,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ int x = 0; if (forceChecked) { - for (Vehicle veh : allVehicle) + for (Vehicle veh : getAllVehicle()) { if (veh.imei.compareTo(UnitIMEI)==0) break; x++; @@ -1933,10 +1931,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ else x = -1; if(liveActivity != null) { - if (x!=allVehicle.size()) - liveActivity.emergencyAlarmReceived(x ,SuperVehHash.get(Long.parseLong(UnitIMEI)).lat,SuperVehHash.get(Long.parseLong(UnitIMEI)).lng); + if (x!= getAllVehicle().size()) + liveActivity.emergencyAlarmReceived(x , getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); else - liveActivity.emergencyAlarmReceived(-1, SuperVehHash.get(Long.parseLong(UnitIMEI)).lat,SuperVehHash.get(Long.parseLong(UnitIMEI)).lng); + liveActivity.emergencyAlarmReceived(-1, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lat, getSuperVehHash().get(Long.parseLong(UnitIMEI)).lng); } } catch (Exception ex) @@ -1963,8 +1961,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if (rec.typeID==1) rec.NameForDisplay = AppParams.USERNAME; else { - if (SuperVehHash.get((long)rec.subID)!=null) - rec.NameForDisplay = SuperVehHash.get((long)rec.subID).name; + if (getSuperVehHash().get((long)rec.subID)!=null) + rec.NameForDisplay = getSuperVehHash().get((long)rec.subID).name; } } @@ -2045,10 +2043,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ activePopupType= MsgType.ALARM; imageViewPopUp.setImageResource(R.drawable.siren_on); slideTabsText.setText(getString(R.string.newAlarm)); - if (getVehicle4Imei(imei)!=null) - textViewNMFrom.setText(getString(R.string.from) + ": " + getVehicle4Imei(imei).name); - else textViewNMFrom.setText(getString(R.string.from) + ": " + imei); - textViewNMMessage.setText("TYPE: " + mess); + if (getVehicle4Imei(getImei())!=null) + textViewNMFrom.setText(getString(R.string.from) + ": " + getVehicle4Imei(getImei()).name); + else textViewNMFrom.setText(getString(R.string.from) + ": " + getImei()); + textViewNMMessage.setText("TYPE: " + getMess()); // show layout layoutNewMessage.setVisibility(View.VISIBLE); @@ -2085,7 +2083,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ // set TextViews String from = ""; Vehicle fromVehicle = null; - if((fromVehicle = getVehicle4Imei(imei)) != null) + if((fromVehicle = getVehicle4Imei(getImei())) != null) from = fromVehicle.name; if(tcp!=null && !AppParams.DEMO) @@ -2094,7 +2092,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ imageViewPopUp.setImageResource(R.drawable.poll); slideTabsText.setText("Poll Reply"); textViewNMFrom.setText("From: " + from); - textViewNMMessage.setText(mess); + textViewNMMessage.setText(getMess()); // show layout layoutNewMessage.setVisibility(View.VISIBLE); @@ -2111,7 +2109,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ imageViewPopUp.setImageResource(R.drawable.poll); slideTabsText.setText("Poll Reply"); textViewNMFrom.setText("From: " + from); - textViewNMMessage.setText(mess); + textViewNMMessage.setText(getMess()); // show layout layoutNewMessage.setVisibility(View.VISIBLE); /* @@ -2143,8 +2141,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ activePopupType = MsgType.SMS; imageViewPopUp.setImageResource(R.drawable.message); slideTabsText.setText("New Message"); - textViewNMFrom.setText("From: " + getVehicle4Imei(imei).name); - textViewNMMessage.setText("MSG: " + mess); + textViewNMFrom.setText("From: " + getVehicle4Imei(getImei()).name); + textViewNMMessage.setText("MSG: " + getMess()); // show layout layoutNewMessage.setVisibility(View.VISIBLE); @@ -2157,11 +2155,11 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } else if(AppParams.DEMO) { - mess = "i got your sms"; + setMess("i got your sms"); activePopupType = MsgType.SMS; imageViewPopUp.setImageResource(R.drawable.message); slideTabsText.setText("New Message"); - textViewNMFrom.setText("From: " + getVehicle4Imei(imei).name); + textViewNMFrom.setText("From: " + getVehicle4Imei(getImei()).name); textViewNMMessage.setText("MSG: " + "i got your sms"); // show layout layoutNewMessage.setVisibility(View.VISIBLE); @@ -2181,31 +2179,31 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ public void createNotification(int icon) { mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - String tickerText = "SafeMobile Dispatch: New Message from " + imei; - String contentTitle = "New Message from " + imei; - String contentText = "\"" + mess + "\""; + String tickerText = "SafeMobile Dispatch: New Message from " + getImei(); + String contentTitle = "New Message from " + getImei(); + String contentText = "\"" + getMess() + "\""; - Vehicle veh = getVehicle4Imei(imei); + Vehicle veh = getVehicle4Imei(getImei()); int icon_value = icon; switch(icon) { case AppParams.messageNotif: - contentText = "\"" + mess + "\""; - contentTitle = "New Message from " + imei; + contentText = "\"" + getMess() + "\""; + contentTitle = "New Message from " + getImei(); icon = R.drawable.message; break; case AppParams.pollNotif: - contentText = "\"" + mess + "\"" ; - contentTitle = "Poll Reply from " + (veh !=null ? getVehicle4Imei(imei).name : imei); - tickerText = "SafeMobile Dispatch: Poll Reply from " + (veh !=null ? getVehicle4Imei(imei).name : imei); + contentText = "\"" + getMess() + "\"" ; + contentTitle = "Poll Reply from " + (veh !=null ? getVehicle4Imei(getImei()).name : getImei()); + tickerText = "SafeMobile Dispatch: Poll Reply from " + (veh !=null ? getVehicle4Imei(getImei()).name : getImei()); icon = R.drawable.poll; break; case AppParams.alertNotif: - String vehName = getString(R.string.from) + ": " + imei; + String vehName = getString(R.string.from) + ": " + getImei(); if(veh!=null) - vehName = getString(R.string.from) + ": " + (veh !=null ? getVehicle4Imei(imei).name : imei); - contentText ="\"" + mess + "\""; + vehName = getString(R.string.from) + ": " + (veh !=null ? getVehicle4Imei(getImei()).name : getImei()); + contentText ="\"" + getMess() + "\""; contentTitle = getString(R.string.newAlarm) + vehName; tickerText = "SafeMobile Dispatch: " + getString(R.string.newAlarm) + vehName; icon = R.drawable.alert; @@ -2240,7 +2238,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ private Vehicle getVehicle4Imei(String imei) { Vehicle veh = null; - for(Vehicle vehicle: allVehicle) + for(Vehicle vehicle: getAllVehicle()) //SM.Debug("Vehicle name:"+vehicle.name+" IMEI:"+vehicle.imei); if(vehicle.imei.equals(imei)) veh = vehicle; @@ -2297,20 +2295,20 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } @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); + double dlat = Math.abs(latMax - latMin); + double dlon = Math.abs(lngMax - lngMin); if(dlat == 0 && dlon == 0) { - if ((LATMAX==LATmin)&&(LATMAX==0)&&(LNGMAX==LNGmin)&&(LNGMAX==0)) return 2; + if ((latMax == latMin)&&(latMax ==0)&&(lngMax == lngMin)&&(lngMax ==0)) return 2; //return 17; } // Center latitude in radians - double clat = Math.PI*(LATmin + LATMAX)/360.; + double clat = Math.PI*(latMin + latMax)/360.; double C = 0.0000107288; double z0 = Math.ceil(Math.log(dlat/(C*height))/0.693); @@ -2550,7 +2548,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ { Long.parseLong(params[2]); } - catch (Exception e) { + catch (Exception ignored) { } getRecentSMSs(Integer.parseInt(params[1]), Long.parseLong(params[2])); @@ -2573,7 +2571,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ break; case OperationCodes.SendAlarmAcknoledge: - sendAlarmAcknoledge(Integer.parseInt(params[1]), Integer.parseInt(params[2])); + sendAlarmAcknowledge(Integer.parseInt(params[1]), Integer.parseInt(params[2])); break; case OperationCodes.GetHistoryPositions: 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 37bdc79..6ffb8a1 100644 --- a/safeDispatch/src/main/java/com/safemobile/lib/sound/TCPaudioClient.java +++ b/safeDispatch/src/main/java/com/safemobile/lib/sound/TCPaudioClient.java @@ -1,21 +1,16 @@ package com.safemobile.lib.sound; -import java.io.BufferedReader; +import com.safemobile.lib.SM; + import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.PrintWriter; import java.net.Socket; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; -import com.safemobile.lib.SM; -import com.safemobile.lib.TCPmsg; - public class TCPaudioClient implements Runnable{ private boolean alive = true;