Android Open Source - callerid-for-android Caller I D Application






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   ww w.  ja  va  2 s .  co m
import java.io.File;
import java.lang.reflect.Method;
import java.net.ResponseCache;
import java.net.URL;

import roboguice.util.Ln;
import android.app.Application;
import android.app.Instrumentation;
import android.content.pm.ApplicationInfo;
import android.os.Build;

import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkHttpURLStreamHandlerFactory;

public class CallerIDApplication extends Application {
  
  public CallerIDApplication() {
    super();
  }

  /**
   * This constructor is necessary for instrumentation testing
   * 
   * @param instrumentation
   */
  public CallerIDApplication(Instrumentation instrumentation) {
    super();
    attachBaseContext(instrumentation.getTargetContext());
  }

  @Override
    public void onCreate() {
    if (isDebugMode()) {
          try {
              final Class<?> strictMode = Class.forName("android.os.StrictMode");
              final Method enableDefaults = strictMode.getMethod("enableDefaults");
              enableDefaults.invoke(null);
          } catch (Exception e) {
                //The version of Android we're on doesn't have android.os.StrictMode
                //so ignore this exception
            Ln.d(e, "Strict mode not available");
          }
    }
        
        //enable the http response cache in a thread to avoid a strict mode violation
        new Thread(){
      @Override
      public void run() {
        enableHttpResponseCache();
      }
        }.start();
  }
  
    private void enableHttpResponseCache() {
        final long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
        final File httpCacheDir = new File(getCacheDir(), "http");
      if (Integer.parseInt(Build.VERSION.SDK) >= 18) {
        // com.squareup.okhttp is at least API 18
        // So if we're on that or later, then the bundled Android implementation
          try {
              Class.forName("android.net.http.HttpResponseCache")
                  .getMethod("install", File.class, long.class)
                  .invoke(null, httpCacheDir, httpCacheSize);
          } catch (Exception httpResponseCacheNotAvailable) {
              Ln.d(httpResponseCacheNotAvailable, "android.net.http.HttpResponseCache failed to install. Using okhttp.");
            installHttpHandler(httpCacheSize, httpCacheDir);
          }
      }else{
        // we're running on a version of Android before Jelly Bean, so
        // com.integralblue.httpresponsecache.HttpResponseCache is always superior.
          installHttpHandler(httpCacheSize, httpCacheDir);
      }
    }
    
    private void installHttpHandler(long httpCacheSize, File httpCacheDir ){
        try{
            HttpResponseCache result = new HttpResponseCache(httpCacheDir, httpCacheSize);
            ResponseCache.setDefault(result);
            URL.setURLStreamHandlerFactory(new OkHttpURLStreamHandlerFactory(new OkHttpClient()));
        }catch(Exception e){
          Ln.e(e, "Failed to set up okhttp");
        }
    }

  public boolean isDebugMode() {
    // check if android:debuggable is set to true
    if (getApplicationInfo() == null) {
      // getApplicationInfo() returns null in unit tests
      return true;
    } else {
      int applicationFlags = getApplicationInfo().flags;
      return ((applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
    }
  }
  
    //copied from Android 2.3 PhoneNumberUtils.isUriNumber
    //SIP support is not available before 2.3 so this method doesn't exist
    public static boolean isUriNumber(String number) {
        // Note we allow either "@" or "%40" to indicate a URI, in case
        // the passed-in string is URI-escaped.  (Neither "@" nor "%40"
        // will ever be found in a legal PSTN number.)
        return number != null && (number.contains("@") || number.contains("%40"));
    }
}




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