1 /* 2 * Copyright (C) 2020 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.car.apps.common; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.res.Resources; 22 import android.net.Uri; 23 24 /** 25 * Helper methods for addresses and navigation. 26 */ 27 public class NavigationUtils { 28 29 /** 30 * Returns the search location intent. 31 * 32 * @param address should be a location as either a place name or address. 33 */ getViewAddressIntent(Resources res, String address)34 public static Intent getViewAddressIntent(Resources res, String address) { 35 String formattedAddress = String.format(res.getString(R.string.config_address_uri_format), 36 Uri.encode(address)); 37 Uri addressUri = Uri.parse(formattedAddress); 38 return new Intent(Intent.ACTION_VIEW, addressUri); 39 } 40 41 /** 42 * Returns the search location intent. 43 * 44 * @param address should be a location as either a place name or address. 45 */ getViewAddressIntent(Context context, String address)46 public static Intent getViewAddressIntent(Context context, String address) { 47 Resources resources = context.getResources(); 48 return getViewAddressIntent(resources, address); 49 } 50 51 /** 52 * Returns the navigation intent. 53 * 54 * @param address should be a location as either a place name or address. 55 */ getNavigationIntent(Resources res, String address)56 public static Intent getNavigationIntent(Resources res, String address) { 57 String formattedAddress = String.format( 58 res.getString(R.string.config_navigation_uri_format), Uri.encode(address)); 59 Uri addressUri = Uri.parse(formattedAddress); 60 return new Intent(Intent.ACTION_VIEW, addressUri); 61 } 62 63 /** 64 * Returns the navigation Intent. 65 * 66 * @param address should be a location as either a place name or address. 67 */ getNavigationIntent(Context context, String address)68 public static Intent getNavigationIntent(Context context, String address) { 69 Resources resources = context.getResources(); 70 return getNavigationIntent(resources, address); 71 } 72 } 73