summaryrefslogtreecommitdiff
path: root/java/com/android/incallui
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
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')
-rw-r--r--java/com/android/incallui/calllocation/impl/AndroidManifest.xml2
-rw-r--r--java/com/android/incallui/calllocation/impl/DownloadMapImageTask.java78
-rw-r--r--java/com/android/incallui/calllocation/impl/LocationFragment.java70
-rw-r--r--java/com/android/incallui/calllocation/impl/LocationPresenter.java8
-rw-r--r--java/com/android/incallui/calllocation/impl/res/layout/location_fragment.xml163
-rw-r--r--java/com/android/incallui/maps/impl/AndroidManifest.xml2
6 files changed, 65 insertions, 258 deletions
diff --git a/java/com/android/incallui/calllocation/impl/AndroidManifest.xml b/java/com/android/incallui/calllocation/impl/AndroidManifest.xml
index fda940483..3e5a6d04e 100644
--- a/java/com/android/incallui/calllocation/impl/AndroidManifest.xml
+++ b/java/com/android/incallui/calllocation/impl/AndroidManifest.xml
@@ -19,6 +19,8 @@
package="com.android.incallui.calllocation.impl">
<application>
+ <!-- Fix for P -->
+ <uses-library android:name="org.apache.http.legacy" android:required="false" />
<meta-data
android:name="com.google.android.gms.version"
diff --git a/java/com/android/incallui/calllocation/impl/DownloadMapImageTask.java b/java/com/android/incallui/calllocation/impl/DownloadMapImageTask.java
deleted file mode 100644
index c7249e0fa..000000000
--- a/java/com/android/incallui/calllocation/impl/DownloadMapImageTask.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2017 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
- */
-
-package com.android.incallui.calllocation.impl;
-
-import android.graphics.drawable.Drawable;
-import android.location.Location;
-import android.net.TrafficStats;
-import android.os.AsyncTask;
-import com.android.dialer.common.LogUtil;
-import com.android.dialer.constants.TrafficStatsTags;
-import com.android.incallui.calllocation.impl.LocationPresenter.LocationUi;
-import java.io.InputStream;
-import java.lang.ref.WeakReference;
-import java.net.URL;
-
-class DownloadMapImageTask extends AsyncTask<Location, Void, Drawable> {
-
- private static final String STATIC_MAP_SRC_NAME = "src";
-
- private final WeakReference<LocationUi> uiReference;
-
- public DownloadMapImageTask(WeakReference<LocationUi> uiReference) {
- this.uiReference = uiReference;
- }
-
- @Override
- protected Drawable doInBackground(Location... locations) {
- LocationUi ui = uiReference.get();
- if (ui == null) {
- return null;
- }
- if (locations == null || locations.length == 0) {
- LogUtil.e("DownloadMapImageTask.doInBackground", "No location provided");
- return null;
- }
-
- try {
- URL mapUrl = new URL(LocationUrlBuilder.getStaticMapUrl(ui.getContext(), locations[0]));
- TrafficStats.setThreadStatsTag(TrafficStatsTags.DOWNLOAD_LOCATION_MAP_TAG);
- InputStream content = (InputStream) mapUrl.getContent();
-
- return Drawable.createFromStream(content, STATIC_MAP_SRC_NAME);
- } catch (Exception ex) {
- LogUtil.e("DownloadMapImageTask.doInBackground", "Exception!!!", ex);
- return null;
- } finally {
- TrafficStats.clearThreadStatsTag();
- }
- }
-
- @Override
- protected void onPostExecute(Drawable mapImage) {
- LocationUi ui = uiReference.get();
- if (ui == null) {
- return;
- }
-
- try {
- ui.setMap(mapImage);
- } catch (Exception ex) {
- LogUtil.e("DownloadMapImageTask.onPostExecute", "Exception!!!", ex);
- }
- }
-}
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();
+ }
}
diff --git a/java/com/android/incallui/calllocation/impl/LocationPresenter.java b/java/com/android/incallui/calllocation/impl/LocationPresenter.java
index 83195baf8..94bd2357a 100644
--- a/java/com/android/incallui/calllocation/impl/LocationPresenter.java
+++ b/java/com/android/incallui/calllocation/impl/LocationPresenter.java
@@ -17,7 +17,6 @@
package com.android.incallui.calllocation.impl;
import android.content.Context;
-import android.graphics.drawable.Drawable;
import android.location.Location;
import android.os.AsyncTask;
import com.android.dialer.common.LogUtil;
@@ -38,7 +37,6 @@ public class LocationPresenter extends Presenter<LocationPresenter.LocationUi>
implements LocationListener {
private Location lastLocation;
- private AsyncTask downloadMapTask;
private AsyncTask reverseGeocodeTask;
LocationPresenter() {}
@@ -55,9 +53,6 @@ public class LocationPresenter extends Presenter<LocationPresenter.LocationUi>
LogUtil.i("LocationPresenter.onUiUnready", "");
super.onUiUnready(ui);
- if (downloadMapTask != null) {
- downloadMapTask.cancel(true);
- }
if (reverseGeocodeTask != null) {
reverseGeocodeTask.cancel(true);
}
@@ -76,7 +71,6 @@ public class LocationPresenter extends Presenter<LocationPresenter.LocationUi>
int status = LocationHelper.checkLocation(location);
LocationUi ui = getUi();
if (status == LocationHelper.LOCATION_STATUS_OK) {
- downloadMapTask = new DownloadMapImageTask(new WeakReference<>(ui)).execute(location);
reverseGeocodeTask = new ReverseGeocodeTask(new WeakReference<>(ui)).execute(location);
if (ui != null) {
ui.setLocation(location);
@@ -103,8 +97,6 @@ public class LocationPresenter extends Presenter<LocationPresenter.LocationUi>
void setAddress(String address);
- void setMap(Drawable mapImage);
-
void setLocation(Location location);
Context getContext();
diff --git a/java/com/android/incallui/calllocation/impl/res/layout/location_fragment.xml b/java/com/android/incallui/calllocation/impl/res/layout/location_fragment.xml
deleted file mode 100644
index 771e1b868..000000000
--- a/java/com/android/incallui/calllocation/impl/res/layout/location_fragment.xml
+++ /dev/null
@@ -1,163 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!--
-~ Copyright (C) 2015 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
--->
-
-<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/location_view_animator"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dp"
- android:background="@drawable/bg_location_card"
- android:elevation="2dp"
- android:inAnimation="@android:anim/fade_in"
- android:measureAllChildren="true"
- android:outAnimation="@android:anim/fade_out">
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/location_loading_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:orientation="vertical">
-
- <ProgressBar
- android:id="@+id/location_loading_spinner"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="28dp"
- android:layout_marginBottom="12dp"
- android:layout_gravity="center_horizontal"/>
-
- <TextView
- android:id="@+id/location_loading_text"
- style="@style/LocationLoadingTextStyle"
- android:layout_width="match_parent"
- android:layout_height="24sp"
- android:layout_marginBottom="20dp"
- android:layout_marginStart="24dp"
- android:layout_marginEnd="24dp"
- android:gravity="center"
- android:text="@string/location_loading"/>
-
- </LinearLayout>
-
- <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/location_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:columnCount="2"
- android:orientation="horizontal">
-
- <TextView
- android:id="@+id/location_address_title"
- style="@style/LocationAddressTitleTextStyle"
- android:layout_width="0dp"
- android:layout_height="20sp"
- android:layout_marginTop="16dp"
- android:layout_marginBottom="4dp"
- android:layout_marginStart="16dp"
- android:layout_columnWeight="1"
- android:text="@string/location_title"/>
-
- <ImageView
- android:id="@+id/location_map"
- android:layout_width="@dimen/location_map_width"
- android:layout_height="@dimen/location_map_height"
- android:layout_margin="16dp"
- android:layout_gravity="end|center_vertical"
- android:layout_rowSpan="4"
- android:contentDescription="@string/location_map_description"
- android:scaleType="centerCrop"
- android:visibility="invisible"
- tools:src="?android:attr/colorPrimaryDark"
- tools:visibility="visible"/>
-
- <TextView
- android:id="@+id/address_line_one"
- style="@style/LocationAddressTextStyle"
- android:layout_width="0dp"
- android:layout_height="24sp"
- android:layout_marginStart="16dp"
- android:layout_columnWeight="1"
- android:ellipsize="end"
- android:lines="1"
- android:visibility="invisible"
- tools:text="1600 Amphitheatre Pkwy And a bit"
- tools:visibility="visible"/>
-
- <TextView
- android:id="@+id/address_line_two"
- style="@style/LocationAddressTextStyle"
- android:layout_width="0dp"
- android:layout_height="24sp"
- android:layout_marginStart="16dp"
- android:layout_columnWeight="1"
- android:ellipsize="end"
- android:lines="1"
- android:visibility="invisible"
- tools:text="Mountain View, CA 94043"
- tools:visibility="visible"/>
-
- <TextView
- android:id="@+id/lat_long_line"
- style="@style/LocationLatLongTextStyle"
- android:layout_width="0dp"
- android:layout_height="24sp"
- android:layout_marginBottom="12dp"
- android:layout_marginStart="16dp"
- android:layout_columnWeight="1"
- android:ellipsize="end"
- android:lines="1"
- android:visibility="invisible"
- tools:text="Lat: 37.421719, Long: -122.085297"
- tools:visibility="visible"/>
-
- </GridLayout>
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/location_error_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:orientation="vertical">
-
- <ImageView
- android:id="@+id/location_error_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="32dp"
- android:layout_marginBottom="12dp"
- android:layout_gravity="center_horizontal"
- android:src="@drawable/quantum_ic_error_outline_vd_theme_36"
- android:tint="@color/dialer_red"/>
-
- <TextView
- android:id="@+id/location_error_text"
- style="@style/LocationErrorTextStyle"
- android:layout_width="match_parent"
- android:layout_height="24sp"
- android:layout_marginBottom="20dp"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
- android:gravity="center"
- android:text="@string/location_error"/>
-
- </LinearLayout>
-
-</ViewAnimator>
diff --git a/java/com/android/incallui/maps/impl/AndroidManifest.xml b/java/com/android/incallui/maps/impl/AndroidManifest.xml
index bc921e906..4c17f33a4 100644
--- a/java/com/android/incallui/maps/impl/AndroidManifest.xml
+++ b/java/com/android/incallui/maps/impl/AndroidManifest.xml
@@ -19,6 +19,8 @@
package="com.android.incallui.maps.impl">
<application>
+ <!-- Fix for P -->
+ <uses-library android:name="org.apache.http.legacy" android:required="false" />
<meta-data
android:name="com.google.android.gms.version"