1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.incallui.maps.impl; 18 19 import android.location.Location; 20 import android.os.Bundle; 21 import android.support.annotation.NonNull; 22 import android.support.annotation.Nullable; 23 import android.support.v4.app.Fragment; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 import com.android.dialer.common.Assert; 28 import com.android.dialer.common.LogUtil; 29 import com.google.android.gms.maps.CameraUpdateFactory; 30 import com.google.android.gms.maps.GoogleMap; 31 import com.google.android.gms.maps.OnMapReadyCallback; 32 import com.google.android.gms.maps.SupportMapFragment; 33 import com.google.android.gms.maps.model.LatLng; 34 import com.google.android.gms.maps.model.MarkerOptions; 35 36 /** Shows a static map centered on a specified location */ 37 public class StaticMapFragment extends Fragment implements OnMapReadyCallback { 38 39 private static final String ARG_LOCATION = "location"; 40 newInstance(@onNull Location location)41 public static StaticMapFragment newInstance(@NonNull Location location) { 42 Bundle args = new Bundle(); 43 args.putParcelable(ARG_LOCATION, Assert.isNotNull(location)); 44 StaticMapFragment fragment = new StaticMapFragment(); 45 fragment.setArguments(args); 46 return fragment; 47 } 48 49 @Nullable 50 @Override onCreateView( LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle)51 public View onCreateView( 52 LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { 53 return layoutInflater.inflate(R.layout.static_map_fragment, viewGroup, false); 54 } 55 56 @Override onViewCreated(View view, @Nullable Bundle bundle)57 public void onViewCreated(View view, @Nullable Bundle bundle) { 58 super.onViewCreated(view, bundle); 59 SupportMapFragment mapFragment = 60 (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.static_map); 61 if (mapFragment != null) { 62 mapFragment.getMapAsync(this); 63 } else { 64 LogUtil.w("StaticMapFragment.onViewCreated", "No map fragment found!"); 65 } 66 } 67 68 @Override onMapReady(GoogleMap googleMap)69 public void onMapReady(GoogleMap googleMap) { 70 Location location = getArguments().getParcelable(ARG_LOCATION); 71 LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); 72 googleMap.addMarker(new MarkerOptions().position(latLng).flat(true).draggable(false)); 73 googleMap.getUiSettings().setMapToolbarEnabled(false); 74 googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15f)); 75 } 76 } 77