aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/utils
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/utils/OnPhoneContactsLoadedListener.java9
-rw-r--r--src/de/gultsch/chat/utils/PhoneHelper.java65
-rw-r--r--src/de/gultsch/chat/utils/UIHelper.java83
3 files changed, 132 insertions, 25 deletions
diff --git a/src/de/gultsch/chat/utils/OnPhoneContactsLoadedListener.java b/src/de/gultsch/chat/utils/OnPhoneContactsLoadedListener.java
new file mode 100644
index 00000000..c4df4ac3
--- /dev/null
+++ b/src/de/gultsch/chat/utils/OnPhoneContactsLoadedListener.java
@@ -0,0 +1,9 @@
+package de.gultsch.chat.utils;
+
+import java.util.Hashtable;
+
+import android.os.Bundle;
+
+public interface OnPhoneContactsLoadedListener {
+ public void onPhoneContactsLoaded(Hashtable<String, Bundle> phoneContacts);
+}
diff --git a/src/de/gultsch/chat/utils/PhoneHelper.java b/src/de/gultsch/chat/utils/PhoneHelper.java
new file mode 100644
index 00000000..f1d491d6
--- /dev/null
+++ b/src/de/gultsch/chat/utils/PhoneHelper.java
@@ -0,0 +1,65 @@
+package de.gultsch.chat.utils;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+import android.content.Context;
+import android.content.CursorLoader;
+import android.content.Loader;
+import android.content.Loader.OnLoadCompleteListener;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.provider.ContactsContract;
+
+public class PhoneHelper {
+
+ public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) {
+ 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);
+ }
+ }
+ });
+ mCursorLoader.startLoading();
+ }
+}
diff --git a/src/de/gultsch/chat/utils/UIHelper.java b/src/de/gultsch/chat/utils/UIHelper.java
index b7ea5289..75c91682 100644
--- a/src/de/gultsch/chat/utils/UIHelper.java
+++ b/src/de/gultsch/chat/utils/UIHelper.java
@@ -1,28 +1,43 @@
package de.gultsch.chat.utils;
+import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Date;
import de.gultsch.chat.R;
+import de.gultsch.chat.entities.Contact;
import de.gultsch.chat.entities.Conversation;
import de.gultsch.chat.ui.ConversationActivity;
+import android.app.Activity;
+import android.app.AlertDialog;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.net.Uri;
import android.preference.PreferenceManager;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.Intents;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.QuickContactBadge;
public class UIHelper {
public static String readableTimeDifference(long time) {
@@ -70,44 +85,62 @@ public class UIHelper {
return bitmap;
}
-
- public static Notification getUnreadMessageNotification(Context context, Conversation conversation) {
-
- SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
- String ringtone = sharedPref.getString("notification_ringtone",null);
-
+
+ public static Notification getUnreadMessageNotification(Context context,
+ Conversation conversation) {
+
+ SharedPreferences sharedPref = PreferenceManager
+ .getDefaultSharedPreferences(context);
+ String ringtone = sharedPref.getString("notification_ringtone", null);
+
Resources res = context.getResources();
- NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
- mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture(conversation.getName(),(int) res.getDimension(android.R.dimen.notification_large_icon_width)));
+ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
+ context);
+ mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture(conversation
+ .getName(), (int) res
+ .getDimension(android.R.dimen.notification_large_icon_width)));
mBuilder.setContentTitle(conversation.getName());
mBuilder.setContentText(conversation.getLatestMessage());
mBuilder.setSmallIcon(R.drawable.notification);
mBuilder.setLights(0xffffffff, 2000, 4000);
- if (ringtone!=null) {
+ if (ringtone != null) {
mBuilder.setSound(Uri.parse(ringtone));
}
-
+
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(ConversationActivity.class);
-
- Intent viewConversationIntent = new Intent(context,ConversationActivity.class);
+
+ Intent viewConversationIntent = new Intent(context,
+ ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
- viewConversationIntent.putExtra(
- ConversationActivity.CONVERSATION,
+ viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
conversation.getUuid());
- viewConversationIntent
- .setType(ConversationActivity.VIEW_CONVERSATION);
-
+ viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
+
stackBuilder.addNextIntent(viewConversationIntent);
-
- PendingIntent resultPendingIntent =
- stackBuilder.getPendingIntent(
- 0,
- PendingIntent.FLAG_UPDATE_CURRENT
- );
-
-
+
+ PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
mBuilder.setContentIntent(resultPendingIntent);
return mBuilder.build();
}
+
+ public static void prepareContactBadge(final Activity activity,
+ QuickContactBadge badge, final Contact contact) {
+ if (contact.getSystemAccount()!=null) {
+ String[] systemAccount = contact.getSystemAccount().split("#");
+ long id = Long.parseLong(systemAccount[0]);
+ badge.assignContactUri(Contacts.getLookupUri(id, systemAccount[1]));
+
+ if (contact.getProfilePhoto() != null) {
+ badge.setImageURI(Uri.parse(contact.getProfilePhoto()));
+ } else {
+ badge.setImageBitmap(UIHelper.getUnknownContactPicture(contact.getDisplayName(), 400));
+ }
+ } else {
+ badge.setImageBitmap(UIHelper.getUnknownContactPicture(contact.getDisplayName(), 400));
+ }
+
+ }
}