diff options
author | repo sync <raychen@google.com> | 2009-06-24 14:59:48 +0800 |
---|---|---|
committer | Ray Chen <raychen@google.com> | 2009-07-10 10:55:33 +0800 |
commit | aa7075cc4e2528d5869f737dc684e2a797be8da3 (patch) | |
tree | 6e7cb42e360b5ddd35a9173677dda8fac13ddfc9 /src/com/android/camera/MenuHelper.java | |
parent | d5d74642d7c0b43578b43cdd46b70671b64c88e2 (diff) | |
download | packages_apps_LegacyCamera-aa7075cc4e2528d5869f737dc684e2a797be8da3.zip packages_apps_LegacyCamera-aa7075cc4e2528d5869f737dc684e2a797be8da3.tar.gz packages_apps_LegacyCamera-aa7075cc4e2528d5869f737dc684e2a797be8da3.tar.bz2 |
Move reverse geocoder to AsyncTask and update location information asynchronously.
Diffstat (limited to 'src/com/android/camera/MenuHelper.java')
-rw-r--r-- | src/com/android/camera/MenuHelper.java | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java index 193f0ed..f631b69 100644 --- a/src/com/android/camera/MenuHelper.java +++ b/src/com/android/camera/MenuHelper.java @@ -49,6 +49,7 @@ import android.widget.Toast; import java.io.Closeable; import java.io.IOException; +import java.lang.ref.WeakReference; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -163,52 +164,52 @@ public class MenuHelper { d.findViewById(rowId).setVisibility(View.GONE); } - private static void setLatLngDetails(View d, Activity context, + private static class UpdateLocationCallback implements + ReverseGeocoderTask.Callback { + WeakReference<View> mView; + + public UpdateLocationCallback(WeakReference<View> view) { + mView = view; + } + + public void onComplete(String location) { + // View d is per-thread data, so when setDetailsValue is + // executed by UI thread, it doesn't matter whether the + // details dialog is dismissed or not. + View view = mView.get(); + if (view == null) return; + if (location != MenuHelper.EMPTY_STRING) { + MenuHelper.setDetailsValue(view, location, + R.id.details_location_value); + } else { + MenuHelper.hideDetailsRow(view, R.id.details_location_row); + } + } + } + + private static void setLatLngDetails(final View d, Activity context, HashMap<String, String> exifData) { float[] latlng = ExifInterface.getLatLng(exifData); if (latlng != null) { setDetailsValue(d, String.valueOf(latlng[0]), R.id.details_latitude_value); setDetailsValue(d, String.valueOf(latlng[1]), - R.id.details_longitude_value); - setReverseGeocodingDetails(d, context, latlng[0], latlng[1]); - } else { - hideDetailsRow(d, R.id.details_latitude_row); - hideDetailsRow(d, R.id.details_longitude_row); - hideDetailsRow(d, R.id.details_location_row); - } - } + R.id.details_longitude_value); - private static void setReverseGeocodingDetails(View d, Activity context, - float lat, float lng) { - // Fill in reverse-geocoded address - String value = EMPTY_STRING; - if (lat == INVALID_LATLNG || lng == INVALID_LATLNG) { - hideDetailsRow(d, R.id.details_location_row); - return; - } + if (latlng[0] == INVALID_LATLNG || latlng[1] == INVALID_LATLNG) { + hideDetailsRow(d, R.id.details_latitude_row); + hideDetailsRow(d, R.id.details_longitude_row); + hideDetailsRow(d, R.id.details_location_row); + return; + } - try { + UpdateLocationCallback cb = new UpdateLocationCallback( + new WeakReference<View>(d)); Geocoder geocoder = new Geocoder(context); - List<Address> address = geocoder.getFromLocation(lat, lng, 1); - StringBuilder sb = new StringBuilder(); - for (Address addr : address) { - int index = addr.getMaxAddressLineIndex(); - sb.append(addr.getAddressLine(index)); - } - value = sb.toString(); - } catch (IOException ex) { - // Ignore this exception. - value = EMPTY_STRING; - Log.e(TAG, "Geocoder exception: ", ex); - } catch (RuntimeException ex) { - // Ignore this exception. - value = EMPTY_STRING; - Log.e(TAG, "Geocoder exception: ", ex); - } - if (value != EMPTY_STRING) { - setDetailsValue(d, value, R.id.details_location_value); + new ReverseGeocoderTask(geocoder, latlng, cb).execute(); } else { + hideDetailsRow(d, R.id.details_latitude_row); + hideDetailsRow(d, R.id.details_longitude_row); hideDetailsRow(d, R.id.details_location_row); } } |