display info bubble

This commit is contained in:
CiufudeanDani 2022-03-16 10:54:41 +02:00
parent 2334dc2e3c
commit 201845da3a
14 changed files with 260 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2012 The Android Open Source Project
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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/custom_info_bubble"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="9dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/containerTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/l_bg_gps"
android:orientation="vertical">
<TextView
android:id="@+id/tvUnitName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:fontFamily="sans-serif-smallcaps"
android:maxLines="1"
android:paddingTop="5dp"
tools:text="Linux 9910"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvGPSLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:fontFamily="sans-serif-smallcaps"
android:maxLines="1"
tools:text="[44.41857,26.09585]"
android:textColor="#FFFFFF"
android:textSize="10sp"
tools:ignore="SmallSp" />
</LinearLayout>
<RelativeLayout
android:layout_width="225dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/rlMapInfoBubbleInfo">
<ImageView
android:id="@+id/time"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="@drawable/l_time"
android:layout_marginEnd="5dp" />
<TextView
android:id="@+id/tvTimeAgo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/time"
android:layout_alignTop="@+id/time"
android:layout_gravity="center_horizontal"
android:layout_toEndOf="@+id/time"
android:layout_toRightOf="@+id/time"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
tools:text="a year ago [01:05:01]"
android:textColor="#ff000000"
android:textSize="10sp" />
<ImageView
android:id="@+id/speed"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_below="@+id/time"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:adjustViewBounds="true"
android:src="@drawable/l_speed" />
<TextView
android:id="@+id/tvSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/speed"
android:layout_alignTop="@+id/speed"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="@+id/speed"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
tools:text="24 kph"
android:textColor="#ff000000"
android:textSize="10sp" />
<ImageView
android:id="@+id/streetView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_below="@+id/speed"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="@drawable/l_street"
android:visibility="visible" />
<TextView
android:id="@+id/tvStreetView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/streetView"
android:layout_gravity="center_horizontal"
android:layout_toRightOf="@+id/streetView"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="5"
tools:text="3601 E Algonquin Rd., Suite 800 Rolling Meadows, IL 60008"
android:textColor="#ff000000"
android:textSize="10sp"
android:visibility="visible" />
</RelativeLayout>
</LinearLayout>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
</resources>

View File

@ -0,0 +1,93 @@
package com.safemobile.dispatch;
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.SuperVehicle;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
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 final Hashtable<Long, SuperVehicle> superVehHash;
private final Context context;
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);
}
@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;
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);
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 = new Date(vehicle.timeGMT);
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) + "]");
}
}

View File

@ -32,6 +32,8 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
@ -307,7 +309,8 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
this.googleMap = googleMap;
GoogleMapsInfoBubble infoBubble = new GoogleMapsInfoBubble(getLayoutInflater(), this, getParentTab().SuperVehHash);
this.googleMap.setInfoWindowAdapter(infoBubble);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
this.googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
@ -475,12 +478,12 @@ public class LiveActivity extends AbstractLiveActivity implements OnMapReadyCall
if (tmpSuper != null) {
LatLng newLocation = new LatLng(tmpSuper.lat, tmpSuper.lng);
MarkerOptions markerOptions = new MarkerOptions().position(newLocation).title(tmpSuper.name);
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);
Marker marker = this.googleMap.addMarker(markerOptions);
}
}
}

View File

@ -232,4 +232,7 @@
<item >German</item>
<item >Romanian</item>
</string-array>
<string name="speedMph">%1$d mph</string>
</resources>

View File

@ -236,4 +236,7 @@
<item >Spanish</item>
<item >Russian</item>
</string-array>
<string name="speedMph">%1$d mph</string>
</resources>

View File

@ -233,4 +233,7 @@
<item >Turca</item>
<item >Romana</item>
</string-array>
<string name="speedMph">%1$d mph</string>
</resources>

View File

@ -232,4 +232,7 @@
<item >German</item>
<item >Romanian</item>
</string-array>
<string name="speedMph">%1$d mph</string>
</resources>

View File

@ -254,4 +254,8 @@
</string-array>
<string name="title_activity_new_live">NewLiveActivity</string>
<string name="title_activity_google_maps">GoogleMapsActivity</string>
<string name="speedMph">%1$d mph</string>
</resources>