Search in sources :

Example 21 with AccountManager

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);
}
Also used : Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AccountManager(android.accounts.AccountManager) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter) OperationCanceledException(android.accounts.OperationCanceledException)

Example 22 with AccountManager

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();
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) TextView(android.widget.TextView) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView)

Example 23 with AccountManager

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;
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

Example 24 with AccountManager

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;
    }
}
Also used : Account(android.accounts.Account) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) AccountManager(android.accounts.AccountManager) IOException(java.io.IOException)

Example 25 with AccountManager

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;
}
Also used : Account(android.accounts.Account) SharedPreferences(android.content.SharedPreferences) AccountManager(android.accounts.AccountManager) File(java.io.File)

Aggregations

AccountManager (android.accounts.AccountManager)180 Account (android.accounts.Account)121 Bundle (android.os.Bundle)28 Intent (android.content.Intent)18 PackageManager (android.content.pm.PackageManager)16 View (android.view.View)16 TextView (android.widget.TextView)16 Context (android.content.Context)15 IOException (java.io.IOException)14 UserAccountManager (com.nextcloud.client.account.UserAccountManager)13 OperationCanceledException (android.accounts.OperationCanceledException)11 ImageView (android.widget.ImageView)9 AuthenticatorDescription (android.accounts.AuthenticatorDescription)8 UserHandle (android.os.UserHandle)8 LayoutInflater (android.view.LayoutInflater)8 AuthenticatorException (android.accounts.AuthenticatorException)7 UserInfo (android.content.pm.UserInfo)7 Resources (android.content.res.Resources)7 Drawable (android.graphics.drawable.Drawable)7 LinearLayout (android.widget.LinearLayout)7