diff options
author | Mike Lockwood <lockwood@android.com> | 2010-01-04 12:14:21 -0500 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-01-05 23:39:29 -0500 |
commit | 34901409a404c8c66914c5a8ad0f29b1bcde0e78 (patch) | |
tree | acb354a4cc41207692e486a84d9541925a15e8e6 /location | |
parent | 3e7b44fade95848a717b0f4d1b7365ce72e885ed (diff) | |
download | frameworks_base-34901409a404c8c66914c5a8ad0f29b1bcde0e78.zip frameworks_base-34901409a404c8c66914c5a8ad0f29b1bcde0e78.tar.gz frameworks_base-34901409a404c8c66914c5a8ad0f29b1bcde0e78.tar.bz2 |
Cleanup and add public wrapper for IGeocodeProvider interface to prepare for network location unbundling.
Change-Id: I6523d115b56dbf450121e73d48e151f200827eb4
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'location')
-rw-r--r-- | location/java/android/location/Geocoder.java | 17 | ||||
-rw-r--r-- | location/java/android/location/GeocoderParams.aidl | 19 | ||||
-rw-r--r-- | location/java/android/location/GeocoderParams.java | 92 | ||||
-rw-r--r-- | location/java/android/location/IGeocodeProvider.aidl | 5 | ||||
-rw-r--r-- | location/java/android/location/ILocationManager.aidl | 5 | ||||
-rw-r--r-- | location/java/android/location/LocationManager.java | 46 |
6 files changed, 166 insertions, 18 deletions
diff --git a/location/java/android/location/Geocoder.java b/location/java/android/location/Geocoder.java index 2ce1273..c325b1b 100644 --- a/location/java/android/location/Geocoder.java +++ b/location/java/android/location/Geocoder.java @@ -45,10 +45,7 @@ import java.util.List; public final class Geocoder { private static final String TAG = "Geocoder"; - private String mLanguage; - private String mCountry; - private String mVariant; - private String mAppName; + private GeocoderParams mParams; private ILocationManager mService; /** @@ -64,11 +61,7 @@ public final class Geocoder { if (locale == null) { throw new NullPointerException("locale == null"); } - mLanguage = locale.getLanguage(); - mCountry = locale.getCountry(); - mVariant = locale.getVariant(); - mAppName = context.getPackageName(); - + mParams = new GeocoderParams(context, locale); IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE); mService = ILocationManager.Stub.asInterface(b); } @@ -119,7 +112,7 @@ public final class Geocoder { try { List<Address> results = new ArrayList<Address>(); String ex = mService.getFromLocation(latitude, longitude, maxResults, - mLanguage, mCountry, mVariant, mAppName, results); + mParams, results); if (ex != null) { throw new IOException(ex); } else { @@ -161,7 +154,7 @@ public final class Geocoder { try { List<Address> results = new ArrayList<Address>(); String ex = mService.getFromLocationName(locationName, - 0, 0, 0, 0, maxResults, mLanguage, mCountry, mVariant, mAppName, results); + 0, 0, 0, 0, maxResults, mParams, results); if (ex != null) { throw new IOException(ex); } else { @@ -234,7 +227,7 @@ public final class Geocoder { ArrayList<Address> result = new ArrayList<Address>(); String ex = mService.getFromLocationName(locationName, lowerLeftLatitude, lowerLeftLongitude, upperRightLatitude, upperRightLongitude, - maxResults, mLanguage, mCountry, mVariant, mAppName, result); + maxResults, mParams, result); if (ex != null) { throw new IOException(ex); } else { diff --git a/location/java/android/location/GeocoderParams.aidl b/location/java/android/location/GeocoderParams.aidl new file mode 100644 index 0000000..2484e20 --- /dev/null +++ b/location/java/android/location/GeocoderParams.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2010, 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 android.location; + +parcelable GeocoderParams; diff --git a/location/java/android/location/GeocoderParams.java b/location/java/android/location/GeocoderParams.java new file mode 100644 index 0000000..8b8e63b --- /dev/null +++ b/location/java/android/location/GeocoderParams.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2010 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 android.location; + +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Locale; + +/** + * This class contains extra parameters to pass to an IGeocodeProvider + * implementation from the Geocoder class. Currently this contains the + * language, country and variant information from the Geocoder's locale + * as well as the Geocoder client's package name for geocoder server + * logging. This information is kept in a separate class to allow for + * future expansion of the IGeocodeProvider interface. + */ +public class GeocoderParams implements Parcelable { + private Locale mLocale; + private String mPackageName; + + // used only for parcelling + private GeocoderParams() { + } + + /** + * This object is only constructed by the Geocoder class + * + * @hide + */ + public GeocoderParams(Context context, Locale locale) { + mLocale = locale; + mPackageName = context.getPackageName(); + } + + /** + * returns the Geocoder's locale + */ + public Locale getLocale() { + return mLocale; + } + + /** + * returns the package name of the Geocoder's client + */ + public String getClientPackage() { + return mPackageName; + } + + public static final Parcelable.Creator<GeocoderParams> CREATOR = + new Parcelable.Creator<GeocoderParams>() { + public GeocoderParams createFromParcel(Parcel in) { + GeocoderParams gp = new GeocoderParams(); + String language = in.readString(); + String country = in.readString(); + String variant = in.readString(); + gp.mLocale = new Locale(language, country, variant); + gp.mPackageName = in.readString(); + return gp; + } + + public GeocoderParams[] newArray(int size) { + return new GeocoderParams[size]; + } + }; + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeString(mLocale.getLanguage()); + parcel.writeString(mLocale.getCountry()); + parcel.writeString(mLocale.getVariant()); + parcel.writeString(mPackageName); + } +} diff --git a/location/java/android/location/IGeocodeProvider.aidl b/location/java/android/location/IGeocodeProvider.aidl index e79e8d2..aaa70c7 100644 --- a/location/java/android/location/IGeocodeProvider.aidl +++ b/location/java/android/location/IGeocodeProvider.aidl @@ -17,6 +17,7 @@ package android.location; import android.location.Address; +import android.location.GeocoderParams; /** * An interface for location providers implementing the Geocoder services. @@ -26,10 +27,10 @@ import android.location.Address; interface IGeocodeProvider { String getFromLocation(double latitude, double longitude, int maxResults, - String language, String country, String variant, String appName, out List<Address> addrs); + in GeocoderParams params, out List<Address> addrs); String getFromLocationName(String locationName, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude, int maxResults, - String language, String country, String variant, String appName, out List<Address> addrs); + in GeocoderParams params, out List<Address> addrs); } diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index b6c59d6..1fac07c 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -18,6 +18,7 @@ package android.location; import android.app.PendingIntent; import android.location.Address; +import android.location.GeocoderParams; import android.location.IGeocodeProvider; import android.location.IGpsStatusListener; import android.location.ILocationListener; @@ -63,11 +64,11 @@ interface ILocationManager void reportLocation(in Location location); String getFromLocation(double latitude, double longitude, int maxResults, - String language, String country, String variant, String appName, out List<Address> addrs); + in GeocoderParams params, out List<Address> addrs); String getFromLocationName(String locationName, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude, int maxResults, - String language, String country, String variant, String appName, out List<Address> addrs); + in GeocoderParams params, out List<Address> addrs); void addTestProvider(String name, boolean requiresNetwork, boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 94ced22..cbe10d9 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -105,6 +105,48 @@ public class LocationManager { */ public static final String KEY_LOCATION_CHANGED = "location"; + public interface GeocodeProvider { + String getFromLocation(double latitude, double longitude, int maxResults, + GeocoderParams params, List<Address> addrs); + + String getFromLocationName(String locationName, + double lowerLeftLatitude, double lowerLeftLongitude, + double upperRightLatitude, double upperRightLongitude, int maxResults, + GeocoderParams params, List<Address> addrs); + } + + private static final class GeocodeProviderProxy extends IGeocodeProvider.Stub { + private GeocodeProvider mProvider; + + GeocodeProviderProxy(GeocodeProvider provider) { + mProvider = provider; + } + + /** + * This method is overridden to implement the + * {@link Geocoder#getFromLocation(double, double, int)} method. + * Classes implementing this method should not hold a reference to the params parameter. + */ + public String getFromLocation(double latitude, double longitude, int maxResults, + GeocoderParams params, List<Address> addrs) { + return mProvider.getFromLocation(latitude, longitude, maxResults, params, addrs); + } + + /** + * This method is overridden to implement the + * {@link Geocoder#getFromLocationName(String, int, double, double, double, double)} method. + * Classes implementing this method should not hold a reference to the params parameter. + */ + public String getFromLocationName(String locationName, + double lowerLeftLatitude, double lowerLeftLongitude, + double upperRightLatitude, double upperRightLongitude, int maxResults, + GeocoderParams params, List<Address> addrs) { + return mProvider.getFromLocationName(locationName, lowerLeftLatitude, + lowerLeftLongitude, upperRightLatitude, upperRightLongitude, + maxResults, params, addrs); + } + } + // Map from LocationListeners to their associated ListenerTransport objects private HashMap<LocationListener,ListenerTransport> mListeners = new HashMap<LocationListener,ListenerTransport>(); @@ -1388,9 +1430,9 @@ public class LocationManager { * * {@hide} */ - public boolean installGeocodeProvider(IGeocodeProvider provider) { + public boolean installGeocodeProvider(GeocodeProvider provider) { try { - mService.installGeocodeProvider(provider); + mService.installGeocodeProvider(new GeocodeProviderProxy(provider)); return true; } catch (RemoteException e) { Log.e(TAG, "RemoteException in setGeocodeProvider: ", e); |