# HG changeset patch # User "Vincent Veronis" # Date 1301520552 -7200 # Node ID 31eec457a6e99d07f18187d40cd0a4d2c3365808 # Parent 085240d5be711f4bb38468fcb59df34f8a2a9901 SyncAdapter 'ok' AccountSettings 'ok' diff -r 085240d5be71 -r 31eec457a6e9 AndroidManifest.xml --- a/AndroidManifest.xml Mon Mar 21 00:14:20 2011 +0100 +++ b/AndroidManifest.xml Wed Mar 30 23:29:12 2011 +0200 @@ -1,70 +1,117 @@ - - - - - + + - - + - - - + + + + android:name="com.beem.project.beem.MAIN" /> + - - - + - - + + - - + + + + + + + - - + + - - + - + - - + + - - + + @@ -76,51 +123,80 @@ android:name="android.intent.action.BOOT_COMPLETED" /> --> - - - + - + - - + - + - - + - + - + + + + + - - - - - - - - - - - - - - + + + + + + + + \ No newline at end of file diff -r 085240d5be71 -r 31eec457a6e9 res/xml/authenticator.xml --- a/res/xml/authenticator.xml Mon Mar 21 00:14:20 2011 +0100 +++ b/res/xml/authenticator.xml Wed Mar 30 23:29:12 2011 +0200 @@ -4,6 +4,6 @@ android:accountType="com.beem.project.com" android:icon="@drawable/beem_launcher_icon_silver" android:smallIcon="@drawable/beem_status_icon" - android:label="@string/app_name" /> - + android:label="@string/app_name" + android:accountPreferences="@xml/preferences" /> \ No newline at end of file diff -r 085240d5be71 -r 31eec457a6e9 src/com/beem/project/beem/BeemConnection.java --- a/src/com/beem/project/beem/BeemConnection.java Mon Mar 21 00:14:20 2011 +0100 +++ b/src/com/beem/project/beem/BeemConnection.java Wed Mar 30 23:29:12 2011 +0200 @@ -95,6 +95,10 @@ mSettings.unregisterOnSharedPreferenceChangeListener(mPreferenceListener); } + public void setNoPresence() { + mConnectionConfiguration.setSendPresence(false); + } + /** * @return the login */ diff -r 085240d5be71 -r 31eec457a6e9 src/com/beem/project/beem/account/Authenticator.java --- a/src/com/beem/project/beem/account/Authenticator.java Mon Mar 21 00:14:20 2011 +0100 +++ b/src/com/beem/project/beem/account/Authenticator.java Wed Mar 30 23:29:12 2011 +0200 @@ -1,7 +1,5 @@ package com.beem.project.beem.account; -import com.beem.project.beem.ui.wizard.AccountConfigure; - import android.accounts.AbstractAccountAuthenticator; import android.accounts.Account; import android.accounts.AccountAuthenticatorResponse; @@ -10,6 +8,9 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; + +import com.beem.project.beem.ui.wizard.AccountConfigure; public class Authenticator extends AbstractAccountAuthenticator { @@ -23,6 +24,8 @@ @Override public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { + Log.v("AUTHENTICATOR", "Add account request type " + accountType + " token " + authTokenType + " features " + requiredFeatures + " option " + options); + Intent intent = new Intent(mContext, AccountConfigure.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); Bundle reply = new Bundle(); diff -r 085240d5be71 -r 31eec457a6e9 src/com/beem/project/beem/account/SyncAdapterService.java --- a/src/com/beem/project/beem/account/SyncAdapterService.java Mon Mar 21 00:14:20 2011 +0100 +++ b/src/com/beem/project/beem/account/SyncAdapterService.java Wed Mar 30 23:29:12 2011 +0200 @@ -64,30 +64,32 @@ return mSyncAdapter; } - public static void performSync(Context context, Account account, Bundle extras, String authority, + public static void performSync(Context context, final Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws OperationCanceledException { mContentResolver = context.getContentResolver(); Log.i(TAG, "performSync: " + account.toString()); BeemConnection beemco = new BeemConnection(mContext.getSharedPreferences(account.name, MODE_PRIVATE), null); - String host = StringUtils.parseServer(account.name); - String user = StringUtils.parseName(account.name); - XMPPConnection con = new XMPPConnection(host); + beemco.setNoPresence(); + XMPPConnection con = new XMPPConnection(beemco.getConnectionConfiguration()); try { con.connect(); - con.login(user, beemco.getPassword()); - } catch (XMPPException e) { - Log.d(TAG, "Error during sync connection", e); - } - Roster roster = con.getRoster(); - if (roster != null) { - for (RosterEntry entry : roster.getEntries()) { - if (entry != null) { - addEntry(account, entry); + con.login(beemco.getLogin(), beemco.getPassword(), "BEEM_SYNC_ADAPTER"); + + Roster roster = con.getRoster(); + if (roster != null) { + for (RosterEntry entry : roster.getEntries()) { + if (entry != null) { + addEntry(account, entry); + } } } + } catch (XMPPException e) { + Log.e(TAG, "Error while connecting with syncAdapter", e); } + con.disconnect(); + } private static void addEntry(Account account, RosterEntry entry) { @@ -106,8 +108,7 @@ builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); builder.withValue(StructuredName.DISPLAY_NAME, entry.getUser()); ops.add(builder.build()); - - //Add row contact information + builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Data.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE); @@ -121,7 +122,6 @@ } catch (Exception e) { Log.d(TAG, "Error during add of contact", e); } - } } diff -r 085240d5be71 -r 31eec457a6e9 src/com/beem/project/beem/ui/Chat.java --- a/src/com/beem/project/beem/ui/Chat.java Mon Mar 21 00:14:20 2011 +0100 +++ b/src/com/beem/project/beem/ui/Chat.java Wed Mar 30 23:29:12 2011 +0200 @@ -40,33 +40,35 @@ Flavien Astraud, November 26, 2009 Head of the EIP Laboratory. -*/ + */ package com.beem.project.beem.ui; +import java.io.IOException; +import java.io.InputStream; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.io.InputStream; -import java.io.IOException; import org.jivesoftware.smack.packet.Presence.Mode; import org.jivesoftware.smack.util.StringUtils; import android.app.Activity; import android.app.Dialog; +import android.content.BroadcastReceiver; import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.SharedPreferences; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -91,7 +93,6 @@ import android.widget.ListView; import android.widget.TextView; - import com.beem.project.beem.R; import com.beem.project.beem.providers.AvatarProvider; import com.beem.project.beem.service.Contact; @@ -510,8 +511,8 @@ @Override public void run() { if (msg.getType() == Message.MSG_TYPE_ERROR) { - mListMessages.add(new MessageText(fromBareJid, mContact.getName(), - msg.getBody(), true, msg.getTimestamp())); + mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(), true, msg + .getTimestamp())); mMessagesListAdapter.notifyDataSetChanged(); } else if (msg.getBody() != null) { MessageText lastMessage = null; @@ -523,8 +524,8 @@ lastMessage.setTimestamp(msg.getTimestamp()); mListMessages.set(mListMessages.size() - 1, lastMessage); } else if (msg.getBody() != null) - mListMessages.add(new MessageText(fromBareJid, mContact.getName(), - msg.getBody(), false, msg.getTimestamp())); + mListMessages.add(new MessageText(fromBareJid, mContact.getName(), msg.getBody(), + false, msg.getTimestamp())); mMessagesListAdapter.notifyDataSetChanged(); } } @@ -581,15 +582,13 @@ } else { Mode m = Status.getPresenceModeFromStatus(mContact.getStatus()); if (m == null) - setTitle(getString(R.string.chat_name) + " " + name - + " (" + getString(R.string.contact_status_msg_offline) + ")"); + setTitle(getString(R.string.chat_name) + " " + name + " (" + + getString(R.string.contact_status_msg_offline) + ")"); else setTitle(getString(R.string.chat_name) + " " + name + " (" + m.name() + ")"); } } - - /** * Update the contact status icon. */ @@ -610,7 +609,6 @@ /** * Get a Drawable containing the avatar icon. - * * @param avatarId the avatar id to retrieve or null to get default * @return a Drawable */ @@ -622,7 +620,7 @@ try { try { in = getContentResolver().openInputStream(uri); - avatarDrawable = Drawable.createFromStream(in, avatarId); + avatarDrawable = Drawable.createFromStream(in, avatarId); } finally { if (in != null) in.close(); @@ -705,7 +703,7 @@ View sv; if (convertView == null) { LayoutInflater inflater = Chat.this.getLayoutInflater(); - sv = inflater.inflate(R.layout.chat_msg_row, null); + sv = inflater.inflate(R.layout.chat_msg_row, null); } else { sv = convertView; } @@ -762,8 +760,7 @@ * @param message A String containing the message. * @param isError if the message is an error message. */ - public MessageText(final String bareJid, final String name, final String message, - final boolean isError) { + public MessageText(final String bareJid, final String name, final String message, final boolean isError) { mBareJid = bareJid; mName = name; mMessage = message; @@ -778,8 +775,8 @@ * @param isError if the message is an error message. * @param date the time of the message. */ - public MessageText(final String bareJid, final String name, final String message, - final boolean isError, Date date) { + public MessageText(final String bareJid, final String name, final String message, final boolean isError, + Date date) { mBareJid = bareJid; mName = name; mMessage = message; @@ -949,4 +946,18 @@ } } } + + public class MyReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + Context c = getApplicationContext(); + Intent sendIntent = new Intent(); + if ( intent.getAction().equals(Intent.ACTION_SENDTO) ) { + sendIntent.setClass(c, Chat.class); + context.startActivity(sendIntent); + } + } + } + }