Android Open Source - callerid-for-android Http Caller I D Lookup






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;
//from w w  w .j  a  v a2  s  .  c o m
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import roboguice.inject.InjectResource;
import android.content.SharedPreferences;

import com.google.inject.Inject;
import com.integralblue.callerid.inject.CountryDetector;

public class HttpCallerIDLookup implements CallerIDLookup {
  @Inject SharedPreferences sharedPreferences;
  @InjectResource(R.string.default_lookup_url) String defaultLookupUrl;
  @Inject RestTemplate restTemplate;
  
  @Inject CountryDetector countryDetector;

  public CallerIDResult lookup(final CharSequence phoneNumber) throws NoResultException {
    
    final String beforeSubstitutionLookupUrl = sharedPreferences.getString("lookup_url", defaultLookupUrl);
    final String url;
    if(beforeSubstitutionLookupUrl.contains("{0}")){
      // ensure backwards compatibility. The URL used to use {0} and {1}
      url = MessageFormat.format(beforeSubstitutionLookupUrl, "{number}", "{agentCountry}");
    }else{
      url = beforeSubstitutionLookupUrl;
    }
    final Map<String, String> urlVariables = new HashMap<String, String>();
    urlVariables.put("number", phoneNumber.toString());
    urlVariables.put("agentCountry", countryDetector.getCountry());
    try{
      return restTemplate.getForObject(url, CallerIDResult.class, urlVariables);
    }catch(HttpClientErrorException e){
      if(HttpStatus.NOT_FOUND.equals(e.getStatusCode())){
        throw new NoResultException();
      }else{
        throw new RuntimeException(e);
      }
    }catch(Exception e){
      throw new RuntimeException(e);
    }
  }

}




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