Java Examples for android.location.Geocoder

The following java examples will help you to understand the usage of android.location.Geocoder. These source code samples are taken from different open source projects.

Example 1
Project: tuberun_android-master  File: ReverseGeocodeFetcher.java View source code
private void reverseGeocode(Location l) {
    final Geocoder myLocation = new Geocoder(context, Locale.getDefault());
    if (myLocation != null) {
        task = new AsyncTask<Double, Integer, List<Address>>() {

            @Override
            protected List<Address> doInBackground(Double... params) {
                List<Address> result = new ArrayList<Address>();
                try {
                    result = myLocation.getFromLocation(params[0], params[1], 1);
                } catch (Exception e) {
                    Log.w(getClass().toString(), e);
                }
                return result;
            }

            protected void onPostExecute(List<Address> res) {
                result = res;
                notifyClients();
            }
        };
        task.execute(l.getLatitude(), l.getLongitude());
    }
}
Example 2
Project: android-15-master  File: GeocoderTest.java View source code
public void testGeocoder() throws Exception {
    Locale locale = new Locale("en", "us");
    Geocoder g = new Geocoder(mContext, locale);
    List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
    assertNotNull(addresses1);
    assertEquals(1, addresses1.size());
    Address addr = addresses1.get(0);
    assertEquals("94305", addr.getFeatureName());
    assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
    assertEquals("USA", addr.getAddressLine(1));
    assertEquals("94305", addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
    List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
    assertNotNull(addresses2);
    assertEquals(1, addresses2.size());
    addr = addresses2.get(0);
    assertEquals("San Francisco", addr.getFeatureName());
    assertEquals("San Francisco, CA", addr.getAddressLine(0));
    assertEquals("United States", addr.getAddressLine(1));
    assertEquals("San Francisco", addr.getLocality());
    assertEquals("CA", addr.getAdminArea());
    assertEquals(null, addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
}
Example 3
Project: property-db-master  File: GeocoderTest.java View source code
public void testGeocoder() throws Exception {
    Locale locale = new Locale("en", "us");
    Geocoder g = new Geocoder(mContext, locale);
    List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
    assertNotNull(addresses1);
    assertEquals(1, addresses1.size());
    Address addr = addresses1.get(0);
    assertEquals("94305", addr.getFeatureName());
    assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
    assertEquals("USA", addr.getAddressLine(1));
    assertEquals("94305", addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
    List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
    assertNotNull(addresses2);
    assertEquals(1, addresses2.size());
    addr = addresses2.get(0);
    assertEquals("San Francisco", addr.getFeatureName());
    assertEquals("San Francisco, CA", addr.getAddressLine(0));
    assertEquals("United States", addr.getAddressLine(1));
    assertEquals("San Francisco", addr.getLocality());
    assertEquals("CA", addr.getAdminArea());
    assertEquals(null, addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
}
Example 4
Project: TweetTopics2.0-master  File: GetGeolocationAddressLoader.java View source code
@Override
public BaseResponse loadInBackground() {
    try {
        GetGeolocationAddressResponse response = new GetGeolocationAddressResponse();
        response.setSingleResult(request.getSingleResult());
        Geocoder geocoder = new Geocoder(request.getContext());
        List<Address> addresses;
        if (request.getSingleResult())
            addresses = geocoder.getFromLocationName(request.getText(), 1);
        else
            addresses = geocoder.getFromLocationName(request.getText(), 5);
        ArrayList<Address> address_list = new ArrayList<Address>();
        for (Address address : addresses) address_list.add(address);
        response.setAddressList(address_list);
        return response;
    } catch (IOException exception) {
        exception.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(exception, exception.getMessage());
        return errorResponse;
    }
}
Example 5
Project: WS171-frameworks-base-master  File: GeocoderTest.java View source code
public void testGeocoder() throws Exception {
    Locale locale = new Locale("en", "us");
    Geocoder g = new Geocoder(mContext, locale);
    List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
    assertNotNull(addresses1);
    assertEquals(1, addresses1.size());
    Address addr = addresses1.get(0);
    assertEquals("94305", addr.getFeatureName());
    assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
    assertEquals("USA", addr.getAddressLine(1));
    assertEquals("94305", addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
    List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
    assertNotNull(addresses2);
    assertEquals(1, addresses2.size());
    addr = addresses2.get(0);
    assertEquals("San Francisco", addr.getFeatureName());
    assertEquals("San Francisco, CA", addr.getAddressLine(0));
    assertEquals("United States", addr.getAddressLine(1));
    assertEquals("San Francisco", addr.getLocality());
    assertEquals("CA", addr.getAdminArea());
    assertEquals(null, addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
}
Example 6
Project: android-sdk-sources-for-api-level-23-master  File: GeocoderTest.java View source code
public void testGeocoder() throws Exception {
    Locale locale = new Locale("en", "us");
    Geocoder g = new Geocoder(mContext, locale);
    List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
    assertNotNull(addresses1);
    assertEquals(1, addresses1.size());
    Address addr = addresses1.get(0);
    assertEquals("94305", addr.getFeatureName());
    assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
    assertEquals("USA", addr.getAddressLine(1));
    assertEquals("94305", addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
    List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
    assertNotNull(addresses2);
    assertEquals(1, addresses2.size());
    addr = addresses2.get(0);
    assertEquals("San Francisco", addr.getFeatureName());
    assertEquals("San Francisco, CA", addr.getAddressLine(0));
    assertEquals("United States", addr.getAddressLine(1));
    assertEquals("San Francisco", addr.getLocality());
    assertEquals("CA", addr.getAdminArea());
    assertEquals(null, addr.getPostalCode());
    assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
}
Example 7
Project: android_packages_apps-master  File: MenuHelper.java View source code
private static void setLatLngDetails(final View d, Activity context, ExifInterface exif) {
    float[] latlng = new float[2];
    if (exif.getLatLong(latlng)) {
        setDetailsValue(d, String.valueOf(latlng[0]), R.id.details_latitude_value);
        setDetailsValue(d, String.valueOf(latlng[1]), R.id.details_longitude_value);
        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;
        }
        UpdateLocationCallback cb = new UpdateLocationCallback(new WeakReference<View>(d));
        Geocoder geocoder = new Geocoder(context);
        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);
    }
}
Example 8
Project: WordPress-Android-master  File: GeocoderUtils.java View source code
public static Address getAddressFromCoords(Context context, double latitude, double longitude) {
    Address address = null;
    List<Address> addresses = null;
    Geocoder gcd = getGeocoder(context);
    if (gcd == null) {
        return null;
    }
    try {
        addresses = gcd.getFromLocation(latitude, longitude, 1);
    } catch (IOException e) {
        AppLog.e(AppLog.T.UTILS, "Unable to parse response from server. Is Geocoder service hitting the server too frequently?", e);
    }
    // addresses may be null or empty if network isn't connected
    if (addresses != null && addresses.size() > 0) {
        address = addresses.get(0);
    }
    return address;
}
Example 9
Project: FasterGallery-master  File: MenuHelper.java View source code
private static void setLatLngDetails(final View d, Activity context, ExifInterface exif) {
    float[] latlng = new float[2];
    if (exif.getLatLong(latlng)) {
        setDetailsValue(d, String.valueOf(latlng[0]), R.id.details_latitude_value);
        setDetailsValue(d, String.valueOf(latlng[1]), R.id.details_longitude_value);
        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;
        }
        UpdateLocationCallback cb = new UpdateLocationCallback(new WeakReference<View>(d));
        Geocoder geocoder = new Geocoder(context);
        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);
    }
}
Example 10
Project: ARKOST-master  File: Status.java View source code
private void cekGPS(Location loc) {
    TextView tgps = (TextView) findViewById(R.id.lGps);
    TextView tlat = (TextView) findViewById(R.id.lLat);
    TextView tlon = (TextView) findViewById(R.id.lLon);
    TextView ttip = (TextView) findViewById(R.id.lTips);
    TextView tjal = (TextView) findViewById(R.id.lLoc);
    String alamat = "Alamat tidak diketahui";
    // cek posisi
    if (loc != null) {
        double lat = loc.getLatitude();
        double lon = loc.getLongitude();
        tgps.setText("GPS = Aktif \n");
        tlat.setText("Latitude = " + lat + "\n");
        tlon.setText("Longitude = " + lon + "\n");
        Geocoder gc = new Geocoder(Status.this, Locale.getDefault());
        try {
            List<Address> addresses = gc.getFromLocation(lat, lon, 10);
            StringBuilder sb = new StringBuilder();
            if (addresses.size() > 0) {
                Address address = addresses.get(0);
                for (int i = 0; i < address.getMaxAddressLineIndex(); i++) sb.append(address.getAddressLine(i)).append(", ");
                sb.append(address.getLocality()).append("\n");
            } else {
                sb.append("Unknown");
            }
            alamat = sb.toString();
        } catch (IOException e) {
        }
        tjal.setText("Lokasi = " + alamat);
        ttip.setText("Tips : Tekan Menu - Refresh untuk meng-update status Anda");
    } else {
        tgps.setText("GPS = Non Aktif");
        tlat.setText("Latitude = Tidak diketahui");
        tlon.setText("Longitude = Tidak diketahui");
        tjal.setText("Lokasi = Tidak diketahui");
        ttip.setText("Tips : Nyalakan GPS. Tekan Menu - setting");
    }
// end posisi
}
Example 11
Project: MyTracks-master  File: TrackNameUtils.java View source code
/**
   * Gets the reverse geo coding string for a location.
   * 
   * @param context the context
   * @param location the location
   */
private static String getReverseGeoCoding(Context context, Location location) {
    if (location == null || !ApiAdapterFactory.getApiAdapter().isGeoCoderPresent()) {
        return null;
    }
    Geocoder geocoder = new Geocoder(context);
    try {
        List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addresses.size() > 0) {
            Address address = addresses.get(0);
            int lines = address.getMaxAddressLineIndex();
            if (lines > 0) {
                return address.getAddressLine(0);
            }
            String featureName = address.getFeatureName();
            if (featureName != null) {
                return featureName;
            }
            String thoroughfare = address.getThoroughfare();
            if (thoroughfare != null) {
                return thoroughfare;
            }
            String locality = address.getLocality();
            if (locality != null) {
                return locality;
            }
        }
    } catch (IOException e) {
    }
    return null;
}
Example 12
Project: ohmagePhone-master  File: LocTrigMapsActivity.java View source code
@Override
protected Address doInBackground(String... params) {
    //Search the address
    Geocoder geoCoder = new Geocoder(LocTrigMapsActivity.this, Locale.getDefault());
    for (int i = 0; i < GEOCODING_RETRIES; i++) {
        try {
            List<Address> addrs = geoCoder.getFromLocationName(params[0], 5);
            if (addrs.size() > 0) {
                return addrs.get(0);
            }
        } catch (Exception e) {
        }
        try {
            Thread.sleep(GEOCODING_RETRY_INTERVAL);
        } catch (InterruptedException e) {
        }
    }
    return null;
}
Example 13
Project: Locast-Android-master  File: LocationLink.java View source code
@Override
protected String doInBackground(Location... params) {
    final Location location = params[0];
    final Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault());
    try {
        final List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
        if (addresses.size() > 0) {
            final Address thisLocation = addresses.get(0);
            // TODO fixme
            return thisLocation.toString();
        //return AddressUtils.addressToName(thisLocation);
        }
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return null;
}
Example 14
Project: 3380-GAS-App-master  File: StationRequest.java View source code
public static LatLng getGeoCoordsFromAddress(Context c, String address) {
    Geocoder geocoder = new Geocoder(c);
    List<Address> addresses;
    try {
        addresses = geocoder.getFromLocationName(address, 1);
        if (addresses.size() > 0) {
            double latitude = addresses.get(0).getLatitude();
            double longitude = addresses.get(0).getLongitude();
            System.out.println(latitude);
            System.out.println(longitude);
            return new LatLng(latitude, longitude);
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Example 15
Project: ijoomer-adv-sdk-master  File: IjoomerMapAddress.java View source code
/**
	 * L Class method
	 */
/**
	 * This method used to getting address from lat-lng.
	 * 
	 * @param lat
	 *            represented latitude
	 * @param lng
	 *            represented longitude
	 */
private void setAddressData(double lat, double lng) {
    Geocoder geocoder;
    if (lat != 0 && lng != 0) {
        geocoder = new Geocoder(IjoomerMapAddress.this);
        try {
            List<Address> list = geocoder.getFromLocation(lat, lng, 10);
            if (list != null && list.size() > 0) {
                if (txtMapAddressHints.getVisibility() == View.GONE) {
                    pbrLstMapAddress.setVisibility(View.VISIBLE);
                }
                addressList = new ArrayList<HashMap<String, String>>();
                for (Address address : list) {
                    HashMap<String, String> data = new HashMap<String, String>();
                    if (address.getAddressLine(0).toString().trim().length() > 0) {
                        data.put("address", address.getAddressLine(0));
                        data.put("latitude", String.valueOf(address.getLatitude()));
                        data.put("longitude", String.valueOf(address.getLongitude()));
                        addressList.add(data);
                    } else if (address.getAddressLine(1).toString().trim().length() > 0) {
                        data.put("address", address.getAddressLine(1));
                        data.put("latitude", String.valueOf(address.getLatitude()));
                        data.put("longitude", String.valueOf(address.getLongitude()));
                        addressList.add(data);
                    } else if (address.getLocality().toString().trim().length() > 0) {
                        data.put("address", address.getLocality());
                        data.put("latitude", String.valueOf(address.getLatitude()));
                        data.put("longitude", String.valueOf(address.getLongitude()));
                        addressList.add(data);
                    } else if (address.getAdminArea().toString().trim().length() > 0) {
                        data.put("address", address.getAdminArea());
                        data.put("latitude", String.valueOf(address.getLatitude()));
                        data.put("longitude", String.valueOf(address.getLongitude()));
                        addressList.add(data);
                    } else if (address.getCountryName().toString().trim().length() > 0) {
                        data.put("address", address.getAdminArea());
                        data.put("latitude", String.valueOf(address.getLatitude()));
                        data.put("longitude", String.valueOf(address.getLongitude()));
                        addressList.add(data);
                    }
                }
                lstMapAddress.setAdapter(getListAdapter(prepareList(addressList)));
                if (txtMapAddressHints.getVisibility() == View.VISIBLE) {
                    lstMapAddress.setVisibility(View.VISIBLE);
                    txtMapAddressHints.setVisibility(View.GONE);
                } else {
                    pbrLstMapAddress.setVisibility(View.GONE);
                }
            } else {
                IjoomerUtilities.getCustomOkDialog(getString(R.string.address_from_map), getString(R.string.lat_long_not_found), getString(R.string.ok), R.layout.ijoomer_ok_dialog, new CustomAlertNeutral() {

                    @Override
                    public void NeutralMethod() {
                    }
                });
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
Example 16
Project: WiFi-Automatic-master  File: Locations.java View source code
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (requestCode == REQUEST_LOCATION) {
        if (resultCode == RESULT_OK) {
            LatLng location = data.getParcelableExtra("location");
            String locationName = "UNKNOWN";
            if (Geocoder.isPresent()) {
                Geocoder gc = new Geocoder(this);
                try {
                    List<Address> result = gc.getFromLocation(location.latitude, location.longitude, 1);
                    if (result != null && !result.isEmpty()) {
                        Address address = result.get(0);
                        locationName = address.getAddressLine(0);
                        if (address.getLocality() != null) {
                            locationName += ", " + address.getLocality();
                        }
                    }
                } catch (IOException e) {
                    if (BuildConfig.DEBUG)
                        Logger.log(e);
                    e.printStackTrace();
                }
            }
            Database db = Database.getInstance(this);
            db.addLocation(locationName, location);
            db.close();
            locations.add(new Location(locationName, location));
            mAdapter.notifyDataSetChanged();
        }
    } else if (requestCode == REQUEST_BUY) {
        if (resultCode == RESULT_OK) {
            if (data.getIntExtra("RESPONSE_CODE", 0) == 0) {
                try {
                    JSONObject jo = new JSONObject(data.getStringExtra("INAPP_PURCHASE_DATA"));
                    PREMIUM_ENABLED = jo.getString("productId").equals("de.j4velin.wifiautomatic.billing.pro") && jo.getString("developerPayload").equals(getPackageName());
                    getSharedPreferences("settings", Context.MODE_PRIVATE).edit().putBoolean("pro", PREMIUM_ENABLED).commit();
                    if (PREMIUM_ENABLED) {
                        Toast.makeText(this, "Thank you!", Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    if (BuildConfig.DEBUG)
                        Logger.log(e);
                    Toast.makeText(this, e.getClass().getName() + ": " + e.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
Example 17
Project: android_packages_apps_Gallery3D-master  File: ReverseGeocoder.java View source code
@Override
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    Deque<MediaSet> queue = sQueue;
    mGeocoder = new Geocoder(mContext);
    queue.clear();
    try {
        for (; ; ) {
            // Wait for the next request.
            MediaSet set;
            synchronized (queue) {
                while ((set = queue.pollFirst()) == null) {
                    queue.wait();
                }
            }
            // Process the request.
            process(set);
        }
    } catch (InterruptedException e) {
    }
}
Example 18
Project: platform-packages-apps-Gallery3D-master  File: ReverseGeocoder.java View source code
@Override
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    Deque<MediaSet> queue = sQueue;
    mGeocoder = new Geocoder(mContext);
    queue.clear();
    try {
        for (; ; ) {
            // Wait for the next request.
            MediaSet set;
            synchronized (queue) {
                while ((set = queue.pollFirst()) == null) {
                    queue.wait();
                }
            }
            // Process the request.
            process(set);
        }
    } catch (InterruptedException e) {
    }
}
Example 19
Project: PhotoPhase-master  File: PhotoViewerActivity.java View source code
@SuppressWarnings("ConstantConditions")
private void updateDetailsInformation() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.US);
    DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
    DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT);
    DecimalFormat nf1 = new DecimalFormat("0");
    DecimalFormat nf2 = new DecimalFormat("0.#");
    String notAvailable = getString(R.string.photoviewer_details_not_available);
    String title = mPhoto.getName();
    Date datetime = null;
    String location = null;
    String manufacturer = null;
    String model = null;
    double exposure = -1d;
    double aperture = -1d;
    String iso = null;
    int flash = -1;
    int w = -1;
    int h = -1;
    int orientation = -1;
    ExifInterface exif;
    try {
        exif = new ExifInterface(mPhoto.getAbsolutePath());
        // Title
        if (AndroidHelper.isNougatOrGreater()) {
            title = exif.getAttribute(ExifInterface.TAG_IMAGE_DESCRIPTION);
            if (TextUtils.isEmpty(title)) {
                title = exif.getAttribute(ExifInterface.TAG_USER_COMMENT);
                if (TextUtils.isEmpty(title)) {
                    title = mPhoto.getName();
                }
            }
        }
        // Date
        String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
        if (date != null) {
            try {
                datetime = sdf.parse(date);
            } catch (ParseException e) {
            }
        }
        // Location
        if (exif.getLatLong(mLocation)) {
            mHasLocation = true;
            if (Geocoder.isPresent()) {
                Geocoder geocoder = new Geocoder(this, AndroidHelper.getLocale(getResources()));
                List<Address> addresses = geocoder.getFromLocation(mLocation[0], mLocation[1], 1);
                if (!addresses.isEmpty()) {
                    Address address = addresses.get(0);
                    int max = address.getMaxAddressLineIndex();
                    location = "";
                    for (int i = 0; i <= max; i++) {
                        if (i > 0) {
                            location += ", ";
                        }
                        location += address.getAddressLine(i);
                    }
                }
            }
        }
        // Camera
        manufacturer = exif.getAttribute(ExifInterface.TAG_MAKE);
        model = exif.getAttribute(ExifInterface.TAG_MODEL);
        try {
            exposure = Double.parseDouble(exif.getAttribute(ExifInterface.TAG_EXPOSURE_TIME));
            if (exposure > 0) {
                exposure = Math.floor(1 / exposure);
            }
        } catch (NullPointerExceptionNumberFormatException |  ex) {
        }
        try {
            if (AndroidHelper.isNougatOrGreater()) {
                aperture = Double.parseDouble(exif.getAttribute(ExifInterface.TAG_F_NUMBER));
            } else {
                //noinspection deprecation
                aperture = Double.parseDouble(exif.getAttribute(ExifInterface.TAG_F_NUMBER));
            }
        } catch (NullPointerExceptionNumberFormatException |  ex) {
        }
        if (AndroidHelper.isNougatOrGreater()) {
            iso = exif.getAttribute(ExifInterface.TAG_ISO_SPEED_RATINGS);
        } else {
            //noinspection deprecation
            iso = exif.getAttribute(ExifInterface.TAG_ISO_SPEED_RATINGS);
        }
        flash = exif.getAttributeInt(ExifInterface.TAG_FLASH, -1);
        // Resolution
        w = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, -1);
        h = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, -1);
        // Orientation
        if (orientation == ExifInterface.ORIENTATION_NORMAL) {
            orientation = 0;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            orientation = 90;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            orientation = 180;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            orientation = 270;
        }
    } catch (IOException ioEx) {
        Log.w(TAG, "Not exif information for " + mPhoto.getAbsolutePath(), ioEx);
    }
    // Ensure we can have information about the picture size
    if (w <= 0 || h <= 0) {
        Rect r = BitmapUtils.getBitmapDimensions(mPhoto);
        w = r.width();
        h = r.height();
    }
    TextView tv;
    // Date
    tv = (TextView) findViewById(R.id.details_datetime);
    tv.setText(datetime == null ? notAvailable : getString(R.string.photoviewer_details_format, df.format(datetime), tf.format(datetime)));
    // Location
    if (!mHasLocation) {
        findViewById(R.id.details_lat_lon).setVisibility(View.GONE);
        findViewById(R.id.details_map_block).setVisibility(View.GONE);
        tv = (TextView) findViewById(R.id.details_location);
        tv.setText(notAvailable);
    } else {
        tv = (TextView) findViewById(R.id.details_location);
        if (location == null) {
            tv.setVisibility(View.GONE);
        } else {
            tv.setText(location);
        }
        tv = (TextView) findViewById(R.id.details_lat_lon);
        tv.setText(getString(R.string.photoviewer_details_latitude_longitude, mLocation[0], mLocation[1]));
        // Check if map can be open in an external app
        if (hasExternalMapApp(mLocation[0], mLocation[1])) {
            View v = findViewById(R.id.details_location_block);
            v.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    openLocationInExternalApp(mLocation[0], mLocation[1]);
                }
            });
        }
    }
    // Camera
    if (manufacturer == null && model == null) {
        findViewById(R.id.details_camera).setVisibility(View.GONE);
    } else {
        tv = (TextView) findViewById(R.id.details_manufacturer);
        tv.setText(manufacturer == null ? getString(R.string.photoviewer_details_manufacturer, notAvailable) : getString(R.string.photoviewer_details_manufacturer, manufacturer));
        tv = (TextView) findViewById(R.id.details_model);
        tv.setText(model == null ? getString(R.string.photoviewer_details_model, notAvailable) : getString(R.string.photoviewer_details_model, model));
        tv = (TextView) findViewById(R.id.details_exposure);
        tv.setText(exposure == -1 ? getString(R.string.photoviewer_details_exposure, notAvailable) : getString(R.string.photoviewer_details_exposure, nf1.format(exposure)));
        tv = (TextView) findViewById(R.id.details_aperture);
        tv.setText(aperture == -1 ? getString(R.string.photoviewer_details_aperture, notAvailable) : getString(R.string.photoviewer_details_aperture, nf2.format(aperture)));
        tv = (TextView) findViewById(R.id.details_iso);
        tv.setText(iso == null ? getString(R.string.photoviewer_details_iso, notAvailable) : getString(R.string.photoviewer_details_iso, iso));
        tv = (TextView) findViewById(R.id.details_flash);
        tv.setText(flash == -1 ? getString(R.string.photoviewer_details_flash, notAvailable) : getString(R.string.photoviewer_details_flash, ((flash & 0x01) == 0x1) ? getString(R.string.photoviewer_details_flash_used) : getString(R.string.photoviewer_details_flash_not_used)));
    }
    // Info
    tv = (TextView) findViewById(R.id.details_name);
    tv.setText(getString(R.string.photoviewer_details_name, title));
    tv = (TextView) findViewById(R.id.details_size);
    tv.setText(getString(R.string.photoviewer_details_size, mPhoto.length() / 1024));
    tv = (TextView) findViewById(R.id.details_resolution);
    if (w == -1 || h == -1) {
        tv.setVisibility(View.GONE);
    } else {
        tv.setText(getString(R.string.photoviewer_details_resolution, w, h));
    }
    tv = (TextView) findViewById(R.id.details_orientation);
    if (orientation == -1) {
        tv.setVisibility(View.GONE);
    } else {
        tv.setText(getString(R.string.photoviewer_details_orientation, orientation));
    }
    tv = (TextView) findViewById(R.id.details_path);
    tv.setText(getString(R.string.photoviewer_details_path, mPhoto.getParent()));
}
Example 20
Project: BioWiki-master  File: EditPostSettingsFragment.java View source code
@Override
protected String doInBackground(Double... args) {
    // args will be the latitude, longitude to look up
    latitude = args[0];
    longitude = args[1];
    // first make sure a Geocoder service exists on this device (requires API 9)
    if (!Geocoder.isPresent())
        return null;
    Geocoder gcd;
    try {
        gcd = new Geocoder(getActivity(), Locale.getDefault());
    } catch (NullPointerException cannotIstantiateEx) {
        AppLog.e(AppLog.T.EDITOR, "Cannot Istantiate Geocoder", cannotIstantiateEx);
        return null;
    }
    List<Address> addresses;
    try {
        addresses = gcd.getFromLocation(latitude, longitude, 1);
        // addresses may be null or empty if network isn't connected
        if (addresses == null || addresses.size() == 0)
            return null;
        String locality = "", adminArea = "", country = "";
        if (addresses.get(0).getLocality() != null)
            locality = addresses.get(0).getLocality();
        if (addresses.get(0).getAdminArea() != null)
            adminArea = addresses.get(0).getAdminArea();
        if (addresses.get(0).getCountryName() != null)
            country = addresses.get(0).getCountryName();
        return ((locality.equals("")) ? locality : locality + ", ") + ((adminArea.equals("")) ? adminArea : adminArea + " ") + country;
    } catch (IOException e) {
        AppLog.e(AppLog.T.EDITOR, "Unable to parse response from server. Is Geocoder service hitting the server too frequently?", e);
        return null;
    }
}
Example 21
Project: viaja-facil-master  File: ViajaFacilActivity.java View source code
protected List<Address> doInBackground(String... s) {
    lastGeocodedAddr[fromOrTo] = s[0];
    Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
    try {
        Log.d("AddressGeoCoder", "Addr: " + s[0]);
        //List<Address> addresses = geoCoder.getFromLocationName(s[0], 5, -35.321848, -59.295959, -34.04697, -57.77298);
        List<Address> addresses = geoCoder.getFromLocationName(s[0], 5);
        return addresses;
    } catch (IOException e) {
        Log.e("ADdressToPointGeocodertask", "Geocoder failed", e);
        return null;
    }
}