use of org.awesomeapp.messenger.ui.legacy.ProviderDef in project Zom-Android by zom.
the class ImApp method loadImProviderSettings.
private void loadImProviderSettings() {
mProviders = new HashMap<Long, ProviderDef>();
ContentResolver cr = getContentResolver();
String[] selectionArgs = new String[1];
selectionArgs[0] = ImApp.IMPS_CATEGORY;
Cursor c = cr.query(Imps.Provider.CONTENT_URI, PROVIDER_PROJECTION, Imps.Provider.CATEGORY + "=?", selectionArgs, null);
if (c == null) {
return;
}
try {
while (c.moveToNext()) {
long id = c.getLong(0);
String providerName = c.getString(1);
String fullName = c.getString(2);
String signUpUrl = c.getString(3);
if (// mProviders has been reset
mProviders == null)
break;
mProviders.put(id, new ProviderDef(id, providerName, fullName, signUpUrl));
}
} finally {
c.close();
}
}
use of org.awesomeapp.messenger.ui.legacy.ProviderDef 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.ProviderDef 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();
}
Aggregations