change package name + apk && aab
This commit is contained in:
@ -0,0 +1,239 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.safemobile.adapters.AlertGridViewAdapter;
|
||||
import com.safemobile.adapters.AlertGridViewAdapter.ViewHolder;
|
||||
|
||||
import com.safemobile.lib.Alarm;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.GridView;
|
||||
|
||||
public class AlarmActivity extends Activity {
|
||||
private Context context;
|
||||
private TabLayoutActivity parentTab;
|
||||
private ArrayList<Alarm> allAlarms = new ArrayList<>();
|
||||
private ArrayList<Boolean> acknowledged = new ArrayList<>();
|
||||
private AlertGridViewAdapter adapter;
|
||||
|
||||
/* Visual resources */
|
||||
private GridView gridView;
|
||||
private View convertViewAlarm;
|
||||
|
||||
private int ackPosition;
|
||||
private Bundle savedInstanceState;
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
private static final String ALARM = "alarm";
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
this.setSavedInstanceState(savedInstanceState);
|
||||
// get parentTab
|
||||
setParentTab((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 = findViewById(R.id.gridViewAlarms);
|
||||
adapter = new AlertGridViewAdapter(this, getAllAlarms(), context, acknowledged);
|
||||
gridView.setAdapter(adapter);
|
||||
|
||||
gridView.setOnItemClickListener(onItemClickListener);
|
||||
|
||||
// change tab header fontFace
|
||||
TextView textView1 = findViewById(R.id.textView1);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
getParentTab().alarmActivity = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.logout))
|
||||
.setPositiveButton(getString(R.string.ext), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.exit))
|
||||
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (!AppParams.DEMO)
|
||||
getAlarms();
|
||||
else {
|
||||
for (int i = getAllAlarms().size() - 1; i >= 0; i--) {
|
||||
Alarm alarm = getAllAlarms().get(i);
|
||||
if (alarm.ack == 1)
|
||||
getAllAlarms().remove(i);
|
||||
}
|
||||
|
||||
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
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
|
||||
long arg3) {
|
||||
SM.Debug(" ### CLICK Alarm : " + position);
|
||||
setConvertViewAlarm(arg1);
|
||||
// save position
|
||||
ackPosition = position;
|
||||
if (!AppParams.DEMO)
|
||||
setACK(getAllAlarms().get(position).idx, getAllAlarms().get(position).type, getAllAlarms().get(position).unitName);
|
||||
else {
|
||||
getAllAlarms().get(position).ack = 1;
|
||||
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
|
||||
public void updateAlarms(ArrayList<Alarm> list) {
|
||||
SM.Debug("## updateAlarms: " + list.size());
|
||||
setAllAlarms(list);
|
||||
acknowledged = new ArrayList<>();
|
||||
// set acknowledged based on alarm.ack value
|
||||
|
||||
for (Alarm alarm : getAllAlarms()) {
|
||||
acknowledged.add(alarm.ack == 1);
|
||||
SM.Debug("ALARM", "SC_ID> " + alarm.sc_id + " | "
|
||||
+ (getParentTab().getVehHashByScId().get(alarm.sc_id) == null ? "null" : getParentTab().getVehHashByScId().get(alarm.sc_id).name));
|
||||
|
||||
|
||||
if (getParentTab().getVehHashByScId().get(alarm.sc_id) != null)
|
||||
alarm.unitName = getParentTab().getVehHashByScId().get(alarm.sc_id).name;
|
||||
}
|
||||
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:
|
||||
viewAlarm.imageViewAlert.setImageResource(R.drawable.alert_off);
|
||||
break;
|
||||
case 0:
|
||||
viewAlarm.imageViewAlert.setImageResource(R.drawable.siren);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + (Boolean.TRUE.equals(acknowledged.get(ackPosition)) ? 1 : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update ACK received from AppServer
|
||||
public void updateACK() {
|
||||
myHandler.post(updateAckRUN);
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateAckRUN = () -> {
|
||||
SM.Debug(" updateACK: ");
|
||||
updateResultsInUi("adapter");
|
||||
};
|
||||
|
||||
// send to AppServer
|
||||
private void getAlarms() {
|
||||
getParentTab().executeNetworkStuff(new String[]{OperationCodes.GetAlarms + "", AppParams.USERID + ""});
|
||||
}
|
||||
|
||||
public TabLayoutActivity getParentTab() {
|
||||
return parentTab;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.safemobile.lib.HistPos;
|
||||
import com.safemobile.lib.SuperVehicle;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
private final String TAG = GoogleMapsInfoBubble.class.getName();
|
||||
|
||||
private final View mWindow;
|
||||
private Hashtable<Long, SuperVehicle> superVehHash;
|
||||
private final Context context;
|
||||
private ArrayList<HistPos> histPosList;
|
||||
private boolean isLiveTab = true;
|
||||
|
||||
|
||||
public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context, Hashtable<Long, SuperVehicle> vehicles) {
|
||||
this.context = context;
|
||||
this.superVehHash = vehicles;
|
||||
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
|
||||
public View getInfoWindow(@NonNull Marker marker) {
|
||||
render(marker, mWindow);
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getInfoContents(@NonNull Marker marker) {
|
||||
render(marker, mWindow);
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
private void render(Marker marker, View view) {
|
||||
long key = 0;
|
||||
int position = 0;
|
||||
if (isLiveTab) {
|
||||
try {
|
||||
key = Long.parseLong(marker.getTitle());
|
||||
} catch (Exception ex) {
|
||||
Log.v(TAG, "Unable to parse Google Maps Info Bubble title");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
position = Integer.getInteger(marker.getTitle());
|
||||
} catch (Exception e) {
|
||||
Log.v(TAG, "Unable to parse Google Maps Info Bubble title on History");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RelativeLayout rlMapInfoBubbleInfo = view.findViewById(R.id.rlMapInfoBubbleInfo);
|
||||
TextView tvUnitName = view.findViewById(R.id.tvUnitName);
|
||||
TextView tvGPSLocation = view.findViewById(R.id.tvGPSLocation);
|
||||
TextView tvTimeAgo = view.findViewById(R.id.tvTimeAgo);
|
||||
TextView tvSpeed = view.findViewById(R.id.tvSpeed);
|
||||
TextView tvStreetView = view.findViewById(R.id.tvStreetView);
|
||||
ImageView streetView = view.findViewById(R.id.streetView);
|
||||
rlMapInfoBubbleInfo.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean isMilitaryTime = false;
|
||||
Date positionTime;
|
||||
String speed, address, gpsLocation, name = "";
|
||||
if (isLiveTab) {
|
||||
SuperVehicle vehicle = superVehHash.get(key);
|
||||
positionTime = new Date(vehicle.timeGMT);
|
||||
address = vehicle.Address != null ? vehicle.Address : "";
|
||||
name = vehicle.name;
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), vehicle.speed);
|
||||
gpsLocation = "[" + String.format("%.4f", vehicle.lat) + "," + String.format("%.4f",vehicle.lng) + "]";
|
||||
} else {
|
||||
HistPos histPos = histPosList.get(position);
|
||||
positionTime = new Date(histPos.timeGMT);
|
||||
address = histPos.Address != null ? histPos.Address : "";
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), histPos.speed);
|
||||
gpsLocation = "[" + String.format("%.4f", histPos.lat) + "," + String.format("%.4f",histPos.lng) + "]";
|
||||
}
|
||||
|
||||
String timeFormat = isMilitaryTime
|
||||
? "HH:mm:ss dd.MMM.yyyy"
|
||||
: "hh:mm:ss a dd.MMM.yyy";
|
||||
|
||||
DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
|
||||
tvTimeAgo.setText(format.format(positionTime));
|
||||
tvStreetView.setText(address);
|
||||
streetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
|
||||
tvStreetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
|
||||
if (!isLiveTab)
|
||||
tvUnitName.setVisibility(View.GONE);
|
||||
else
|
||||
tvUnitName.setText(name);
|
||||
|
||||
tvSpeed.setText(speed);
|
||||
tvGPSLocation.setText(gpsLocation);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,241 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.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.HistPos;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class HistoryActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
public Bundle savedInstanceState;
|
||||
private TabLayoutActivity parentTab;
|
||||
private GoogleMap googleMap;
|
||||
private Spinner spinnerVehicle;
|
||||
private Button displayButton;
|
||||
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");
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
setContentView(R.layout.tabhistory);
|
||||
|
||||
parentTab = (TabLayoutActivity) getParent();
|
||||
parentTab.historyActivity = this;
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
|
||||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.map);
|
||||
if (mapFragment != null)
|
||||
mapFragment.getMapAsync(this);
|
||||
|
||||
spinnerVehicle = findViewById(R.id.spinnerVehicle);
|
||||
getVehicles();
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
|
||||
spinnerVehicle.setAdapter(adapter);
|
||||
spinnerVehicle.setSelection(0);
|
||||
|
||||
changeMapType();
|
||||
changeTraffic();
|
||||
|
||||
displayButton = findViewById(R.id.buttonDisplay);
|
||||
displayButton.setOnClickListener(view -> {
|
||||
googleMap.clear();
|
||||
if (!AppParams.DEMO) {
|
||||
parentTab.dropAllData =false;
|
||||
parentTab.firstHistData = true;
|
||||
parentTab.HistMsgList.clear();
|
||||
parentTab.HistPosList.clear();
|
||||
|
||||
// request history
|
||||
parentTab.executeNetworkStuff(new String[] {OperationCodes.GetHistoryPositions + "", allVehicle.get(spinnerVehicle.getSelectedItemPosition()).sc_id + "",
|
||||
(startDate.getTime()/ 1000L) + "", (endDate.getTime()/ 1000L) + ""});
|
||||
} else {
|
||||
parentTab.demoPositionsList();
|
||||
displayHistory(parentTab.demoPositions);
|
||||
}
|
||||
});
|
||||
|
||||
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() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
endDate = calendar.getTime();
|
||||
calendar.add(Calendar.DATE, -1);
|
||||
startDate = calendar.getTime();
|
||||
|
||||
TextView textViewStartDate = findViewById(R.id.textViewStartDate);
|
||||
TextView textViewEndDate = findViewById(R.id.textViewEndDate);
|
||||
|
||||
textViewStartDate.setText(sdf.format(startDate));
|
||||
textViewEndDate.setText(sdf.format(endDate));
|
||||
|
||||
textViewStartDate.setOnClickListener(view -> openDialog(textViewStartDate, true));
|
||||
textViewEndDate.setOnClickListener(view -> openDialog(textViewEndDate, false));
|
||||
}
|
||||
|
||||
private void openDialog(TextView textView, Boolean isStartDate) {
|
||||
Date date = startDate;
|
||||
if (!isStartDate)
|
||||
date = endDate;
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
|
||||
DatePickerDialog.OnDateSetListener setListener = (datePicker, y, m, d) -> {
|
||||
calendar.set(y, m, d);
|
||||
String dateString = sdf.format(calendar.getTime());
|
||||
textView.setText(dateString);
|
||||
if (isStartDate)
|
||||
startDate = calendar.getTime();
|
||||
else
|
||||
endDate = calendar.getTime();
|
||||
};
|
||||
|
||||
Dialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, setListener,
|
||||
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void changeTraffic() {
|
||||
ImageView changeTrafficImageView = findViewById(R.id.changeTraffic);
|
||||
changeTrafficImageView.setOnClickListener(v -> {
|
||||
if (googleMap.isTrafficEnabled()) {
|
||||
changeTrafficImageView.setImageResource(R.drawable.traffic_off);
|
||||
googleMap.setTrafficEnabled(false);
|
||||
} else {
|
||||
changeTrafficImageView.setImageResource(R.drawable.traffic);
|
||||
googleMap.setTrafficEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void changeMapType() {
|
||||
ImageView changeMapType = findViewById(R.id.changeMapType);
|
||||
changeMapType.setOnClickListener(view -> {
|
||||
if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) {
|
||||
changeMapType.setImageResource(R.drawable.satellite);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
|
||||
} else {
|
||||
changeMapType.setImageResource(R.drawable.map);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getVehicles() {
|
||||
try {
|
||||
allVehicle.clear();
|
||||
allVehicleNames.clear();
|
||||
for (Vehicle vehicle : parentTab.getAllVehicle()) {
|
||||
allVehicleNames.add(vehicle.name);
|
||||
allVehicle.add(vehicle);
|
||||
}
|
||||
} 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() {
|
||||
myHandler.post(UpdateMapResults);
|
||||
SM.Debug("Do the updateMAP post");
|
||||
}
|
||||
|
||||
public void UpdateUnableDisp() {
|
||||
SM.Debug("Do Cancelwindow");
|
||||
}
|
||||
|
||||
public void UpdateCancel() {
|
||||
SM.Debug("Do Cancelwindow");
|
||||
}
|
||||
|
||||
public void UpdateNrPos(int size) {
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Tani Group
|
||||
* http://android-demo.blogspot.com/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* @author nguyendt
|
||||
*
|
||||
*/
|
||||
public class IconContextMenu implements DialogInterface.OnCancelListener,
|
||||
DialogInterface.OnDismissListener{
|
||||
|
||||
private static final int LIST_PREFERED_HEIGHT = 65;
|
||||
|
||||
private IconMenuAdapter menuAdapter;
|
||||
private Activity parentActivity;
|
||||
|
||||
private IconContextMenuOnClickListener clickHandler = null;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param parent
|
||||
* @param id
|
||||
*/
|
||||
public IconContextMenu(Activity parent, int id) {
|
||||
this.parentActivity = parent;
|
||||
|
||||
menuAdapter = new IconMenuAdapter(parentActivity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
* @param menuItem
|
||||
*/
|
||||
public void addItem(Resources res, CharSequence title,
|
||||
int imageResourceId, int actionTag) {
|
||||
menuAdapter.addItem(new IconContextMenuItem(res, title, imageResourceId, actionTag));
|
||||
}
|
||||
|
||||
public void addItem(Resources res, int textResourceId,
|
||||
int imageResourceId, int actionTag) {
|
||||
menuAdapter.addItem(new IconContextMenuItem(res, textResourceId, imageResourceId, actionTag));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set menu onclick listener
|
||||
* @param listener
|
||||
*/
|
||||
public void setOnClickListener(IconContextMenuOnClickListener listener) {
|
||||
clickHandler = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create menu
|
||||
* @return
|
||||
*/
|
||||
public Dialog createMenu(String menuItitle) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
||||
builder.setTitle(menuItitle);
|
||||
builder.setAdapter(menuAdapter, (dialoginterface, i) -> {
|
||||
IconContextMenuItem item = (IconContextMenuItem) menuAdapter.getItem(i);
|
||||
if (clickHandler != null)
|
||||
clickHandler.onClick(item.actionTag);
|
||||
});
|
||||
|
||||
builder.setInverseBackgroundForced(true);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setOnCancelListener(this);
|
||||
dialog.setOnDismissListener(this);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
// parentActivity.dismissDialog(dialogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* IconContextMenu On Click Listener interface
|
||||
*/
|
||||
public interface IconContextMenuOnClickListener {
|
||||
public abstract void onClick(int menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu-like list adapter with icon
|
||||
*/
|
||||
protected class IconMenuAdapter extends BaseAdapter {
|
||||
private Context context;
|
||||
|
||||
private ArrayList<IconContextMenuItem> mItems = new ArrayList<IconContextMenuItem>();
|
||||
|
||||
public IconMenuAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* add item to adapter
|
||||
* @param menuItem
|
||||
*/
|
||||
public void addItem(IconContextMenuItem menuItem) {
|
||||
mItems.add(menuItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
IconContextMenuItem item = (IconContextMenuItem) getItem(position);
|
||||
return item.actionTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
IconContextMenuItem item = (IconContextMenuItem) getItem(position);
|
||||
|
||||
Resources res = parentActivity.getResources();
|
||||
|
||||
if (convertView == null) {
|
||||
TextView temp = new TextView(context);
|
||||
AbsListView.LayoutParams param = new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT,
|
||||
AbsListView.LayoutParams.WRAP_CONTENT);
|
||||
temp.setLayoutParams(param);
|
||||
temp.setPadding((int)toPixel(res, 15), 0, (int)toPixel(res, 15), 0);
|
||||
temp.setGravity(android.view.Gravity.CENTER_VERTICAL);
|
||||
|
||||
Theme th = context.getTheme();
|
||||
TypedValue tv = new TypedValue();
|
||||
|
||||
if (th.resolveAttribute(android.R.attr.textAppearanceLargeInverse, tv, true)) {
|
||||
temp.setTextAppearance(context, tv.resourceId);
|
||||
}
|
||||
|
||||
temp.setMinHeight(LIST_PREFERED_HEIGHT);
|
||||
temp.setCompoundDrawablePadding((int)toPixel(res, 14));
|
||||
convertView = temp;
|
||||
}
|
||||
|
||||
TextView textView = (TextView) convertView;
|
||||
textView.setTag(item);
|
||||
textView.setText(item.text);
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
|
||||
textView.setTextColor(R.color.black);
|
||||
|
||||
return textView;
|
||||
}
|
||||
|
||||
private float toPixel(Resources res, int dip) {
|
||||
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, res.getDisplayMetrics());
|
||||
return px;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* menu-like list item with icon
|
||||
*/
|
||||
protected class IconContextMenuItem {
|
||||
public final CharSequence text;
|
||||
public final Drawable image;
|
||||
public final int actionTag;
|
||||
|
||||
/**
|
||||
* public constructor
|
||||
*
|
||||
* @param res
|
||||
* resource handler
|
||||
* @param textResourceId
|
||||
* id of title in resource
|
||||
* @param imageResourceId
|
||||
* id of icon in resource
|
||||
* @param actionTag
|
||||
* indicate action of menu item
|
||||
*/
|
||||
public IconContextMenuItem(Resources res, int textResourceId,
|
||||
int imageResourceId, int actionTag) {
|
||||
text = res.getString(textResourceId);
|
||||
if (imageResourceId != -1) {
|
||||
image = res.getDrawable(imageResourceId);
|
||||
} else {
|
||||
image = null;
|
||||
}
|
||||
this.actionTag = actionTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* public constructor
|
||||
* @param res
|
||||
* resource handler
|
||||
* @param title
|
||||
* menu item title
|
||||
* @param imageResourceId
|
||||
* id of icon in resource
|
||||
* @param actionTag
|
||||
* indicate action of menu item
|
||||
*/
|
||||
public IconContextMenuItem(Resources res, CharSequence title,
|
||||
int imageResourceId, int actionTag) {
|
||||
text = title;
|
||||
if (imageResourceId != -1) {
|
||||
image = res.getDrawable(imageResourceId);
|
||||
} else {
|
||||
image = null;
|
||||
}
|
||||
this.actionTag = actionTag;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,796 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.BitmapDescriptor;
|
||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import com.safemobile.activities.AbstractLiveActivity;
|
||||
import com.safemobile.activities.AbstractSDParentActivity;
|
||||
import com.safemobile.adapters.VehiclesGridViewAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.SuperVehicle;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCallback {
|
||||
|
||||
private GoogleMap googleMap;
|
||||
|
||||
/* Context Menu */
|
||||
private static final int MENU_ENABLE = 150;
|
||||
private static final int MENU_DISABLE = 151;
|
||||
private static final int MENU_REMOTE = 161;
|
||||
private static final int MENU_POLL = 154;
|
||||
private static final double LAT_OUTLIMIT = 91;
|
||||
private static final double LNG_OUTLIMIT = 181;
|
||||
private IconContextMenu iconContextMenu = null;
|
||||
|
||||
/* Dialog */
|
||||
private Dialog loadingDialog;
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler(Looper.getMainLooper());
|
||||
private Thread threadUI;
|
||||
|
||||
/* Misc */
|
||||
private Context context;
|
||||
private Resources res;
|
||||
private Activity activity;
|
||||
|
||||
/* Visual Elements */
|
||||
private ImageButton imageViewCheckAll;
|
||||
private Button displayButton;
|
||||
private boolean isFirstRun = true;
|
||||
private boolean isFirstMap = true;
|
||||
private boolean isAck = false;
|
||||
private boolean showVehicle = true;
|
||||
private int contextMenuPosition;
|
||||
private int vehStatus;
|
||||
private int position; // vehStatus = vehicle status received from apps
|
||||
|
||||
/* Live Vehicle GridView */
|
||||
private GridView gridVehicle;
|
||||
private ArrayList<Vehicle> liveVehicle = new ArrayList<>();
|
||||
private ArrayList<Boolean> displayedVehicles = new ArrayList<>();
|
||||
private ArrayList<Boolean> disabledVehicles = new ArrayList<>();
|
||||
private VehiclesGridViewAdapter adapter;
|
||||
private final HashMap<Integer, ArrayList<SuperVehicle>> tableHashOverlay = new HashMap<>();
|
||||
|
||||
//value poll
|
||||
private double latPoll = 0;
|
||||
private double lngPoll = 0;
|
||||
private ArrayList<Marker> markers = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setSavedInstanceState(savedInstanceState);
|
||||
// get parentTab
|
||||
setParentTab((AbstractSDParentActivity) getParent());
|
||||
try {
|
||||
((TabLayoutActivity) getParentTab()).liveActivity = this;
|
||||
} catch (Exception ignored) {
|
||||
// ignored
|
||||
}
|
||||
context = this;
|
||||
activity = this;
|
||||
res = getResources();
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
// get mapView only when creating first time
|
||||
if (isFirstMap) {
|
||||
setContentView(R.layout.tablive);
|
||||
isFirstMap = false;
|
||||
}
|
||||
|
||||
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
|
||||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.map);
|
||||
if (mapFragment != null) {
|
||||
mapFragment.getMapAsync(this);
|
||||
}
|
||||
|
||||
// create on vehicle long click menu
|
||||
createIconContextMenu();
|
||||
|
||||
// image View for changing map type satellite or map
|
||||
ImageView changeMapTypeImageView = findViewById(R.id.changeMapType);
|
||||
changeMapTypeImageView.setOnClickListener(v -> {
|
||||
if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) {
|
||||
changeMapTypeImageView.setImageResource(R.drawable.satellite);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
|
||||
} else {
|
||||
changeMapTypeImageView.setImageResource(R.drawable.map);
|
||||
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
|
||||
}
|
||||
});
|
||||
|
||||
ImageView changeTrafficImageView = findViewById(R.id.changeTraffic);
|
||||
changeTrafficImageView.setOnClickListener(v -> {
|
||||
if (googleMap.isTrafficEnabled()) {
|
||||
changeTrafficImageView.setImageResource(R.drawable.traffic_off);
|
||||
googleMap.setTrafficEnabled(false);
|
||||
} else {
|
||||
changeTrafficImageView.setImageResource(R.drawable.traffic);
|
||||
googleMap.setTrafficEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
// change tab header font
|
||||
TextView textView1 = findViewById(R.id.textView1);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
// get grid view and set empty data adapter
|
||||
gridVehicle = findViewById(R.id.gridVehicle);
|
||||
|
||||
if (AppParams.DEMO) {
|
||||
disabledVehicles = new ArrayList<>();
|
||||
for (Vehicle veh : getParentTab().getAllVehicle())
|
||||
disabledVehicles.add(!veh.status);
|
||||
}
|
||||
|
||||
|
||||
adapter = new VehiclesGridViewAdapter(activity, context, getParentTab().getAllVehicle(), disabledVehicles);
|
||||
adapter.notifyDataSetChanged();
|
||||
gridVehicle.setAdapter(adapter);
|
||||
|
||||
// get vehicle display click
|
||||
gridVehicle.setOnItemClickListener((parent, view, position, id) -> {
|
||||
threadUI = new Thread(() -> {
|
||||
myHandler.post(() -> itemClick(position, view));
|
||||
threadUI.interrupt();
|
||||
});
|
||||
threadUI.start();
|
||||
});
|
||||
|
||||
// get vehicle menu creation
|
||||
gridVehicle.setOnItemLongClickListener((adapterView, view, i, l) -> {
|
||||
contextMenuPosition = position;
|
||||
iconContextMenu.createMenu(getString(R.string.options)).show();
|
||||
return true;
|
||||
});
|
||||
|
||||
LinearLayout slideLayout = findViewById(R.id.slidelayout);
|
||||
ImageView slideLayoutImageView = findViewById(R.id.slideLayoutImage);
|
||||
LinearLayout linearLayoutVehicles = findViewById(R.id.layoutBig);
|
||||
slideLayout.setOnClickListener(v -> {
|
||||
if (showVehicle) {
|
||||
linearLayoutVehicles.setVisibility(View.GONE);
|
||||
slideLayoutImageView.setImageResource(R.drawable.arrow_right);
|
||||
showVehicle = false;
|
||||
} else {
|
||||
linearLayoutVehicles.setVisibility(View.VISIBLE);
|
||||
slideLayoutImageView.setImageResource(R.drawable.arrow_left);
|
||||
showVehicle = true;
|
||||
}
|
||||
});
|
||||
|
||||
imageViewCheckAll = findViewById(R.id.imageCheckAll);
|
||||
imageViewCheckAll.setSelected(false);
|
||||
imageViewCheckAll.setOnClickListener(arg0 -> {
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
|
||||
adapter.changeDisplayAll(!imageViewCheckAll.isSelected());
|
||||
|
||||
|
||||
VehiclesGridViewAdapter.ViewHolder viewLive = (VehiclesGridViewAdapter.ViewHolder) gridVehicle.getChildAt(0).getTag();
|
||||
|
||||
if (!imageViewCheckAll.isSelected())
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
|
||||
Enumeration<Long> keyList = getParentTab().getSuperVehHash().keys();
|
||||
while (keyList.hasMoreElements()) {
|
||||
(Objects.requireNonNull(getParentTab().getSuperVehHash().get(keyList.nextElement()))).needUpdate = true;
|
||||
}
|
||||
|
||||
// change button title
|
||||
if (!imageViewCheckAll.isSelected()) {
|
||||
imageViewCheckAll.setSelected(true);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.check_all);
|
||||
displayButton.setText(getString(R.string.hideAll));
|
||||
// set all vehicles to be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
} else {
|
||||
imageViewCheckAll.setSelected(false);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.uncheck_all);
|
||||
displayButton.setText(getString(R.string.displayAll));
|
||||
// set all vehicles to not be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, false);
|
||||
}
|
||||
|
||||
// refresh UI
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
});
|
||||
|
||||
displayButton = findViewById(R.id.buttonDisplay);
|
||||
displayButton.setText(getString(R.string.displayAll));
|
||||
|
||||
|
||||
displayButton.setOnClickListener(v -> {
|
||||
// set all displayed vehicles to true
|
||||
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
|
||||
Enumeration<Long> keyList = getParentTab().getSuperVehHash().keys();
|
||||
while (keyList.hasMoreElements())
|
||||
(Objects.requireNonNull(getParentTab().getSuperVehHash().get(keyList.nextElement()))).needUpdate = true;
|
||||
|
||||
// change button title
|
||||
if (displayButton.getText().toString().equals(getString(R.string.displayAll))) {
|
||||
displayButton.setText(getString(R.string.hideAll));
|
||||
// set all vehicles to be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, true);
|
||||
} else {
|
||||
displayButton.setText(getString(R.string.displayAll));
|
||||
// set all vehicles to not be displayed
|
||||
for (int i = 0; i < displayedVehicles.size(); i++)
|
||||
displayedVehicles.set(i, false);
|
||||
}
|
||||
|
||||
// refresh UI
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
});
|
||||
|
||||
// display Vehicles
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
|
||||
// register to receive broadcasts
|
||||
registerBroadcastIntents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manipulates the map once available.
|
||||
* This callback is triggered when the map is ready to be used.
|
||||
* This is where we can add markers or lines, add listeners or move the camera. In this case,
|
||||
* we just add a marker near Sydney, Australia.
|
||||
* If Google Play services is not installed on the device, the user will be prompted to install
|
||||
* it inside the SupportMapFragment. This method will only be triggered once the user has
|
||||
* installed Google Play services and returned to the app.
|
||||
*/
|
||||
@Override
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.googleMap = googleMap;
|
||||
GoogleMapsInfoBubble infoBubble = new GoogleMapsInfoBubble(getLayoutInflater(), this, getParentTab().getSuperVehHash());
|
||||
this.googleMap.setInfoWindowAdapter(infoBubble);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// cancel loading dialog if showing
|
||||
if (loadingDialog.isShowing()) {
|
||||
cancelLoadingDialog();
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.logout))
|
||||
.setPositiveButton(getString(R.string.ext), (dialog, id) -> getParentTab().whenBackPressed(AppParams.ActivityResult.exit))
|
||||
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (isFirstRun) {
|
||||
// show loading dialog
|
||||
showLoadingDialog("Getting vehicles from database...");
|
||||
// send liveActivity
|
||||
getParentTab().setLiveActivity((AbstractLiveActivity) activity);
|
||||
// get all vehicles
|
||||
isAck = false;
|
||||
// start a thread to wait 3 seconds for ack
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
SM.Exception(e.toString());
|
||||
// Restore interrupted state
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
// if not getVehicle not isAck
|
||||
if (!isAck)
|
||||
myHandler.post(cancelLoadingDialogRUN);
|
||||
}).start();
|
||||
|
||||
SM.Debug("GetVehs");
|
||||
isFirstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// clear previous vehicles
|
||||
SM.Debug("onResume");
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
}
|
||||
|
||||
final Runnable cancelLoadingDialogRUN = LiveActivity.this::cancelLoadingDialog;
|
||||
|
||||
// cancel loading dialog and show sending error message
|
||||
private void cancelLoadingDialog() {
|
||||
// cancel loading dialog
|
||||
try {
|
||||
loadingDialog.cancel();
|
||||
} catch (Exception ex) {
|
||||
SM.Exception(ex.toString());
|
||||
}
|
||||
if (!isAck) {
|
||||
// show connection error
|
||||
Toast.makeText(context, "Could not get Vehicles... ", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void createIconContextMenu() {
|
||||
iconContextMenu = new IconContextMenu(this, 1);
|
||||
iconContextMenu.addItem(res, R.string.enable, R.drawable.enable, MENU_ENABLE);
|
||||
iconContextMenu.addItem(res, R.string.disable, R.drawable.disable, MENU_DISABLE);
|
||||
iconContextMenu.addItem(res, R.string.poll, R.drawable.poll, MENU_POLL);
|
||||
|
||||
//set onclick listener for context menu
|
||||
iconContextMenu.setOnClickListener(menuId -> {
|
||||
int radioCode = 30;
|
||||
switch (menuId) {
|
||||
case MENU_ENABLE: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_ENABLE, liveVehicle.get(contextMenuPosition).id + "");
|
||||
if (AppParams.DEMO)
|
||||
vehicleStatusReceived(liveVehicle.get(contextMenuPosition).id, 101, 1);
|
||||
SM.Debug("MENU: Enable for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
case MENU_DISABLE: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_DISABLE, liveVehicle.get(contextMenuPosition).id + "");
|
||||
if (AppParams.DEMO)
|
||||
vehicleStatusReceived(liveVehicle.get(contextMenuPosition).id, 101, 0);
|
||||
SM.Debug("MENU: Disable for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
case MENU_REMOTE: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_REMOTE, liveVehicle.get(contextMenuPosition).id + "");
|
||||
SM.Debug("MENU: Remote for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
case MENU_POLL: {
|
||||
// send change to AppServer
|
||||
optionForUnit(radioCode, MENU_POLL, liveVehicle.get(contextMenuPosition).id + "");
|
||||
if (AppParams.DEMO) {
|
||||
getParentTab().setImei(liveVehicle.get(contextMenuPosition).sc_id + "");
|
||||
getParentTab().updateDemoPosition();
|
||||
getParentTab().updateResultsPollInUi("realpha");
|
||||
}
|
||||
|
||||
SM.Debug("MENU: P for " + liveVehicle.get(contextMenuPosition).id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + menuId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void displayVehicle(boolean withZoom, double latZoom, double lngZoom) {
|
||||
if (googleMap != null) {
|
||||
String openWindow = "";
|
||||
for (Marker marker : markers) {
|
||||
if (marker.isInfoWindowShown()) {
|
||||
openWindow = marker.getTitle();
|
||||
}
|
||||
}
|
||||
googleMap.clear();
|
||||
|
||||
for (int i = 0; i < displayedVehicles.size(); i++) {
|
||||
if (displayedVehicles.get(i)) {
|
||||
SuperVehicle tmpSuper = getParentTab().getSuperVehHash().get(Long.valueOf(liveVehicle.get(i).imei));
|
||||
|
||||
if (tmpSuper != null) {
|
||||
LatLng newLocation = new LatLng(tmpSuper.lat, tmpSuper.lng);
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(newLocation).title(liveVehicle.get(i).imei);
|
||||
|
||||
BitmapDescriptor markerIcon = getProperBitmap(tmpSuper.getLargeIcon(), tmpSuper.name);
|
||||
markerOptions.icon(markerIcon);
|
||||
|
||||
Marker marker = this.googleMap.addMarker(markerOptions);
|
||||
if (openWindow.equals(marker.getTitle()))
|
||||
marker.showInfoWindow();
|
||||
|
||||
markers.add(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showOpenedBalloon(boolean demo) {
|
||||
//TODO: add show balloon
|
||||
}
|
||||
|
||||
private BitmapDescriptor getProperBitmap(int largeIcon, String text) {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), largeIcon);
|
||||
Bitmap textBitmap = getTextAsDrawable(this, text);
|
||||
Bitmap b3 = overlay(bitmap, textBitmap);
|
||||
return BitmapDescriptorFactory.fromBitmap(b3);
|
||||
}
|
||||
|
||||
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
|
||||
int maxWidth = Math.max(bmp1.getWidth(), bmp2.getWidth());
|
||||
|
||||
Bitmap bmOverlay = Bitmap.createBitmap(maxWidth, bmp1.getHeight() + bmp2.getHeight(), bmp1.getConfig());
|
||||
Canvas canvas = new Canvas(bmOverlay);
|
||||
canvas.drawBitmap(bmp1, new Matrix(), null);
|
||||
canvas.drawBitmap(bmp2, 0, bmp1.getHeight(), null);
|
||||
bmp1.recycle();
|
||||
bmp2.recycle();
|
||||
return bmOverlay;
|
||||
}
|
||||
|
||||
public Bitmap getTextAsDrawable(Context context, String text) {
|
||||
Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);
|
||||
|
||||
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
paint.setColor(Color.WHITE);
|
||||
paint.setTypeface(tf);
|
||||
paint.setTextSize(convertToPixels(context, 16));
|
||||
|
||||
Rect textRect = new Rect();
|
||||
paint.getTextBounds(text, 0, text.length(), textRect);
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(textRect.width(), textRect.height() + 5,
|
||||
Bitmap.Config.ARGB_8888);
|
||||
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
paint.setColor(getResources().getColor(R.color.cardview_dark_background));
|
||||
canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), paint);
|
||||
|
||||
|
||||
float scale = context.getResources().getDisplayMetrics().density;
|
||||
// text color - #3D3D3D
|
||||
paint.setColor(Color.rgb(255, 255, 255));
|
||||
// text size in pixels
|
||||
|
||||
// draw text to the Canvas center
|
||||
Rect bounds = new Rect();
|
||||
paint.getTextBounds(text, 0, text.length(), bounds);
|
||||
int x = (bitmap.getWidth() - bounds.width()) / 2;
|
||||
int y = (bitmap.getHeight() + bounds.height()) / 2;
|
||||
|
||||
canvas.drawText(text, x, y, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public int convertToPixels(Context context, int nDP) {
|
||||
final float conversionScale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) ((nDP * conversionScale) + 0.5f);
|
||||
}
|
||||
|
||||
public void showLoadingDialog(String message) {
|
||||
loadingDialog = new Dialog(context);
|
||||
loadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
loadingDialog.setContentView(R.layout.dialogloading);
|
||||
loadingDialog.setCancelable(true);
|
||||
loadingDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
Button cancel = loadingDialog.findViewById(R.id.buttonCancel);
|
||||
cancel.setVisibility(View.GONE);
|
||||
TextView textView1 = loadingDialog.findViewById(R.id.textView1);
|
||||
textView1.setText(message);
|
||||
|
||||
loadingDialog.show();
|
||||
}
|
||||
|
||||
// save Vehicles
|
||||
@Override
|
||||
public void vehiclesReceived(ArrayList<Vehicle> list) {
|
||||
|
||||
SM.Debug("vehiclesReceived");
|
||||
isAck = true;
|
||||
liveVehicle = list;
|
||||
disabledVehicles = new ArrayList<>();
|
||||
displayedVehicles = new ArrayList<>();
|
||||
// set displayed to false and add icons to hashTable
|
||||
int i = 0;
|
||||
SM.Debug("DISPLAY LIVE VEHICLE");
|
||||
for (Vehicle veh : list) {
|
||||
|
||||
SM.Debug(veh.toString());
|
||||
liveVehicle.get(i).id = veh.sc_id;
|
||||
i++;
|
||||
// set vehicle to false
|
||||
displayedVehicles.add(AppParams.DEMO && (veh.sc_id == 101 || veh.sc_id == 102));
|
||||
// set disable to false
|
||||
disabledVehicles.add(!veh.status);
|
||||
|
||||
// add vehicle to hash Table according to driver_id
|
||||
if (tableHashOverlay.get((int) veh.driver_id) == null) {
|
||||
ArrayList<SuperVehicle> array = new ArrayList<>();
|
||||
SuperVehicle superVehicle = new SuperVehicle(veh.sc_id, veh.imei, veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen);
|
||||
array.add(superVehicle);
|
||||
tableHashOverlay.put((int) veh.driver_id, array);
|
||||
} else {
|
||||
// another vehicle with same driver_id exists
|
||||
ArrayList<SuperVehicle> array = tableHashOverlay.get((int) veh.driver_id);
|
||||
SuperVehicle superVehicle = new SuperVehicle(veh.sc_id, veh.imei, veh.lp, veh.name, veh.driver_id, veh.time_route, veh.GPS_reporting_interval, veh.is_stolen);
|
||||
// add vehicle to array
|
||||
if (array != null) {
|
||||
array.add(superVehicle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set adapter
|
||||
adapter = new VehiclesGridViewAdapter(activity, context, list, disabledVehicles);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
// Update UI
|
||||
myHandler.post(updateResultsRUN);
|
||||
|
||||
// hide loading dialog
|
||||
loadingDialog.cancel();
|
||||
if (!AppParams.DEMO)
|
||||
getLastPos();
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateResultsRUN = this::updateResultsUI;
|
||||
|
||||
// show vehicles in gridView
|
||||
private void updateResultsUI() {
|
||||
gridVehicle.setAdapter(adapter);
|
||||
try {
|
||||
// hide loading dialog
|
||||
loadingDialog.cancel();
|
||||
} catch (Exception e) {
|
||||
SM.Exception(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshMap() {
|
||||
// Update UI
|
||||
myHandler.post(updateMapResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pollReceived(int position, double lat, double lng) {
|
||||
// Update UI
|
||||
latPoll = lat;
|
||||
lngPoll = lng;
|
||||
this.position = position;
|
||||
myHandler.post(updatePollResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vehicleStatusReceived(long imei, int opCode, int status) {
|
||||
vehStatus = status;
|
||||
SM.Debug("UpdateOptions from APP with-> imei: " + imei + " | opCode: " + opCode + " | status: " + vehStatus);
|
||||
contextMenuPosition = getPositionFromImei(imei);
|
||||
// Update UI
|
||||
myHandler.post(updateOptionsRUN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emergencyAlarmReceived(int position, double lat, double lng) {
|
||||
pollReceived(position,lat,lng);
|
||||
}
|
||||
|
||||
public void updatePosition(int pos) {
|
||||
contextMenuPosition = pos;
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateMapResults = () -> displayVehicle(false, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updatePollResults = () -> {
|
||||
if (position != -1) {
|
||||
SM.Debug("updatePosition :" + position + " last value:" + displayedVehicles.get(position));
|
||||
// change in adapter
|
||||
adapter.changeDisplayed(position, true);
|
||||
}
|
||||
|
||||
displayVehicle(true, latPoll, lngPoll); };
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable updateOptionsRUN = this::updateOptionsUI;
|
||||
|
||||
private void updateOptionsUI() {
|
||||
SM.Debug("REFRESHDisableEnable" + (Boolean.TRUE.equals(disabledVehicles.get(contextMenuPosition)) ? "true" : "false"));
|
||||
// change Enable/Disable in adapter
|
||||
adapter.changeDisabled(contextMenuPosition, disabledVehicles.get(contextMenuPosition));
|
||||
}
|
||||
|
||||
/**
|
||||
* visual modifications when a vehicle is clicked
|
||||
*
|
||||
* @param position position in grid that was clicked
|
||||
* @param view View in which will do the modifications
|
||||
*/
|
||||
private void itemClick(int position, View view) {
|
||||
// change displayed state
|
||||
displayedVehicles.set(position, !Boolean.TRUE.equals(displayedVehicles.get(position)));
|
||||
|
||||
// change in the adapter
|
||||
adapter.changeDisplayed(position, displayedVehicles.get(position));
|
||||
|
||||
// change check image for selected value
|
||||
VehiclesGridViewAdapter.ViewHolder viewLive = (VehiclesGridViewAdapter.ViewHolder) view.getTag();
|
||||
|
||||
if (Boolean.TRUE.equals(displayedVehicles.get(position)))
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.checked);
|
||||
else
|
||||
viewLive.imgViewChecked.setImageResource(R.drawable.unchecked);
|
||||
|
||||
// check if all values are identical
|
||||
boolean identical = true;
|
||||
for (Boolean displ : displayedVehicles)
|
||||
if (!Objects.equals(displ, displayedVehicles.get(0))) {
|
||||
identical = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// change image when all values are identical
|
||||
if (identical && Boolean.TRUE.equals(displayedVehicles.get(0))) {
|
||||
imageViewCheckAll.setSelected(true);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.check_all);
|
||||
} else if (identical && Boolean.TRUE.equals(!displayedVehicles.get(0))) {
|
||||
imageViewCheckAll.setSelected(false);
|
||||
imageViewCheckAll.setBackgroundResource(R.drawable.uncheck_all);
|
||||
}
|
||||
|
||||
// display vehicle
|
||||
displayVehicle(true, LAT_OUTLIMIT, LNG_OUTLIMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* get last position for all vehicles
|
||||
*/
|
||||
private void getLastPos() {
|
||||
getParentTab().executeNetworkStuff(new String[]{OperationCodes.GetLastPositions + "", AppParams.USERID + ""});
|
||||
}
|
||||
|
||||
/**
|
||||
* send a command that enable/disable a vehicle or request a poll
|
||||
*
|
||||
* @param radioCode is a hardcoded values set to 30
|
||||
* @param opCode the operation code. It can be :
|
||||
* MENU_ENABLE = 150,
|
||||
* MENU_DISABLE = 151,
|
||||
* MENU_REMOTE = 161,
|
||||
* MENU_POLL = 154;
|
||||
* @param scId vehicle imei for which we do the operation
|
||||
*/
|
||||
public void optionForUnit(int radioCode, int opCode, String scId) {
|
||||
// last values is set to 0 for disable and 1 for others
|
||||
getParentTab().executeNetworkStuff(new String[]{OperationCodes.Option4Unit + "", radioCode + "", (opCode == MENU_DISABLE ? MENU_ENABLE : opCode) + "", scId,
|
||||
(opCode == MENU_DISABLE ? 0 : 1) + ""});
|
||||
}
|
||||
|
||||
/**
|
||||
* return the position in the grid for a Vehicle specified by imei
|
||||
*
|
||||
* @param imei vehicle's imei
|
||||
*/
|
||||
private int getPositionFromImei(long imei) {
|
||||
int positionFromImei = -1;
|
||||
for (int i = 0; i < liveVehicle.size(); i++)
|
||||
if (liveVehicle.get(i).imei.equalsIgnoreCase(imei + ""))
|
||||
positionFromImei = i;
|
||||
SM.Debug("Position: " + positionFromImei);
|
||||
return positionFromImei;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register for broadcasts
|
||||
*/
|
||||
private void registerBroadcastIntents() {
|
||||
// zone and channel change intent
|
||||
IntentFilter intentFilter = new IntentFilter(OperationCodes.UNIT_STATUS_UPDATE + "");
|
||||
this.registerReceiver(mReceiver, intentFilter);
|
||||
}
|
||||
|
||||
//The BroadcastReceiver that listens for Notification broadcasts
|
||||
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
final String action = intent.getAction();
|
||||
|
||||
if (action.equals(OperationCodes.UNIT_STATUS_UPDATE + "")) {
|
||||
try {
|
||||
final String[] extra = intent.getStringExtra("unitStatus").split("#");
|
||||
|
||||
SM.Debug("extra has " + extra.length + " objects");
|
||||
Toast.makeText(context, "Unit was " + (Integer.parseInt(extra[1]) == 0 ? "DISABLED" : "ENABLED"), Toast.LENGTH_LONG).show();
|
||||
|
||||
myHandler.post(() -> {
|
||||
vehStatus = Integer.parseInt(extra[1]);
|
||||
contextMenuPosition = getPositionFromImei(Integer.parseInt(extra[0]));
|
||||
disabledVehicles.remove(contextMenuPosition);
|
||||
// invert logic is used
|
||||
disabledVehicles.add(contextMenuPosition, vehStatus != 1);
|
||||
adapter.changeDisabled(contextMenuPosition, disabledVehicles.get(contextMenuPosition));
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
SM.Exception("Exception in live BroadCastReceived" + ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public GoogleMap getMap() {
|
||||
return googleMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
public class MapDemo extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.mapdemo);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,699 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.safemobile.adapters.ConversationGridViewAdapter;
|
||||
import com.safemobile.adapters.MessagesGridViewAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.Msg;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.SMS;
|
||||
import com.safemobile.lib.Vehicle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* fix import
|
||||
*/
|
||||
|
||||
public class MessagesActivity extends Activity {
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
|
||||
private MessagesGridViewAdapter mAdapter;
|
||||
private ConversationGridViewAdapter convAdapter;
|
||||
private ArrayList<Msg> listLastMessages = new ArrayList<>();
|
||||
private ArrayList<Msg> listSpecificConversation = new ArrayList<>();
|
||||
private ArrayList<Boolean> dispatcherPositions = new ArrayList<>();
|
||||
|
||||
private GridView gridView;
|
||||
private Context context;
|
||||
private Activity activity;
|
||||
|
||||
private final Hashtable<Long, ArrayList<SMS>> tableSMS = new Hashtable<>();
|
||||
private final Hashtable<String, Long> seqIDSMSHash = new Hashtable<>();
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
/* Visual resources */
|
||||
private LinearLayout layoutSend;
|
||||
private LinearLayout layoutHeader;
|
||||
private LinearLayout layoutHeaderConversation;
|
||||
private TextView textViewSelectedContact;
|
||||
private ImageView imageViewSelectedContact;
|
||||
|
||||
private Button imageButtonSend;
|
||||
private EditText editTextMsg;
|
||||
|
||||
private TabLayoutActivity parentTab;
|
||||
|
||||
/* Message args */
|
||||
private int ACTION;
|
||||
private static final int MSG_UPDATE = 0;
|
||||
|
||||
private ArrayList<String> allVehicleNames = new ArrayList<>();
|
||||
private ArrayList<Vehicle> allVehicle = new ArrayList<>();
|
||||
|
||||
// tip of Messages and flag first load
|
||||
public boolean LASTMESSAGES = true;
|
||||
private boolean FIRST = true;
|
||||
|
||||
// store selected scId and selected unitType
|
||||
private long scId = 0;
|
||||
private int unitType = 0;
|
||||
|
||||
private Bundle savedInstanceState;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.setSavedInstanceState(savedInstanceState);
|
||||
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity) getParent();
|
||||
|
||||
context = this;
|
||||
activity = this;
|
||||
|
||||
Locale locale = new Locale(AppParams.LANGUAGETMP);
|
||||
Locale.setDefault(locale);
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
getBaseContext().getResources().updateConfiguration(config,
|
||||
getBaseContext().getResources().getDisplayMetrics());
|
||||
|
||||
setContentView(R.layout.tabtext);
|
||||
|
||||
// get LayoutSend and hide
|
||||
layoutSend = findViewById(R.id.layoutSendMsg);
|
||||
layoutSend.setVisibility(View.GONE);
|
||||
// get header layout
|
||||
layoutHeader = findViewById(R.id.layoutHeader);
|
||||
layoutHeaderConversation = findViewById(R.id.layoutHeaderConversation);
|
||||
// show only header layout
|
||||
layoutHeaderConversation.setVisibility(View.GONE);
|
||||
|
||||
// get SelectedContact TextView and ImageView
|
||||
textViewSelectedContact = findViewById(R.id.textViewSelectedContact);
|
||||
imageViewSelectedContact = findViewById(R.id.imageViewSelectedContact);
|
||||
|
||||
ImageView imageBarcode = findViewById(R.id.imageBarcode);
|
||||
imageBarcode.setOnClickListener(v -> {
|
||||
try {
|
||||
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
||||
startActivityForResult(intent, 0);
|
||||
} catch (Exception e) {
|
||||
showErrorDialog(getResources().getString(R.string.barcodeError));
|
||||
}
|
||||
});
|
||||
|
||||
// change tab header fontFace
|
||||
TextView textView1 = findViewById(R.id.textView1);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
// prepared arraylist and passed it to the Adapter class
|
||||
mAdapter = new MessagesGridViewAdapter(this, listLastMessages);
|
||||
convAdapter = new ConversationGridViewAdapter(this, listSpecificConversation, dispatcherPositions, new ArrayList<>());
|
||||
// Set custom adapter to gridview
|
||||
gridView = findViewById(R.id.gridView1);
|
||||
gridView.setAdapter(mAdapter);
|
||||
|
||||
// Implement On Item click listener
|
||||
gridView.setOnItemClickListener((arg0, arg1, position, arg3) -> {
|
||||
if (LASTMESSAGES) {
|
||||
// get position
|
||||
Msg item = mAdapter.getItem(position);
|
||||
// get Specific Conversation
|
||||
setScId(item.from.sc_id);
|
||||
SM.Debug("Selected scId: " + getScId());
|
||||
// set Conversation type
|
||||
LASTMESSAGES = false;
|
||||
// call get SMS
|
||||
getSMS4unit(getScId());
|
||||
// create crt_Vehicle
|
||||
setUnitType((int) item.from.driver_id);
|
||||
// save selected vehicle
|
||||
}
|
||||
|
||||
if (AppParams.DEMO) {
|
||||
// modify UI
|
||||
ACTION = MSG_UPDATE;
|
||||
updateResultsInUi();
|
||||
}
|
||||
});
|
||||
|
||||
/* Buttons and EditBoxes */
|
||||
ImageButton imageButtonAdd = findViewById(R.id.imageButtonAdd);
|
||||
imageButtonAdd.setOnClickListener(v -> showDialog());
|
||||
|
||||
// button send message
|
||||
imageButtonSend = findViewById(R.id.imageButtonSend);
|
||||
imageButtonSend.setOnClickListener(v -> {
|
||||
sendSMS(getScId(), editTextMsg.getText().toString());
|
||||
Toast.makeText(context, "Sending message...", Toast.LENGTH_SHORT).show();
|
||||
// disable send button and editBox
|
||||
editTextMsg.setEnabled(false);
|
||||
imageButtonSend.setEnabled(false);
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
myHandler.post(enableButtonRUN);
|
||||
|
||||
if (AppParams.DEMO) {
|
||||
Thread.sleep(5500);
|
||||
myHandler.post(demoReceivedSMSRUN);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
|
||||
// button back to conversations
|
||||
ImageButton imageButtonBack = findViewById(R.id.imageButtonBack);
|
||||
imageButtonBack.setOnClickListener(v -> {
|
||||
// set LastMessage conversation type
|
||||
LASTMESSAGES = true;
|
||||
// refresh Grid
|
||||
getLastSMS();
|
||||
if (AppParams.DEMO)
|
||||
updateResultsInUi();
|
||||
});
|
||||
|
||||
// get Message editText
|
||||
editTextMsg = findViewById(R.id.editTextMsg);
|
||||
|
||||
gridView.setId(1); // id needed for IconContextMenu
|
||||
registerForContextMenu(gridView);
|
||||
parentTab.messageActivity = this;
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable demoReceivedSMSRUN = new Runnable() {
|
||||
public void run() {
|
||||
parentTab.setImei(getScId() + "");
|
||||
parentTab.updateResultsInUi("realpha");
|
||||
|
||||
int timeGMT = (int) (System.currentTimeMillis() / 1000L);
|
||||
String sendSMSSeqID = "1." + timeGMT;
|
||||
// add mess to not ack list
|
||||
seqIDSMSHash.put(sendSMSSeqID, getScId());
|
||||
// get scId conversation and add message
|
||||
ArrayList<SMS> crtSmsList = tableSMS.get(getScId());
|
||||
SMS sms = new SMS(0, 0, timeGMT, "i got your sms", 0, getScId());
|
||||
sms.seq_idx = sendSMSSeqID;
|
||||
if (crtSmsList != null)
|
||||
crtSmsList.add(sms);
|
||||
|
||||
// add message to listLast
|
||||
boolean exists = false;
|
||||
for (Msg msg : listLastMessages)
|
||||
// if conversation exists in lastMessages
|
||||
if (msg.from.sc_id == getScId()) {
|
||||
exists = true;
|
||||
msg.message = "i got your sms";
|
||||
msg.received = Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
// if last messages doesn't contain this conversation
|
||||
if (!exists) {
|
||||
Vehicle sentVehicle = null;
|
||||
for (Vehicle veh : getAllVehicle())
|
||||
if (veh.sc_id == getScId())
|
||||
sentVehicle = veh;
|
||||
|
||||
listLastMessages.add(new Msg(sentVehicle, "i got your sms", Calendar.getInstance().getTime(), sendSMSSeqID));
|
||||
}
|
||||
SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime());
|
||||
|
||||
updateResultsInUi();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.logout))
|
||||
.setPositiveButton(getString(R.string.ext), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.exit))
|
||||
.setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel());
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (parentTab.getTCPState() != null && FIRST) {
|
||||
updateVehicles(parentTab.getAllVehicle());
|
||||
FIRST = false;
|
||||
if (LASTMESSAGES)
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetLastSMS + "", AppParams.USERID + ""});
|
||||
}
|
||||
SM.Debug("onResume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
if (requestCode == 0 && resultCode == RESULT_OK) {
|
||||
String contents = intent.getStringExtra("SCAN_RESULT");
|
||||
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
||||
editTextMsg.setText(String.format("%s%s", editTextMsg.getText().toString(), contents));
|
||||
// Handle successful scan
|
||||
Toast.makeText(this, getResources().getString(R.string.barcodeContent) + ":" + contents + " with format:" + format, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
// Request SMS 4 Unit from AppServer
|
||||
private void getSMS4UnitWithTime(long scId, long time) {
|
||||
if (!AppParams.DEMO) {
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetRecentSMSs + "", scId + "", time + ""});
|
||||
|
||||
SM.Debug(" #### GetSMS4uni:" + scId);
|
||||
}
|
||||
}
|
||||
|
||||
private void getSMS4unit(long scId) {
|
||||
if (!AppParams.DEMO) {
|
||||
SM.Debug("getSMS4unit : " + scId);
|
||||
ArrayList<SMS> listSMS = tableSMS.get(scId);
|
||||
long timeGMT = 0;
|
||||
if (listSMS != null && !listSMS.isEmpty())
|
||||
timeGMT = listSMS.get(listSMS.size() - 1).timeGMT;
|
||||
|
||||
// error in DB
|
||||
if (String.valueOf(timeGMT).contains(".")) {
|
||||
try {
|
||||
// remove the dot and the parse it to String
|
||||
timeGMT = Long.parseLong(String.valueOf(timeGMT).split("\\.")[1]);
|
||||
} catch (Exception e) {
|
||||
timeGMT = Long.parseLong(String.valueOf(timeGMT).replace(".", ""));
|
||||
}
|
||||
}
|
||||
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetRecentSMSs + "", scId + "", timeGMT + ""});
|
||||
|
||||
SM.Debug(" #### GetSMS4uni:" + scId);
|
||||
}
|
||||
}
|
||||
|
||||
// Request Last SMS from AppServer
|
||||
public void getLastSMS() {
|
||||
if (!AppParams.DEMO) {
|
||||
if (LASTMESSAGES)
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetLastSMS + "", AppParams.USERID + ""});
|
||||
else {
|
||||
ArrayList<SMS> listSMS = tableSMS.get(getScId());
|
||||
long timeGMT = 0;
|
||||
if (listSMS != null && !listSMS.isEmpty())
|
||||
timeGMT = listSMS.get(listSMS.size() - 1).timeGMT;
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.GetRecentSMSs + "", getScId() + "", timeGMT + ""});
|
||||
}
|
||||
} else
|
||||
updateResultsInUi();
|
||||
}
|
||||
|
||||
|
||||
private void sendSMS(long scIdd, String txt) {
|
||||
if (!AppParams.DEMO) {
|
||||
int timeGMT = (int) (System.currentTimeMillis() / 1000L);
|
||||
String sendSMSSeqID = "1." + timeGMT;
|
||||
// add mess to not ack list
|
||||
seqIDSMSHash.put(sendSMSSeqID, scIdd);
|
||||
// get scId conversation and add message
|
||||
SMS sms = new SMS(0, 0, timeGMT, txt, scIdd, 0);
|
||||
sms.seq_idx = sendSMSSeqID;
|
||||
tableSMS.get(scIdd).add(sms);
|
||||
parentTab.executeNetworkStuff(new String[]{OperationCodes.SEND_TM + "", sendSMSSeqID, scIdd + "", txt});
|
||||
|
||||
updateResultsInUi();
|
||||
} else {
|
||||
int timeGMT = (int) (System.currentTimeMillis() / 1000L);
|
||||
String sendSMSSeqID = "1." + timeGMT;
|
||||
// add mess to not ack list
|
||||
seqIDSMSHash.put(sendSMSSeqID, scIdd);
|
||||
// get scId conversation and add message
|
||||
ArrayList<SMS> crtSmsList = tableSMS.get(scIdd);
|
||||
SMS sms = new SMS(0, 0, timeGMT, txt, scIdd, 0);
|
||||
sms.seq_idx = sendSMSSeqID;
|
||||
crtSmsList.add(sms);
|
||||
|
||||
// add message to listLast
|
||||
boolean exists = false;
|
||||
for (Msg msg : listLastMessages)
|
||||
// if conversation exists in lastMessages
|
||||
if (msg.from.sc_id == scIdd) {
|
||||
exists = true;
|
||||
msg.message = txt;
|
||||
msg.received = Calendar.getInstance().getTime();
|
||||
}
|
||||
|
||||
// if last messages doesn't contain this conversation
|
||||
if (!exists) {
|
||||
Vehicle sentVehicle = null;
|
||||
for (Vehicle veh : getAllVehicle())
|
||||
if (veh.sc_id == scIdd)
|
||||
sentVehicle = veh;
|
||||
|
||||
listLastMessages.add(new Msg(sentVehicle, txt, Calendar.getInstance().getTime(), sendSMSSeqID));
|
||||
}
|
||||
SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime());
|
||||
LASTMESSAGES = false;
|
||||
|
||||
updateResultsInUi();
|
||||
}
|
||||
}
|
||||
|
||||
// Update Vehicles received from AppServer
|
||||
public void updateVehicles(ArrayList<Vehicle> list) {
|
||||
SM.Debug("## updateVehicles: " + list.size());
|
||||
setAllVehicle(list);
|
||||
allVehicleNames = new ArrayList<>();
|
||||
for (Vehicle v : getAllVehicle())
|
||||
allVehicleNames.add(v.name);
|
||||
|
||||
if (tableSMS.size() == 0) {
|
||||
for (Vehicle veh : getAllVehicle()) {
|
||||
ArrayList<SMS> smsList = new ArrayList<>();
|
||||
// populate conversation list if demo
|
||||
if (AppParams.DEMO)
|
||||
smsList = getDemoConversation(veh.sc_id);
|
||||
|
||||
tableSMS.put(veh.sc_id, smsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gets DEMO conversations
|
||||
private ArrayList<SMS> getDemoConversation(long scId) {
|
||||
ArrayList<SMS> smsList = new ArrayList<>();
|
||||
if (scId == 101)
|
||||
smsList.add(new SMS(1, 2, 1324016412, "Only one left", 101, 0));
|
||||
else if (scId == 102)
|
||||
smsList.add(new SMS(1, 2, 1328060100, "i'm at the train station", 0, 102));
|
||||
else if (scId == 103) {
|
||||
smsList.add(new SMS(1, 2, 1121016637, "Where are you now?", 103, 0));
|
||||
smsList.add(new SMS(2, 2, 1121016693, "Near Elementary School 81", 0, 103));
|
||||
smsList.add(new SMS(3, 2, 1121016693, "We have a client on Belmont Ave", 103, 0));
|
||||
smsList.add(new SMS(4, 2, 1121016724, "It's only 4 blocks away", 103, 0));
|
||||
smsList.add(new SMS(5, 2, 1121016693, "Can you take him?", 103, 0));
|
||||
smsList.add(new SMS(6, 2, 1121016818, "I'll be right there", 0, 103));
|
||||
} else if (scId == 105)
|
||||
smsList.add(new SMS(1, 2, 1328061660, "Thanks", 0, 105));
|
||||
return smsList;
|
||||
}
|
||||
|
||||
public void updateSMS(ArrayList<SMS> list) {
|
||||
SM.Debug("## updateSMS: " + list.size() + " [LASTMESSAGES:" + LASTMESSAGES + "]");
|
||||
|
||||
// populate listLastMessages
|
||||
if (LASTMESSAGES) {
|
||||
listLastMessages = new ArrayList<>();
|
||||
for (SMS sms : list) {
|
||||
// get for sender
|
||||
long senderId = sms.sc_id_dest;
|
||||
if (senderId == 0)
|
||||
senderId = sms.sc_id_sour;
|
||||
// get vehicle with sender id
|
||||
Vehicle messageVeh;
|
||||
messageVeh = getVehicleById(senderId);
|
||||
listLastMessages.add(0, new Msg(messageVeh, sms.mess, new Date((long) sms.timeGMT * 1000), sms.seq_idx));
|
||||
}
|
||||
|
||||
// update GridView
|
||||
mAdapter = new MessagesGridViewAdapter(activity, listLastMessages);
|
||||
} else {
|
||||
// add new values to hashTable for key = scId
|
||||
ArrayList<SMS> listScId = tableSMS.get(getScId());
|
||||
if (!list.isEmpty())
|
||||
for (SMS sms : list) {
|
||||
// compare last item in hashList with first elem in arrived list
|
||||
// protect is listSc_Id size = 0
|
||||
if (listScId != null && (listScId.isEmpty()
|
||||
|| (sms.sc_id_dest != listScId.get(listScId.size() - 1).sc_id_dest
|
||||
|| sms.sc_id_sour != listScId.get(listScId.size() - 1).sc_id_sour
|
||||
|| !Objects.equals(sms.mess, listScId.get(listScId.size() - 1).mess))))
|
||||
listScId.add(sms);
|
||||
}
|
||||
}
|
||||
// modify UI
|
||||
ACTION = MSG_UPDATE;
|
||||
myHandler.post(this::updateResultsInUi);
|
||||
}
|
||||
|
||||
// Confirmation for sending message
|
||||
public void confirmSMS(String data, final String seqID) {
|
||||
SM.Debug("confirmSMS");
|
||||
if (data.equals("0")) {
|
||||
SM.Debug("Error on sending SMS");
|
||||
showErrorDialog("Error on sending message.");
|
||||
} else {
|
||||
SM.Debug("ACK received for text message");
|
||||
//get scId for crt message
|
||||
long scId = seqIDSMSHash.get(seqID);
|
||||
// get SMS list for crt scId
|
||||
ArrayList<SMS> crtSMSList = tableSMS.get(scId);
|
||||
if (crtSMSList != null) {
|
||||
for (SMS sms : crtSMSList) {
|
||||
|
||||
if (sms.seq_idx.equals(seqID)) {
|
||||
SM.Debug("######### AM SCHIMBAT STATUSUL pt: " + sms.mess + " | " + scId + " | " + seqID + " || " + sms.seq_idx);
|
||||
// set ACK
|
||||
sms.status = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove message from seqIDSMS Hash = don't wait confirmation for it
|
||||
seqIDSMSHash.remove(seqID);
|
||||
|
||||
// store sms seqId to set to ACK in adapter
|
||||
myHandler.post(() -> {
|
||||
convAdapter.setACK(seqID);
|
||||
convAdapter.changeView(seqID);
|
||||
convAdapter.notifyDataSetChanged();
|
||||
});
|
||||
|
||||
myHandler.post(() -> editTextMsg.setText(""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void newSMS(String imei, String message, final long time) {
|
||||
SM.Debug(" ## newSMS: " + imei + " | " + message);
|
||||
if (!LASTMESSAGES) {
|
||||
// if received message from current conversation
|
||||
if (getVehicleByImei(imei).sc_id == getScId())
|
||||
getSMS4UnitWithTime(getScId(), time); // refresh MSG List
|
||||
} else
|
||||
getLastSMS(); // get last SMS
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable enableButtonRUN = this::updateEnableButtonsUI;
|
||||
|
||||
// enable buttons in UI after 200ms from send
|
||||
private void updateEnableButtonsUI() {
|
||||
// enable buttons
|
||||
imageButtonSend.setEnabled(true);
|
||||
editTextMsg.setEnabled(true);
|
||||
editTextMsg.setText("");
|
||||
}
|
||||
|
||||
private void updateResultsInUi() {
|
||||
if (getAllVehicle() == null)
|
||||
updateVehicles(parentTab.getAllVehicle());
|
||||
|
||||
if (ACTION == MSG_UPDATE) {
|
||||
if (LASTMESSAGES) {
|
||||
// show Header Layout
|
||||
layoutHeader.setVisibility(View.VISIBLE);
|
||||
// hide Conversation Header Layout
|
||||
layoutHeaderConversation.setVisibility(View.GONE);
|
||||
// hide Send Layout
|
||||
layoutSend.setVisibility(View.GONE);
|
||||
// change GridView adapter
|
||||
gridView.setAdapter(mAdapter);
|
||||
gridView.invalidate();
|
||||
} else {
|
||||
SM.Debug(" #### Modify adapter for SMS4unit");
|
||||
// populate specific conversation
|
||||
listSpecificConversation = new ArrayList<>();
|
||||
dispatcherPositions = new ArrayList<>();
|
||||
ArrayList<Boolean> ackPosition = new ArrayList<>();
|
||||
ArrayList<SMS> list;
|
||||
list = tableSMS.get(getScId());
|
||||
if (list != null) {
|
||||
for (SMS sms : list) {
|
||||
// get for sender
|
||||
long senderId = sms.sc_id_dest;
|
||||
if (senderId == 0)
|
||||
senderId = sms.sc_id_sour;
|
||||
// get vehicle with sender id
|
||||
Vehicle messageVeh;
|
||||
messageVeh = getVehicleById(senderId);
|
||||
// flag dispatcher message when source is 0
|
||||
dispatcherPositions.add(sms.sc_id_sour == 0);
|
||||
ackPosition.add(sms.status == 2);
|
||||
|
||||
listSpecificConversation.add(new Msg(messageVeh, sms.mess, new Date((long) sms.timeGMT * 1000), sms.seq_idx));
|
||||
}
|
||||
}
|
||||
|
||||
convAdapter = new ConversationGridViewAdapter(activity, listSpecificConversation, dispatcherPositions, ackPosition);
|
||||
gridView.setAdapter(convAdapter);
|
||||
if (!listSpecificConversation.isEmpty())
|
||||
gridView.setSelection(listSpecificConversation.size() - 1);
|
||||
|
||||
// set unit name and image in Header Conversation
|
||||
textViewSelectedContact.setText(getVehicleByScId(getScId()).name);
|
||||
imageViewSelectedContact.setImageResource(getVehicleByScId(getScId()).getLargeIcon());
|
||||
|
||||
// clear editText
|
||||
editTextMsg.setText("");
|
||||
|
||||
// change layouts visibility
|
||||
layoutSend.setVisibility(View.VISIBLE);
|
||||
layoutHeader.setVisibility(View.GONE);
|
||||
layoutHeaderConversation.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
gridView.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
// gets Vehicle from id
|
||||
public Vehicle getVehicleById(long vehicleId) {
|
||||
for (Vehicle vehicle : getAllVehicle())
|
||||
if (vehicle.sc_id == vehicleId)
|
||||
return vehicle;
|
||||
return null;
|
||||
}
|
||||
|
||||
// get Vehicle from imei
|
||||
public Vehicle getVehicleByImei(String imei) {
|
||||
for (Vehicle vehicle : getAllVehicle())
|
||||
if (vehicle.imei.equalsIgnoreCase(imei))
|
||||
return vehicle;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Vehicle getVehicleByScId(long scId) {
|
||||
for (Vehicle vehicle : getAllVehicle())
|
||||
if (vehicle.sc_id == scId)
|
||||
return vehicle;
|
||||
return null;
|
||||
}
|
||||
|
||||
// show a dialog
|
||||
public void showDialog() {
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.template_simple_list_item, allVehicleNames);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(getString(R.string.selectVehicle));
|
||||
builder.setAdapter(adapter, (dialog, which) -> {
|
||||
// get position
|
||||
Vehicle item = getAllVehicle().get(which);
|
||||
// get Specific Conversation
|
||||
setScId(item.sc_id);
|
||||
SM.Debug("Selected scId: " + getScId());
|
||||
// set Conversation type
|
||||
LASTMESSAGES = false;
|
||||
// call get SMS
|
||||
getSMS4unit(getScId());
|
||||
// create crt_Vehicle
|
||||
setUnitType((int) item.driver_id);
|
||||
|
||||
SM.Debug("AM SELECTAT: " + getScId() + " | " + item.name + " | " + getUnitType() + "\n\t " + item);
|
||||
|
||||
if (AppParams.DEMO)
|
||||
updateResultsInUi();
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
public void showErrorDialog(String errorMsg) {
|
||||
Dialog dialog = new Dialog(context);
|
||||
dialog.setTitle(getString(R.string.sendingError));
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = dialog.findViewById(R.id.text);
|
||||
ImageView image = dialog.findViewById(R.id.image);
|
||||
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText(errorMsg);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public ArrayList<Vehicle> getAllVehicle() {
|
||||
return allVehicle;
|
||||
}
|
||||
|
||||
public void setAllVehicle(ArrayList<Vehicle> allVehicle) {
|
||||
this.allVehicle = allVehicle;
|
||||
}
|
||||
|
||||
public long getScId() {
|
||||
return scId;
|
||||
}
|
||||
|
||||
public void setScId(long scId) {
|
||||
this.scId = scId;
|
||||
}
|
||||
|
||||
public int getUnitType() {
|
||||
return unitType;
|
||||
}
|
||||
|
||||
public void setUnitType(int unitType) {
|
||||
this.unitType = unitType;
|
||||
}
|
||||
|
||||
public Bundle getSavedInstanceState() {
|
||||
return savedInstanceState;
|
||||
}
|
||||
|
||||
public void setSavedInstanceState(Bundle savedInstanceState) {
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.safemobile.lib.AppParams;
|
||||
|
||||
public class NotificationActivity extends Activity{
|
||||
|
||||
public static final String NOTIFICATION_MESSAGE_INTENT = "notification_message_clicked_intent";
|
||||
public static final String NOTIFICATION_ALERT_INTENT = "notification_alert_clicked_intent";
|
||||
public static final String NOTIFICATION_POLL_INTENT = "notification_poll_clicked_intent";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// get notification type
|
||||
int key = getIntent().getExtras().getInt("key");
|
||||
|
||||
// broadcast intent
|
||||
Intent i = new Intent();
|
||||
switch(key)
|
||||
{
|
||||
case AppParams.messageNotif: i.setAction(NOTIFICATION_MESSAGE_INTENT); break;
|
||||
case AppParams.alertNotif: i.setAction(NOTIFICATION_ALERT_INTENT); break;
|
||||
case AppParams.pollNotif: i.setAction(NOTIFICATION_POLL_INTENT); break;
|
||||
}
|
||||
|
||||
getBaseContext().sendBroadcast(i);
|
||||
|
||||
/* Set activity result and send intent data */
|
||||
setResult(RESULT_OK, getIntent());
|
||||
/* Finish activity and return to parent activity */
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,411 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Typeface;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.safemobile.adapters.RecordingsGridViewAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.OperationCodes;
|
||||
import com.safemobile.lib.Recording;
|
||||
import com.safemobile.lib.SM;
|
||||
import com.safemobile.lib.radio.RadioGW;
|
||||
import com.safemobile.lib.sound.RecordingHandle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* fix import
|
||||
*/
|
||||
|
||||
public class RecordingsActivity extends Activity {
|
||||
private Context context;
|
||||
private Activity activity;
|
||||
public TabLayoutActivity parentTab;
|
||||
public ArrayList<Recording> allRecordings = new ArrayList<Recording>();
|
||||
private ArrayList<Boolean> playingPositions = new ArrayList<Boolean>();
|
||||
private ArrayList<String> allGWsIP = new ArrayList<String>();
|
||||
private GridView gridView;
|
||||
private RecordingsGridViewAdapter adapter;
|
||||
public View convertViewRecording;
|
||||
|
||||
public int playingPosition = -1;
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
private final Handler myHandler = new Handler();
|
||||
|
||||
//recoding TCP and audio
|
||||
private RecordingHandle recHandle = null;
|
||||
|
||||
/* Dialog */
|
||||
private TextView textViewCount, textViewGateway;
|
||||
|
||||
public Bundle savedInstanceState;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
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());
|
||||
|
||||
setContentView(R.layout.tabrecordings);
|
||||
|
||||
|
||||
// get context
|
||||
context = this;
|
||||
activity = this;
|
||||
|
||||
|
||||
// change tab header fontface
|
||||
TextView textView1 = (TextView) findViewById(R.id.textViewTitle);
|
||||
textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textView1.setTextSize(24);
|
||||
|
||||
gridView = (GridView) findViewById(R.id.gridViewRecordings);
|
||||
adapter = new RecordingsGridViewAdapter(activity, context, allRecordings, playingPositions);
|
||||
gridView.setAdapter(adapter);
|
||||
|
||||
gridView.setOnItemClickListener(onItemClickListener);
|
||||
|
||||
if(recHandle == null && !AppParams.DEMO)
|
||||
recHandle = new RecordingHandle(AppParams.IP);
|
||||
|
||||
|
||||
textViewCount = (TextView) findViewById(R.id.textViewCount);
|
||||
updateNumberOfRecordings();
|
||||
|
||||
textViewGateway = (TextView) findViewById(R.id.textViewGateway);
|
||||
textViewGateway.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf"));
|
||||
textViewGateway.setTextSize(24);
|
||||
textViewGateway.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
allGWsIP.clear();
|
||||
for(RadioGW radio: AppParams.listRadios)
|
||||
allGWsIP.add(radio.IP);
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.template_simple_list_item,
|
||||
allGWsIP);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
context);
|
||||
builder.setTitle("Select RadioGW");
|
||||
builder.setAdapter(adapter,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// change gateway
|
||||
textViewGateway.setText(allGWsIP.get(which));
|
||||
Toast.makeText(context, getString(R.string.loadingRecordings), Toast.LENGTH_SHORT).show();
|
||||
GetRecordings(parentTab.allRadios.get(which).GW_ID, parentTab.allRadios.get(which).ID);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
});
|
||||
textViewGateway.setVisibility(View.INVISIBLE);
|
||||
|
||||
|
||||
parentTab.recordingsActivity = this;
|
||||
|
||||
// register to receive broadcasts
|
||||
registerBroadcastIntents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
|
||||
/** Update the number of recordings displayed on the top layout */
|
||||
private void updateNumberOfRecordings() {
|
||||
textViewCount.setText("[" + AppParams.recordings.size() + "]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void showDialog(String errorMsg)
|
||||
{
|
||||
Dialog dialog = new Dialog(context);
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setTitle("Message");
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = dialog.findViewById(R.id.text);
|
||||
ImageView image = dialog.findViewById(R.id.image);
|
||||
|
||||
image.setImageResource(R.mipmap.ic_launcher);
|
||||
text.setText(errorMsg);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
SM.Debug("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if(parentTab.getTCPState() != null && !AppParams.DEMO){
|
||||
|
||||
Toast.makeText(context, getString(R.string.moreRecordings), Toast.LENGTH_SHORT).show();
|
||||
|
||||
if(parentTab.crtRadio != null)
|
||||
textViewGateway.setText(parentTab.crtRadio.IP);
|
||||
|
||||
/*
|
||||
if(parentTab.allRadios == null)
|
||||
GetGWRadios();
|
||||
*/
|
||||
if(playingPosition < 0 && parentTab.crtRadio != null)
|
||||
{
|
||||
SM.Debug("GetRecordings resume + crtRadio:"+parentTab.crtRadio.toString());
|
||||
GetRecordings(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID);
|
||||
}
|
||||
|
||||
}
|
||||
SM.Debug("onResume");
|
||||
}
|
||||
|
||||
private OnItemClickListener onItemClickListener = new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
|
||||
|
||||
// disable grid scrolling and item click
|
||||
gridView.setEnabled(false);
|
||||
convertViewRecording = view;
|
||||
|
||||
// change background to playing
|
||||
adapter.changePlaying(position, true);
|
||||
|
||||
// if no recording is playing and not DEMO
|
||||
if(playingPosition<0 && !AppParams.DEMO)
|
||||
{
|
||||
// send recording request to App Server
|
||||
SendPlayRequest(allRecordings.get(position).ID);
|
||||
// flag that sound is needed
|
||||
recHandle.StartSound();
|
||||
recHandle.soundNeeded = true;
|
||||
}
|
||||
// no recording is playing and DEMO
|
||||
else if(playingPosition<0 && AppParams.DEMO)
|
||||
{
|
||||
// create player which will play demo recordings
|
||||
MediaPlayer player = new MediaPlayer();
|
||||
|
||||
AssetFileDescriptor afd;
|
||||
try {
|
||||
switch(position)
|
||||
{
|
||||
case 1: afd = getAssets().openFd("startwindows.mp3"); break;
|
||||
case 2: afd = getAssets().openFd("exitwindows.mp3"); break;
|
||||
default : afd = getAssets().openFd("mike.mp3"); break;
|
||||
};
|
||||
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
|
||||
player.prepare();
|
||||
player.start();
|
||||
|
||||
} catch (IOException e) { }
|
||||
}
|
||||
|
||||
// save playing position
|
||||
playingPosition = position;
|
||||
|
||||
// start the timer which will reset the UI to 'no recording playing'
|
||||
startRecordingStoperTimer(allRecordings.get(playingPosition).endGMT - allRecordings.get(playingPosition).startGMT);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** create Timer which will stop the recording after a specific time */
|
||||
private void startRecordingStoperTimer(final int seconds) {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// sleep for at least 1 second
|
||||
final int ms = (seconds > 1 ? seconds * 1000 : 1000);
|
||||
|
||||
// sleep for amount of time
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// modify the UI after the recording is done playing
|
||||
myHandler.post(stopRecordingRUN);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable stopRecordingRUN = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateStopRecording();
|
||||
}
|
||||
};
|
||||
|
||||
private void updateStopRecording()
|
||||
{
|
||||
// change playing icon
|
||||
adapter.changePlaying(playingPosition, false);
|
||||
|
||||
// enable grid
|
||||
gridView.setEnabled(true);
|
||||
|
||||
// set playing Recording position to -1
|
||||
playingPosition = -1;
|
||||
|
||||
}
|
||||
|
||||
// Update Recordings received from AppServer
|
||||
public void UpdateRecordings(ArrayList<Recording> list)
|
||||
{
|
||||
//SM.Debug("## UpdateRecordings: " + list.size());
|
||||
allRecordings = new ArrayList<Recording>();
|
||||
for(Recording rec : list)
|
||||
{
|
||||
if(rec.typeID == 1 && rec.subID == AppParams.USERID)
|
||||
allRecordings.add(rec);
|
||||
else if (rec.typeID != 1)
|
||||
allRecordings.add(rec);
|
||||
}
|
||||
myHandler.post(UpdateResultsRUN);
|
||||
|
||||
}
|
||||
|
||||
// PlayRecording received from AppServer
|
||||
public void PlayRecording(long id)
|
||||
{
|
||||
// change adapter image
|
||||
|
||||
}
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable UpdateResultsRUN = new Runnable() {
|
||||
public void run() {
|
||||
updateResultsInUi();
|
||||
}
|
||||
};
|
||||
|
||||
private void updateResultsInUi()
|
||||
{
|
||||
// clear played items
|
||||
playingPositions = new ArrayList<Boolean>();
|
||||
for(int i=0; i<allRecordings.size(); i++)
|
||||
playingPositions.add(true);
|
||||
// set adapter - where playingPositions stores exists values
|
||||
adapter = new RecordingsGridViewAdapter(activity, context, allRecordings, playingPositions);
|
||||
|
||||
// playing positions need to be false because no recording is played
|
||||
playingPositions.clear();
|
||||
for(int i=0; i<allRecordings.size(); i++)
|
||||
playingPositions.add(false);
|
||||
|
||||
updateNumberOfRecordings();
|
||||
|
||||
gridView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
// send
|
||||
private void GetRecordings(int radioGWID, int radioID)
|
||||
{
|
||||
parentTab.getRecordings(radioGWID, radioID);
|
||||
}
|
||||
|
||||
public void SendPlayRequest(long record_id)
|
||||
{
|
||||
parentTab.sendPlayRecordingRequest(record_id);
|
||||
}
|
||||
|
||||
|
||||
/** Register for broadcasts */
|
||||
private void registerBroadcastIntents() {
|
||||
IntentFilter intentFilter = new IntentFilter(OperationCodes.RECORDINGS_LIST_REP+"");
|
||||
this.registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
intentFilter = new IntentFilter(OperationCodes.RADIOID_CHANGED+"");
|
||||
this.registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
}
|
||||
|
||||
//The BroadcastReceiver that listens for Notification broadcasts
|
||||
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
//SM.Debug("### NOTIFICATION ###", "Radio: " + intent.getAction());
|
||||
|
||||
final String action = intent.getAction();
|
||||
// zone and/or channel changed
|
||||
if (action.equals(OperationCodes.RECORDINGS_LIST_REP+"")) {
|
||||
UpdateRecordings(AppParams.recordings);
|
||||
updateNumberOfRecordings();
|
||||
}
|
||||
else if (action.equals(OperationCodes.RADIOID_CHANGED+"")) {
|
||||
textViewGateway.setText(parentTab.crtRadio.IP);
|
||||
GetRecordings(parentTab.crtRadio.GW_ID, parentTab.crtRadio.ID);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,295 @@
|
||||
package com.safemobile.safedispatch;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/** fix import */
|
||||
import com.safemobile.adapters.LanguageSpinnerAdapter;
|
||||
import com.safemobile.lib.AppParams;
|
||||
import com.safemobile.lib.SM;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SetupActivity extends Activity {
|
||||
|
||||
/* Preferences */
|
||||
private SharedPreferences.Editor editor;
|
||||
//private String IP, PORT, AUDIOPORT, COMPORT, LANGUAGE;
|
||||
|
||||
/* Visual Elements */
|
||||
private EditText appServerIP, appServerPort;
|
||||
private LinearLayout layoutPath;
|
||||
private Button btn_save;
|
||||
|
||||
/* Misc */
|
||||
private Context context;
|
||||
private TabLayoutActivity parentTab;
|
||||
|
||||
/* Language */
|
||||
private String[] Languages = {"English", "German", "Turkish", "Romanian", "Russian", "Spanish"};
|
||||
private ImageView imageLanguage;
|
||||
private LinearLayout layoutSpinnerLanguage;
|
||||
private TextView textViewSpinnerLanguage;
|
||||
|
||||
private Bundle savedInstanceState;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
context = this;
|
||||
|
||||
// get parentTab
|
||||
parentTab = (TabLayoutActivity)getParent();
|
||||
|
||||
// get settings
|
||||
loadSettings();
|
||||
|
||||
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)};
|
||||
// set contextView
|
||||
setContentView(R.layout.tabsetup);
|
||||
|
||||
|
||||
layoutSpinnerLanguage = (LinearLayout) findViewById(R.id.layoutSpinnerLanguage);
|
||||
layoutSpinnerLanguage.setOnClickListener(LanguageListener);
|
||||
imageLanguage = (ImageView) findViewById(R.id.imageLanguage);
|
||||
textViewSpinnerLanguage = (TextView) findViewById(R.id.textViewSpinnerLanguage);
|
||||
|
||||
// change spinner icon and selected language according to tmpLanguage
|
||||
if (AppParams.LANGUAGETMP.equals("en")){
|
||||
imageLanguage.setImageResource(R.drawable.en);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.en));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("de")){
|
||||
imageLanguage.setImageResource(R.drawable.de);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.de));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("tr")){
|
||||
imageLanguage.setImageResource(R.drawable.tr);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.tr));
|
||||
}
|
||||
else if (AppParams.LANGUAGETMP.equals("ro")){
|
||||
imageLanguage.setImageResource(R.drawable.ro);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.ro));
|
||||
}
|
||||
else if(AppParams.LANGUAGETMP.equals("es")){
|
||||
imageLanguage.setImageResource(R.drawable.es);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.es));
|
||||
}
|
||||
else if(AppParams.LANGUAGETMP.equals("ru")){
|
||||
imageLanguage.setImageResource(R.drawable.ru);
|
||||
textViewSpinnerLanguage.setText(getString(R.string.ru));
|
||||
}
|
||||
|
||||
// get visual elements
|
||||
appServerIP = (EditText) findViewById(R.id.appServerIP);
|
||||
appServerPort = (EditText) findViewById(R.id.appServerPort);
|
||||
|
||||
// hide path layout used only on Pad/Pod
|
||||
layoutPath = (LinearLayout) findViewById(R.id.layoutPath);
|
||||
layoutPath.setVisibility(View.GONE);
|
||||
btn_save = (Button) findViewById(R.id.btn_save);
|
||||
|
||||
btn_save.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveSettings();
|
||||
}
|
||||
});
|
||||
|
||||
// set values
|
||||
if(!AppParams.IP.equals("n/a"))
|
||||
appServerIP.setText(AppParams.IP);
|
||||
if(!AppParams.PORT.equals("n/a"))
|
||||
appServerPort.setText(AppParams.PORT);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(getString(R.string.exit))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.logout);
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
parentTab.whenBackPressed(AppParams.ActivityResult.exit);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
// listener when select language pressed
|
||||
private OnClickListener LanguageListener = new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final LanguageSpinnerAdapter adapter = new LanguageSpinnerAdapter(context, android.R.layout.simple_spinner_item, Languages, getLayoutInflater());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(getString(R.string.selLanguage));
|
||||
builder.setAdapter(adapter , new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
textViewSpinnerLanguage.setText(adapter.getItem(which));
|
||||
switch(which)
|
||||
{
|
||||
case 0: imageLanguage.setImageResource(R.drawable.en); AppParams.LANGUAGETMP = "en"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 1: imageLanguage.setImageResource(R.drawable.de); AppParams.LANGUAGETMP = "de"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 2: imageLanguage.setImageResource(R.drawable.tr); AppParams.LANGUAGETMP = "tr"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 3: imageLanguage.setImageResource(R.drawable.ro); AppParams.LANGUAGETMP = "ro"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 4: imageLanguage.setImageResource(R.drawable.ru); AppParams.LANGUAGETMP = "ru"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
case 5: imageLanguage.setImageResource(R.drawable.es); AppParams.LANGUAGETMP = "es"; onCreate(savedInstanceState); parentTab.changeLanguage(); break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// load settings
|
||||
public void loadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
// get Preferences for SafeDispatch
|
||||
AppParams.prefs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
|
||||
// get default IP
|
||||
AppParams.IP = AppParams.prefs.getString("ip", "n/a");
|
||||
// get default communication port
|
||||
AppParams.PORT = AppParams.prefs.getString("port", "n/a");
|
||||
// get default audio port
|
||||
//AUDIOPORT = prefs.getString("audioport", "n/a");
|
||||
// get default com port
|
||||
//COMPORT = prefs.getString("comport", "n/a");
|
||||
// get Language
|
||||
AppParams.LANGUAGE = AppParams.prefs.getString("language", parentTab.databaseLanguage);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.e("Exception", "loadSettings exception");
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSettings()
|
||||
{
|
||||
// get editor
|
||||
editor = AppParams.prefs.edit();
|
||||
// save old IP and PORT values
|
||||
String oldIP = AppParams.IP;
|
||||
String oldPort = AppParams.PORT;
|
||||
|
||||
editor.putString("ip", appServerIP.getText().toString());
|
||||
editor.putString("port", appServerPort.getText().toString());
|
||||
editor.putString("language", AppParams.LANGUAGETMP);
|
||||
Boolean result = editor.commit();
|
||||
// saved completed
|
||||
if(result)
|
||||
Toast.makeText(context, "Settings saved successfully.", Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(context, "Settings failed to complete!", Toast.LENGTH_LONG).show();
|
||||
// if port or IP changed
|
||||
if((!appServerIP.getText().toString().equalsIgnoreCase(AppParams.IP) ||
|
||||
!appServerPort.getText().toString().equalsIgnoreCase(AppParams.PORT)) && !AppParams.DEMO)
|
||||
{
|
||||
SM.Debug("### SETTINGS ###", "IP and/or PORT had been changed");
|
||||
// load new settings
|
||||
parentTab.loadSettings();
|
||||
|
||||
|
||||
parentTab.removeITCPListener();
|
||||
|
||||
// recreateTCP
|
||||
parentTab.stopTCP();
|
||||
parentTab.recreateTCPConnection();
|
||||
|
||||
/*
|
||||
// stop old TCP
|
||||
parentTab.stopTCP();
|
||||
parentTab.stopTCPParser();
|
||||
// recreate TCP with new settings
|
||||
parentTab.loadSettings();
|
||||
parentTab.TCPinit();
|
||||
*/
|
||||
// start thread to add listener
|
||||
/*
|
||||
SM.Debug("##### initTCPRUN");
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
parentTab.myHandler.post(parentTab.initTCPRUN);
|
||||
}
|
||||
}).start();*/
|
||||
}
|
||||
// show dialog
|
||||
//showDialog(result);
|
||||
}
|
||||
|
||||
public void showDialog(Boolean result)
|
||||
{
|
||||
Dialog dialog = new Dialog(context);
|
||||
if(result)
|
||||
dialog.setTitle("Save Completed");
|
||||
else
|
||||
dialog.setTitle("Save Failed");
|
||||
dialog.setContentView(R.layout.dialog);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
TextView text = (TextView) dialog.findViewById(R.id.text);
|
||||
ImageView image = (ImageView) dialog.findViewById(R.id.image);
|
||||
if(result)
|
||||
{
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText("Settings saved successfully.");
|
||||
}
|
||||
else
|
||||
{
|
||||
image.setImageResource(R.drawable.error);
|
||||
text.setText("Settings failed to complete!");
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user