Android Open Source - callerid-for-android Geocoder Helper Provider






From Project

Back to project page callerid-for-android.

License

The source code is released under:

GNU General Public License

If you think the Android project callerid-for-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.integralblue.callerid.inject;
//from   w  ww . j av  a2  s.  c  o m
import java.lang.reflect.Method;

import roboguice.util.Ln;
import android.app.Application;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.integralblue.callerid.geocoder.AndroidGeocoder;
import com.integralblue.callerid.geocoder.Geocoder;
import com.integralblue.callerid.geocoder.NominatimGeocoder;

public class GeocoderHelperProvider implements Provider<Geocoder> {
  @Inject
  Application application;

  @Inject
  Injector injector;
  
  @Inject
  NominatimGeocoder nominatimGeocoder;
  
  public Geocoder get() {
    //Only use the built in (aka Android) geocoder if it is present
    //Otherwise, use the Nominatim geocoder (from OpenStreetMaps)
    
    //the GeoCoder.isPresent() method exists only starting with API 9,
    //so use reflection to check it
    Class<android.location.Geocoder> geocoderClass = android.location.Geocoder.class;
    try {
      Method method = geocoderClass.getMethod("isPresent");
      Boolean isPresent = (Boolean) method.invoke(null, (Object[])null);
      if(isPresent){
        AndroidGeocoder ret = new AndroidGeocoder(application);
        injector.injectMembers(ret);
        return ret;
      }
    } catch (Exception e) {
      Ln.d(e, "falling back to Nominatim geocoder");
      //ignore the exception - we'll just fall back to our geocoder
    }
    return nominatimGeocoder;
  }

}




Java Source Code List

com.blundell.tut.LoaderImageView.java
com.integralblue.callerid.CallerIDApplication.java
com.integralblue.callerid.CallerIDBroadcastReceiver.java
com.integralblue.callerid.CallerIDLookup.java
com.integralblue.callerid.CallerIDResult.java
com.integralblue.callerid.CallerIDService.java
com.integralblue.callerid.GeocoderAsyncTask.java
com.integralblue.callerid.HttpCallerIDLookup.java
com.integralblue.callerid.LookupAsyncTask.java
com.integralblue.callerid.LookupFragment.java
com.integralblue.callerid.MainActivity.java
com.integralblue.callerid.PreferencesActivity.java
com.integralblue.callerid.RecentCallsFragment.java
com.integralblue.callerid.SpecialPhoneNumbers.java
com.integralblue.callerid.TabsAdapter.java
com.integralblue.callerid.contacts.ContactsHelper.java
com.integralblue.callerid.contacts.NewContactsHelper.java
com.integralblue.callerid.contacts.OldContactsHelper.java
com.integralblue.callerid.geocoder.AndroidGeocoder.java
com.integralblue.callerid.geocoder.Geocoder.java
com.integralblue.callerid.geocoder.NominatimGeocoder.java
com.integralblue.callerid.inject.CallerIDModule.java
com.integralblue.callerid.inject.ContactsHelperProvider.java
com.integralblue.callerid.inject.CountryDetector.java
com.integralblue.callerid.inject.GeocoderHelperProvider.java
com.integralblue.callerid.inject.PreferencesNameProvider.java
com.integralblue.callerid.inject.RestTemplateProvider.java
com.integralblue.callerid.inject.TextToSpeechHelper.java
com.integralblue.callerid.inject.VersionInformationHelper.java
com.integralblue.callerid.widget.DontPressWithParentImageView.java
com.squareup.okhttp.OkHttpURLStreamHandlerFactory.java
com.squareup.okhttp.internal.OkHttpClientHandler.java