Compare commits

...

14 Commits

10 changed files with 728 additions and 973 deletions

0
gradlew vendored Normal file → Executable file
View File

View File

@ -155,12 +155,12 @@ public abstract class AbstractSDParentActivity extends TabActivity {
} }
public boolean sendAlarmAcknowledge(int alarm_id, int type) public boolean sendAlarmAcknowledge(int alarm_id, int type, String unitName)
{ {
if(tcp == null) if(tcp == null)
return false; return false;
boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#"); boolean res = tcp.Write("0.0", "#28#" + alarm_id + "#" + type + "#" + AppParams.USERID + "#" + unitName + "#");
if(res) if(res)
SM.Debug("Message [sendAlarmAcknowledge] 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 else
@ -198,12 +198,11 @@ public abstract class AbstractSDParentActivity extends TabActivity {
return res; return res;
} }
public boolean getHistoryPositions(int sc_id, long timeGMTStart, long timeGMTStop) public boolean getHistoryPositions(int sc_id, long timeGMTStart, long timeGMTStop) {
{
if(tcp == null) if(tcp == null)
return false; return false;
String histSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); String histSeqID = "1."+ (int) (System.currentTimeMillis() / 1000L);
boolean res = tcp.Write(histSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#"); boolean res = tcp.Write(histSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#");
if(res) if(res)
SM.Debug("Message [getHistoryPositions] sent to app server"); SM.Debug("Message [getHistoryPositions] sent to app server");
@ -213,8 +212,7 @@ public abstract class AbstractSDParentActivity extends TabActivity {
return res; return res;
} }
public boolean getRadiosList() public boolean getRadiosList() {
{
if(tcp == null) if(tcp == null)
return false; return false;

View File

@ -1,5 +1,24 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' apply plugin: 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
apply plugin: "com.gladed.androidgitversion"
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.3"
}
}
androidGitVersion {
codeFormat 'MNNBBBB'
format '%tag%%.count%'
hideBranches = ['develop']
}
android { android {
compileSdkVersion 31 compileSdkVersion 31
@ -9,6 +28,9 @@ android {
applicationId "com.safemobile.dispatch" applicationId "com.safemobile.dispatch"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 31 targetSdkVersion 31
versionName androidGitVersion.name()
versionCode androidGitVersion.code()
archivesBaseName = "SafeDispatchMobile_v.$versionName"
} }
buildTypes { buildTypes {

View File

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.safemobile.dispatch" package="com.safemobile.dispatch">
android:versionCode="9"
android:versionName="1.0.9">
<!-- require OpenGL ES version 2 for Google Maps --> <!-- require OpenGL ES version 2 for Google Maps -->
<uses-feature <uses-feature

View File

@ -3,7 +3,6 @@ package com.safemobile.dispatch;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
/** fix import*/
import com.safemobile.adapters.AlertGridViewAdapter; import com.safemobile.adapters.AlertGridViewAdapter;
import com.safemobile.adapters.AlertGridViewAdapter.ViewHolder; import com.safemobile.adapters.AlertGridViewAdapter.ViewHolder;
@ -15,11 +14,11 @@ import com.safemobile.lib.SM;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.TextView; import android.widget.TextView;
@ -28,232 +27,213 @@ import android.widget.GridView;
public class AlarmActivity extends Activity { public class AlarmActivity extends Activity {
private Context context; private Context context;
public TabLayoutActivity parentTab; private TabLayoutActivity parentTab;
public ArrayList<Alarm> allAlarms = new ArrayList<Alarm>(); private ArrayList<Alarm> allAlarms = new ArrayList<>();
private ArrayList<Boolean> acknowledged = new ArrayList<Boolean>(); private ArrayList<Boolean> acknowledged = new ArrayList<>();
private AlertGridViewAdapter adapter; private AlertGridViewAdapter adapter;
/* Visual resources */ /* Visual resources */
private GridView gridView; private GridView gridView;
public View convertViewAlarm; private View convertViewAlarm;
private int ack_position;
public Bundle savedInstanceState;
// Need handler for callbacks to the UI thread
private final Handler myHandler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.savedInstanceState = savedInstanceState;
// get parentTab
parentTab = (TabLayoutActivity)getParent();
Locale locale = new Locale(AppParams.LANGUAGETMP);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
context = this;
setContentView(R.layout.tabalarm);
gridView = (GridView) findViewById(R.id.gridViewAlarms); private int ackPosition;
adapter = new AlertGridViewAdapter(this, allAlarms, context, acknowledged); private Bundle savedInstanceState;
gridView.setAdapter(adapter);
// Need handler for callbacks to the UI thread
gridView.setOnItemClickListener(onItemClickListener); private final Handler myHandler = new Handler(Looper.getMainLooper());
// change tab header fontface private static final String ALARM = "alarm";
TextView textView1 = (TextView) findViewById(R.id.textView1);
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf")); /**
textView1.setTextSize(24); * Called when the activity is first created.
*/
parentTab.alarmActivity = this; @Override
} public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
public void onBackPressed() this.setSavedInstanceState(savedInstanceState);
{ // get parentTab
AlertDialog.Builder builder = new AlertDialog.Builder(this); setParentTab((TabLayoutActivity) getParent());
builder.setMessage(getString(R.string.exit))
.setCancelable(false) Locale locale = new Locale(AppParams.LANGUAGETMP);
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() { Locale.setDefault(locale);
public void onClick(DialogInterface dialog, int id) { Configuration config = new Configuration();
parentTab.whenBackPressed(AppParams.ActivityResult.logout); config.locale = locale;
} getBaseContext().getResources().updateConfiguration(config,
}) getBaseContext().getResources().getDisplayMetrics());
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { context = this;
parentTab.whenBackPressed(AppParams.ActivityResult.exit); setContentView(R.layout.tabalarm);
}
}) gridView = findViewById(R.id.gridViewAlarms);
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { adapter = new AlertGridViewAdapter(this, getAllAlarms(), context, acknowledged);
public void onClick(DialogInterface dialog, int id) { gridView.setAdapter(adapter);
dialog.cancel();
} gridView.setOnItemClickListener(onItemClickListener);
});
AlertDialog alert = builder.create(); // change tab header fontFace
alert.show(); TextView textView1 = findViewById(R.id.textView1);
} textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
textView1.setTextSize(24);
@Override
public void onPause() getParentTab().alarmActivity = this;
{ }
super.onPause();
SM.Debug("onPause"); @Override
} public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@Override builder.setMessage(getString(R.string.exit))
public void onResume() .setCancelable(false)
{ .setNeutralButton(getString(R.string.logout), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.logout))
super.onResume(); .setPositiveButton(getString(R.string.ext), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.exit))
if(!AppParams.DEMO) .setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
GetAlarms(); AlertDialog alert = builder.create();
else if (AppParams.DEMO) alert.show();
{ }
for(int i=allAlarms.size()-1; i>=0; i--)
{ @Override
Alarm alarm = allAlarms.get(i); public void onPause() {
if(alarm.ack==1) super.onPause();
allAlarms.remove(i); SM.Debug("onPause");
} }
acknowledged = new ArrayList<Boolean>(); @Override
public void onResume() {
for(int i=0;i<allAlarms.size();i++) super.onResume();
acknowledged.add(false); if (!AppParams.DEMO)
updateResultsInUi("alarm"); getAlarms();
} else {
SM.Debug("onResume"); for (int i = getAllAlarms().size() - 1; i >= 0; i--) {
} Alarm alarm = getAllAlarms().get(i);
if (alarm.ack == 1)
getAllAlarms().remove(i);
private OnItemClickListener onItemClickListener = new OnItemClickListener() { }
acknowledged = new ArrayList<>();
for (int i = 0; i < getAllAlarms().size(); i++)
acknowledged.add(false);
updateResultsInUi(ALARM);
}
SM.Debug("onResume");
}
private final OnItemClickListener onItemClickListener = new OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) { long arg3) {
SM.Debug(" ### CLICK Alarm : " + position); SM.Debug(" ### CLICK Alarm : " + position);
convertViewAlarm = arg1; setConvertViewAlarm(arg1);
// save position // save position
ack_position = position; ackPosition = position;
//Toast.makeText(context, "SETACK " + idx, 1000).show(); if (!AppParams.DEMO)
if(!AppParams.DEMO) setACK(getAllAlarms().get(position).idx, getAllAlarms().get(position).type, getAllAlarms().get(position).unitName);
setACK(allAlarms.get(position).idx,allAlarms.get(position).type); else {
else getAllAlarms().get(position).ack = 1;
{
allAlarms.get(position).ack = 1;
updateResultsInUi("else"); updateResultsInUi("else");
} }
} }
// send ACK to AppServer
private void setACK(int idx, int type, String unitName) {
getParentTab().executeNetworkStuff(new String[]{OperationCodes.SendAlarmAcknoledge + "", idx + "", type + "", unitName});
}
}; };
// Update Alarms received from AppServer // Update Alarms received from AppServer
public void UpdateAlarms(ArrayList<Alarm> list) public void updateAlarms(ArrayList<Alarm> list) {
{ SM.Debug("## updateAlarms: " + list.size());
SM.Debug("## UpdateAlarms: " + list.size()); setAllAlarms(list);
allAlarms = list; acknowledged = new ArrayList<>();
acknowledged = new ArrayList<Boolean>();
// set acknowledged based on alarm.ack value // set acknowledged based on alarm.ack value
for(Alarm alarm: allAlarms)
{
acknowledged.add((alarm.ack == 1)? true: false);
SM.Debug("ALARM", "SC_ID> " + alarm.sc_id + " | "
+ (parentTab.getVehHashByScId().get(alarm.sc_id) == null ? "null" : parentTab.getVehHashByScId().get(alarm.sc_id).name ));
if (parentTab.getVehHashByScId().get(alarm.sc_id)!=null)
alarm.unitName = parentTab.getVehHashByScId().get(alarm.sc_id).name;
/*Enumeration<Long> keylist = parentTab.SuperVehHash.keys();
while(keylist.hasMoreElements())
{
SuperVehicle tmp = (SuperVehicle)((parentTab.SuperVehHash.get((long)keylist.nextElement())));
if (tmp.sc_id==alarm.sc_id)
{
alarm.unitName = tmp.name;
break;
}
}*/
}
myHandler.post(UpdateResultsRUN);
}
// Create runnable for posting
final Runnable UpdateResultsRUN = new Runnable() {
public void run() {
updateResultsInUi("alarm");
}
};
private void updateResultsInUi(String param) for (Alarm alarm : getAllAlarms()) {
{ acknowledged.add(alarm.ack == 1);
if(param.equals("alarm")) SM.Debug("ALARM", "SC_ID> " + alarm.sc_id + " | "
{ + (getParentTab().getVehHashByScId().get(alarm.sc_id) == null ? "null" : getParentTab().getVehHashByScId().get(alarm.sc_id).name));
// set adapter
adapter = new AlertGridViewAdapter(this, allAlarms, context, acknowledged);
gridView.setAdapter(adapter);
}
else
{
adapter.changeACK(ack_position);
SM.Debug("Set ACK: " + ack_position + " | " + (acknowledged.get(ack_position) ? "true": "false"));
ViewHolder viewAlarm = new ViewHolder();
viewAlarm = (ViewHolder) convertViewAlarm.getTag(); if (getParentTab().getVehHashByScId().get(alarm.sc_id) != null)
alarm.unitName = getParentTab().getVehHashByScId().get(alarm.sc_id).name;
switch(acknowledged.get(ack_position) ? 1 : 0) }
{ myHandler.post(updateResultsRUN);
}
// Create runnable for posting
final Runnable updateResultsRUN = () -> updateResultsInUi(ALARM);
private void updateResultsInUi(String param) {
if (param.equals(ALARM)) {
// set adapter
adapter = new AlertGridViewAdapter(this, getAllAlarms(), context, acknowledged);
gridView.setAdapter(adapter);
} else {
adapter.changeACK(ackPosition);
SM.Debug("Set ACK: " + ackPosition + " | " + (Boolean.TRUE.equals(acknowledged.get(ackPosition)) ? "true" : "false"));
ViewHolder viewAlarm;
viewAlarm = (ViewHolder) getConvertViewAlarm().getTag();
switch (Boolean.TRUE.equals(acknowledged.get(ackPosition)) ? 1 : 0) {
case 1: case 1:
viewAlarm.imageViewAlert.setImageResource(R.drawable.alert_off); viewAlarm.imageViewAlert.setImageResource(R.drawable.alert_off);
//view.imgViewIcon.setImageDrawable(adapter.convertToGrayscale(activity.getResources().getDrawable(liveVehicle.get(position).getSmallIcon())));
break; break;
case 0: case 0:
//view.imgViewAlarm.setImageResource(R.drawable.siren); viewAlarm.imageViewAlert.setImageResource(R.drawable.siren);
//view.imgViewIcon.setImageResource(liveVehicle.get(position).getSmallIcon());
break; break;
default:
throw new IllegalStateException("Unexpected value: " + (Boolean.TRUE.equals(acknowledged.get(ackPosition)) ? 1 : 0));
} }
} }
} }
// update ACK received from AppServer // update ACK received from AppServer
public void UpdateACK() public void updateACK() {
{ myHandler.post(updateAckRUN);
myHandler.post(UpdateAckRUN);
} }
// Create runnable for posting // Create runnable for posting
final Runnable UpdateAckRUN = new Runnable() { final Runnable updateAckRUN = () -> {
public void run() { SM.Debug(" updateACK: ");
SM.Debug(" UpdateACK: "); updateResultsInUi("adapter");
updateResultsInUi("adapter"); };
}
}; // send to AppServer
private void getAlarms() {
getParentTab().executeNetworkStuff(new String[]{OperationCodes.GetAlarms + "", AppParams.USERID + ""});
// send to AppServer }
private void GetAlarms()
{ public TabLayoutActivity getParentTab() {
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetAlarms +"", AppParams.USERID + ""}); return parentTab;
//parentTab.getAlarms(AppParams.USERID); }
public void setParentTab(TabLayoutActivity parentTab) {
this.parentTab = parentTab;
}
public ArrayList<Alarm> getAllAlarms() {
return allAlarms;
}
public void setAllAlarms(ArrayList<Alarm> allAlarms) {
this.allAlarms = allAlarms;
}
public View getConvertViewAlarm() {
return convertViewAlarm;
}
public void setConvertViewAlarm(View convertViewAlarm) {
this.convertViewAlarm = convertViewAlarm;
}
public Bundle getSavedInstanceState() {
return savedInstanceState;
}
public void setSavedInstanceState(Bundle savedInstanceState) {
this.savedInstanceState = savedInstanceState;
} }
// send ACK to AppServer
private void setACK(int idx, int type)
{
parentTab.executeNetworkStuff(new String[]{OperationCodes.SendAlarmAcknoledge +"", idx + "", type + ""});
//parentTab.sendAlarmAcknowledge(idx, type);
}
} }

View File

@ -12,10 +12,12 @@ import androidx.annotation.NonNull;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.Marker;
import com.safemobile.lib.HistPos;
import com.safemobile.lib.SuperVehicle; import com.safemobile.lib.SuperVehicle;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale; import java.util.Locale;
@ -25,8 +27,10 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
private final String TAG = GoogleMapsInfoBubble.class.getName(); private final String TAG = GoogleMapsInfoBubble.class.getName();
private final View mWindow; private final View mWindow;
private final Hashtable<Long, SuperVehicle> superVehHash; private Hashtable<Long, SuperVehicle> superVehHash;
private final Context context; private final Context context;
private ArrayList<HistPos> histPosList;
private boolean isLiveTab = true;
public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context, Hashtable<Long, SuperVehicle> vehicles) { public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context, Hashtable<Long, SuperVehicle> vehicles) {
@ -35,6 +39,17 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null); mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null);
} }
public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context) {
isLiveTab = false;
this.context = context;
// this.superVehHash = vehicles;
mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null);
}
public void setHistoryPositions(ArrayList<HistPos> positions) {
this.histPosList = positions;
}
@Override @Override
public View getInfoWindow(@NonNull Marker marker) { public View getInfoWindow(@NonNull Marker marker) {
render(marker, mWindow); render(marker, mWindow);
@ -49,13 +64,21 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
private void render(Marker marker, View view) { private void render(Marker marker, View view) {
long key = 0; long key = 0;
int position = 0;
try { if (isLiveTab) {
key = Long.parseLong(marker.getTitle()); try {
} catch (Exception ex) { key = Long.parseLong(marker.getTitle());
Log.v(TAG, "Unable to parse Google Maps Info Bubble title"); } catch (Exception ex) {
Log.v(TAG, "Unable to parse Google Maps Info Bubble title");
}
} else {
try {
position = Integer.getInteger(marker.getTitle());
} catch (Exception e) {
Log.v(TAG, "Unable to parse Google Maps Info Bubble title on History");
}
} }
SuperVehicle vehicle = superVehHash.get(key);
RelativeLayout rlMapInfoBubbleInfo = view.findViewById(R.id.rlMapInfoBubbleInfo); RelativeLayout rlMapInfoBubbleInfo = view.findViewById(R.id.rlMapInfoBubbleInfo);
TextView tvUnitName = view.findViewById(R.id.tvUnitName); TextView tvUnitName = view.findViewById(R.id.tvUnitName);
@ -67,27 +90,39 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
rlMapInfoBubbleInfo.setVisibility(View.VISIBLE); rlMapInfoBubbleInfo.setVisibility(View.VISIBLE);
boolean isMilitaryTime = false; boolean isMilitaryTime = false;
Date positionTime = new Date(vehicle.timeGMT); Date positionTime;
String speed, address, gpsLocation, name = "";
if (isLiveTab) {
SuperVehicle vehicle = superVehHash.get(key);
positionTime = new Date(vehicle.timeGMT);
address = vehicle.Address != null ? vehicle.Address : "";
name = vehicle.name;
speed = String.format(context.getResources().getString(R.string.speedMph), vehicle.speed);
gpsLocation = "[" + String.format("%.4f", vehicle.lat) + "," + String.format("%.4f",vehicle.lng) + "]";
} else {
HistPos histPos = histPosList.get(position);
positionTime = new Date(histPos.timeGMT);
address = histPos.Address != null ? histPos.Address : "";
speed = String.format(context.getResources().getString(R.string.speedMph), histPos.speed);
gpsLocation = "[" + String.format("%.4f", histPos.lat) + "," + String.format("%.4f",histPos.lng) + "]";
}
String timeFormat = isMilitaryTime String timeFormat = isMilitaryTime
? "HH:mm:ss dd.MMM.yyyy" ? "HH:mm:ss dd.MMM.yyyy"
: "hh:mm:ss a dd.MMM.yyy"; : "hh:mm:ss a dd.MMM.yyy";
DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH); DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
tvTimeAgo.setText(format.format(positionTime)); tvTimeAgo.setText(format.format(positionTime));
tvSpeed.setText(String.format(context.getResources().getString(R.string.speedMph), vehicle.speed));
String address = vehicle.Address != null ? vehicle.Address : "";
tvStreetView.setText(address); tvStreetView.setText(address);
streetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE); streetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
tvStreetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE); tvStreetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
tvUnitName.setText(vehicle.name); if (!isLiveTab)
tvGPSLocation.setText("[" + String.format("%.4f", vehicle.lat) tvUnitName.setVisibility(View.GONE);
+ "," + String.format("%.4f",vehicle.lng) + "]"); else
tvUnitName.setText(name);
tvSpeed.setText(speed);
tvGPSLocation.setText(gpsLocation);
} }
} }

View File

@ -1,17 +1,33 @@
package com.safemobile.dispatch; package com.safemobile.dispatch;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;
import com.safemobile.lib.AppParams; import com.safemobile.lib.AppParams;
import com.safemobile.lib.HistPos;
import com.safemobile.lib.OperationCodes;
import com.safemobile.lib.SM; import com.safemobile.lib.SM;
import com.safemobile.lib.Vehicle; import com.safemobile.lib.Vehicle;
@ -21,19 +37,21 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
public class HistoryActivity extends AppCompatActivity { public class HistoryActivity extends AppCompatActivity implements OnMapReadyCallback {
public Bundle savedInstanceState; public Bundle savedInstanceState;
private TabLayoutActivity parentTab; private TabLayoutActivity parentTab;
private GoogleMap googleMap; private GoogleMap googleMap;
private Spinner spinnerVehicle; private Spinner spinnerVehicle;
private ImageView changeMapType, checkTraffic, slideLayoutImage; private Button displayButton;
private LinearLayout layoutTraffic, slidelayout, layoutVehicles; private Date startDate, endDate;
private final Handler myHandler = new Handler();
private GoogleMapsInfoBubble infoBubble;
private final ArrayList<Vehicle> allVehicle = new ArrayList<>();
private final ArrayList<String> allVehicleNames = new ArrayList<>();
private final SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy");
private ArrayList<Vehicle> allVehicle = new ArrayList<>();
private ArrayList<String> allVehicleNames = new ArrayList<>();
private ArrayAdapter<String> adapter;
private boolean showVehicle = true;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -47,14 +65,15 @@ public class HistoryActivity extends AppCompatActivity {
Locale locale = new Locale(AppParams.LANGUAGETMP); Locale locale = new Locale(AppParams.LANGUAGETMP);
Locale.setDefault(locale); Locale.setDefault(locale);
googleMap = parentTab.liveActivity.getMap();
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map); .findFragmentById(R.id.map);
if (mapFragment != null)
mapFragment.getMapAsync(this);
spinnerVehicle = findViewById(R.id.spinnerVehicle); spinnerVehicle = findViewById(R.id.spinnerVehicle);
getVehicles(); getVehicles();
adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinnerVehicle.setAdapter(adapter); spinnerVehicle.setAdapter(adapter);
spinnerVehicle.setSelection(0); spinnerVehicle.setSelection(0);
@ -62,49 +81,87 @@ public class HistoryActivity extends AppCompatActivity {
changeMapType(); changeMapType();
changeTraffic(); changeTraffic();
slidelayout = findViewById(R.id.slidelayout); displayButton = findViewById(R.id.buttonDisplay);
slideLayoutImage = findViewById(R.id.slideLayoutImage); displayButton.setOnClickListener(view -> {
layoutVehicles = findViewById(R.id.layoutBig); googleMap.clear();
// slidelayout.setOnTouchListener((v, event) -> { if (!AppParams.DEMO) {
// if (showVehicle) { parentTab.dropAllData =false;
// layoutVehicles.setVisibility(View.GONE); parentTab.firstHistData = true;
// slideLayoutImage.setImageResource(R.drawable.arrow_right); parentTab.HistMsgList.clear();
// showVehicle = false; parentTab.HistPosList.clear();
// } else {
// layoutVehicles.setVisibility(View.VISIBLE); // request history
// slideLayoutImage.setImageResource(R.drawable.arrow_left); parentTab.executeNetworkStuff(new String[] {OperationCodes.GetHistoryPositions + "", allVehicle.get(spinnerVehicle.getSelectedItemPosition()).sc_id + "",
// showVehicle = true; (startDate.getTime()/ 1000L) + "", (endDate.getTime()/ 1000L) + ""});
// } } else {
// return false; parentTab.demoPositionsList();
// }); displayHistory(parentTab.demoPositions);
}
});
setDate(); setDate();
} }
private void displayHistory(ArrayList<HistPos> positions) {
LatLng latLng = null;
PolylineOptions polylineOptions = new PolylineOptions();
BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.history_pin);
for (int i = 0; i < positions.size(); i++) {
HistPos pos = positions.get(i);
if (pos.speed > 0) {
latLng = new LatLng(pos.lat, pos.lng);
polylineOptions.add(latLng);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.icon(markerIcon)
.title(String.valueOf(i)));
}
}
googleMap.addPolyline(polylineOptions);
if (latLng != null)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));
}
private void setDate() { private void setDate() {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Date endDate = calendar.getTime(); endDate = calendar.getTime();
calendar.add(Calendar.DATE, -1); calendar.add(Calendar.DATE, -1);
Date startDate = calendar.getTime(); startDate = calendar.getTime();
LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker); TextView textViewStartDate = findViewById(R.id.textViewStartDate);
TextView textViewDate = findViewById(R.id.textViewStartDate); TextView textViewEndDate = findViewById(R.id.textViewEndDate);
textViewDate.setText(new SimpleDateFormat("HH:mm, dd.MM.yyyy").format(startDate)); textViewStartDate.setText(sdf.format(startDate));
// layoutStartPicker.setOnTouchListener((v, event) -> { textViewEndDate.setText(sdf.format(endDate));
// showDialog(layoutStartPicker);
// return false;
// });
// layoutEndPicker.setOnTouchListener(new OnTouchListener() { textViewStartDate.setOnClickListener(view -> openDialog(textViewStartDate, true));
// @Override textViewEndDate.setOnClickListener(view -> openDialog(textViewEndDate, false));
// public boolean onTouch(View v, MotionEvent event) { }
// showDialog(layoutEndPicker);
// return false;
// }
// });
private void openDialog(TextView textView, Boolean isStartDate) {
Date date = startDate;
if (!isStartDate)
date = endDate;
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
DatePickerDialog.OnDateSetListener setListener = (datePicker, y, m, d) -> {
calendar.set(y, m, d);
String dateString = sdf.format(calendar.getTime());
textView.setText(dateString);
if (isStartDate)
startDate = calendar.getTime();
else
endDate = calendar.getTime();
};
Dialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, setListener,
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
} }
private void changeTraffic() { private void changeTraffic() {
@ -121,14 +178,13 @@ public class HistoryActivity extends AppCompatActivity {
} }
private void changeMapType() { private void changeMapType() {
changeMapType = findViewById(R.id.changeMapType); ImageView changeMapType = findViewById(R.id.changeMapType);
ImageView changeMapTypeImageView = findViewById(R.id.changeMapType);
changeMapType.setOnClickListener(view -> { changeMapType.setOnClickListener(view -> {
if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) { if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) {
changeMapTypeImageView.setImageResource(R.drawable.satellite); changeMapType.setImageResource(R.drawable.satellite);
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
} else { } else {
changeMapTypeImageView.setImageResource(R.drawable.map); changeMapType.setImageResource(R.drawable.map);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
} }
}); });
@ -136,15 +192,27 @@ public class HistoryActivity extends AppCompatActivity {
public void getVehicles() { public void getVehicles() {
try { try {
allVehicle.clear();
allVehicleNames.clear();
for (Vehicle vehicle : parentTab.getAllVehicle()) { for (Vehicle vehicle : parentTab.getAllVehicle()) {
allVehicleNames.add(vehicle.name); allVehicleNames.add(vehicle.name);
allVehicle.add(vehicle); allVehicle.add(vehicle);
} }
} catch (Exception ex) { } } catch (Exception ignored) { }
} }
final Runnable UpdateMapResults = new Runnable() {
public void run() {
Log.v("updateMap", parentTab.HistPosList.toString());
SM.Debug("Do the Display");
infoBubble.setHistoryPositions(parentTab.HistPosList);
displayHistory(parentTab.HistPosList);
}
};
public void UpdateMap() { public void UpdateMap() {
myHandler.post(UpdateMapResults);
SM.Debug("Do the updateMAP post"); SM.Debug("Do the updateMAP post");
} }
@ -159,4 +227,15 @@ public class HistoryActivity extends AppCompatActivity {
public void UpdateNrPos(int size) { public void UpdateNrPos(int size) {
SM.Debug("Do Cancelwindow"); SM.Debug("Do Cancelwindow");
} }
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
this.googleMap = googleMap;
infoBubble = new GoogleMapsInfoBubble(getLayoutInflater(), this);
this.googleMap.setInfoWindowAdapter(infoBubble);
parentTab.demoPositionsList();
displayButton.performClick();
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -162,10 +162,11 @@
android:text="@string/startDate" android:text="@string/startDate"
android:textSize="22dp" android:textSize="22dp"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:layout_marginTop="15sp"
android:textColor="#000000" android:textColor="#000000"
android:gravity="left" android:gravity="left"
android:id="@+id/labelStartDate" android:id="@+id/labelStartDate"
android:visibility="gone"/> />
<LinearLayout <LinearLayout
android:id="@+id/layoutStartPicker" android:id="@+id/layoutStartPicker"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -202,7 +203,7 @@
android:textColor="#000000" android:textColor="#000000"
android:gravity="left" android:gravity="left"
android:id="@+id/labelEndDate" android:id="@+id/labelEndDate"
android:visibility="gone"/> />
<LinearLayout <LinearLayout
android:id="@+id/layoutEndPicker" android:id="@+id/layoutEndPicker"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -284,14 +285,15 @@
</LinearLayout> </LinearLayout>
<fragment <fragment
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:id="@+id/map" android:id="@+id/map"
android:layout_toRightOf="@id/slidelayout" android:layout_toRightOf="@id/slidelayout"
android:layout_weight="1" android:layout_weight="1"
tools:context=".HistoryActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" /> android:name="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/changeMapType" android:id="@+id/changeMapType"