Example usage for android.content ContentResolver notifyChange

List of usage examples for android.content ContentResolver notifyChange

Introduction

In this page you can find the example usage for android.content ContentResolver notifyChange.

Prototype

public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer) 

Source Link

Document

Notify registered observers that a row was updated and attempt to sync changes to the network.

Usage

From source file:com.akop.bach.parser.PsnParser.java

@Override
public void deleteAccount(BasicAccount account) {
    ContentResolver cr = mContext.getContentResolver();
    long accountId = account.getId();

    // Clear games & achievements
    StringBuffer buffer = new StringBuffer();
    Cursor c = cr.query(Games.CONTENT_URI, new String[] { Games._ID }, Games.ACCOUNT_ID + "=" + accountId, null,
            null);//w  w w .  java2s.  com

    try {
        if (c != null) {
            while (c.moveToNext()) {
                if (buffer.length() > 0)
                    buffer.append(",");
                buffer.append(c.getLong(0));
            }
        }
    } finally {
        if (c != null)
            c.close();
    }

    // Clear trophies
    cr.delete(Trophies.CONTENT_URI, Trophies.GAME_ID + " IN (" + buffer.toString() + ")", null);

    // Clear rest of data
    cr.delete(Games.CONTENT_URI, Games.ACCOUNT_ID + "=" + accountId, null);
    cr.delete(Profiles.CONTENT_URI, Profiles.ACCOUNT_ID + "=" + accountId, null);
    cr.delete(Friends.CONTENT_URI, Friends.ACCOUNT_ID + "=" + accountId, null);

    // Send notifications
    cr.notifyChange(Profiles.CONTENT_URI, null);
    cr.notifyChange(Trophies.CONTENT_URI, null);
    cr.notifyChange(Games.CONTENT_URI, null);
    cr.notifyChange(Friends.CONTENT_URI, null);

    // Delete authenticated session
    deleteSession(account);
}

From source file:cn.edu.nju.dapenti.activity.EditFeedActivity.java

@Override
protected void onDestroy() {
    if (getIntent().getAction().equals(Intent.ACTION_EDIT)) {
        String url = mUrlEditText.getText().toString();
        ContentResolver cr = getContentResolver();

        Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI, FeedColumns.PROJECTION_ID,
                FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null);

        if (cursor.moveToFirst() && !getIntent().getData().getLastPathSegment().equals(cursor.getString(0))) {
            cursor.close();//from  w w  w.  j a v  a2  s  .  c om
            Toast.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Toast.LENGTH_LONG).show();
        } else {
            cursor.close();
            ContentValues values = new ContentValues();

            if (!url.startsWith(Constants.HTTP) && !url.startsWith(Constants.HTTPS)) {
                url = Constants.HTTP + url;
            }
            values.put(FeedColumns.URL, url);

            String name = mNameEditText.getText().toString();

            values.put(FeedColumns.NAME, name.trim().length() > 0 ? name : null);
            values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null);
            values.put(FeedColumns.FETCH_MODE, 0);
            values.putNull(FeedColumns.ERROR);

            cr.update(getIntent().getData(), values, null, null);
            if (!name.equals(mPreviousName)) {
                cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null);
                cr.notifyChange(FeedColumns.GROUPED_FEEDS_CONTENT_URI, null);
            }
        }
    }

    super.onDestroy();
}

From source file:co.nerdart.ourss.activity.EditFeedActivity.java

@Override
protected void onDestroy() {
    if (getIntent().getAction().equals(Intent.ACTION_EDIT)) {
        String url = mUrlEditText.getText().toString();
        ContentResolver cr = getContentResolver();

        Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI, FeedColumns.PROJECTION_ID,
                FeedColumns.URL + Constants.DB_ARG, new String[] { url }, null);

        if (cursor.moveToFirst() && !getIntent().getData().getLastPathSegment().equals(cursor.getString(0))) {
            cursor.close();/*from   ww  w.  j a va  2s . com*/
            //Toast.makeText(EditFeedActivity.this, R.string.error_feed_url_exists,
            //      Toast.LENGTH_LONG).show();
            Crouton.makeText(EditFeedActivity.this, R.string.error_feed_url_exists, Style.INFO);
        } else {
            cursor.close();
            ContentValues values = new ContentValues();

            if (!url.startsWith(Constants.HTTP) && !url.startsWith(Constants.HTTPS)) {
                url = Constants.HTTP + url;
            }
            values.put(FeedColumns.URL, url);

            String name = mNameEditText.getText().toString();

            values.put(FeedColumns.NAME, name.trim().length() > 0 ? name : null);
            values.put(FeedColumns.RETRIEVE_FULLTEXT, mRetrieveFulltextCb.isChecked() ? 1 : null);
            values.put(FeedColumns.FETCH_MODE, 0);
            values.putNull(FeedColumns.ERROR);

            cr.update(getIntent().getData(), values, null, null);
            if (!name.equals(mPreviousName)) {
                cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null);
            }
        }
    }

    super.onDestroy();
}

From source file:com.akop.bach.parser.XboxLiveParser.java

public void createAccount(BasicAccount account, ContentValues cv) {
    XboxLiveAccount xblAccount = (XboxLiveAccount) account;

    // Save changes to preferences
    xblAccount.setGamertag(cv.getAsString(Profiles.GAMERTAG));
    xblAccount.setLastSummaryUpdate(System.currentTimeMillis());
    xblAccount.setIconUrl(cv.getAsString(Profiles.ICON_URL));
    xblAccount.setGoldStatus(cv.getAsBoolean(Profiles.IS_GOLD));

    account.save(Preferences.get(mContext));

    // Add profile to database
    ContentResolver cr = mContext.getContentResolver();
    cr.insert(Profiles.CONTENT_URI, cv);
    cr.notifyChange(Profiles.CONTENT_URI, null);
}

From source file:com.akop.bach.parser.XboxLiveParser.java

private void parseDeleteMessage(XboxLiveAccount account, long messageUid) throws IOException, ParserException {
    String token = getVToken(String.format(URL_VTOKEN_MESSAGES, mLocale));

    String url = String.format(URL_JSON_DELETE_MESSAGE, mLocale);

    List<NameValuePair> inputs = new ArrayList<NameValuePair>(3);

    // Message ID
    addValue(inputs, "msgID", messageUid);

    // Req. ver. token
    addValue(inputs, "__RequestVerificationToken", token);

    String page = getResponse(url, inputs, true);

    long started = System.currentTimeMillis();

    JSONObject json = getJSONObject(page, false);

    try {//from  w  ww .j  a va  2s .  c  om
        if (!json.getBoolean("Success")) {
            if (App.getConfig().logToConsole())
                App.logv("XboxLiveParser/parseDeleteMessage: Parser error: " + page);

            throw new ParserException(
                    json.optString("Status", mContext.getString(R.string.message_could_not_be_deleted)));
        }
    } catch (JSONException e) {
        if (App.getConfig().logToConsole()) {
            App.logv("XboxLiveParser/parseDeleteMessage: JSON error: " + page);
            e.printStackTrace();
        }
    }

    ContentResolver cr = mContext.getContentResolver();
    int rows = cr.delete(Messages.CONTENT_URI,
            Messages.UID + "=" + messageUid + " AND " + Messages.ACCOUNT_ID + "=" + account.getId(), null);

    if (rows > 0)
        cr.notifyChange(Messages.CONTENT_URI, null);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Message deletion processing", started);
}

From source file:com.akop.bach.parser.XboxLiveParser.java

private void parseBlockMessage(XboxLiveAccount account, long messageUid) throws IOException, ParserException {
    String token = getVToken(String.format(URL_VTOKEN_MESSAGES, mLocale));

    String url = String.format(URL_JSON_BLOCK_MESSAGE, mLocale);

    List<NameValuePair> inputs = new ArrayList<NameValuePair>(3);

    // Message ID
    addValue(inputs, "msgID", messageUid);

    // Req. ver. token
    addValue(inputs, "__RequestVerificationToken", getVToken(token));

    String page = getResponse(url, inputs, true);

    long started = System.currentTimeMillis();

    JSONObject json = getJSONObject(page, false);

    try {//from w  w  w. j a  va 2  s  . co m
        if (!json.getBoolean("Success")) {
            if (App.getConfig().logToConsole())
                App.logv("XboxLiveParser/parseBlockMessage: Parser error: " + page);

            throw new ParserException(
                    json.optString("Status", mContext.getString(R.string.sender_not_blocked)));
        }
    } catch (JSONException e) {
        if (App.getConfig().logToConsole()) {
            App.logv("XboxLiveParser/parseDeleteMessage: JSON error: " + page);
            e.printStackTrace();
        }
    }

    ContentResolver cr = mContext.getContentResolver();
    int rows = cr.delete(Messages.CONTENT_URI,
            Messages.UID + "=" + messageUid + " AND " + Messages.ACCOUNT_ID + "=" + account.getId(), null);

    if (rows > 0)
        cr.notifyChange(Messages.CONTENT_URI, null);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Message deletion processing", started);
}

From source file:com.akop.bach.parser.XboxLiveParser.java

private void parseUpdateProfile(XboxLiveAccount account, String motto, String name, String location, String bio)
        throws ParserException, IOException {
    long started = System.currentTimeMillis();

    String url = String.format(URL_EDIT_PROFILE, mLocale);
    String page = getResponse(url);

    if (App.getConfig().logToConsole())
        started = displayTimeTaken("Profile load", started);

    List<NameValuePair> inputs = new ArrayList<NameValuePair>(10);
    getInputs(page, inputs, null);/*from  w  w w.j  a v a 2s .  c o m*/

    setValue(inputs, "Motto", motto);
    setValue(inputs, "RealName", name);
    setValue(inputs, "Location", location);
    setValue(inputs, "Bio", bio);

    try {
        submitRequest(url, inputs);

        // This shouldn't happen - user was not redirected
        throw new ParserException(mContext, R.string.error_updating_profile);
    } catch (ClientProtocolException e) {
        // This is normal; user is redirected to his overview page
    }

    if (App.getConfig().logToConsole())
        started = displayTimeTaken("Profile update", started);

    // Update local information

    ContentResolver cr = mContext.getContentResolver();
    ContentValues cv = new ContentValues(10);

    cv.put(Profiles.MOTTO, motto);
    cv.put(Profiles.NAME, name);
    cv.put(Profiles.LOCATION, location);
    cv.put(Profiles.BIO, bio);

    Uri uri = ContentUris.withAppendedId(Profiles.CONTENT_URI, account.getId());

    cr.update(uri, cv, null, null);

    account.setLastSummaryUpdate(System.currentTimeMillis());
    account.save(Preferences.get(mContext));

    cr.notifyChange(uri, null);
}

From source file:com.akop.bach.parser.XboxLiveParser.java

private void parseViewMessage(XboxLiveAccount account, long messageUid) throws IOException, ParserException {
    long started = System.currentTimeMillis();

    String token = getVToken(String.format(URL_VTOKEN_MESSAGES, mLocale));

    String url = String.format(URL_JSON_READ_MESSAGE, mLocale);

    List<NameValuePair> inputs = new ArrayList<NameValuePair>(3);

    addValue(inputs, "msgID", messageUid);
    addValue(inputs, "__RequestVerificationToken", token);

    String page = getResponse(url, inputs, true);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Message page fetch", started);

    JSONObject json = getXboxJsonObject(page);
    String message;/* w  w w  . j  a  va  2 s  .  com*/

    if ((json == null) || (message = json.optString("Text")) == null)
        throw new ParserException(mContext, R.string.error_json_parser_error);

    ContentResolver cr = mContext.getContentResolver();
    ContentValues cv = new ContentValues();

    if (!json.isNull("Text"))
        cv.put(Messages.BODY, htmlDecode(message));

    cv.put(Messages.IS_DIRTY, 0);
    cv.put(Messages.IS_READ, 1);

    int rows = cr.update(Messages.CONTENT_URI, cv,
            Messages.UID + "=" + messageUid + " AND " + Messages.ACCOUNT_ID + "=" + account.getId(), null);

    if (rows < 1)
        throw new ParserException(mContext, R.string.message_not_found);

    cr.notifyChange(Messages.CONTENT_URI, null);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Message processing", started);
}

From source file:com.akop.bach.parser.XboxLiveParser.java

private void parseAccountSummary(XboxLiveAccount account) throws ParserException, IOException {
    ContentValues cv = parseSummaryData(account);
    ContentResolver cr = mContext.getContentResolver();

    long accountId = account.getId();
    boolean newRecord = true;

    long started = System.currentTimeMillis();
    Cursor c = cr.query(Profiles.CONTENT_URI, new String[] { Profiles._ID },
            Profiles.ACCOUNT_ID + "=" + accountId, null, null);

    if (c != null) {
        if (c.moveToFirst())
            newRecord = false;/*from w  ww.ja  va 2  s  .c o m*/
        c.close();
    }

    if (newRecord) {
        cv.put(Profiles.ACCOUNT_ID, account.getId());
        cv.put(Profiles.UUID, account.getUuid());

        cr.insert(Profiles.CONTENT_URI, cv);
    } else {
        cr.update(Profiles.CONTENT_URI, cv, Profiles.ACCOUNT_ID + "=" + accountId, null);
    }

    cr.notifyChange(Profiles.CONTENT_URI, null);

    if (App.getConfig().logToConsole())
        displayTimeTaken("Summary update", started);

    account.refresh(Preferences.get(mContext));
    account.setGamertag(cv.getAsString(Profiles.GAMERTAG));
    account.setIconUrl(cv.getAsString(Profiles.ICON_URL));
    account.setGoldStatus(cv.getAsBoolean(Profiles.IS_GOLD));
    account.setLastSummaryUpdate(System.currentTimeMillis());
    account.save(Preferences.get(mContext));
}

From source file:com.akop.bach.parser.PsnUsParser.java

protected void parseFriendSummary(PsnAccount account, String friendOnlineId)
        throws ParserException, IOException {
    long updated = System.currentTimeMillis();
    long started = updated;

    GamerProfileInfo gpi = parseGamerProfile(account, friendOnlineId);

    ContentResolver cr = mContext.getContentResolver();
    Cursor c = cr.query(Friends.CONTENT_URI, FRIEND_ID_PROJECTION,
            Friends.ACCOUNT_ID + "=" + account.getId() + " AND " + Friends.ONLINE_ID + "=?",
            new String[] { friendOnlineId }, null);

    long friendId = -1;

    try {//from w ww.j a  v a  2 s . c  o  m
        if (c != null && c.moveToFirst())
            friendId = c.getLong(0);
    } finally {
        if (c != null)
            c.close();
    }

    ContentValues cv = new ContentValues(15);

    cv.put(Friends.ONLINE_ID, gpi.OnlineId);
    cv.put(Friends.ICON_URL, gpi.AvatarUrl);
    cv.put(Friends.LEVEL, gpi.Level);
    cv.put(Friends.PROGRESS, gpi.Progress);
    cv.put(Friends.ONLINE_STATUS, gpi.OnlineStatus);
    cv.put(Friends.TROPHIES_PLATINUM, gpi.PlatinumTrophies);
    cv.put(Friends.TROPHIES_GOLD, gpi.GoldTrophies);
    cv.put(Friends.TROPHIES_SILVER, gpi.SilverTrophies);
    cv.put(Friends.TROPHIES_BRONZE, gpi.BronzeTrophies);
    cv.put(Friends.PLAYING, gpi.Playing);
    cv.put(Friends.LAST_UPDATED, updated);

    if (friendId < 0) {
        // New
        cv.put(Friends.ACCOUNT_ID, account.getId());
        cr.insert(Friends.CONTENT_URI, cv);
    } else {
        cr.update(ContentUris.withAppendedId(Friends.CONTENT_URI, friendId), cv, null, null);
    }

    if (App.getConfig().logToConsole())
        started = displayTimeTaken("Friend page processing", started);

    cr.notifyChange(ContentUris.withAppendedId(Friends.CONTENT_URI, friendId), null);
}