Search in sources :

Example 1 with MultiChoiceModeWrapper

use of it.sephiroth.android.library.util.v11.MultiChoiceModeWrapper in project Klyph by jonathangerbaud.

the class AbsHListView method confirmCheckedPositionsById.

@TargetApi(16)
void confirmCheckedPositionsById() {
    // Clear out the positional check states, we'll rebuild it below from IDs.
    mCheckStates.clear();
    boolean checkedCountChanged = false;
    for (int checkedIndex = 0; checkedIndex < mCheckedIdStates.size(); checkedIndex++) {
        final long id = mCheckedIdStates.keyAt(checkedIndex);
        final int lastPos = mCheckedIdStates.valueAt(checkedIndex);
        final long lastPosId = mAdapter.getItemId(lastPos);
        if (id != lastPosId) {
            // Look around to see if the ID is nearby. If not, uncheck it.
            final int start = Math.max(0, lastPos - CHECK_POSITION_SEARCH_DISTANCE);
            final int end = Math.min(lastPos + CHECK_POSITION_SEARCH_DISTANCE, mItemCount);
            boolean found = false;
            for (int searchPos = start; searchPos < end; searchPos++) {
                final long searchId = mAdapter.getItemId(searchPos);
                if (id == searchId) {
                    found = true;
                    mCheckStates.put(searchPos, true);
                    mCheckedIdStates.setValueAt(checkedIndex, searchPos);
                    break;
                }
            }
            if (!found) {
                mCheckedIdStates.delete(id);
                checkedIndex--;
                mCheckedItemCount--;
                checkedCountChanged = true;
                if (android.os.Build.VERSION.SDK_INT > 11) {
                    if (mChoiceActionMode != null && mMultiChoiceModeCallback != null) {
                        ((MultiChoiceModeWrapper) mMultiChoiceModeCallback).onItemCheckedStateChanged((ActionMode) mChoiceActionMode, lastPos, id, false);
                    }
                }
            }
        } else {
            mCheckStates.put(lastPos, true);
        }
    }
    if (checkedCountChanged && mChoiceActionMode != null) {
        ((ActionMode) mChoiceActionMode).invalidate();
    }
}
Also used : ActionMode(android.view.ActionMode) MultiChoiceModeWrapper(it.sephiroth.android.library.util.v11.MultiChoiceModeWrapper) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 ActionMode (android.view.ActionMode)1 MultiChoiceModeWrapper (it.sephiroth.android.library.util.v11.MultiChoiceModeWrapper)1