Java Code Examples for android.util.SparseBooleanArray#valueAt()

The following examples show how to use android.util.SparseBooleanArray#valueAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigureORMs.java    From Storm with Apache License 2.0 6 votes vote down vote up
@Override
public BuildConfig.ORM[] getSelectedValues() {

    final BuildConfig.ORM[] orms = BuildConfig.ORM.values();
    final SparseBooleanArray array = getSelectedPositions();
    final List<BuildConfig.ORM> list = new ArrayList<>();

    for (int i = 0; i < array.size(); i++) {
        if (array.valueAt(i)) {
            list.add(orms[array.keyAt(i)]);
        }
    }

    final BuildConfig.ORM[] selected = new BuildConfig.ORM[list.size()];
    list.toArray(selected);

    return selected;
}
 
Example 2
Source File: SelectPopupDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int[] getSelectedIndices(ListView listView) {
    SparseBooleanArray sparseArray = listView.getCheckedItemPositions();
    int selectedCount = 0;
    for (int i = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            selectedCount++;
        }
    }
    int[] indices = new int[selectedCount];
    for (int i = 0, j = 0; i < sparseArray.size(); ++i) {
        if (sparseArray.valueAt(i)) {
            indices[j++] = sparseArray.keyAt(i);
        }
    }
    return indices;
}
 
Example 3
Source File: MultiSelectionUtil.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    // Check to see what the new checked state is, and then notify the listener
    final boolean checked = mListView.isItemChecked(position);
    mListener.onItemCheckedStateChanged(mActionMode, position, id, checked);
    boolean hasCheckedItem = checked;
    // Check to see if we have any checked items
    if (!hasCheckedItem) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        if (checkedItemPositions != null) {
            // Iterate through the SparseBooleanArray to see if there is a checked item
            int i = 0;
            while (!hasCheckedItem && i < checkedItemPositions.size()) {
                hasCheckedItem = checkedItemPositions.valueAt(i++);
            }
        }
    }
    // If we don't have any checked items, finish the action mode
    if (!hasCheckedItem) {
        mActionMode.finish();
    }
}
 
Example 4
Source File: MultiSelectionUtil.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    // Check to see what the new checked state is, and then notify the listener
    final boolean checked = mListView.isItemChecked(position);
    mListener.onItemCheckedStateChanged(mActionMode, position, id, checked);
    boolean hasCheckedItem = checked;
    // Check to see if we have any checked items
    if (!hasCheckedItem) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        if (checkedItemPositions != null) {
            // Iterate through the SparseBooleanArray to see if there is a checked item
            int i = 0;
            while (!hasCheckedItem && i < checkedItemPositions.size()) {
                hasCheckedItem = checkedItemPositions.valueAt(i++);
            }
        }
    }
    // If we don't have any checked items, finish the action mode
    if (!hasCheckedItem) {
        mActionMode.finish();
    }
}
 
Example 5
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
private void deleteSelectedItems(){
    ArrayAdapter adapter = (ArrayAdapter) lvItemList.getAdapter();
    SparseBooleanArray checkedItemPositions = lvItemList.getCheckedItemPositions();
    ArrayList<CheckListItem> temp = new ArrayList<>();
    for (int i=0; i < checkedItemPositions.size(); i++) {
        if(checkedItemPositions.valueAt(i)) {
            temp.add((CheckListItem) adapter.getItem(checkedItemPositions.keyAt(i)));
        }
    }
    if (temp.size() > 0) {
        itemNamesList.removeAll(temp);
    }
}
 
Example 6
Source File: ListView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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}.
 *
 * @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 != CHOICE_MODE_NONE && mCheckStates != null && mAdapter != null) {
        final SparseBooleanArray 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];
}
 
Example 7
Source File: HListView.java    From Klyph with MIT License 5 votes vote down vote up
/**
 * 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}.
 * 
 * @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 SparseBooleanArray 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];
}
 
Example 8
Source File: ServerListActivity.java    From padland with Apache License 2.0 5 votes vote down vote up
private void uncheckAllItems() {
    if( listView == null ) {
        return;
    }
    SparseBooleanArray checked = listView.getCheckedItemPositions();
    for (int i = 0; i < checked.size(); i++) {
        // Item position in adapter
        int position = checked.keyAt(i);
        // Add sport if it is checked i.e.) == TRUE!
        if (checked.valueAt(i)) {
            listView.setItemChecked(position, false);
        }
    }
}
 
Example 9
Source File: ManageCategoriesActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
private void deleteSelectedItems(){
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    boolean delNotes = sp.getBoolean(SettingsActivity.PREF_DEL_NOTES, false);
    CursorAdapter adapter = (CursorAdapter) list.getAdapter();
    SparseBooleanArray checkedItemPositions = list.getCheckedItemPositions();
    for (int i=0; i < checkedItemPositions.size(); i++) {
        if(checkedItemPositions.valueAt(i)) {
            if (delNotes) {
                DbAccess.trashNotesByCategoryId(getBaseContext(), (int) (long) adapter.getItemId(checkedItemPositions.keyAt(i)));
            }
            DbAccess.deleteCategory(getBaseContext(), (int) (long) adapter.getItemId(checkedItemPositions.keyAt(i)));
        }
    }
}
 
Example 10
Source File: DragSortListView.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private static int findFirstSetIndex(SparseBooleanArray sba, int rangeStart, int rangeEnd) {
    int size = sba.size();
    int i = insertionIndexForKey(sba, rangeStart);
    while (i < size && sba.keyAt(i) < rangeEnd && !sba.valueAt(i))
        i++;
    if (i == size || sba.keyAt(i) >= rangeEnd)
        return -1;
    return i;
}
 
Example 11
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
	final SparseBooleanArray checked = mCurrentView.getCheckedItemPositions();
	final ArrayList<DocumentInfo> docs = new ArrayList<>();
	final int size = checked.size();
	for (int i = 0; i < size; i++) {
		if (checked.valueAt(i)) {
			final Cursor cursor = mAdapter.getItem(checked.keyAt(i));
                  if(null != cursor) {
                      final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
                      docs.add(doc);
                  }
		}
	}
          if(docs.isEmpty()){
              return false;
          }
	final int id = item.getItemId();
	switch (id) {
	case R.id.menu_open:
		BaseActivity.get(DirectoryFragment.this).onDocumentsPicked(docs);
		mode.finish();
		return true;

	case R.id.menu_share:
		onShareDocuments(docs);
		mode.finish();
		return true;

	case R.id.menu_copy:
		moveDocument(docs, false);
		mode.finish();
		return true;

	case R.id.menu_cut:
		moveDocument(docs, true);
		mode.finish();
		return true;

	case R.id.menu_delete:
		deleteDocument(docs, id);
		mode.finish();
		return true;

	case R.id.menu_stop:
		stopDocument(docs, id);
		mode.finish();
		return true;
	case R.id.menu_save:
          case R.id.menu_compress:
		new OperationTask(docs, id).execute();
		mode.finish();
		return true;

	case R.id.menu_select_all:
		int count = mAdapter.getCount();
		for (int i = 0; i < count; i++) {
			mCurrentView.setItemChecked(i, selectAll);
		}
		selectAll = !selectAll;
		Bundle params = new Bundle();
		params.putInt(FILE_COUNT, count);
		AnalyticsManager.logEvent("select", params);
		return true;

	case R.id.menu_info:
		infoDocument(docs.get(0));
		mode.finish();
		return true;

	case R.id.menu_rename:
		renameDocument(docs.get(0));
		mode.finish();
		return true;

	default:
		return false;
	}
}
 
Example 12
Source File: DragSortListView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private static int buildRunList(SparseBooleanArray cip, int rangeStart,
        int rangeEnd, int[] runStart, int[] runEnd) {
    int runCount = 0;

    int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
    if (i == -1)
        return 0;

    int position = cip.keyAt(i);
    int currentRunStart = position;
    int currentRunEnd = currentRunStart + 1;
    for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
        if (!cip.valueAt(i)) // not checked => not interesting
            continue;
        if (position == currentRunEnd) {
            currentRunEnd++;
        } else {
            runStart[runCount] = currentRunStart;
            runEnd[runCount] = currentRunEnd;
            runCount++;
            currentRunStart = position;
            currentRunEnd = position + 1;
        }
    }

    if (currentRunEnd == rangeEnd) {
        // rangeStart and rangeEnd are equivalent positions so to be
        // consistent we translate them to the same integer value. That way
        // we can check whether a run covers the entire range by just
        // checking if the start equals the end position.
        currentRunEnd = rangeStart;
    }
    runStart[runCount] = currentRunStart;
    runEnd[runCount] = currentRunEnd;
    runCount++;

    if (runCount > 1) {
        if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
            // The last run ends at the end of the range, and the first run
            // starts at the beginning of the range. So they are actually
            // part of the same run, except they wrap around the end of the
            // range. To avoid adjacent runs, we need to merge them.
            runStart[0] = runStart[runCount - 1];
            runCount--;
        }
    }
    return runCount;
}
 
Example 13
Source File: DragSortListView.java    From google-authenticator-android with Apache License 2.0 4 votes vote down vote up
private static int buildRunList(SparseBooleanArray cip, int rangeStart,
        int rangeEnd, int[] runStart, int[] runEnd) {
    int runCount = 0;

    int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
    if (i == -1)
        return 0;

    int position = cip.keyAt(i);
    int currentRunStart = position;
    int currentRunEnd = currentRunStart + 1;
    for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
        if (!cip.valueAt(i)) // not checked => not interesting
            continue;
        if (position == currentRunEnd) {
            currentRunEnd++;
        } else {
            runStart[runCount] = currentRunStart;
            runEnd[runCount] = currentRunEnd;
            runCount++;
            currentRunStart = position;
            currentRunEnd = position + 1;
        }
    }

    if (currentRunEnd == rangeEnd) {
        // rangeStart and rangeEnd are equivalent positions so to be
        // consistent we translate them to the same integer value. That way
        // we can check whether a run covers the entire range by just
        // checking if the start equals the end position.
        currentRunEnd = rangeStart;
    }
    runStart[runCount] = currentRunStart;
    runEnd[runCount] = currentRunEnd;
    runCount++;

    if (runCount > 1) {
        if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
            // The last run ends at the end of the range, and the first run
            // starts at the beginning of the range. So they are actually
            // part of the same run, except they wrap around the end of the
            // range. To avoid adjacent runs, we need to merge them.
            runStart[0] = runStart[runCount - 1];
            runCount--;
        }
    }
    return runCount;
}
 
Example 14
Source File: DragSortListView.java    From simpletask-android with GNU General Public License v3.0 4 votes vote down vote up
private static int buildRunList(@NonNull SparseBooleanArray cip, int rangeStart,
        int rangeEnd, int[] runStart, int[] runEnd) {
    int runCount = 0;

    int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
    if (i == -1)
        return 0;

    int position = cip.keyAt(i);
    int currentRunStart = position;
    int currentRunEnd = currentRunStart + 1;
    for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
        if (!cip.valueAt(i)) // not checked => not interesting
            continue;
        if (position == currentRunEnd) {
            currentRunEnd++;
        } else {
            runStart[runCount] = currentRunStart;
            runEnd[runCount] = currentRunEnd;
            runCount++;
            currentRunStart = position;
            currentRunEnd = position + 1;
        }
    }

    if (currentRunEnd == rangeEnd) {
        // rangeStart and rangeEnd are equivalent positions so to be
        // consistent we translate them to the same integer value. That way
        // we can check whether a run covers the entire range by just
        // checking if the start equals the end position.
        currentRunEnd = rangeStart;
    }
    runStart[runCount] = currentRunStart;
    runEnd[runCount] = currentRunEnd;
    runCount++;

    if (runCount > 1) {
        if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
            // The last run ends at the end of the range, and the first run
            // starts at the beginning of the range. So they are actually
            // part of the same run, except they wrap around the end of the
            // range. To avoid adjacent runs, we need to merge them.
            runStart[0] = runStart[runCount - 1];
            runCount--;
        }
    }
    return runCount;
}
 
Example 15
Source File: DragSortListView.java    From biermacht with Apache License 2.0 4 votes vote down vote up
private static int buildRunList(SparseBooleanArray cip, int rangeStart,
                                int rangeEnd, int[] runStart, int[] runEnd) {
  int runCount = 0;

  int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
  if (i == - 1) {
    return 0;
  }

  int position = cip.keyAt(i);
  int currentRunStart = position;
  int currentRunEnd = currentRunStart + 1;
  for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
    if (! cip.valueAt(i)) // not checked => not interesting
    {
      continue;
    }
    if (position == currentRunEnd) {
      currentRunEnd++;
    }
    else {
      runStart[runCount] = currentRunStart;
      runEnd[runCount] = currentRunEnd;
      runCount++;
      currentRunStart = position;
      currentRunEnd = position + 1;
    }
  }

  if (currentRunEnd == rangeEnd) {
    // rangeStart and rangeEnd are equivalent positions so to be
    // consistent we translate them to the same integer value. That way
    // we can check whether a run covers the entire range by just
    // checking if the start equals the end position.
    currentRunEnd = rangeStart;
  }
  runStart[runCount] = currentRunStart;
  runEnd[runCount] = currentRunEnd;
  runCount++;

  if (runCount > 1) {
    if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
      // The last run ends at the end of the range, and the first run
      // starts at the beginning of the range. So they are actually
      // part of the same run, except they wrap around the end of the
      // range. To avoid adjacent runs, we need to merge them.
      runStart[0] = runStart[runCount - 1];
      runCount--;
    }
  }
  return runCount;
}
 
Example 16
Source File: DragSortListView.java    From android-kernel-tweaker with GNU General Public License v3.0 4 votes vote down vote up
private static int buildRunList(SparseBooleanArray cip, int rangeStart,
        int rangeEnd, int[] runStart, int[] runEnd) {
    int runCount = 0;

    int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
    if (i == -1)
        return 0;

    int position = cip.keyAt(i);
    int currentRunStart = position;
    int currentRunEnd = currentRunStart + 1;
    for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
        if (!cip.valueAt(i)) // not checked => not interesting
            continue;
        if (position == currentRunEnd) {
            currentRunEnd++;
        } else {
            runStart[runCount] = currentRunStart;
            runEnd[runCount] = currentRunEnd;
            runCount++;
            currentRunStart = position;
            currentRunEnd = position + 1;
        }
    }

    if (currentRunEnd == rangeEnd) {
        // rangeStart and rangeEnd are equivalent positions so to be
        // consistent we translate them to the same integer value. That way
        // we can check whether a run covers the entire range by just
        // checking if the start equals the end position.
        currentRunEnd = rangeStart;
    }
    runStart[runCount] = currentRunStart;
    runEnd[runCount] = currentRunEnd;
    runCount++;

    if (runCount > 1) {
        if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
            // The last run ends at the end of the range, and the first run
            // starts at the beginning of the range. So they are actually
            // part of the same run, except they wrap around the end of the
            // range. To avoid adjacent runs, we need to merge them.
            runStart[0] = runStart[runCount - 1];
            runCount--;
        }
    }
    return runCount;
}
 
Example 17
Source File: History.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    // Calls getSelectedIds method from ListViewAdapter Class
    SparseBooleanArray selected = history.historyListAdapter
            .getSelectedIds();
    // Captures all selected ids with a loop
    List<Integer> selectedRecordIds = new ArrayList<Integer>();
    for (int i = (selected.size() - 1); i >= 0; i--) {
        if (selected.valueAt(i)) {
            selectedRecordIds.add((int)history.historyListAdapter.getItemId(selected.keyAt(i)));
        }
    }
    switch (item.getItemId()) {
        case R.id.delete:
            if(!selectedRecordIds.isEmpty()) {
                // Remove selected items following the ids
                history.historyListAdapter.remove(selectedRecordIds);
            }
            // Close CAB
            mode.finish();
            return true;
        case R.id.publish:
            boolean deleted = false;
            if(!selectedRecordIds.isEmpty()) {
                for(Integer recordId : new ArrayList<Integer>(selectedRecordIds)) {
                    Storage.Record record = history.measurementManager.getRecord(recordId);
                    if (!record.getUploadId().isEmpty()) {
                        selectedRecordIds.remove(recordId);
                        deleted = true;
                    }
                }
                if(deleted) {
                    Toast.makeText(history, history.getString(R.string.history_already_uploaded), Toast.LENGTH_LONG).show();
                }
                // publish selected items following the ids
                history.doTransferRecords(selectedRecordIds);
            }
            // Close CAB
            mode.finish();
            return true;
        default:
            return false;
    }
}
 
Example 18
Source File: ScansActivity.java    From spidey with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    // retrieve selected items and print them out
    ScanAdapter adapter = (ScanAdapter) ScansActivity.this.getListAdapter();
    SparseBooleanArray selected = adapter.getSelectedIds();
    
    if (item.getItemId() == R.id.compare_item)
    {
    
	    if (selected.size() == 2)
	    {
	    	Scan scanOne = adapter.getItem(selected.keyAt(0));
	    	Scan scanTwo = adapter.getItem(selected.keyAt(1));
	    	
	    	ScanDiff diff = ScanDiff.compare(scanOne, scanTwo);
	    	
	    	showDiffReport(diff);
	    	
	    }
	    else
	    {
	        Toast.makeText(ScansActivity.this, "Please select two scans to compare", Toast.LENGTH_LONG).show();
	    }
	    
    }
    else if (item.getItemId() == R.id.share_item)
    {
	    for (int i = 0; i < selected.size(); i++){               
	        if (selected.valueAt(i)) {
	            
	        	Scan selectedItem = adapter.getItem(selected.keyAt(i));
	        	
	        	
	        	String shareText = selectedItem.toString();
	        	shareText(shareText);
	            
	        }
	    }
    }
    
    
 
    // close action mode
    mode.finish();
    return false;
}
 
Example 19
Source File: DragSortListView.java    From Field-Book with GNU General Public License v2.0 4 votes vote down vote up
private static int buildRunList(SparseBooleanArray cip, int rangeStart, int rangeEnd,
                                int[] runStart, int[] runEnd) {

    int runCount = 0;

    int i = findFirstSetIndex(cip, rangeStart, rangeEnd);
    if (i == -1)
        return 0;

    int position = cip.keyAt(i);
    int currentRunStart = position;
    int currentRunEnd = currentRunStart + 1;
    for (i++; i < cip.size() && (position = cip.keyAt(i)) < rangeEnd; i++) {
        if (!cip.valueAt(i)) // not checked => not interesting
            continue;
        if (position == currentRunEnd) {
            currentRunEnd++;
        } else {
            runStart[runCount] = currentRunStart;
            runEnd[runCount] = currentRunEnd;
            runCount++;
            currentRunStart = position;
            currentRunEnd = position + 1;
        }
    }

    if (currentRunEnd == rangeEnd) {
        // rangeStart and rangeEnd are equivalent positions so to be
        // consistent we translate them to the same integer value. That way
        // we can check whether a run covers the entire range by just
        // checking if the start equals the end position.
        currentRunEnd = rangeStart;
    }
    runStart[runCount] = currentRunStart;
    runEnd[runCount] = currentRunEnd;
    runCount++;

    if (runCount > 1) {
        if (runStart[0] == rangeStart && runEnd[runCount - 1] == rangeStart) {
            // The last run ends at the end of the range, and the first run
            // starts at the beginning of the range. So they are actually
            // part of the same run, except they wrap around the end of the
            // range. To avoid adjacent runs, we need to merge them.
            runStart[0] = runStart[runCount - 1];
            runCount--;
        }
    }
    return runCount;
}
 
Example 20
Source File: TrustManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case MSG_REGISTER_LISTENER:
            addListener((ITrustListener) msg.obj);
            break;
        case MSG_UNREGISTER_LISTENER:
            removeListener((ITrustListener) msg.obj);
            break;
        case MSG_DISPATCH_UNLOCK_ATTEMPT:
            dispatchUnlockAttempt(msg.arg1 != 0, msg.arg2);
            break;
        case MSG_DISPATCH_UNLOCK_LOCKOUT:
            dispatchUnlockLockout(msg.arg1, msg.arg2);
            break;
        case MSG_ENABLED_AGENTS_CHANGED:
            refreshAgentList(UserHandle.USER_ALL);
            // This is also called when the security mode of a user changes.
            refreshDeviceLockedForUser(UserHandle.USER_ALL);
            break;
        case MSG_KEYGUARD_SHOWING_CHANGED:
            refreshDeviceLockedForUser(mCurrentUser);
            break;
        case MSG_START_USER:
        case MSG_CLEANUP_USER:
        case MSG_UNLOCK_USER:
            refreshAgentList(msg.arg1);
            break;
        case MSG_SWITCH_USER:
            mCurrentUser = msg.arg1;
            refreshDeviceLockedForUser(UserHandle.USER_ALL);
            break;
        case MSG_STOP_USER:
            setDeviceLockedForUser(msg.arg1, true);
            break;
        case MSG_FLUSH_TRUST_USUALLY_MANAGED:
            SparseBooleanArray usuallyManaged;
            synchronized (mTrustUsuallyManagedForUser) {
                usuallyManaged = mTrustUsuallyManagedForUser.clone();
            }

            for (int i = 0; i < usuallyManaged.size(); i++) {
                int userId = usuallyManaged.keyAt(i);
                boolean value = usuallyManaged.valueAt(i);
                if (value != mLockPatternUtils.isTrustUsuallyManaged(userId)) {
                    mLockPatternUtils.setTrustUsuallyManaged(value, userId);
                }
            }
            break;
        case MSG_REFRESH_DEVICE_LOCKED_FOR_USER:
            refreshDeviceLockedForUser(msg.arg1);
            break;
    }
}