# HG changeset patch # User Vincent V. # Date 1325797945 -3600 # Node ID 6a4029cc7882a06d319adf9e970e5f20a81357b4 # Parent 5aece2c91befe464bf6412f50b81157a9c4c3ef0 Multi user chat join + multi user chat provider diff -r 5aece2c91bef -r 6a4029cc7882 AndroidManifest.xml --- a/AndroidManifest.xml Thu Dec 29 22:40:40 2011 +0100 +++ b/AndroidManifest.xml Thu Jan 05 22:12:25 2012 +0100 @@ -146,6 +146,10 @@ android:authorities="com.beem.project.beem.providers.messageprovider" android:label="Message Provider" android:name=".providers.MessageProvider" /> + list = null; + try { + BookmarkManager bm = BookmarkManager.getBookmarkManager(xmppCo); + list = bm.getBookmarkedConferences(); + } catch (XMPPException e) { + Log.e(TAG, "BookmarkManager", e); + } + for (BookmarkedConference bookmarkedConference : list) { + Log.e("TAG + BOOKMARK", bookmarkedConference.getName()); + // Create a MultiUserChat using a Connection for a room + MultiUserChat muc2 = new MultiUserChat(xmppCo, bookmarkedConference.getJid()); + + // User2 joins the new room using a password and specifying + // the amount of history to receive. In this example we are requesting the last 5 messages. + DiscussionHistory history = new DiscussionHistory(); + history.setMaxStanzas(5); + try { + muc2.join(bookmarkedConference.getNickname(), bookmarkedConference.getPassword(), history, SmackConfiguration.getPacketReplyTimeout()); + } catch (XMPPException e) { + Log.e(TAG, "MUC Join Problem", e); + } + } + } + //TODO: ADD MESSAGE || TOAST TO CONFIRM CONNECTION OF THE ACCOUNT sendBroadcast(res); } diff -r 5aece2c91bef -r 6a4029cc7882 src/com/beem/project/beem/providers/MUCs.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/providers/MUCs.java Thu Jan 05 22:12:25 2012 +0100 @@ -0,0 +1,55 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + */ + +package com.beem.project.beem.providers; + +import android.net.Uri; +import android.provider.BaseColumns; + +public class MUCs implements BaseColumns { + + /** + * Constructor. + */ + public MUCs() { + + } + + public static final Uri CONTENT_URI = Uri.parse("content://" + + MessageProvider.AUTHORITY + "/mucs"); + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.com.beem.project.beem.provider.mucs"; + + public static final String _ID = "_id"; + public static final String NAME = "_NAME"; + public static final String JID = "_JID"; + public static final String AUTO_JOIN = "_AUTO_JOIN"; + public static final String SHARED = "_SHARED"; + public static final String NICKNAME = "_NICKNAME"; + public static final String PASSWORD = "_PASSWORD"; +} diff -r 5aece2c91bef -r 6a4029cc7882 src/com/beem/project/beem/providers/MUCsProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/providers/MUCsProvider.java Thu Jan 05 22:12:25 2012 +0100 @@ -0,0 +1,207 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + */ + +package com.beem.project.beem.providers; + +import java.util.HashMap; + +import android.content.ContentProvider; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.database.sqlite.SQLiteQueryBuilder; +import android.net.Uri; +import android.util.Log; + +/** + * Provider to store mucs. + * @author marseille + */ +public class MUCsProvider extends ContentProvider { + + private static final String TAG = "MUCsProvider"; + private static final String DATABASE_NAME = "mucs.db"; + private static final int DATABASE_VERSION = 1; + private static final int MUCS = 1; + private static final String MUCS_TABLE_NAME = "mucs"; + private static final UriMatcher sUriMatcher; + + public static final String AUTHORITY = "com.beem.project.beem.providers.mucprovider"; + + private static HashMap mucsProjectionMap; + private DatabaseHelper mDbHelper; + + /** + * Constructor. + */ + public MUCsProvider() { + } + + @Override + public boolean onCreate() { + mDbHelper = new DatabaseHelper(getContext()); + return true; + + } + + @Override + public Uri insert(Uri uri, ContentValues initialValues) { + if (sUriMatcher.match(uri) != MUCS) { + throw new IllegalArgumentException("Unknown URI " + uri); + } + ContentValues values; + if (initialValues != null) + values = new ContentValues(initialValues); + else + values = new ContentValues(); + SQLiteDatabase db = null; + db = mDbHelper.getWritableDatabase(); + long rowId = db.insert(MUCS_TABLE_NAME, null, values); + if (rowId == -1) + throw new SQLException("Failed to insert row into " + uri); + Uri mucUri = ContentUris.withAppendedId(MUCs.CONTENT_URI, rowId); + getContext().getContentResolver().notifyChange(mucUri, null); + return mucUri; + + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { + SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); + + switch (sUriMatcher.match(uri)) { + case MUCS: + qb.setTables(MUCS_TABLE_NAME); + qb.setProjectionMap(mucsProjectionMap); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + SQLiteDatabase db = mDbHelper.getReadableDatabase(); + Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder); + c.setNotificationUri(getContext().getContentResolver(), uri); + return c; + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + int count; + SQLiteDatabase db = mDbHelper.getWritableDatabase(); + switch (sUriMatcher.match(uri)) { + case MUCS: + count = db.update(MUCS_TABLE_NAME, values, selection, selectionArgs); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + getContext().getContentResolver().notifyChange(uri, null); + return count; + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + int count; + SQLiteDatabase db = mDbHelper.getWritableDatabase(); + switch (sUriMatcher.match(uri)) { + case MUCS: + count = db.delete(MUCS_TABLE_NAME, selection, selectionArgs); + break; + + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + getContext().getContentResolver().notifyChange(uri, null); + return count; + } + + @Override + public String getType(Uri uri) { + switch (sUriMatcher.match(uri)) { + case MUCS: + return Messages.CONTENT_TYPE; + default: + throw new IllegalArgumentException("Unknown URI " + uri); + } + } + + private class DatabaseHelper extends SQLiteOpenHelper { + + DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + String createDatabase = "CREATE TABLE " + MUCS_TABLE_NAME + " ("; + createDatabase += MUCs._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"; + createDatabase += MUCs.NAME + " VARCHAR(255),"; + createDatabase += MUCs.JID + " VARCHAR(255),"; + createDatabase += MUCs.AUTO_JOIN + " BOOLEAN,"; + createDatabase += MUCs.SHARED + " BOOLEAN,"; + createDatabase += MUCs.NICKNAME + " VARCHAR(255),"; + createDatabase += MUCs.PASSWORD + " VARCHAR(255)"; + createDatabase += ");"; + try { + db.execSQL(createDatabase); + } catch (SQLException e) { + Log.e(TAG, "CREATE DB (MUC) PROBLEM", e); + } + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + + ", which will destroy all old data"); + db.execSQL("DROP TABLE IF EXISTS " + MUCS_TABLE_NAME); + onCreate(db); + } + } + + static { + sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + sUriMatcher.addURI(AUTHORITY, MUCS_TABLE_NAME, MUCS); + + mucsProjectionMap = new HashMap(); + mucsProjectionMap.put(MUCs._ID, MUCs._ID); + mucsProjectionMap.put(MUCs.NAME, MUCs.NAME); + mucsProjectionMap.put(MUCs.JID, MUCs.JID); + mucsProjectionMap.put(MUCs.AUTO_JOIN, MUCs.AUTO_JOIN); + mucsProjectionMap.put(MUCs.SHARED, MUCs.SHARED); + mucsProjectionMap.put(MUCs.NICKNAME, MUCs.NICKNAME); + mucsProjectionMap.put(MUCs.PASSWORD, MUCs.PASSWORD); + } + +}