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

The following examples show how to use android.util.SparseBooleanArray#put() . 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: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @return ids of tasks that are presented in Recents UI.
 */
SparseBooleanArray getRecentTaskIds() {
    final SparseBooleanArray res = new SparseBooleanArray();
    final int size = mTasks.size();
    int numVisibleTasks = 0;
    for (int i = 0; i < size; i++) {
        final TaskRecord tr = mTasks.get(i);
        if (isVisibleRecentTask(tr)) {
            numVisibleTasks++;
            if (isInVisibleRange(tr, numVisibleTasks)) {
                res.put(tr.taskId, true);
            }
        }
    }
    return res;
}
 
Example 2
Source File: GroupCreateActivity.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
private void updateGroupParticipants() {
  SparseBooleanArray currentChatContactIds = new SparseBooleanArray();
  for(int chatContactId : dcContext.getChatContacts(groupChatId)) {
    currentChatContactIds.put(chatContactId, false);
  }

  Set<Recipient> recipients = getAdapter().getRecipients();
  for(Recipient recipient : recipients) {
    Address address = recipient.getAddress();
    if(address.isDcContact()) {
      int contactId = address.getDcContactId();
      if(currentChatContactIds.indexOfKey(contactId) < 0) {
        dcContext.addContactToChat(groupChatId, contactId);
      } else {
        currentChatContactIds.put(contactId, true);
      }
    }
  }
  for(int index = 0; index < currentChatContactIds.size(); index++) {
    if (!currentChatContactIds.valueAt(index)) {
      dcContext.removeContactFromChat(groupChatId, currentChatContactIds.keyAt(index));
    }
  }
}
 
Example 3
Source File: TableLayout.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Parses a sequence of columns ids defined in a CharSequence with the
 * following pattern (regex): \d+(\s*,\s*\d+)*</p>
 *
 * <p>Examples: "1" or "13, 7, 6" or "".</p>
 *
 * <p>The result of the parsing is stored in a sparse boolean array. The
 * parsed column ids are used as the keys of the sparse array. The values
 * are always true.</p>
 *
 * @param sequence a sequence of column ids, can be empty but not null
 * @return a sparse array of boolean mapping column indexes to the columns
 *         collapse state
 */
private static SparseBooleanArray parseColumns(String sequence) {
    SparseBooleanArray columns = new SparseBooleanArray();
    Pattern pattern = Pattern.compile("\\s*,\\s*");
    String[] columnDefs = pattern.split(sequence);

    for (String columnIdentifier : columnDefs) {
        try {
            int columnIndex = Integer.parseInt(columnIdentifier);
            // only valid, i.e. positive, columns indexes are handled
            if (columnIndex >= 0) {
                // putting true in this sparse array indicates that the
                // column index was defined in the XML file
                columns.put(columnIndex, true);
            }
        } catch (NumberFormatException e) {
            // we just ignore columns that don't exist
        }
    }

    return columns;
}
 
Example 4
Source File: ImageSlideshow.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 设置指示器
 */
private void setIndicator() {
    try {
        isLarge = new SparseBooleanArray();
        // 记得创建前先清空数据,否则会受遗留数据的影响。
        llDot.removeAllViews();
        for (int i = 0; i < count; i++) {
            View view = new View(context);
            view.setBackgroundResource(R.drawable.found_vp_indicator_normal);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Utils.dip2px(9), Utils.dip2px(3));
            if (i != 0) {
                layoutParams.leftMargin = dotSpace;
            }
            llDot.addView(view, layoutParams);
            isLarge.put(i, false);
        }
        llDot.getChildAt(0).setBackgroundResource(R.drawable.found_vp_indicator_focused);
        animatorToLarge.setTarget(llDot.getChildAt(0));
        animatorToLarge.start();
        isLarge.put(0, true);
    } catch (Exception e) {

    }
}
 
Example 5
Source File: BasicAdapter.java    From basic-adapter with MIT License 6 votes vote down vote up
private void initCheckStates() {
    mCheckStates = new SparseBooleanArray();

    for (int i = mData.size() - 1; i >= 0; i--) {
        T t = mData.get(i);
        if (mParams.choiceMode == BasicController.CHOICE_MODE_SINGLE) {
            mCheckStates.put(i, isItemChecked(t, i));
            if (isItemChecked(t, i)) {
                break;
            }
        } else if (mParams.choiceMode == BasicController.CHOICE_MODE_MULTIPLE) {
            mCheckStates.put(i, isItemChecked(t, i));
        }
    }

}
 
Example 6
Source File: FakeExtractorInput.java    From ExoPlayer-Offline with Apache License 2.0 6 votes vote down vote up
private boolean checkXFully(boolean allowEndOfInput, int position, int length,
    SparseBooleanArray failedPositions) throws IOException {
  if (simulateIOErrors && !failedPositions.get(position)) {
    failedPositions.put(position, true);
    peekPosition = readPosition;
    throw new SimulatedIOException("Simulated IO error at position: " + position);
  }
  if (length > 0 && position == data.length) {
    if (allowEndOfInput) {
      return false;
    }
    throw new EOFException();
  }
  if (position + length > data.length) {
    throw new EOFException("Attempted to move past end of data: (" + position + " + "
        + length + ") > " + data.length);
  }
  return true;
}
 
Example 7
Source File: MultiCurrencyListAdapter.java    From mobikul-standalone-pos with MIT License 5 votes vote down vote up
public MultiCurrencyListAdapter(Context context, List<ExtendedCurrency> currencies, Set<String> selectedCurrencies) {
    super();
    this.mContext = context;
    this.currencies = currencies;
    this.selectedCurrencies = selectedCurrencies;
    checkedCurrencies = new SparseBooleanArray(currencies.size());
    for(String code : selectedCurrencies){
        int position = currencies.indexOf(ExtendedCurrency.getCurrencyByISO(code));
        checkedCurrencies.put(position, true);
    }

    inflater = LayoutInflater.from(context);
}
 
Example 8
Source File: SparseParcelable.java    From android-parcelable-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public static SparseParcelable create() {
    SparseArray<String> sampleSparseArray = new SparseArray<String>(10);
    sampleSparseArray.put(10, "abcd");

    SparseBooleanArray sparseBooleanArray = new SparseBooleanArray();
    sparseBooleanArray.put(1, false);

    return new SparseParcelable(
            sampleSparseArray,
            sparseBooleanArray
    );
}
 
Example 9
Source File: BaseConfigureChildFragment.java    From Storm with Apache License 2.0 5 votes vote down vote up
protected SparseBooleanArray getSelectedPositions() {
    final SparseBooleanArray array = new SparseBooleanArray();
    final ConfigureAdapterItem[] items = mAdapter.getItems();
    for (int i = 0; i < items.length; i++) {
        if (items[i].isChecked()) {
            array.put(i, true);
        }
    }
    return array;
}
 
Example 10
Source File: NetworkStats.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Return list of unique UIDs known by this data structure.
 */
public int[] getUniqueUids() {
    final SparseBooleanArray uids = new SparseBooleanArray();
    for (int uid : this.uid) {
        uids.put(uid, true);
    }

    final int size = uids.size();
    final int[] result = new int[size];
    for (int i = 0; i < size; i++) {
        result[i] = uids.keyAt(i);
    }
    return result;
}
 
Example 11
Source File: TypeAdapterTest.java    From paperparcel with Apache License 2.0 5 votes vote down vote up
@Test public void sparseBooleanArraysAreCorrectlyParcelled() {
  TypeAdapter<SparseBooleanArray> adapter = StaticAdapters.SPARSE_BOOLEAN_ARRAY_ADAPTER;
  SparseBooleanArray expected = new SparseBooleanArray();
  expected.put(42, false);
  expected.put(420, true);
  SparseBooleanArray result = writeThenRead(adapter, expected);
  assertThat(expected.size()).isEqualTo(result.size());
  for (int i = 0; i < result.size(); i++) {
    assertThat(result.keyAt(i)).isEqualTo(expected.keyAt(i));
    assertThat(result.valueAt(i)).isEqualTo(expected.valueAt(i));
  }
}
 
Example 12
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public SparseBooleanArray getKnownUsersLocked() {
    SparseBooleanArray users = new SparseBooleanArray();
    for (int i = mSettingsStates.size()-1; i >= 0; i--) {
        users.put(getUserIdFromKey(mSettingsStates.keyAt(i)), true);
    }
    return users;
}
 
Example 13
Source File: MultiCurrencyListAdapter.java    From currency-picker-android with Apache License 2.0 5 votes vote down vote up
public MultiCurrencyListAdapter(Context context, List<ExtendedCurrency> currencies, Set<String> selectedCurrencies) {
    super();
    this.mContext = context;
    this.currencies = currencies;
    this.selectedCurrencies = selectedCurrencies;
    checkedCurrencies = new SparseBooleanArray(currencies.size());
    for(String code : selectedCurrencies){
        int position = currencies.indexOf(ExtendedCurrency.getCurrencyByISO(code));
        checkedCurrencies.put(position, true);
    }

    inflater = LayoutInflater.from(context);
}
 
Example 14
Source File: AppStateTracker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static boolean addUidToArray(SparseBooleanArray array, int uid) {
    if (UserHandle.isCore(uid)) {
        return false;
    }
    if (array.get(uid)) {
        return false;
    }
    array.put(uid, true);
    return true;
}
 
Example 15
Source File: SourceManager.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
public static SparseBooleanArray getSourceEnableSparseArray() {
    String json = SPUtils.getInstance().getString("source_setting_list",
            AssetsUtils.readAssetsTxt(Global.getApplication(), "SourceEnable.json"));
    List<SourceEnable> enables = new Gson().fromJson(json,
            new TypeToken<List<SourceEnable>>() {
            }.getType());

    SparseBooleanArray checkedMap = new SparseBooleanArray();
    for (SourceEnable sourceEnable : enables) {
        checkedMap.put(sourceEnable.id, sourceEnable.enable);
    }
    return checkedMap;
}
 
Example 16
Source File: NetworkStats.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Return list of unique UIDs known by this data structure.
 */
public int[] getUniqueUids() {
    final SparseBooleanArray uids = new SparseBooleanArray();
    for (int uid : this.uid) {
        uids.put(uid, true);
    }

    final int size = uids.size();
    final int[] result = new int[size];
    for (int i = 0; i < size; i++) {
        result[i] = uids.keyAt(i);
    }
    return result;
}
 
Example 17
Source File: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the persistent recentTasks for {@code userId} into this list from persistent storage.
 * Does nothing if they are already loaded.
 *
 * @param userId the user Id
 */
void loadUserRecentsLocked(int userId) {
    if (mUsersWithRecentsLoaded.get(userId)) {
        // User already loaded, return early
        return;
    }

    // Load the task ids if not loaded.
    loadPersistedTaskIdsForUserLocked(userId);

    // Check if any tasks are added before recents is loaded
    final SparseBooleanArray preaddedTasks = new SparseBooleanArray();
    for (final TaskRecord task : mTasks) {
        if (task.userId == userId && shouldPersistTaskLocked(task)) {
            preaddedTasks.put(task.taskId, true);
        }
    }

    Slog.i(TAG, "Loading recents for user " + userId + " into memory.");
    mTasks.addAll(mTaskPersister.restoreTasksForUserLocked(userId, preaddedTasks));
    cleanupLocked(userId);
    mUsersWithRecentsLoaded.put(userId, true);

    // If we have tasks added before loading recents, we need to update persistent task IDs.
    if (preaddedTasks.size() > 0) {
        syncPersistentTaskIdsLocked();
    }
}
 
Example 18
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void evalForegroundWatchers(int op, SparseArray<ArraySet<ModeCallback>> watchers,
        SparseBooleanArray which) {
    boolean curValue = which.get(op, false);
    ArraySet<ModeCallback> callbacks = watchers.get(op);
    if (callbacks != null) {
        for (int cbi = callbacks.size() - 1; !curValue && cbi >= 0; cbi--) {
            if ((callbacks.valueAt(cbi).mFlags
                    & AppOpsManager.WATCH_FOREGROUND_CHANGES) != 0) {
                hasForegroundWatchers = true;
                curValue = true;
            }
        }
    }
    which.put(op, curValue);
}
 
Example 19
Source File: NetworkManagementService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setUidOnMeteredNetworkList(int uid, boolean blacklist, boolean enable) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);

    // silently discard when control disabled
    // TODO: eventually migrate to be always enabled
    if (!mBandwidthControlEnabled) return;

    final String chain = blacklist ? "naughtyapps" : "niceapps";
    final String suffix = enable ? "add" : "remove";

    synchronized (mQuotaLock) {
        boolean oldEnable;
        SparseBooleanArray quotaList;
        synchronized (mRulesLock) {
            quotaList = blacklist ? mUidRejectOnMetered : mUidAllowOnMetered;
            oldEnable = quotaList.get(uid, false);
        }
        if (oldEnable == enable) {
            // TODO: eventually consider throwing
            return;
        }

        Trace.traceBegin(Trace.TRACE_TAG_NETWORK, "inetd bandwidth");
        try {
            mConnector.execute("bandwidth", suffix + chain, uid);
            synchronized (mRulesLock) {
                if (enable) {
                    quotaList.put(uid, true);
                } else {
                    quotaList.delete(uid);
                }
            }
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
        }
    }
}
 
Example 20
Source File: AppStateTracker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static boolean removeUidFromArray(SparseBooleanArray array, int uid, boolean remove) {
    if (UserHandle.isCore(uid)) {
        return false;
    }
    if (!array.get(uid)) {
        return false;
    }
    if (remove) {
        array.delete(uid);
    } else {
        array.put(uid, false);
    }
    return true;
}