feature/apk_versioning_mechanism #7
@ -12,10 +12,12 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.safemobile.lib.HistPos;
|
||||
import com.safemobile.lib.SuperVehicle;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
@ -25,8 +27,10 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
private final String TAG = GoogleMapsInfoBubble.class.getName();
|
||||
|
||||
private final View mWindow;
|
||||
private final Hashtable<Long, SuperVehicle> superVehHash;
|
||||
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) {
|
||||
@ -35,6 +39,17 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null);
|
||||
}
|
||||
|
||||
public GoogleMapsInfoBubble(LayoutInflater layoutInflater, Context context) {
|
||||
isLiveTab = false;
|
||||
this.context = context;
|
||||
// this.superVehHash = vehicles;
|
||||
mWindow = layoutInflater.inflate(R.layout.map_marker_info_bubble, null);
|
||||
}
|
||||
|
||||
public void setHistoryPositions(ArrayList<HistPos> positions) {
|
||||
this.histPosList = positions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getInfoWindow(@NonNull Marker marker) {
|
||||
render(marker, mWindow);
|
||||
@ -49,13 +64,21 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
|
||||
private void render(Marker marker, View view) {
|
||||
long key = 0;
|
||||
|
||||
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");
|
||||
}
|
||||
SuperVehicle vehicle = superVehHash.get(key);
|
||||
} 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);
|
||||
@ -67,27 +90,39 @@ public class GoogleMapsInfoBubble implements GoogleMap.InfoWindowAdapter {
|
||||
rlMapInfoBubbleInfo.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean isMilitaryTime = false;
|
||||
Date positionTime = new Date(vehicle.timeGMT);
|
||||
|
||||
Date positionTime;
|
||||
String speed, address, gpsLocation, name = "";
|
||||
if (isLiveTab) {
|
||||
SuperVehicle vehicle = superVehHash.get(key);
|
||||
positionTime = new Date(vehicle.timeGMT);
|
||||
address = vehicle.Address != null ? vehicle.Address : "";
|
||||
name = vehicle.name;
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), vehicle.speed);
|
||||
gpsLocation = "[" + String.format("%.4f", vehicle.lat) + "," + String.format("%.4f",vehicle.lng) + "]";
|
||||
} else {
|
||||
HistPos histPos = histPosList.get(position);
|
||||
positionTime = new Date(histPos.timeGMT);
|
||||
address = histPos.Address != null ? histPos.Address : "";
|
||||
speed = String.format(context.getResources().getString(R.string.speedMph), histPos.speed);
|
||||
gpsLocation = "[" + String.format("%.4f", histPos.lat) + "," + String.format("%.4f",histPos.lng) + "]";
|
||||
}
|
||||
|
||||
String timeFormat = isMilitaryTime
|
||||
? "HH:mm:ss dd.MMM.yyyy"
|
||||
: "hh:mm:ss a dd.MMM.yyy";
|
||||
|
||||
DateFormat format = new SimpleDateFormat(timeFormat, Locale.ENGLISH);
|
||||
|
||||
tvTimeAgo.setText(format.format(positionTime));
|
||||
|
||||
tvSpeed.setText(String.format(context.getResources().getString(R.string.speedMph), vehicle.speed));
|
||||
|
||||
String address = vehicle.Address != null ? vehicle.Address : "";
|
||||
|
||||
tvStreetView.setText(address);
|
||||
streetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
|
||||
tvStreetView.setVisibility(address.length() > 0 ? View.VISIBLE : View.GONE);
|
||||
tvUnitName.setText(vehicle.name);
|
||||
tvGPSLocation.setText("[" + String.format("%.4f", vehicle.lat)
|
||||
+ "," + String.format("%.4f",vehicle.lng) + "]");
|
||||
if (!isLiveTab)
|
||||
tvUnitName.setVisibility(View.GONE);
|
||||
else
|
||||
tvUnitName.setText(name);
|
||||
|
||||
tvSpeed.setText(speed);
|
||||
tvGPSLocation.setText(gpsLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,18 @@ package com.safemobile.dispatch;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
@ -45,11 +52,14 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
||||
private Button displayButton;
|
||||
private Date startDate, endDate;
|
||||
private final Handler myHandler = new Handler();
|
||||
private GoogleMapsInfoBubble infoBubble;
|
||||
|
||||
private ArrayList<Vehicle> allVehicle = new ArrayList<>();
|
||||
private ArrayList<String> allVehicleNames = new ArrayList<>();
|
||||
private ArrayAdapter<String> adapter;
|
||||
private boolean showVehicle = true;
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy");
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -98,18 +108,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
||||
displayHistory(parentTab.demoPositions);
|
||||
}
|
||||
});
|
||||
// slidelayout.setOnTouchListener((v, event) -> {
|
||||
// if (showVehicle) {
|
||||
// layoutVehicles.setVisibility(View.GONE);
|
||||
// slideLayoutImage.setImageResource(R.drawable.arrow_right);
|
||||
// showVehicle = false;
|
||||
// } else {
|
||||
// layoutVehicles.setVisibility(View.VISIBLE);
|
||||
// slideLayoutImage.setImageResource(R.drawable.arrow_left);
|
||||
// showVehicle = true;
|
||||
// }
|
||||
// return false;
|
||||
// });
|
||||
|
||||
setDate();
|
||||
}
|
||||
@ -117,14 +115,16 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
||||
private void displayHistory(ArrayList<HistPos> positions) {
|
||||
LatLng latLng = null;
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
BitmapDescriptor markerIcon = BitmapDescriptorFactory.fromResource(R.drawable.bus);
|
||||
for (HistPos pos : positions) {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
Polyline polyline1 = googleMap.addPolyline(polylineOptions);
|
||||
@ -139,23 +139,38 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
||||
startDate = calendar.getTime();
|
||||
|
||||
LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker);
|
||||
TextView textViewDate = findViewById(R.id.textViewStartDate);
|
||||
TextView textViewStartDate = findViewById(R.id.textViewStartDate);
|
||||
TextView textViewEndDate = findViewById(R.id.textViewEndDate);
|
||||
|
||||
textViewDate.setText(new SimpleDateFormat("HH:mm, dd.MM.yyyy").format(startDate));
|
||||
// layoutStartPicker.setOnTouchListener((v, event) -> {
|
||||
// showDialog(layoutStartPicker);
|
||||
// return false;
|
||||
// });
|
||||
textViewStartDate.setText(sdf.format(startDate));
|
||||
textViewEndDate.setText(sdf.format(endDate));
|
||||
|
||||
// layoutEndPicker.setOnTouchListener(new OnTouchListener() {
|
||||
// @Override
|
||||
// public boolean onTouch(View v, MotionEvent event) {
|
||||
// showDialog(layoutEndPicker);
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
textViewStartDate.setOnClickListener(view -> openDialog(textViewStartDate, true));
|
||||
textViewEndDate.setOnClickListener(view -> openDialog(textViewEndDate, false));
|
||||
}
|
||||
|
||||
private void openDialog(TextView textView, Boolean isStartDate) {
|
||||
Date date = startDate;
|
||||
if (!isStartDate)
|
||||
date = endDate;
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
|
||||
DatePickerDialog.OnDateSetListener setListener = (datePicker, y, m, d) -> {
|
||||
calendar.set(y, m, d);
|
||||
String dateString = sdf.format(calendar.getTime());
|
||||
textView.setText(dateString);
|
||||
if (isStartDate)
|
||||
startDate = calendar.getTime();
|
||||
else
|
||||
endDate = calendar.getTime();
|
||||
};
|
||||
|
||||
Dialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, setListener,
|
||||
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void changeTraffic() {
|
||||
@ -199,6 +214,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
||||
public void run() {
|
||||
Log.v("updateMap", parentTab.HistPosList.toString());
|
||||
SM.Debug("Do the Display");
|
||||
infoBubble.setHistoryPositions(parentTab.HistPosList);
|
||||
displayHistory(parentTab.HistPosList);
|
||||
}
|
||||
};
|
||||
@ -224,6 +240,9 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
|
||||
public void onMapReady(@NonNull GoogleMap googleMap) {
|
||||
this.googleMap = googleMap;
|
||||
|
||||
infoBubble = new GoogleMapsInfoBubble(getLayoutInflater(), this);
|
||||
this.googleMap.setInfoWindowAdapter(infoBubble);
|
||||
|
||||
parentTab.demoPositionsList();
|
||||
displayButton.performClick();
|
||||
}
|
||||
|
@ -162,10 +162,11 @@
|
||||
android:text="@string/startDate"
|
||||
android:textSize="22dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:layout_marginTop="15sp"
|
||||
android:textColor="#000000"
|
||||
android:gravity="left"
|
||||
android:id="@+id/labelStartDate"
|
||||
android:visibility="gone"/>
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutStartPicker"
|
||||
android:layout_height="wrap_content"
|
||||
@ -202,7 +203,7 @@
|
||||
android:textColor="#000000"
|
||||
android:gravity="left"
|
||||
android:id="@+id/labelEndDate"
|
||||
android:visibility="gone"/>
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutEndPicker"
|
||||
android:layout_height="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user