display Markers

This commit is contained in:
CiufudeanDani 2022-03-15 14:45:18 +02:00
parent 4ee6b53d97
commit 3da44593dd
2 changed files with 98 additions and 17 deletions

View File

@ -21,36 +21,28 @@ public class SuperVehicle extends Vehicle{
// TODO Auto-generated constructor stub
}
public void SetDataFromLastPos(Double _lat,Double _lng,long _time,int _speed,String _Address,Boolean _isON)
{
try
{
public void SetDataFromLastPos(Double _lat,Double _lng,long _time,int _speed,String _Address,Boolean _isON) {
try {
lat = _lat;
lng = _lng;
timeGMT = _time;
speed = _speed;
Address = _Address;
isON = _isON;
}
catch (Exception ex)
{
Log.d("Erorr", "Contert Error:"+ex.toString());
} catch (Exception ex) {
Log.d("Erorr", "Contert Error: "+ ex);
}
}
public void SetNewPosition(Double _lat,Double _lng,long _time,int _speed)
{
try
{
public void SetNewPosition(Double _lat,Double _lng,long _time,int _speed) {
try {
lat = _lat;
lng = _lng;
timeGMT = _time;
speed = _speed;
isON = true;
}
catch (Exception ex)
{
Log.d("Erorr", "Contert Error:"+ex.toString());
} catch (Exception ex) {
Log.d("Erorr", "Contert Error: " + ex);
}
}

View File

@ -9,6 +9,13 @@ 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;
@ -30,7 +37,10 @@ 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.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.safemobile.activities.AbstractLiveActivity;
import com.safemobile.activities.AbstractSDParentActivity;
@ -456,13 +466,92 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
});
public void displayVehicle(boolean withZoom, double latZoom, double lngZoom) {
//TODO: add makers for vehicles
if (googleMap != null) {
googleMap.clear();
for (int i = 0; i < displayedVehicles.size(); i++) {
if (displayedVehicles.get(i)) {
SuperVehicle tmpSuper = Objects.requireNonNull(tableHashOverlay.get((int) liveVehicle.get(i).driver_id)).get(0);
if (tmpSuper != null) {
LatLng newLocation = new LatLng(tmpSuper.lat, tmpSuper.lng);
MarkerOptions markerOptions = new MarkerOptions().position(newLocation).title(tmpSuper.name);
BitmapDescriptor markerIcon = getProperBitmap(tmpSuper.getLargeIcon(), tmpSuper.name);
markerOptions.icon(markerIcon);
Marker marker = this.googleMap.addMarker(markerOptions);
this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(newLocation));
}
}
}
}
}
public void showOpenedBalloon(boolean demo) {
int i =0;
//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);