Search in sources :

Example 41 with SparseBooleanArray

use of android.util.SparseBooleanArray in project SeriesGuide by UweTrottmann.

the class ManageListsDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View layout = inflater.inflate(R.layout.dialog_manage_lists, container, false);
    // buttons
    Button dontAddButton = (Button) layout.findViewById(R.id.buttonNegative);
    dontAddButton.setText(android.R.string.cancel);
    dontAddButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    Button addButton = (Button) layout.findViewById(R.id.buttonPositive);
    addButton.setText(android.R.string.ok);
    addButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // add item to selected lists, remove from previously selected lists
            SparseBooleanArray checkedLists = mAdapter.getCheckedPositions();
            List<String> addToTheseLists = new ArrayList<>();
            List<String> removeFromTheseLists = new ArrayList<>();
            for (int position = 0; position < mAdapter.getCount(); position++) {
                final Cursor listEntry = (Cursor) mAdapter.getItem(position);
                boolean wasListChecked = !TextUtils.isEmpty(listEntry.getString(ListsQuery.LIST_ITEM_ID));
                boolean isListChecked = checkedLists.get(position);
                String listId = listEntry.getString(ListsQuery.LIST_ID);
                if (wasListChecked && !isListChecked) {
                    // remove from list
                    removeFromTheseLists.add(listId);
                } else if (!wasListChecked && isListChecked) {
                    // add to list
                    addToTheseLists.add(listId);
                }
            }
            int itemTvdbId = getArguments().getInt(InitBundle.INT_ITEM_TVDB_ID);
            int itemType = getArguments().getInt(InitBundle.INT_ITEM_TYPE);
            ListsTools.changeListsOfItem(SgApp.from(getActivity()), itemTvdbId, itemType, addToTheseLists, removeFromTheseLists);
            dismiss();
        }
    });
    // lists list
    mListView = (ListView) layout.findViewById(R.id.list);
    /*
         * As using CHOICE_MODE_MULTIPLE does not seem to work before Jelly
         * Bean, do everything ourselves.
         */
    mListView.setOnItemClickListener(this);
    return layout;
}
Also used : Button(android.widget.Button) SparseBooleanArray(android.util.SparseBooleanArray) OnClickListener(android.view.View.OnClickListener) ArrayList(java.util.ArrayList) List(java.util.List) Cursor(android.database.Cursor) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView)

Example 42 with SparseBooleanArray

use of android.util.SparseBooleanArray in project Fragmentation by YoKeyword.

the class MenuAdapter method setDatas.

public void setDatas(List<String> items) {
    mItems.clear();
    mItems.addAll(items);
    mBooleanArray = new SparseBooleanArray(mItems.size());
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray)

Example 43 with SparseBooleanArray

use of android.util.SparseBooleanArray in project GT by Tencent.

the class DragSortListView method moveCheckState.

/**
     * Use this to move the check state of an item from one position to another
     * in a drop operation. If you have a choiceMode which is not none, this
     * method must be called when the order of items changes in an underlying
     * adapter which does not have stable IDs (see
     * {@link ListAdapter#hasStableIds()}). This is because without IDs, the
     * ListView has no way of knowing which items have moved where, and cannot
     * update the check state accordingly.
     * <p>
     * A word of warning about a "feature" in Android that you may run into when
     * dealing with movable list items: for an adapter that <em>does</em> have
     * stable IDs, ListView will attempt to locate each item based on its ID and
     * move the check state from the item's old position to the new position —
     * which is all fine and good (and removes the need for calling this
     * function), except for the half-baked approach. Apparently to save time in
     * the naive algorithm used, ListView will only search for an ID in the
     * close neighborhood of the old position. If the user moves an item too far
     * (specifically, more than 20 rows away), ListView will give up and just
     * force the item to be unchecked. So if there is a reasonable chance that
     * the user will move items more than 20 rows away from the original
     * position, you may wish to use an adapter with unstable IDs and call this
     * method manually instead.
     * 
     * @param from
     * @param to
     */
public void moveCheckState(int from, int to) {
    // This method runs in O(n log n) time (n being the number of list
    // items). The bottleneck is the call to AbsListView.setItemChecked,
    // which is O(log n) because of the binary search involved in calling
    // SparseBooleanArray.put().
    //
    // To improve on the average time, we minimize the number of calls to
    // setItemChecked by only calling it for items that actually have a
    // changed state. This is achieved by building a list containing the
    // start and end of the "runs" of checked items, and then moving the
    // runs. Note that moving an item from A to B is essentially a rotation
    // of the range of items in [A, B]. Let's say we have
    // . . U V X Y Z . .
    // and move U after Z. This is equivalent to a rotation one step to the
    // left within the range you are moving across:
    // . . V X Y Z U . .
    //
    // So, to perform the move we enumerate all the runs within the move
    // range, then rotate each run one step to the left or right (depending
    // on move direction). For example, in the list:
    // X X . X X X . X
    // we have two runs. One begins at the last item of the list and wraps
    // around to the beginning, ending at position 1. The second begins at
    // position 3 and ends at position 5. To rotate a run, regardless of
    // length, we only need to set a check mark at one end of the run, and
    // clear a check mark at the other end:
    // X . X X X . X X
    SparseBooleanArray cip = getCheckedItemPositions();
    int rangeStart = from;
    int rangeEnd = to;
    if (to < from) {
        rangeStart = to;
        rangeEnd = from;
    }
    rangeEnd += 1;
    int[] runStart = new int[cip.size()];
    int[] runEnd = new int[cip.size()];
    int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd);
    if (runCount == 1 && (runStart[0] == runEnd[0])) {
        // item to false like we do below.
        return;
    }
    if (from < to) {
        for (int i = 0; i != runCount; i++) {
            setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd), true);
            setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false);
        }
    } else {
        for (int i = 0; i != runCount; i++) {
            setItemChecked(runStart[i], false);
            setItemChecked(runEnd[i], true);
        }
    }
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray) Point(android.graphics.Point)

Example 44 with SparseBooleanArray

use of android.util.SparseBooleanArray in project android_frameworks_base by ParanoidAndroid.

the class NetworkPolicyManagerService method computeUidForegroundLocked.

/**
     * Foreground for PID changed; recompute foreground at UID level. If
     * changed, will trigger {@link #updateRulesForUidLocked(int)}.
     */
private void computeUidForegroundLocked(int uid) {
    final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
    // current pid is dropping foreground; examine other pids
    boolean uidForeground = false;
    final int size = pidForeground.size();
    for (int i = 0; i < size; i++) {
        if (pidForeground.valueAt(i)) {
            uidForeground = true;
            break;
        }
    }
    final boolean oldUidForeground = mUidForeground.get(uid, false);
    if (oldUidForeground != uidForeground) {
        // foreground changed, push updated rules
        mUidForeground.put(uid, uidForeground);
        updateRulesForUidLocked(uid);
    }
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray)

Example 45 with SparseBooleanArray

use of android.util.SparseBooleanArray in project android_frameworks_base by ParanoidAndroid.

the class UsbSettingsManager method dump.

public void dump(FileDescriptor fd, PrintWriter pw) {
    synchronized (mLock) {
        pw.println("  Device permissions:");
        for (String deviceName : mDevicePermissionMap.keySet()) {
            pw.print("    " + deviceName + ": ");
            SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
            int count = uidList.size();
            for (int i = 0; i < count; i++) {
                pw.print(Integer.toString(uidList.keyAt(i)) + " ");
            }
            pw.println("");
        }
        pw.println("  Accessory permissions:");
        for (UsbAccessory accessory : mAccessoryPermissionMap.keySet()) {
            pw.print("    " + accessory + ": ");
            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
            int count = uidList.size();
            for (int i = 0; i < count; i++) {
                pw.print(Integer.toString(uidList.keyAt(i)) + " ");
            }
            pw.println("");
        }
        pw.println("  Device preferences:");
        for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
            pw.println("    " + filter + ": " + mDevicePreferenceMap.get(filter));
        }
        pw.println("  Accessory preferences:");
        for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
            pw.println("    " + filter + ": " + mAccessoryPreferenceMap.get(filter));
        }
    }
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray) UsbAccessory(android.hardware.usb.UsbAccessory)

Aggregations

SparseBooleanArray (android.util.SparseBooleanArray)235 Selection (com.android.documentsui.dirlist.MultiSelectManager.Selection)30 ArrayList (java.util.ArrayList)25 View (android.view.View)20 Point (android.graphics.Point)18 ViewGroup (android.view.ViewGroup)16 Paint (android.graphics.Paint)13 HashMap (java.util.HashMap)12 Map (java.util.Map)11 SparseArray (android.util.SparseArray)7 File (java.io.File)7 Pattern (java.util.regex.Pattern)7 Cursor (android.database.Cursor)6 SparseIntArray (android.util.SparseIntArray)6 ActionMenuChildView (com.actionbarsherlock.internal.view.menu.ActionMenuView.ActionMenuChildView)6 IndentingPrintWriter (com.android.internal.util.IndentingPrintWriter)6 Account (android.accounts.Account)5 NonNull (android.annotation.NonNull)5 ContentValues (android.content.ContentValues)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)5