Add isGeoCoderPresent in the ApiAdapter.java.

This commit is contained in:
Jimmy Shih
2012-06-19 15:43:12 -07:00
parent 5d2144f698
commit 76ed9a92b1
4 changed files with 22 additions and 4 deletions
@@ -85,7 +85,12 @@ public class Api7Adapter implements ApiAdapter {
public HttpTransport getHttpTransport() { public HttpTransport getHttpTransport() {
return new ApacheHttpTransport(); return new ApacheHttpTransport();
} }
@Override
public boolean isGeoCoderPresent() {
return true;
}
@Override @Override
public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException { public BluetoothSocket getBluetoothSocket(BluetoothDevice bluetoothDevice) throws IOException {
try { try {
@@ -21,6 +21,7 @@ import com.google.api.client.http.javanet.NetHttpTransport;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.location.Geocoder;
import android.os.StrictMode; import android.os.StrictMode;
import android.util.Log; import android.util.Log;
@@ -53,14 +54,19 @@ public class Api9Adapter extends Api8Adapter {
.penaltyLog() .penaltyLog()
.build()); .build());
} }
@Override @Override
public byte[] copyByteArray(byte[] input, int start, int end) { public byte[] copyByteArray(byte[] input, int start, int end) {
return Arrays.copyOfRange(input, start, end); return Arrays.copyOfRange(input, start, end);
} }
@Override @Override
public HttpTransport getHttpTransport() { public HttpTransport getHttpTransport() {
return new NetHttpTransport(); return new NetHttpTransport();
} }
@Override
public boolean isGeoCoderPresent() {
return Geocoder.isPresent();
}
} }
@@ -96,6 +96,13 @@ public interface ApiAdapter {
*/ */
public HttpTransport getHttpTransport(); public HttpTransport getHttpTransport();
/**
* Returns true if GeoCoder is present.
* <p>
* Due to changes in API level 9.
*/
public boolean isGeoCoderPresent();
/** /**
* Gets a {@link BluetoothSocket}. * Gets a {@link BluetoothSocket}.
* <p> * <p>
@@ -95,7 +95,7 @@ public class TrackNameUtils {
* @param location the location * @param location the location
*/ */
private static String getReverseGeoCoding(Context context, Location location) { private static String getReverseGeoCoding(Context context, Location location) {
if (location == null || !Geocoder.isPresent()) { if (location == null || !ApiAdapterFactory.getApiAdapter().isGeoCoderPresent()) {
return null; return null;
} }
Geocoder geocoder = new Geocoder(context); Geocoder geocoder = new Geocoder(context);