Example usage for android.support.v4.util SimpleArrayMap remove

List of usage examples for android.support.v4.util SimpleArrayMap remove

Introduction

In this page you can find the example usage for android.support.v4.util SimpleArrayMap remove.

Prototype

public V remove(Object obj) 

Source Link

Usage

From source file:org.bubenheimer.android.preference.SharedPreferencesUtility.java

@UiThread
public static void unregisterOnSharedPreferenceChangeListener(@NonNull final Context context,
        @NonNull final SharedPreferences prefs, @NonNull final OnSharedPreferenceChangeListener listener,
        @StringRes final int... resIds) {
    final SimpleArrayMap<String, Pair<Integer, ? extends List<OnSharedPreferenceChangeListener>>> prefsEntry = masterMap
            .get(prefs);//from  w  ww  .j ava  2 s.  c om
    if (prefsEntry == null) {
        Log.w(TAG, "Shared preferences not registered: ", prefs);
        return;
    }
    final int cnt = resIds.length;
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < cnt; ++i) {
        final int resId = resIds[i];
        final String key = context.getString(resId);
        final Pair<Integer, ? extends List<OnSharedPreferenceChangeListener>> pair = prefsEntry.get(key);
        if (pair == null) {
            Log.w(TAG, "Shared preference not registered: ", key, " - ", prefs);
            return;
        }
        final List<OnSharedPreferenceChangeListener> list = pair.second;
        if (!list.remove(listener)) {
            Log.w(TAG, "Listener not registered: ", key, " - ", prefs);
            return;
        }
        if (list.isEmpty()) {
            prefsEntry.remove(key);
        }
    }
    if (prefsEntry.isEmpty()) {
        masterMap.remove(prefs);
        prefs.unregisterOnSharedPreferenceChangeListener(masterListener);
    }
}

From source file:com.firebase.jobdispatcher.GooglePlayReceiver.java

@Override
protected void onJobFinished(@NonNull JobParameters js, @JobResult int result) {
    synchronized (this) {
        SimpleArrayMap<String, JobCallback> map = callbacks.get(js.getService());
        if (map == null) {
            return;
        }//from w  w  w.ja va  2s . c o m

        JobCallback callback = map.remove(js.getTag());
        if (callback != null) {
            Log.i(TAG, "sending jobFinished for " + js.getTag() + " = " + result);
            callback.jobFinished(result);
        }

        if (map.isEmpty()) {
            callbacks.remove(js.getService());
        }
    }
}

From source file:com.android.messaging.datamodel.BugleDatabaseOperations.java

/**
 * Update draft message for specified conversation
 * @param dbWrapper       local database (wrapped)
 * @param conversationId  conversation to update
 * @param message         Optional message to preserve attachments for (either as draft or for
 *                        sending)//from   w w  w .jav  a 2s  . c o m
 * @param updateMode      either {@link #UPDATE_MODE_CLEAR_DRAFT} or
 *                        {@link #UPDATE_MODE_ADD_DRAFT}
 * @return message id of newly written draft (else null)
 */
@DoesNotRunOnMainThread
public static String updateDraftMessageData(final DatabaseWrapper dbWrapper, final String conversationId,
        @Nullable final MessageData message, final int updateMode) {
    Assert.isNotMainThread();
    Assert.notNull(conversationId);
    Assert.inRange(updateMode, UPDATE_MODE_CLEAR_DRAFT, UPDATE_MODE_ADD_DRAFT);
    String messageId = null;
    Cursor cursor = null;
    dbWrapper.beginTransaction();
    try {
        // Find all draft parts for the current conversation
        final SimpleArrayMap<Uri, MessagePartData> currentDraftParts = new SimpleArrayMap<>();
        cursor = dbWrapper.query(DatabaseHelper.DRAFT_PARTS_VIEW, MessagePartData.getProjection(),
                MessageColumns.CONVERSATION_ID + " =?", new String[] { conversationId }, null, null, null);
        while (cursor.moveToNext()) {
            final MessagePartData part = MessagePartData.createFromCursor(cursor);
            if (part.isAttachment()) {
                currentDraftParts.put(part.getContentUri(), part);
            }
        }
        // Optionally, preserve attachments for "message"
        final boolean conversationExists = getConversationExists(dbWrapper, conversationId);
        if (message != null && conversationExists) {
            for (final MessagePartData part : message.getParts()) {
                if (part.isAttachment()) {
                    currentDraftParts.remove(part.getContentUri());
                }
            }
        }

        // Delete orphan content
        for (int index = 0; index < currentDraftParts.size(); index++) {
            final MessagePartData part = currentDraftParts.valueAt(index);
            part.destroySync();
        }

        // Delete existing draft (cascade deletes parts)
        dbWrapper.delete(DatabaseHelper.MESSAGES_TABLE,
                MessageColumns.STATUS + "=? AND " + MessageColumns.CONVERSATION_ID + "=?",
                new String[] { Integer.toString(MessageData.BUGLE_STATUS_OUTGOING_DRAFT), conversationId });

        // Write new draft
        if (updateMode == UPDATE_MODE_ADD_DRAFT && message != null && message.hasContent()
                && conversationExists) {
            Assert.equals(MessageData.BUGLE_STATUS_OUTGOING_DRAFT, message.getStatus());

            // Now add draft to message table
            insertNewMessageInTransaction(dbWrapper, message);
            messageId = message.getMessageId();
        }

        if (conversationExists) {
            updateConversationDraftSnippetAndPreviewInTransaction(dbWrapper, conversationId, message);

            if (message != null && message.getSelfId() != null) {
                updateConversationSelfIdInTransaction(dbWrapper, conversationId, message.getSelfId());
            }
        }

        dbWrapper.setTransactionSuccessful();
    } finally {
        dbWrapper.endTransaction();
        if (cursor != null) {
            cursor.close();
        }
    }
    if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
        LogUtil.v(TAG, "Updated draft message " + messageId + " for conversation " + conversationId);
    }
    return messageId;
}