use of org.awesomeapp.messenger.tasks.AddContactAsyncTask in project Zom-Android by zom.
the class MainActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CHANGE_SETTINGS) {
finish();
startActivity(new Intent(this, MainActivity.class));
} else if (requestCode == REQUEST_ADD_CONTACT) {
String username = data.getStringExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME);
if (username != null) {
long providerId = data.getLongExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, -1);
long accountId = data.getLongExtra(ContactsPickerActivity.EXTRA_RESULT_ACCOUNT, -1);
startChat(providerId, accountId, username, false);
}
} else if (requestCode == REQUEST_CHOOSE_CONTACT) {
String username = data.getStringExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME);
if (username != null) {
long providerId = data.getLongExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, -1);
long accountId = data.getLongExtra(ContactsPickerActivity.EXTRA_RESULT_ACCOUNT, -1);
startChat(providerId, accountId, username, true);
} else {
ArrayList<String> users = data.getStringArrayListExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAMES);
if (users != null) {
// start group and do invite here
startGroupChat(users);
}
}
} else if (requestCode == ConversationDetailActivity.REQUEST_TAKE_PICTURE) {
try {
if (mLastPhoto != null)
importPhoto();
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error importing photo", e);
}
} else if (requestCode == OnboardingManager.REQUEST_SCAN) {
ArrayList<String> resultScans = data.getStringArrayListExtra("result");
for (String resultScan : resultScans) {
try {
String address = null;
if (resultScan.startsWith("xmpp:")) {
address = XmppUriHelper.parse(Uri.parse(resultScan)).get(XmppUriHelper.KEY_ADDRESS);
String fingerprint = XmppUriHelper.getOtrFingerprint(resultScan);
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(address, fingerprint);
} else {
// parse each string and if they are for a new user then add the user
OnboardingManager.DecodedInviteLink diLink = OnboardingManager.decodeInviteLink(resultScan);
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(diLink.username, diLink.fingerprint, diLink.nickname);
}
if (address != null)
startChat(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), address, true);
// if they are for a group chat, then add the group
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error parsing QR invite link", e);
}
}
}
}
}
use of org.awesomeapp.messenger.tasks.AddContactAsyncTask in project Zom-Android by zom.
the class ImUrlActivity method resolveIntent.
private boolean resolveIntent(Intent intent) {
Uri data = intent.getData();
mHost = data.getHost();
if (data.getScheme().equals("https") && mHost.equals("zom.im")) {
try {
// parse each string and if they are for a new user then add the user
OnboardingManager.DecodedInviteLink diLink = OnboardingManager.decodeInviteLink(data.toString());
ImApp app = (ImApp) getApplication();
app.initAccountInfo();
new AddContactAsyncTask(app.getDefaultProviderId(), app.getDefaultAccountId(), (ImApp) getApplication()).executeOnExecutor(ImApp.sThreadPoolExecutor, diLink.username, diLink.fingerprint, diLink.nickname);
Intent resultIntent = new Intent();
resultIntent.putExtra("newcontact", diLink.username);
setResult(RESULT_OK, resultIntent);
// the work is done so we will finish!
return false;
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error parsing QR invite link", e);
}
} else if (data.getScheme().equals("immu")) {
mFromAddress = data.getUserInfo();
// remove username non-letters
mFromAddress = mFromAddress.replaceAll(USERNAME_ONLY_ALPHANUM, "").toLowerCase(Locale.ENGLISH);
String chatRoom = null;
if (data.getPathSegments().size() > 0) {
chatRoom = data.getPathSegments().get(0);
// replace chat room name non-letters with underscores
chatRoom = chatRoom.replaceAll("[\\d[^\\w]]+", "_");
mToAddress = chatRoom + '@' + mHost;
mProviderName = findMatchingProvider(mHost);
return true;
}
return false;
} else if (data.getScheme().equals("otr-in-band")) {
this.openOtrInBand(data, intent.getType());
return true;
} else if (data.getScheme().equals("xmpp")) {
mToAddress = data.getSchemeSpecificPart();
try {
// parse each string and if they are for a new user then add the user
String[] parts = mToAddress.split("\\?subscribe&otr-fingerprint=");
ImApp app = (ImApp) getApplication();
app.initAccountInfo();
String username = parts[0];
String fingerprint = null;
String nickname = null;
if (parts.length > 1)
fingerprint = parts[1];
if (parts.length > 2)
nickname = parts[2];
new AddContactAsyncTask(app.getDefaultProviderId(), app.getDefaultAccountId(), (ImApp) getApplication()).executeOnExecutor(ImApp.sThreadPoolExecutor, username, fingerprint);
Intent resultIntent = new Intent();
resultIntent.putExtra("newcontact", username);
setResult(RESULT_OK, resultIntent);
// the work is done so we will finish!
return false;
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error parsing QR invite link", e);
}
}
if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
log("resolveIntent: host=" + mHost);
}
if (TextUtils.isEmpty(mHost)) {
Set<String> categories = intent.getCategories();
if (categories != null) {
Iterator<String> iter = categories.iterator();
if (iter.hasNext()) {
String category = iter.next();
String providerName = getProviderNameForCategory(category);
mProviderName = findMatchingProvider(providerName);
if (mProviderName == null) {
Log.w(ImApp.LOG_TAG, "resolveIntent: IM provider " + category + " not supported");
return false;
}
}
}
mToAddress = data.getSchemeSpecificPart();
} else {
mProviderName = findMatchingProvider(mHost);
if (mProviderName == null) {
Log.w(ImApp.LOG_TAG, "resolveIntent: IM provider " + mHost + " not supported");
return false;
}
String path = data.getPath();
if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG))
log("resolveIntent: path=" + path);
if (!TextUtils.isEmpty(path)) {
int index;
if ((index = path.indexOf('/')) != -1) {
mToAddress = path.substring(index + 1);
}
}
}
if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
log("resolveIntent: provider=" + mProviderName + ", to=" + mToAddress);
}
return true;
}
use of org.awesomeapp.messenger.tasks.AddContactAsyncTask in project Zom-Android by zom.
the class AddContactActivity method inviteBuddies.
void inviteBuddies() {
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Rfc822Token[] recipients = Rfc822Tokenizer.tokenize(mNewAddress.getText());
boolean foundOne = false;
for (Rfc822Token recipient : recipients) {
String address = recipient.getAddress();
if (pattern.matcher(address).matches()) {
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(address, null, null);
foundOne = true;
}
}
if (foundOne) {
Intent intent = new Intent();
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, recipients[0].getAddress());
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mApp.getDefaultProviderId());
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_ACCOUNT, mApp.getDefaultAccountId());
setResult(RESULT_OK, intent);
finish();
} else {
String inviteAddress = mNewAddress.getText().toString();
String domain = mApp.getDefaultUsername().split("@")[1];
inviteAddress += "@" + domain;
if (pattern.matcher(inviteAddress).matches()) {
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(inviteAddress, null, null);
Intent intent = new Intent();
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, inviteAddress);
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mApp.getDefaultProviderId());
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_ACCOUNT, mApp.getDefaultAccountId());
setResult(RESULT_OK, intent);
finish();
}
}
}
use of org.awesomeapp.messenger.tasks.AddContactAsyncTask in project Zom-Android by zom.
the class ContactListActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == OnboardingManager.REQUEST_SCAN) {
ArrayList<String> resultScans = data.getStringArrayListExtra("result");
for (String resultScan : resultScans) {
try {
// parse each string and if they are for a new user then add the user
OnboardingManager.DecodedInviteLink diLink = OnboardingManager.decodeInviteLink(resultScan);
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(diLink.username, diLink.fingerprint, diLink.nickname);
// if they are for a group chat, then add the group
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error parsing QR invite link", e);
}
}
}
}
}
use of org.awesomeapp.messenger.tasks.AddContactAsyncTask in project Zom-Android by zom.
the class AddContactActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultIntent) {
if (resultCode == RESULT_OK) {
if (requestCode == OnboardingManager.REQUEST_SCAN) {
ArrayList<String> resultScans = resultIntent.getStringArrayListExtra("result");
for (String resultScan : resultScans) {
try {
if (resultScan.startsWith("xmpp:")) {
String address = XmppUriHelper.parse(Uri.parse(resultScan)).get(XmppUriHelper.KEY_ADDRESS);
String fingerprint = XmppUriHelper.getOtrFingerprint(resultScan);
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(address, fingerprint);
Intent intent = new Intent();
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, address);
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mApp.getDefaultProviderId());
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_ACCOUNT, mApp.getDefaultAccountId());
setResult(RESULT_OK, intent);
} else {
// parse each string and if they are for a new user then add the user
OnboardingManager.DecodedInviteLink diLink = OnboardingManager.decodeInviteLink(resultScan);
new AddContactAsyncTask(mApp.getDefaultProviderId(), mApp.getDefaultAccountId(), mApp).execute(diLink.username, diLink.fingerprint, diLink.nickname);
Intent intent = new Intent();
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME, diLink.username);
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, mApp.getDefaultProviderId());
intent.putExtra(ContactsPickerActivity.EXTRA_RESULT_ACCOUNT, mApp.getDefaultAccountId());
setResult(RESULT_OK, intent);
}
// if they are for a group chat, then add the group
} catch (Exception e) {
Log.w(ImApp.LOG_TAG, "error parsing QR invite link", e);
}
}
}
finish();
}
}
Aggregations