diff options
author | Rohit Yengisetty <rohit@cyngn.com> | 2015-06-16 16:58:55 -0700 |
---|---|---|
committer | Rohit Yengisetty <rohit@cyngn.com> | 2015-07-22 19:30:44 -0700 |
commit | 8911a8b1f2da20fa18e001415f3f9168e2f029b8 (patch) | |
tree | dba183c6a82d348fed010941984b11a30379b0ab | |
parent | 49ff098b926834a59280737c0a912ef54a260419 (diff) | |
download | android_packages_apps_ContactsCommon-8911a8b1f2da20fa18e001415f3f9168e2f029b8.tar.gz android_packages_apps_ContactsCommon-8911a8b1f2da20fa18e001415f3f9168e2f029b8.tar.bz2 android_packages_apps_ContactsCommon-8911a8b1f2da20fa18e001415f3f9168e2f029b8.zip |
Add generic hooks for contact info lookup based on phone number
Change-Id: Ic66c936fb29579724c930232f5cc1ef2ae135313
7 files changed, 188 insertions, 1 deletions
@@ -41,7 +41,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ LOCAL_PACKAGE_NAME := com.android.contacts.common -LOCAL_PROGUARD_ENABLED := disabled +# LOCAL_PROGUARD_ENABLED := disabled LOCAL_PROGUARD_FLAG_FILES := proguard.flags include $(BUILD_PACKAGE) diff --git a/info_lookup/phonenumber_lookup_provider.mk b/info_lookup/phonenumber_lookup_provider.mk new file mode 100644 index 00000000..54fcd1c8 --- /dev/null +++ b/info_lookup/phonenumber_lookup_provider.mk @@ -0,0 +1 @@ +LOCAL_SRC_FILES += $(call all-java-files-under, info_lookup/src/com/cyanogen/lookup/phonenumber)
\ No newline at end of file diff --git a/info_lookup/src/com/cyanogen/lookup/phonenumber/LookupHandlerThread.java b/info_lookup/src/com/cyanogen/lookup/phonenumber/LookupHandlerThread.java new file mode 100644 index 00000000..5f59d481 --- /dev/null +++ b/info_lookup/src/com/cyanogen/lookup/phonenumber/LookupHandlerThread.java @@ -0,0 +1,71 @@ +package com.cyanogen.lookup.phonenumber; + +import android.content.Context; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Message; +import com.cyanogen.lookup.phonenumber.provider.LookupProviderImpl; +import com.cyanogen.lookup.phonenumber.request.LookupRequest; + +import java.util.HashSet; + +public class LookupHandlerThread extends HandlerThread implements Handler.Callback { + + private static final int MSG_FETCH_INFO = 0; + + private Context mContext; + private Handler mHandler; + private LookupProviderImpl mLookupProvider; + private HashSet<LookupRequest> mSubmittedRequests; + + public LookupHandlerThread(String name, Context ctx) { + super(name); + mContext = ctx; + } + + public LookupHandlerThread(String name, int priority, Context ctx) { + super(name, priority); + mContext = ctx; + } + + public boolean initialize() { + mLookupProvider = new LookupProviderImpl(mContext, null); + boolean isSuccessful = mLookupProvider.initialize(); + if (isSuccessful) { + mSubmittedRequests = new HashSet<>(); + mHandler = new Handler(getLooper(), this); + start(); + } else { + mLookupProvider = null; + } + + return isSuccessful; + } + + public boolean fetchInfoForPhoneNumber(LookupRequest lookupRequest) { + if (!mSubmittedRequests.contains(lookupRequest)) { + Message msg = mHandler.obtainMessage(MSG_FETCH_INFO); + msg.obj = lookupRequest; + boolean requested = mHandler.sendMessage(msg); + if (requested) { + mSubmittedRequests.add(lookupRequest); + } + return requested; + } + + return false; + } + + @Override + public boolean handleMessage(Message msg) { + int what = msg.what; + LookupRequest lookupRequest = (LookupRequest) msg.obj; + switch (what) { + case MSG_FETCH_INFO : + if (mLookupProvider != null) { + mLookupProvider.fetchInfo(lookupRequest); + } + } + return true; + } +}
\ No newline at end of file diff --git a/info_lookup/src/com/cyanogen/lookup/phonenumber/contract/LookupProvider.java b/info_lookup/src/com/cyanogen/lookup/phonenumber/contract/LookupProvider.java new file mode 100644 index 00000000..1047b9aa --- /dev/null +++ b/info_lookup/src/com/cyanogen/lookup/phonenumber/contract/LookupProvider.java @@ -0,0 +1,28 @@ +package com.cyanogen.lookup.phonenumber.contract; + +import com.cyanogen.lookup.phonenumber.request.LookupRequest; + +/** + * Notion of a phone number lookup provider + */ +public interface LookupProvider { + + /** + * Explicit call to the provider to initialize itself. Decoupling it from provider construction + * to enable explicit setup and tear down based on resource constraints. + */ + boolean initialize(); + + /** + * Request to lookup contact info asynchronously. The callback is embedded + * within {@link LookupRequest} + */ + void fetchInfo(LookupRequest request); + + /** + * Explicit call to disable provider and free resources + */ + void disable(); + +} + diff --git a/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java b/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java new file mode 100644 index 00000000..b35d8e86 --- /dev/null +++ b/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java @@ -0,0 +1,32 @@ +package com.cyanogen.lookup.phonenumber.provider; + +import android.content.Context; +import android.os.Handler; +import com.cyanogen.lookup.phonenumber.contract.LookupProvider; +import com.cyanogen.lookup.phonenumber.request.LookupRequest; + +/** + * Shell implementation of a phonenumber LookupProvider + */ +public class LookupProviderImpl implements LookupProvider { + + public LookupProviderImpl(Context context, Handler handler) { + /* NOT IMPLEMENTED */ + } + + @Override + public boolean initialize() { + /* NOT a valid implementation */ + return false; + } + + @Override + public void fetchInfo(final LookupRequest request) { + /* NOT IMPLEMENTED */ + } + + @Override + public void disable() { + /* NOT IMPLEMENTED */ + } +} diff --git a/info_lookup/src/com/cyanogen/lookup/phonenumber/request/LookupRequest.java b/info_lookup/src/com/cyanogen/lookup/phonenumber/request/LookupRequest.java new file mode 100644 index 00000000..e160bbb6 --- /dev/null +++ b/info_lookup/src/com/cyanogen/lookup/phonenumber/request/LookupRequest.java @@ -0,0 +1,25 @@ +package com.cyanogen.lookup.phonenumber.request; + +import com.cyanogen.lookup.phonenumber.response.LookupResponse; + +/** + * Encapsulates the notion of a phone number lookup request + */ +public class LookupRequest { + public String mPhoneNumber; + public Callback mCallback; + + public LookupRequest(String phoneNumber, Callback callback) { + mPhoneNumber = phoneNumber; + mCallback = callback; + } + + @Override + public int hashCode() { + return mPhoneNumber.hashCode(); + } + + public interface Callback { + void onNewInfo(LookupRequest lookupRequest, LookupResponse response); + } +} diff --git a/info_lookup/src/com/cyanogen/lookup/phonenumber/response/LookupResponse.java b/info_lookup/src/com/cyanogen/lookup/phonenumber/response/LookupResponse.java new file mode 100644 index 00000000..ce60ffbf --- /dev/null +++ b/info_lookup/src/com/cyanogen/lookup/phonenumber/response/LookupResponse.java @@ -0,0 +1,30 @@ +package com.cyanogen.lookup.phonenumber.response; + +import android.graphics.drawable.Drawable; + +/** + * ADT to store the result of a phone number lookup + */ +public class LookupResponse { + public String mName; + public String mNumber; + public String mCity; + public String mCountry; + public String mAddress; + public String mPhotoUrl; + public int mSpamCount; + + public Drawable mAttributionLogo; + + @Override + public String toString() { + return String.format("{ name = %s, number = %s, city = %s, country = %s, address = %s, photo-url : %s, spam-count = %d}", + mName != null ? mName : "null" , + mNumber != null ? mNumber : "null" , + mCity != null ? mCity : "null" , + mCountry != null ? mCountry : "null" , + mAddress != null ? mAddress : "null" , + mPhotoUrl != null ? mPhotoUrl : "null" , + mSpamCount ); + } +}
\ No newline at end of file |