use of org.awesomeapp.messenger.ui.legacy.ImPluginHelper in project Zom-Android by zom.
the class AccountActivity method onCreate.
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent i = getIntent();
mApp = (ImApp) getApplication();
String action = i.getAction();
if (i.hasExtra("isSignedIn"))
isSignedIn = i.getBooleanExtra("isSignedIn", false);
final ProviderDef provider;
mSignInHelper = new SignInHelper(this, null);
SignInHelper.SignInListener signInListener = new SignInHelper.SignInListener() {
@Override
public void connectedToService() {
}
@Override
public void stateChanged(int state, long accountId) {
if (state == ImConnection.LOGGED_IN) {
// mSignInHelper.goToAccount(accountId);
// finish();
isSignedIn = true;
} else {
isSignedIn = false;
}
}
};
mSignInHelper.setSignInListener(signInListener);
ContentResolver cr = getContentResolver();
Uri uri = i.getData();
// check if there is account information and direct accordingly
if (Intent.ACTION_INSERT_OR_EDIT.equals(action)) {
if ((uri == null) || !Imps.Account.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) {
action = Intent.ACTION_INSERT;
} else {
action = Intent.ACTION_EDIT;
}
}
if (Intent.ACTION_INSERT.equals(action) && uri.getScheme().equals("ima")) {
ImPluginHelper helper = ImPluginHelper.getInstance(this);
String authority = uri.getAuthority();
String[] userpass_host = authority.split("@");
String[] user_pass = userpass_host[0].split(":");
mUserName = user_pass[0].toLowerCase(Locale.getDefault());
String pass = user_pass[1];
mDomain = userpass_host[1].toLowerCase(Locale.getDefault());
mPort = 0;
final boolean regWithTor = i.getBooleanExtra("useTor", false);
Cursor cursor = openAccountByUsernameAndDomain(cr);
boolean exists = cursor.moveToFirst();
long accountId;
if (exists) {
accountId = cursor.getLong(0);
mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
pass = cursor.getString(ACCOUNT_PASSWORD_COLUMN);
setAccountKeepSignedIn(true);
mSignInHelper.activateAccount(mProviderId, accountId);
mSignInHelper.signIn(pass, mProviderId, accountId, true);
setResult(RESULT_OK);
cursor.close();
finish();
return;
} else {
// xmpp FIXME
mProviderId = helper.createAdditionalProvider(helper.getProviderNames().get(0));
accountId = ImApp.insertOrUpdateAccount(cr, mProviderId, mAccountId, mUserName, mUserName, pass);
mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
mSignInHelper.activateAccount(mProviderId, accountId);
createNewAccount(mUserName, pass, accountId, regWithTor);
cursor.close();
return;
}
} else if (Intent.ACTION_INSERT.equals(action)) {
setupUIPre();
mOriginalUserAccount = "";
// TODO once we implement multiple IM protocols
mProviderId = ContentUris.parseId(uri);
provider = mApp.getProvider(mProviderId);
if (provider != null) {
setTitle(getResources().getString(R.string.add_account, provider.mFullName));
} else {
finish();
}
} else if (Intent.ACTION_EDIT.equals(action)) {
setupUIPre();
if ((uri == null) || !Imps.Account.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) {
LogCleaner.warn(ImApp.LOG_TAG, "<AccountActivity>Bad data");
return;
}
isEdit = true;
Cursor cursor = cr.query(uri, ACCOUNT_PROJECTION, null, null, null);
if (cursor == null) {
finish();
return;
}
if (!cursor.moveToFirst()) {
cursor.close();
finish();
return;
}
setTitle(R.string.sign_in);
mAccountId = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID));
mProviderId = cursor.getLong(ACCOUNT_PROVIDER_COLUMN);
provider = mApp.getProvider(mProviderId);
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, mProviderId, false, /* don't keep updated */
null);
try {
mOriginalUserAccount = cursor.getString(ACCOUNT_USERNAME_COLUMN) + "@" + settings.getDomain();
mEditUserAccount.setText(mOriginalUserAccount);
mEditPass.setText(cursor.getString(ACCOUNT_PASSWORD_COLUMN));
// mRememberPass.setChecked(!cursor.isNull(ACCOUNT_PASSWORD_COLUMN));
// mUseTor.setChecked(settings.getUseTor());
mPort = settings.getPort();
} finally {
settings.close();
cursor.close();
}
} else {
LogCleaner.warn(ImApp.LOG_TAG, "<AccountActivity> unknown intent action " + action);
finish();
return;
}
setupUIPost();
}
use of org.awesomeapp.messenger.ui.legacy.ImPluginHelper in project Zom-Android by zom.
the class AccountViewFragment method setupUIPost.
private void setupUIPost() {
Intent i = getIntent();
if (isSignedIn) {
mBtnSignIn.setText(getString(R.string.menu_sign_out));
mBtnSignIn.setBackgroundResource(R.drawable.btn_red);
}
mEditUserAccount.addTextChangedListener(mTextWatcher);
mEditPass.addTextChangedListener(mTextWatcher);
mBtnAdvanced.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showAdvanced();
}
});
mBtnQrDisplay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showQR();
}
});
mBtnSignIn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
checkUserChanged();
/**
* if (mUseTor.isChecked())
* {
* OrbotHelper oh = new OrbotHelper(AccountActivity.this);
* if (!oh.isOrbotRunning())
* {
* oh.requestOrbotStart(AccountActivity.this);
* return;
* }
* }
*/
final String pass = mEditPass.getText().toString();
final String passConf = mEditPassConfirm.getText().toString();
final boolean rememberPass = true;
// TODO(miron) does this ever need to be true?
final boolean isActive = false;
ContentResolver cr = getActivity().getContentResolver();
if (mIsNewAccount) {
mDomain = mSpinnerDomains.getText().toString();
String fullUser = mEditUserAccount.getText().toString();
if (fullUser.indexOf("@") == -1)
fullUser += '@' + mDomain;
if (!parseAccount(fullUser)) {
mEditUserAccount.selectAll();
mEditUserAccount.requestFocus();
return;
}
ImPluginHelper helper = ImPluginHelper.getInstance(getActivity());
// xmpp FIXME
mProviderId = helper.createAdditionalProvider(helper.getProviderNames().get(0));
} else {
if (!parseAccount(mEditUserAccount.getText().toString())) {
mEditUserAccount.selectAll();
mEditUserAccount.requestFocus();
return;
} else {
// apply final settings
settingsForDomain(mDomain, mPort);
}
}
mAccountId = ImApp.insertOrUpdateAccount(cr, mProviderId, -1, mUserName, mUserName, rememberPass ? pass : null);
mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, mAccountId);
// if remember pass is true, set the "keep signed in" property to true
if (mIsNewAccount) {
if (pass.equals(passConf)) {
setAccountKeepSignedIn(rememberPass);
createNewAccount(mUserName, pass, mAccountId, false);
} else {
Toast.makeText(getActivity(), getString(R.string.error_account_password_mismatch), Toast.LENGTH_SHORT).show();
}
} else {
if (isSignedIn) {
signOut();
isSignedIn = false;
} else {
setAccountKeepSignedIn(rememberPass);
mSignInHelper.signIn(pass, mProviderId, mAccountId, isActive);
isSignedIn = true;
}
updateWidgetState();
}
}
});
/**
* mUseTor.setOnCheckedChangeListener(new OnCheckedChangeListener() {
* @Override
* public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
* updateUseTor(isChecked);
* }
* });
*/
updateWidgetState();
if (i.hasExtra("title")) {
String title = i.getExtras().getString("title");
}
if (i.hasExtra("newuser")) {
String newuser = i.getExtras().getString("newuser");
mEditUserAccount.setText(newuser);
parseAccount(newuser);
settingsForDomain(mDomain, mPort);
}
if (i.hasExtra("newpass")) {
mEditPass.setText(i.getExtras().getString("newpass"));
mEditPass.setVisibility(View.GONE);
// mRememberPass.setChecked(true);
// mRememberPass.setVisibility(View.GONE);
}
if (i.getBooleanExtra("hideTor", false)) {
// mUseTor.setVisibility(View.GONE);
}
}
use of org.awesomeapp.messenger.ui.legacy.ImPluginHelper in project Zom-Android by zom.
the class AccountViewFragment method initFragment.
private void initFragment() {
Intent i = getIntent();
mApp = (ImApp) getActivity().getApplication();
String action = i.getAction();
if (i.hasExtra("isSignedIn"))
isSignedIn = i.getBooleanExtra("isSignedIn", false);
final ProviderDef provider;
mSignInHelper = new SignInHelper(getActivity(), new SimpleAlertHandler(getActivity()));
SignInHelper.SignInListener signInListener = new SignInHelper.SignInListener() {
@Override
public void connectedToService() {
}
@Override
public void stateChanged(int state, long accountId) {
if (state == ImConnection.LOGGED_IN) {
// mSignInHelper.goToAccount(accountId);
// finish();
isSignedIn = true;
} else {
isSignedIn = false;
}
}
};
mSignInHelper.setSignInListener(signInListener);
ContentResolver cr = getActivity().getContentResolver();
Uri uri = i.getData();
// check if there is account information and direct accordingly
if (Intent.ACTION_INSERT_OR_EDIT.equals(action)) {
if ((uri == null) || !Imps.Account.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) {
action = Intent.ACTION_INSERT;
} else {
action = Intent.ACTION_EDIT;
}
}
if (Intent.ACTION_INSERT.equals(action) && uri.getScheme().equals("ima")) {
ImPluginHelper helper = ImPluginHelper.getInstance(getActivity());
String authority = uri.getAuthority();
String[] userpass_host = authority.split("@");
String[] user_pass = userpass_host[0].split(":");
mUserName = user_pass[0].toLowerCase(Locale.getDefault());
String pass = user_pass[1];
mDomain = userpass_host[1].toLowerCase(Locale.getDefault());
mPort = 0;
final boolean regWithTor = i.getBooleanExtra("useTor", false);
Cursor cursor = openAccountByUsernameAndDomain(cr);
boolean exists = cursor.moveToFirst();
long accountId;
if (exists) {
accountId = cursor.getLong(0);
mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
pass = cursor.getString(ACCOUNT_PASSWORD_COLUMN);
setAccountKeepSignedIn(true);
mSignInHelper.activateAccount(mProviderId, accountId);
mSignInHelper.signIn(pass, mProviderId, accountId, true);
// setResult(RESULT_OK);
cursor.close();
// finish();
return;
} else {
// xmpp FIXME
mProviderId = helper.createAdditionalProvider(helper.getProviderNames().get(0));
accountId = ImApp.insertOrUpdateAccount(cr, mProviderId, -1, mUserName, mUserName, pass);
mAccountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
mSignInHelper.activateAccount(mProviderId, accountId);
createNewAccount(mUserName, pass, accountId, regWithTor);
cursor.close();
return;
}
} else if (Intent.ACTION_INSERT.equals(action)) {
mOriginalUserAccount = "";
// TODO once we implement multiple IM protocols
mProviderId = ContentUris.parseId(uri);
provider = mApp.getProvider(mProviderId);
} else if (Intent.ACTION_EDIT.equals(action)) {
if ((uri == null) || !Imps.Account.CONTENT_ITEM_TYPE.equals(cr.getType(uri))) {
LogCleaner.warn(ImApp.LOG_TAG, "<AccountActivity>Bad data");
return;
}
isEdit = true;
Cursor cursor = cr.query(uri, ACCOUNT_PROJECTION, null, null, null);
if (cursor == null) {
return;
}
if (!cursor.moveToFirst()) {
cursor.close();
return;
}
mAccountId = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID));
mProviderId = cursor.getLong(ACCOUNT_PROVIDER_COLUMN);
provider = mApp.getProvider(mProviderId);
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(mProviderId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, mProviderId, false, /* don't keep updated */
null);
try {
mOriginalUserAccount = cursor.getString(ACCOUNT_USERNAME_COLUMN) + "@" + settings.getDomain();
mEditUserAccount.setText(mOriginalUserAccount);
mEditPass.setText(cursor.getString(ACCOUNT_PASSWORD_COLUMN));
// mRememberPass.setChecked(!cursor.isNull(ACCOUNT_PASSWORD_COLUMN));
// mUseTor.setChecked(settings.getUseTor());
mBtnQrDisplay.setVisibility(View.VISIBLE);
} finally {
settings.close();
cursor.close();
}
} else {
LogCleaner.warn(ImApp.LOG_TAG, "<AccountActivity> unknown intent action " + action);
return;
}
setupUIPost();
}
use of org.awesomeapp.messenger.ui.legacy.ImPluginHelper in project Zom-Android by zom.
the class OnboardingManager method registerAccount.
public static OnboardingAccount registerAccount(Context context, String nickname, String username, String password, String domain, String server, int port) throws JSONException {
if (password == null)
password = generatePassword();
ContentResolver cr = context.getContentResolver();
ImPluginHelper helper = ImPluginHelper.getInstance(context);
// xmpp FIXME
long providerId = helper.createAdditionalProvider(helper.getProviderNames().get(0));
long accountId = ImApp.insertOrUpdateAccount(cr, providerId, -1, nickname, username, password);
Uri accountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(providerId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, providerId, false, /* don't keep updated */
null);
settings.setRequireTls(true);
settings.setTlsCertVerify(true);
settings.setAllowPlainAuth(false);
try {
settings.setDomain(domain);
settings.setPort(port);
if (server != null) {
// if we have a host, then we should use it
settings.setServer(server);
settings.setDoDnsSrv(false);
} else {
settings.setServer(null);
settings.setDoDnsSrv(true);
}
settings.requery();
HashMap<String, String> aParams = new HashMap<String, String>();
XmppConnection xmppConn = new XmppConnection(context);
xmppConn.initUser(providerId, accountId);
boolean success = xmppConn.registerAccount(settings, username, password, aParams);
if (success) {
OnboardingAccount result = new OnboardingAccount();
result.username = username;
result.domain = domain;
result.password = password;
result.providerId = providerId;
result.accountId = accountId;
result.nickname = nickname;
// now keep this account signed-in
ContentValues values = new ContentValues();
values.put(Imps.AccountColumns.KEEP_SIGNED_IN, 1);
cr.update(accountUri, values, null, null);
settings.close();
return result;
}
} catch (Exception e) {
LogCleaner.error(ImApp.LOG_TAG, "error registering new account", e);
}
ImApp.deleteAccount(context.getContentResolver(), accountId, providerId);
settings.close();
return null;
}
use of org.awesomeapp.messenger.ui.legacy.ImPluginHelper in project Zom-Android by zom.
the class OnboardingManager method addExistingAccount.
public static OnboardingAccount addExistingAccount(Activity context, Handler handler, String nickname, String jabberId, String password) {
OnboardingAccount result = null;
String[] jabberParts = jabberId.split("@");
String username = jabberParts[0];
String domain = jabberParts[1];
int port = 5222;
ContentResolver cr = context.getContentResolver();
ImPluginHelper helper = ImPluginHelper.getInstance(context);
// xmpp FIXME
long providerId = helper.createAdditionalProvider(helper.getProviderNames().get(0));
long accountId = ImApp.insertOrUpdateAccount(cr, providerId, -1, nickname, username, password);
if (accountId == -1)
return null;
Uri accountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId);
Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(providerId) }, null);
Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap(pCursor, cr, providerId, false, /* don't keep updated */
null);
// should check to see if Orbot is installed and running
boolean doDnsSrvLookup = true;
settings.setRequireTls(true);
settings.setTlsCertVerify(true);
settings.setAllowPlainAuth(false);
settings.setDoDnsSrv(doDnsSrvLookup);
try {
settings.setDomain(domain);
settings.setPort(port);
settings.requery();
result = new OnboardingAccount();
result.username = username;
result.domain = domain;
result.password = password;
result.providerId = providerId;
result.accountId = accountId;
// now keep this account signed-in
ContentValues values = new ContentValues();
values.put(Imps.AccountColumns.KEEP_SIGNED_IN, 1);
cr.update(accountUri, values, null, null);
// settings closed in registerAccount
} catch (Exception e) {
LogCleaner.error(ImApp.LOG_TAG, "error registering new account", e);
}
settings.close();
return result;
}
Aggregations