Live Page #3

Merged
CiufudeanDani merged 8 commits from feature/live into develop 2022-03-17 08:20:52 +00:00
2 changed files with 98 additions and 17 deletions
Showing only changes of commit 3da44593dd - Show all commits

View File

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

View File

@ -9,6 +9,13 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; 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.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; 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.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
import com.safemobile.activities.AbstractLiveActivity; import com.safemobile.activities.AbstractLiveActivity;
import com.safemobile.activities.AbstractSDParentActivity; 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) { 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) { public void showOpenedBalloon(boolean demo) {
int i =0;
//TODO: add show balloon //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) { public void showLoadingDialog(String message) {
loadingDialog = new Dialog(context); loadingDialog = new Dialog(context);
loadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); loadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);