use of org.awesomeapp.messenger.service.IImConnection in project Zom-Android by zom.
the class MainActivity method checkConnection.
private boolean checkConnection() {
try {
if (mSbStatus != null)
mSbStatus.dismiss();
if (!isNetworkAvailable()) {
mSbStatus = Snackbar.make(mViewPager, "No Internet", Snackbar.LENGTH_INDEFINITE);
mSbStatus.show();
return false;
}
if (mApp.getDefaultProviderId() != -1) {
IImConnection conn = mApp.getConnection(mApp.getDefaultProviderId(), mApp.getDefaultAccountId());
if (conn.getState() == ImConnection.DISCONNECTED || conn.getState() == ImConnection.SUSPENDED || conn.getState() == ImConnection.SUSPENDING) {
mSbStatus = Snackbar.make(mViewPager, R.string.error_suspended_connection, Snackbar.LENGTH_INDEFINITE);
mSbStatus.setAction(getString(R.string.connect), new View.OnClickListener() {
@Override
public void onClick(View view) {
mSbStatus.dismiss();
Intent i = new Intent(MainActivity.this, AccountsActivity.class);
startActivity(i);
}
});
mSbStatus.show();
return false;
} else if (conn.getState() == ImConnection.LOGGED_IN) {
// do nothing
} else if (conn.getState() == ImConnection.LOGGING_IN) {
mSbStatus = Snackbar.make(mViewPager, R.string.signing_in_wait, Snackbar.LENGTH_INDEFINITE);
mSbStatus.show();
} else if (conn.getState() == ImConnection.LOGGING_OUT) {
mSbStatus = Snackbar.make(mViewPager, R.string.signing_out_wait, Snackbar.LENGTH_INDEFINITE);
mSbStatus.show();
}
}
return true;
} catch (Exception e) {
return false;
}
}
use of org.awesomeapp.messenger.service.IImConnection in project Zom-Android by zom.
the class MainActivity method startGroupChat.
private void startGroupChat(ArrayList<String> invitees) {
String chatRoom = "groupchat" + UUID.randomUUID().toString().substring(0, 8);
// use the default
String chatServer = "";
String nickname = mApp.getDefaultUsername().split("@")[0];
try {
IImConnection conn = mApp.getConnection(mApp.getDefaultProviderId(), mApp.getDefaultAccountId());
if (conn.getState() == ImConnection.LOGGED_IN) {
this.startGroupChat(chatRoom, chatServer, nickname, invitees, conn);
}
} catch (RemoteException re) {
}
}
use of org.awesomeapp.messenger.service.IImConnection in project Zom-Android by zom.
the class ImUrlActivity method sendOtrInBand.
private void sendOtrInBand(String username, long providerId, long accountId) {
try {
IImConnection conn = ((ImApp) getApplication()).getConnection(providerId, accountId);
if (conn == null)
// can't send without a connection
return;
mChatSessionManager = conn.getChatSessionManager();
IChatSession session = getChatSession(username);
if (mSendText != null)
session.sendMessage(mSendText, false);
else if (mSendUri != null) {
try {
String offerId = UUID.randomUUID().toString();
// Log.i(TAG, "mSendUrl " +mSendUrl);
Uri vfsUri = null;
if (SecureMediaStore.isVfsUri(mSendUri)) {
vfsUri = mSendUri;
boolean sent = session.offerData(offerId, vfsUri.toString(), mSendType);
if (sent)
return;
} else {
InputStream is = getContentResolver().openInputStream(mSendUri);
String fileName = mSendUri.getLastPathSegment();
FileInfo importInfo = SystemServices.getFileInfoFromURI(this, mSendUri);
if (!TextUtils.isEmpty(importInfo.type)) {
if (importInfo.type.startsWith("image"))
vfsUri = SecureMediaStore.resizeAndImportImage(this, session.getId() + "", mSendUri, importInfo.type);
else
vfsUri = SecureMediaStore.importContent(session.getId() + "", fileName, is);
boolean sent = session.offerData(offerId, vfsUri.toString(), importInfo.type);
if (sent)
return;
}
}
} catch (Exception e) {
Log.e(TAG, "error sending external file", e);
}
Toast.makeText(this, R.string.unable_to_securely_share_this_file, Toast.LENGTH_LONG).show();
}
} catch (RemoteException e) {
Log.e(TAG, "Error sending data", e);
}
}
use of org.awesomeapp.messenger.service.IImConnection in project Zom-Android by zom.
the class ImUrlActivity method handleIntent.
void handleIntent() {
ContentResolver cr = getContentResolver();
long providerId = -1;
long accountId = -1;
Collection<IImConnection> listConns = ((ImApp) getApplication()).getActiveConnections();
if (TextUtils.isEmpty(mHost)) {
mConn = listConns.iterator().next();
} else {
// look for active connections that match the host we need
for (IImConnection conn : listConns) {
try {
long connProviderId = conn.getProviderId();
Cursor cursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(connProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(cursor, cr, connProviderId, false, /* don't keep updated */
null);
try {
String domainToCheck = settings.getDomain();
if (domainToCheck != null && domainToCheck.length() > 0 && mHost.contains(domainToCheck)) {
mConn = conn;
providerId = connProviderId;
accountId = conn.getAccountId();
break;
}
} finally {
settings.close();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
// nothing active, let's see if non-active connections match
if (mConn == null) {
Cursor cursorProvider = initProviderCursor();
if (cursorProvider == null || cursorProvider.isClosed() || cursorProvider.getCount() == 0) {
createNewAccount();
return;
} else {
while (cursorProvider.moveToNext()) {
// make sure there is a stored password
if (!cursorProvider.isNull(ACTIVE_ACCOUNT_PW_COLUMN)) {
long cProviderId = cursorProvider.getLong(PROVIDER_ID_COLUMN);
Cursor cursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(cProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(cursor, cr, cProviderId, false, /* don't keep updated */
null);
// does the conference host we need, match the settings domain for a logged in account
String domainToCheck = settings.getDomain();
if (domainToCheck != null && domainToCheck.length() > 0 && mHost.contains(domainToCheck)) {
providerId = cProviderId;
accountId = cursorProvider.getLong(ACTIVE_ACCOUNT_ID_COLUMN);
mConn = ((ImApp) getApplication()).getConnection(providerId, accountId);
// now sign in
signInAccount(accountId, providerId, cursorProvider.getString(ACTIVE_ACCOUNT_PW_COLUMN));
settings.close();
cursorProvider.close();
return;
}
settings.close();
}
}
cursorProvider.close();
}
}
if (mConn != null) {
try {
int state = mConn.getState();
accountId = mConn.getAccountId();
providerId = mConn.getProviderId();
if (state < ImConnection.LOGGED_IN) {
Cursor cursorProvider = initProviderCursor();
while (cursorProvider.moveToNext()) {
if (cursorProvider.getLong(ACTIVE_ACCOUNT_ID_COLUMN) == accountId) {
signInAccount(accountId, providerId, cursorProvider.getString(ACTIVE_ACCOUNT_PW_COLUMN));
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
// wait here for three seconds
mConn = ((ImApp) getApplication()).getConnection(providerId, accountId);
break;
}
}
cursorProvider.close();
}
if (state == ImConnection.LOGGED_IN || state == ImConnection.SUSPENDED) {
Uri data = getIntent().getData();
if (data.getScheme().equals("immu")) {
Toast.makeText(this, "immu: URI handling not yet implemented!", Toast.LENGTH_LONG).show();
} else if (!isValidToAddress()) {
showContactList(accountId);
} else {
openChat(providerId, accountId);
}
}
} catch (RemoteException e) {
// Ouch! Service died! We'll just disappear.
Log.w("ImUrlActivity", "Connection disappeared!");
finish();
}
} else {
createNewAccount();
return;
}
}
use of org.awesomeapp.messenger.service.IImConnection in project Zom-Android by zom.
the class AccountFragment method signOut.
void signOut(long providerId, long accountId) {
try {
IImConnection conn = mApp.getConnection(mProviderId, mAccountId);
if (conn != null) {
conn.logout();
} else {
// Normally, we can always get the connection when user chose to
// sign out. However, if the application crash unexpectedly, the
// status will never be updated. Clear the status in this case
// to make it recoverable from the crash.
ContentValues values = new ContentValues(2);
values.put(Imps.AccountStatusColumns.PRESENCE_STATUS, Imps.CommonPresenceColumns.OFFLINE);
values.put(Imps.AccountStatusColumns.CONNECTION_STATUS, Imps.ConnectionStatus.OFFLINE);
String where = Imps.AccountStatusColumns.ACCOUNT + "=?";
getActivity().getContentResolver().update(Imps.AccountStatus.CONTENT_URI, values, where, new String[] { Long.toString(accountId) });
}
} catch (RemoteException ex) {
Log.e(ImApp.LOG_TAG, "signout: caught ", ex);
} finally {
}
}
Aggregations