aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/utils/PhoneHelper.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-28 18:46:01 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-28 18:46:01 +0100
commitacf80bddd07d5579cdb20a888b3f9e99e53030a5 (patch)
tree034a8e364488c89c8e1997f56313d919019afa65 /src/eu/siacs/conversations/utils/PhoneHelper.java
parent03d96266f8bbb76e25610e903d74a0afa7dcd03b (diff)
rebranding
Diffstat (limited to 'src/eu/siacs/conversations/utils/PhoneHelper.java')
-rw-r--r--src/eu/siacs/conversations/utils/PhoneHelper.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/eu/siacs/conversations/utils/PhoneHelper.java b/src/eu/siacs/conversations/utils/PhoneHelper.java
new file mode 100644
index 00000000..e28f817e
--- /dev/null
+++ b/src/eu/siacs/conversations/utils/PhoneHelper.java
@@ -0,0 +1,87 @@
+package eu.siacs.conversations.utils;
+
+import java.util.Hashtable;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.CursorLoader;
+import android.content.Loader;
+import android.content.Loader.OnLoadCompleteListener;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Looper;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.Profile;
+
+public class PhoneHelper {
+
+ public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
+ if (Looper.myLooper()==null) {
+ Looper.prepare();
+ }
+ final Looper mLooper = Looper.myLooper();
+ final Hashtable<String, Bundle> phoneContacts = new Hashtable<String, Bundle>();
+
+ final String[] PROJECTION = new String[] {
+ ContactsContract.Data._ID,
+ ContactsContract.Data.DISPLAY_NAME,
+ ContactsContract.Data.PHOTO_THUMBNAIL_URI,
+ ContactsContract.Data.LOOKUP_KEY,
+ ContactsContract.CommonDataKinds.Im.DATA };
+
+ final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\""
+ + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
+ + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
+ + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
+ + "\")";
+
+ CursorLoader mCursorLoader = new CursorLoader(context,
+ ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
+ null);
+ mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
+
+ @Override
+ public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
+ while (cursor.moveToNext()) {
+ Bundle contact = new Bundle();
+ contact.putInt("phoneid", cursor.getInt(cursor
+ .getColumnIndex(ContactsContract.Data._ID)));
+ contact.putString(
+ "displayname",
+ cursor.getString(cursor
+ .getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
+ contact.putString(
+ "photouri",
+ cursor.getString(cursor
+ .getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI)));
+ contact.putString("lookup",cursor.getString(cursor
+ .getColumnIndex(ContactsContract.Data.LOOKUP_KEY)));
+ phoneContacts.put(
+ cursor.getString(cursor
+ .getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
+ contact);
+ }
+ if (listener!=null) {
+ listener.onPhoneContactsLoaded(phoneContacts);
+ }
+ mLooper.quit();
+ }
+ });
+ mCursorLoader.startLoading();
+ }
+
+ public static Uri getSefliUri(Activity activity) {
+ String[] mProjection = new String[] { Profile._ID,
+ Profile.PHOTO_THUMBNAIL_URI };
+ Cursor mProfileCursor = activity.getContentResolver().query(
+ Profile.CONTENT_URI, mProjection, null, null, null);
+
+ if (mProfileCursor.getCount()==0) {
+ return null;
+ } else {
+ mProfileCursor.moveToFirst();
+ return Uri.parse(mProfileCursor.getString(1));
+ }
+ }
+}