summaryrefslogtreecommitdiff
path: root/java/com/android/incallui/calllocation/impl/LocationFragment.java
diff options
context:
space:
mode:
authoryueg <yueg@google.com>2018-05-23 16:36:49 -0700
committerEric Erfanian <erfanian@google.com>2018-05-30 14:02:19 +0000
commit2ad3c08bc26edee0c721505e21c9764c10e3e5f7 (patch)
tree3962125fa654b2d94b7c579520f3dddde47b51b0 /java/com/android/incallui/calllocation/impl/LocationFragment.java
parentf13f0b8bc727c3a9428c78fd193197b3232cf1e0 (diff)
Use Maps SDK lite mode instead of static API for emergency call.
Test: manual PiperOrigin-RevId: 197810897 Change-Id: Ia9dff17333152763b6c644d4f89bc32eedcc2aab
Diffstat (limited to 'java/com/android/incallui/calllocation/impl/LocationFragment.java')
-rw-r--r--java/com/android/incallui/calllocation/impl/LocationFragment.java70
1 files changed, 61 insertions, 9 deletions
diff --git a/java/com/android/incallui/calllocation/impl/LocationFragment.java b/java/com/android/incallui/calllocation/impl/LocationFragment.java
index 6b2c876b0..760829da2 100644
--- a/java/com/android/incallui/calllocation/impl/LocationFragment.java
+++ b/java/com/android/incallui/calllocation/impl/LocationFragment.java
@@ -18,21 +18,26 @@ package com.android.incallui.calllocation.impl;
import android.animation.LayoutTransition;
import android.content.Context;
-import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
+import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewAnimator;
+import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.incallui.baseui.BaseFragment;
+import com.google.android.gms.maps.CameraUpdateFactory;
+import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.MapView;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.MarkerOptions;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -54,13 +59,16 @@ public class LocationFragment extends BaseFragment<LocationPresenter, LocationPr
private static final long FIND_LOCATION_SPINNING_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);
private static final long LOAD_DATA_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);
+ private static final float MAP_ZOOM_LEVEL = 15f;
+
private ViewAnimator viewAnimator;
- private ImageView locationMap;
+ private MapView locationMapView;
private TextView addressLine1;
private TextView addressLine2;
private TextView latLongLine;
private Location location;
private ViewGroup locationLayout;
+ private GoogleMap savedGoogleMap;
private boolean isMapSet;
private boolean isAddressSet;
@@ -101,11 +109,12 @@ public class LocationFragment extends BaseFragment<LocationPresenter, LocationPr
LogUtil.enterBlock("LocationFragment.onCreateView");
final View view = inflater.inflate(R.layout.location_fragment, container, false);
viewAnimator = (ViewAnimator) view.findViewById(R.id.location_view_animator);
- locationMap = (ImageView) view.findViewById(R.id.location_map);
addressLine1 = (TextView) view.findViewById(R.id.address_line_one);
addressLine2 = (TextView) view.findViewById(R.id.address_line_two);
latLongLine = (TextView) view.findViewById(R.id.lat_long_line);
locationLayout = (ViewGroup) view.findViewById(R.id.location_layout);
+ locationMapView = (MapView) view.findViewById(R.id.location_map_view);
+ locationMapView.onCreate(savedInstanceState);
return view;
}
@@ -122,16 +131,46 @@ public class LocationFragment extends BaseFragment<LocationPresenter, LocationPr
handler.removeCallbacks(spinningTimeoutRunnable);
}
- @Override
- public void setMap(Drawable mapImage) {
+ private void setMap(@NonNull Location location) {
LogUtil.enterBlock("LocationFragment.setMap");
- isMapSet = true;
- locationMap.setVisibility(View.VISIBLE);
- locationMap.setImageDrawable(mapImage);
+ Assert.isNotNull(location);
+
+ if (savedGoogleMap == null) {
+ locationMapView.getMapAsync(
+ (googleMap) -> {
+ LogUtil.enterBlock("LocationFragment.onMapReady");
+ savedGoogleMap = googleMap;
+ savedGoogleMap.getUiSettings().setMapToolbarEnabled(false);
+ updateMap(location);
+ isMapSet = true;
+ locationMapView.setVisibility(View.VISIBLE);
+
+ // Hide Google logo
+ View child = locationMapView.getChildAt(0);
+ if (child instanceof ViewGroup) {
+ // Only the first child (View) is useful.
+ // Google logo can be in any other child (ViewGroup).
+ for (int i = 1; i < ((ViewGroup) child).getChildCount(); ++i) {
+ ((ViewGroup) child).getChildAt(i).setVisibility(View.GONE);
+ }
+ }
+ });
+ } else {
+ updateMap(location);
+ }
displayWhenReady();
Logger.get(getContext()).logImpression(DialerImpression.Type.EMERGENCY_GOT_MAP);
}
+ private void updateMap(@NonNull Location location) {
+ Assert.isNotNull(location);
+ Assert.isNotNull(savedGoogleMap);
+ LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
+ savedGoogleMap.clear();
+ savedGoogleMap.addMarker(new MarkerOptions().position(latLng).flat(true).draggable(false));
+ savedGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, MAP_ZOOM_LEVEL));
+ }
+
@Override
public void setAddress(String address) {
LogUtil.i("LocationFragment.setAddress", address);
@@ -175,6 +214,7 @@ public class LocationFragment extends BaseFragment<LocationPresenter, LocationPr
R.string.lat_long_format, location.getLatitude(), location.getLongitude()));
Logger.get(getContext()).logImpression(DialerImpression.Type.EMERGENCY_GOT_LOCATION);
+ setMap(location);
}
displayWhenReady();
}
@@ -218,4 +258,16 @@ public class LocationFragment extends BaseFragment<LocationPresenter, LocationPr
view.setText(text);
}
}
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ locationMapView.onResume();
+ }
+
+ @Override
+ public void onPause() {
+ locationMapView.onPause();
+ super.onPause();
+ }
}