Example usage for android.support.v4.util SparseArrayCompat keyAt

List of usage examples for android.support.v4.util SparseArrayCompat keyAt

Introduction

In this page you can find the example usage for android.support.v4.util SparseArrayCompat keyAt.

Prototype

public int keyAt(int i) 

Source Link

Usage

From source file:com.indeema.mail.browse.ConversationCursor.java

/**
 * If a destructive notification action was triggered, but has not yet been processed because an
 * "Undo" action is available, we do not want to show the conversation in the list.
 *///from   w w w. j  a v  a 2s  .c o  m
public void handleNotificationActions() {
    // Needs to be on the UI thread because it updates the ConversationCursor's internal
    // state which violates assumptions about how the ListView works and how
    // the ConversationViewPager works if performed off of the UI thread.
    // Also, prevents ConcurrentModificationExceptions on mNotificationTempDeleted.
    mMainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            final SparseArrayCompat<NotificationAction> undoNotifications = NotificationActionUtils.sUndoNotifications;
            final Set<Conversation> undoneConversations = NotificationActionUtils.sUndoneConversations;

            final Set<Conversation> undoConversations = Sets
                    .newHashSetWithExpectedSize(undoNotifications.size());

            boolean changed = false;

            for (int i = 0; i < undoNotifications.size(); i++) {
                final NotificationAction notificationAction = undoNotifications.get(undoNotifications.keyAt(i));

                // We only care about notifications that were for this folder
                // or if the action was delete
                final Folder folder = notificationAction.getFolder();
                final boolean deleteAction = notificationAction
                        .getNotificationActionType() == NotificationActionType.DELETE;

                if (folder.conversationListUri.equals(qUri) || deleteAction) {
                    // We only care about destructive actions
                    if (notificationAction.getNotificationActionType().getIsDestructive()) {
                        final Conversation conversation = notificationAction.getConversation();

                        undoConversations.add(conversation);

                        if (!mNotificationTempDeleted.contains(conversation)) {
                            sProvider.deleteLocal(conversation.uri, ConversationCursor.this);
                            mNotificationTempDeleted.add(conversation);

                            changed = true;
                        }
                    }
                }
            }

            // Remove any conversations from the temporary deleted state
            // if they no longer have an undo notification
            final Iterator<Conversation> iterator = mNotificationTempDeleted.iterator();
            while (iterator.hasNext()) {
                final Conversation conversation = iterator.next();

                if (!undoConversations.contains(conversation)) {
                    // We should only be un-deleting local cursor edits
                    // if the notification was undone rather than just
                    // disappearing because the internal cursor
                    // gets updated when the undo goes away via timeout which
                    // will update everything properly.
                    if (undoneConversations.contains(conversation)) {
                        sProvider.undeleteLocal(conversation.uri, ConversationCursor.this);
                        undoneConversations.remove(conversation);
                    }
                    iterator.remove();

                    changed = true;
                }
            }

            if (changed) {
                notifyDataChanged();
            }
        }
    });
}

From source file:com.chen.mail.browse.ConversationCursor.java

/**
 * If a destructive notification action was triggered, but has not yet been processed because an
 * "Undo" action is available, we do not want to show the conversation in the list.
 *//*from   ww w .  j  a  v  a 2s . c o  m*/
public void handleNotificationActions() {
    // Needs to be on the UI thread because it updates the ConversationCursor's internal
    // state which violates assumptions about how the ListView works and how
    // the ConversationViewPager works if performed off of the UI thread.
    // Also, prevents ConcurrentModificationExceptions on mNotificationTempDeleted.
    mMainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            final SparseArrayCompat<NotificationActionUtils.NotificationAction> undoNotifications = NotificationActionUtils.sUndoNotifications;
            final Set<Conversation> undoneConversations = NotificationActionUtils.sUndoneConversations;

            final Set<Conversation> undoConversations = Sets
                    .newHashSetWithExpectedSize(undoNotifications.size());

            boolean changed = false;

            for (int i = 0; i < undoNotifications.size(); i++) {
                final NotificationActionUtils.NotificationAction notificationAction = undoNotifications
                        .get(undoNotifications.keyAt(i));

                // We only care about notifications that were for this folder
                // or if the action was delete
                final Folder folder = notificationAction.getFolder();
                final boolean deleteAction = notificationAction
                        .getNotificationActionType() == NotificationActionUtils.NotificationActionType.DELETE;

                if (folder.conversationListUri.equals(qUri) || deleteAction) {
                    // We only care about destructive actions
                    if (notificationAction.getNotificationActionType().getIsDestructive()) {
                        final Conversation conversation = notificationAction.getConversation();

                        undoConversations.add(conversation);

                        if (!mNotificationTempDeleted.contains(conversation)) {
                            sProvider.deleteLocal(conversation.uri, ConversationCursor.this);
                            mNotificationTempDeleted.add(conversation);

                            changed = true;
                        }
                    }
                }
            }

            // Remove any conversations from the temporary deleted state
            // if they no longer have an undo notification
            final Iterator<Conversation> iterator = mNotificationTempDeleted.iterator();
            while (iterator.hasNext()) {
                final Conversation conversation = iterator.next();

                if (!undoConversations.contains(conversation)) {
                    // We should only be un-deleting local cursor edits
                    // if the notification was undone rather than just
                    // disappearing because the internal cursor
                    // gets updated when the undo goes away via timeout which
                    // will update everything properly.
                    if (undoneConversations.contains(conversation)) {
                        sProvider.undeleteLocal(conversation.uri, ConversationCursor.this);
                        undoneConversations.remove(conversation);
                    }
                    iterator.remove();

                    changed = true;
                }
            }

            if (changed) {
                notifyDataChanged();
            }
        }
    });
}

From source file:com.android.mail.browse.ConversationCursor.java

/**
 * If a destructive notification action was triggered, but has not yet been processed because an
 * "Undo" action is available, we do not want to show the conversation in the list.
 *///from w  w  w  .j a  va 2  s .c o m
public void handleNotificationActions() {
    // Needs to be on the UI thread because it updates the ConversationCursor's internal
    // state which violates assumptions about how the ListView works and how
    // the ConversationViewPager works if performed off of the UI thread.
    // Also, prevents ConcurrentModificationExceptions on mNotificationTempDeleted.
    mMainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            final SparseArrayCompat<NotificationAction> undoNotifications = NotificationActionUtils.sUndoNotifications;
            final Set<Conversation> undoneConversations = NotificationActionUtils.sUndoneConversations;

            final Set<Conversation> undoConversations = Sets
                    .newHashSetWithExpectedSize(undoNotifications.size());

            boolean changed = false;

            for (int i = 0; i < undoNotifications.size(); i++) {
                final NotificationAction notificationAction = undoNotifications.get(undoNotifications.keyAt(i));

                // We only care about notifications that were for this folder
                // or if the action was delete
                final Folder folder = notificationAction.getFolder();
                final boolean deleteAction = notificationAction
                        .getNotificationActionType() == NotificationActionType.DELETE;

                if (folder.conversationListUri.equals(qUri) || deleteAction) {
                    // We only care about destructive actions
                    if (notificationAction.getNotificationActionType().getIsDestructive()) {
                        final Conversation conversation = notificationAction.getConversation();

                        undoConversations.add(conversation);

                        if (!mNotificationTempDeleted.contains(conversation)) {
                            sProvider.deleteLocal(conversation.uri, ConversationCursor.this, null);
                            mNotificationTempDeleted.add(conversation);

                            changed = true;
                        }
                    }
                }
            }

            // Remove any conversations from the temporary deleted state
            // if they no longer have an undo notification
            final Iterator<Conversation> iterator = mNotificationTempDeleted.iterator();
            while (iterator.hasNext()) {
                final Conversation conversation = iterator.next();

                if (!undoConversations.contains(conversation)) {
                    // We should only be un-deleting local cursor edits
                    // if the notification was undone rather than just
                    // disappearing because the internal cursor
                    // gets updated when the undo goes away via timeout which
                    // will update everything properly.
                    if (undoneConversations.contains(conversation)) {
                        sProvider.undeleteLocal(conversation.uri, ConversationCursor.this);
                        undoneConversations.remove(conversation);
                    }
                    iterator.remove();

                    changed = true;
                }
            }

            if (changed) {
                notifyDataChanged();
            }
        }
    });
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE}.//w w w.  j a va 2s  . c om
 * 
 * @return A new array which contains the id of each checked item in the list.
 * 
 * @deprecated Use {@link #getCheckedItemIds()} instead.
 */
@Deprecated
public long[] getCheckItemIds() {
    // Use new behavior that correctly handles stable ID mapping.
    if (mAdapter != null && mAdapter.hasStableIds()) {
        return getCheckedItemIds();
    }

    // Old behavior was buggy, but would sort of work for adapters without stable IDs.
    // Fall back to it to support legacy apps.
    if (mChoiceMode != AbsListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) {
        final SparseArrayCompat<Boolean> states = mCheckStates;
        final int count = states.size();
        final long[] ids = new long[count];
        final ListAdapter adapter = mAdapter;

        int checkedCount = 0;
        for (int i = 0; i < count; i++) {
            if (states.valueAt(i)) {
                ids[checkedCount++] = adapter.getItemId(states.keyAt(i));
            }
        }

        // Trim array if needed. mCheckStates may contain false values
        // resulting in checkedCount being smaller than count.
        if (checkedCount == count) {
            return ids;
        } else {
            final long[] result = new long[checkedCount];
            System.arraycopy(ids, 0, result, 0, checkedCount);

            return result;
        }
    }
    return new long[0];
}

From source file:com.awrtechnologies.valor.valorfireplace.hlistview.widget.HListView.java

/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE}./* w  w w .  j av a2 s.  c o  m*/
 * 
 * @return A new array which contains the id of each checked item in the list.
 * 
 * @deprecated Use {@link #getCheckedItemIds()} instead.
 */
@Deprecated
public long[] getCheckItemIds() {
    // Use new behavior that correctly handles stable ID mapping.
    if (mAdapter != null && mAdapter.hasStableIds()) {
        return getCheckedItemIds();
    }

    // Old behavior was buggy, but would sort of work for adapters without stable IDs.
    // Fall back to it to support legacy apps.
    if (mChoiceMode != ListView.CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) {
        final SparseArrayCompat<Boolean> states = mCheckStates;
        final int count = states.size();
        final long[] ids = new long[count];
        final ListAdapter adapter = mAdapter;

        int checkedCount = 0;
        for (int i = 0; i < count; i++) {
            if (states.valueAt(i)) {
                ids[checkedCount++] = adapter.getItemId(states.keyAt(i));
            }
        }

        // Trim array if needed. mCheckStates may contain false values
        // resulting in checkedCount being smaller than count.
        if (checkedCount == count) {
            return ids;
        } else {
            final long[] result = new long[checkedCount];
            System.arraycopy(ids, 0, result, 0, checkedCount);

            return result;
        }
    }
    return new long[0];
}