Example usage for android.app Activity getContentResolver

List of usage examples for android.app Activity getContentResolver

Introduction

In this page you can find the example usage for android.app Activity getContentResolver.

Prototype

@Override
    public ContentResolver getContentResolver() 

Source Link

Usage

From source file:com.android.mms.ui.MessageUtils.java

public static void confirmDeleteMessage(final Activity activity, final Uri msgUri) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.confirm_dialog_title);
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setCancelable(true);// w  ww.j  a  v a 2s.  c  o  m
    builder.setMessage(R.string.confirm_delete_message);
    builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            /// M: fix bug ALPS00351620; for requery searchactivity.
            SearchActivity.setNeedRequery();
            SqliteWrapper.delete(activity.getApplicationContext(), activity.getContentResolver(), msgUri, null,
                    null);
            dialog.dismiss();
            activity.finish();
        }
    });
    builder.setNegativeButton(R.string.no, null);
    builder.show();
}

From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java

/**
 * Adds an account to the local database. Must not be called on the main thread.
 *//*  w  ww .ja  v a 2  s.c om*/
public static MMyAccount addAccountToDatabase(Activity activity, AccountDetails accountDetails) {
    SQLiteOpenHelper databaseSource = App.getDatabaseSource(activity);
    IdentitiesManager im = new IdentitiesManager(databaseSource);
    MyAccountManager am = new MyAccountManager(databaseSource);
    DeviceManager dm = new DeviceManager(databaseSource);
    FeedManager fm = new FeedManager(databaseSource);

    String accountType = accountDetails.accountType;
    String accountName = accountDetails.accountName;
    String principal = accountDetails.principal;
    boolean owned = accountDetails.owned;
    IBIdentity ibid;
    if (accountType.equals(ACCOUNT_TYPE_GOOGLE)) {
        ibid = new IBIdentity(Authority.Email, principal, 0);
    } else if (accountType.equals(ACCOUNT_TYPE_FACEBOOK)) {
        ibid = new IBIdentity(Authority.Facebook, principal, 0);
    } else if (accountType.equals(ACCOUNT_TYPE_PHONE)) {
        ibid = new IBIdentity(Authority.PhoneNumber, principal, 0);
    } else {
        throw new RuntimeException("Unsupported account type " + accountType);
    }

    SQLiteDatabase db = databaseSource.getWritableDatabase();
    db.beginTransaction();
    try {
        // Ensure identity in the database
        MIdentity id = im.getIdentityForIBHashedIdentity(ibid);
        //don't repeatedly add profile broadcast groups or do any
        //of this processing if the account is already owned.
        if (id != null && id.owned_) {
            return null;
        }

        MIdentity original = im.getOwnedIdentities().get(0);
        //if this identity wasnt already in the contact book, we need to update it
        if (id == null) {
            id = new MIdentity();
            populateMyNewIdentity(activity, principal, im, ibid, id, original, owned);
            im.insertIdentity(id);
        } else {
            populateMyNewIdentity(activity, principal, im, ibid, id, original, owned);
            im.updateIdentity(id);
        }

        im.updateMyProfileName(activity, id.musubiName_, false);
        im.updateMyProfileThumbnail(activity, id.musubiThumbnail_, false);

        // Ensure account entry exists
        MMyAccount account = am.lookupAccount(accountName, accountType);
        if (account == null) {
            //create the account
            account = new MMyAccount();
            account.accountName_ = accountName;
            account.accountType_ = accountType;
            account.identityId_ = id.id_;
            am.insertAccount(account);
        } else {
            account.identityId_ = id.id_;
            am.updateAccount(account);
        }

        // For accounts linked to identities that are not yet owned,
        // skip further initialization
        if (owned) {
            MDevice dev = dm.getDeviceForName(id.id_, dm.getLocalDeviceName());
            // Ensure device exists
            if (dev == null) {
                dev = new MDevice();
                dev.deviceName_ = dm.getLocalDeviceName();
                dev.identityId_ = id.id_;
                dm.insertDevice(dev);
            }
            //this feed will contain all members who should receive
            //a profile for the account because of a friend introduction
            MFeed provisional = new MFeed();
            provisional.name_ = MFeed.PROVISONAL_WHITELIST_FEED_NAME;
            provisional.type_ = MFeed.FeedType.ASYMMETRIC;
            fm.insertFeed(provisional);
            //XXX
            //TODO: in other places in the code, we should be pruning the
            //provisional whitelist feed as people become whitelisted..

            //these get inserted for owned identities to allow profile
            //broadcasts to go out
            MMyAccount provAccount = new MMyAccount();
            provAccount.accountName_ = MMyAccount.PROVISIONAL_WHITELIST_ACCOUNT;
            provAccount.accountType_ = MMyAccount.INTERNAL_ACCOUNT_TYPE;
            provAccount.identityId_ = id.id_;
            provAccount.feedId_ = provisional.id_;
            am.insertAccount(provAccount);

            //this feed will contain all members who should receive
            //a profile for the account because they are whitelisted
            //and contacted you on one of your accounts.
            MFeed accountBroadcastFeed = new MFeed();
            accountBroadcastFeed.name_ = MFeed.LOCAL_WHITELIST_FEED_NAME;
            accountBroadcastFeed.type_ = MFeed.FeedType.ASYMMETRIC;
            fm.insertFeed(accountBroadcastFeed);

            MMyAccount localAccount = new MMyAccount();
            localAccount.accountName_ = MMyAccount.LOCAL_WHITELIST_ACCOUNT;
            localAccount.accountType_ = MMyAccount.INTERNAL_ACCOUNT_TYPE;
            localAccount.identityId_ = id.id_;
            localAccount.feedId_ = accountBroadcastFeed.id_;
            am.insertAccount(localAccount);

            db.setTransactionSuccessful();

            ContentResolver resolver = activity.getContentResolver();
            // Notify interested services (identity available makes AMQP wake up for example)
            resolver.notifyChange(MusubiService.OWNED_IDENTITY_AVAILABLE, null);
            resolver.notifyChange(MusubiService.MY_PROFILE_UPDATED, null);

            // Makes key update wake up
            resolver.notifyChange(MusubiService.AUTH_TOKEN_REFRESH, null);
            WizardStepHandler.accomplishTask(activity, WizardStepHandler.TASK_LINK_ACCOUNT);

            App.getUsageMetrics(activity).report(MusubiMetrics.ACCOUNT_CONNECTED, account.accountType_);
        } else {
            db.setTransactionSuccessful();
        }
        return account;
    } finally {
        db.endTransaction();
    }
}