use of android.accounts.AccountManager in project android by nextcloud.
the class ManageAccountsActivity method createAccount.
@Override
public void createAccount() {
AccountManager am = AccountManager.get(getApplicationContext());
am.addAccount(MainApp.getAccountType(), null, null, null, this, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
if (future != null) {
try {
Bundle result = future.getResult();
String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name);
mAccountListAdapter = new AccountListAdapter(ManageAccountsActivity.this, getAccountListItems(), mTintedCheck);
mListView.setAdapter(mAccountListAdapter);
runOnUiThread(new Runnable() {
@Override
public void run() {
mAccountListAdapter.notifyDataSetChanged();
}
});
} catch (OperationCanceledException e) {
Log_OC.d(TAG, "Account creation canceled");
} catch (Exception e) {
Log_OC.e(TAG, "Account creation finished in exception: ", e);
}
}
}
}, mHandler);
}
use of android.accounts.AccountManager in project android by nextcloud.
the class WhatsNewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.whats_new_activity);
int fontColor = ThemeUtils.fontColor();
mProgress = findViewById(R.id.progressIndicator);
mPager = findViewById(R.id.contentPanel);
final boolean isBeta = getResources().getBoolean(R.bool.is_beta);
final boolean isMultiAccount = getResources().getBoolean(R.bool.multiaccount_support);
String[] urls = getResources().getStringArray(R.array.whatsnew_urls);
// Sometimes, accounts are not deleted when you uninstall the application so we'll do it now
if (isFirstRun()) {
AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
for (Account account : AccountUtils.getAccounts(this)) {
am.removeAccount(account, null, null);
}
}
boolean showWebView = urls.length > 0;
if (showWebView) {
FeaturesWebViewAdapter featuresWebViewAdapter = new FeaturesWebViewAdapter(getSupportFragmentManager(), urls);
mProgress.setNumberOfSteps(featuresWebViewAdapter.getCount());
mPager.setAdapter(featuresWebViewAdapter);
} else {
FeaturesViewAdapter featuresViewAdapter = new FeaturesViewAdapter(getSupportFragmentManager(), FeatureList.getFiltered(getLastSeenVersionCode(), isFirstRun(), isBeta, isMultiAccount));
mProgress.setNumberOfSteps(featuresViewAdapter.getCount());
mPager.setAdapter(featuresViewAdapter);
}
mPager.addOnPageChangeListener(this);
mForwardFinishButton = findViewById(R.id.forward);
ThemeUtils.colorImageButton(mForwardFinishButton, fontColor);
mForwardFinishButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mProgress.hasNextStep()) {
mPager.setCurrentItem(mPager.getCurrentItem() + 1, true);
mProgress.animateToStep(mPager.getCurrentItem() + 1);
} else {
onFinish();
finish();
}
updateNextButtonIfNeeded();
}
});
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mForwardFinishButton.setBackground(null);
} else {
mForwardFinishButton.setBackgroundDrawable(null);
}
mSkipButton = findViewById(R.id.skip);
mSkipButton.setTextColor(fontColor);
mSkipButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onFinish();
finish();
}
});
TextView tv = findViewById(R.id.welcomeText);
if (showWebView) {
tv.setText(R.string.app_name);
} else if (isFirstRun()) {
tv.setText(R.string.empty);
} else {
tv.setText(String.format(getString(R.string.whats_new_title), MainApp.getVersionName()));
}
updateNextButtonIfNeeded();
}
use of android.accounts.AccountManager in project apps-android-commons by commons-app.
the class CommonsApplication method getCurrentAccount.
/**
* @return Account|null
*/
public Account getCurrentAccount() {
if (currentAccount == null) {
AccountManager accountManager = AccountManager.get(this);
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
if (allAccounts.length != 0) {
currentAccount = allAccounts[0];
}
}
return currentAccount;
}
use of android.accounts.AccountManager in project apps-android-commons by commons-app.
the class CommonsApplication method revalidateAuthToken.
public Boolean revalidateAuthToken() {
AccountManager accountManager = AccountManager.get(this);
Account curAccount = getCurrentAccount();
if (curAccount == null) {
// This should never happen
return false;
}
accountManager.invalidateAuthToken(AccountUtil.accountType(), getMWApi().getAuthCookie());
try {
String authCookie = accountManager.blockingGetAuthToken(curAccount, "", false);
getMWApi().setAuthCookie(authCookie);
return true;
} catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e) {
e.printStackTrace();
return false;
}
}
use of android.accounts.AccountManager in project apps-android-commons by commons-app.
the class CommonsApplication method clearApplicationData.
public void clearApplicationData(Context context) {
File cacheDirectory = context.getCacheDir();
File applicationDirectory = new File(cacheDirectory.getParent());
if (applicationDirectory.exists()) {
String[] fileNames = applicationDirectory.list();
for (String fileName : fileNames) {
if (!fileName.equals("lib")) {
FileUtils.deleteFile(new File(applicationDirectory, fileName));
}
}
}
AccountManager accountManager = AccountManager.get(this);
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
for (int index = 0; index < allAccounts.length; index++) {
accountManager.removeAccount(allAccounts[index], null, null);
}
//TODO: fix preference manager
PreferenceManager.getDefaultSharedPreferences(getInstance()).edit().clear().commit();
SharedPreferences preferences = context.getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
preferences.edit().clear().commit();
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
preferences.edit().putBoolean("firstrun", false).apply();
updateAllDatabases();
currentAccount = null;
}
Aggregations