Android Open Source - callerid-for-android Old Contacts Helper






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.contacts;
/*  w w  w. j  ava  2 s  .  c  o m*/
import android.app.Activity;
import android.app.Application;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.Contacts;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.integralblue.callerid.CallerIDLookup.NoResultException;
import com.integralblue.callerid.CallerIDResult;


@SuppressWarnings("deprecation")
public class OldContactsHelper implements ContactsHelper {
  @Inject Application application;
  @Inject
  Provider<Activity> activityProvider;

  final static String[] HAVE_CONTACT_PROJECTION = new String[] { Contacts.Phones.NUMBER };
  final static String[] GET_CONTACT_PROJECTION = new String[] { Contacts.Phones.NUMBER, Contacts.Phones.DISPLAY_NAME };
    static final int NUMBER_COLUMN_INDEX = 0;
    static final int DISPLAY_NAME_COLUMN_INDEX = 1;

  public boolean haveContactWithPhoneNumber(String phoneNumber) {
    final Uri uri = Uri.withAppendedPath(
        Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(phoneNumber));

    final Cursor cursor = application.getContentResolver().query(uri,HAVE_CONTACT_PROJECTION,null,null,null);
    try{
      return cursor.moveToNext();
    }finally{
      cursor.close();
    }
  }

  public Intent createContactEditor(CallerIDResult result) {
      final Intent intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI);
      intent.putExtra(Contacts.Intents.Insert.NAME, result.getName());
      intent.putExtra(Contacts.Intents.Insert.PHONE, result.getPhoneNumber());
      if(result.getAddress()!=null) intent.putExtra(Contacts.Intents.Insert.POSTAL, result.getAddress());
      return intent;
  }

  public CallerIDResult getContact(String phoneNumber) throws NoResultException {
    final Uri uri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(phoneNumber));
    final ContentResolver contentResolver = application.getContentResolver();
    final Cursor cursor = contentResolver.query(uri,GET_CONTACT_PROJECTION,null,null,null);
    try{
      if(cursor.moveToNext()){
        CallerIDResult ret = new CallerIDResult();
        ret.setPhoneNumber(cursor.getString(NUMBER_COLUMN_INDEX));
        ret.setName(cursor.getString(DISPLAY_NAME_COLUMN_INDEX));
        return ret;
      }else{
        throw new NoResultException();
      }
    }finally{
      cursor.close();
    }
  }
}




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