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

The following examples show how to use android.util.SparseBooleanArray#get() . 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: MyPMFragment.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onDelete() {

    ZogUtils.printLog(MyPMFragment.class, "mListView.getCheckedItemCount():" + mListView.getCheckedItemCount());
    if (mListView.getCheckedItemCount() < 1) {
        return;
    }
    int headerCount = mListView.getRefreshableView().getHeaderViewsCount();
    SparseBooleanArray array = mListView.getChoicePostions();
    int count = mAdapter.getCount();
    StringBuffer sb = new StringBuffer();
    for (int i = headerCount; i < count + headerCount; i++) {
        if (array.get(i)) {
            Mypm mypm = (Mypm) mAdapter.getItem(i - headerCount);
            if (mypm != null && !TextUtils.isEmpty(mypm.getTouid())) {
                sb.append(mypm.getTouid()).append("_");
            }
        }
    }
    doDelete(sb.toString(), mAdapter, null);
}
 
Example 2
Source File: RecentTasks.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @return whether the given task should be considered active.
 */
private boolean isActiveRecentTask(TaskRecord task, SparseBooleanArray quietProfileUserIds) {
    if (DEBUG_RECENTS_TRIM_TASKS) Slog.d(TAG, "isActiveRecentTask: task=" + task
            + " globalMax=" + mGlobalMaxNumTasks);

    if (quietProfileUserIds.get(task.userId)) {
        // Quiet profile user's tasks are never active
        if (DEBUG_RECENTS_TRIM_TASKS) Slog.d(TAG, "\tisQuietProfileTask=true");
        return false;
    }

    if (task.mAffiliatedTaskId != INVALID_TASK_ID && task.mAffiliatedTaskId != task.taskId) {
        // Keep the task active if its affiliated task is also active
        final TaskRecord affiliatedTask = getTask(task.mAffiliatedTaskId);
        if (affiliatedTask != null) {
            if (!isActiveRecentTask(affiliatedTask, quietProfileUserIds)) {
                if (DEBUG_RECENTS_TRIM_TASKS) Slog.d(TAG,
                        "\taffiliatedWithTask=" + affiliatedTask + " is not active");
                return false;
            }
        }
    }

    // All other tasks are considered active
    return true;
}
 
Example 3
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 4
Source File: ApplicationFilter.java    From Introspy-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
	try {
		_lastItemSelected = _appList.get(position);
		int count = getListView().getCount();			
		SparseBooleanArray sparseBooleanArray = getListView().getCheckedItemPositions();
		_lastItemChecked = false;
		for (int i = 0; i < count; i++){
			if (sparseBooleanArray.get(i) && i == position) {
					_lastItemChecked = true;
			}
		}
		// commit the change to preferences
		_sp.edit().putBoolean(_lastItemSelected, _lastItemChecked).commit();
		
	} catch (Exception e) {
		Log.w("IntrospyConfig", "Error:onListItemClick:" + e + 
				"\n SP: "+ _sp);
	}
	InjectConfig.getInstance().writeConfig(_lastItemChecked, 
			_lastItemSelected, _context);
	InjectConfig.getInstance().commit();
}
 
Example 5
Source File: DataList.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
private void populateSelectedItems(HashSet<Waypoint> waypoints, HashSet<Track> tracks, HashSet<Route> routes) {
    SparseBooleanArray positions = getListView().getCheckedItemPositions();
    for (int position = 0; position < mAdapter.getCount(); position++) {
        if (positions.get(position)) {
            Cursor cursor = (Cursor) mAdapter.getItem(position);
            int type = mDataSource.getDataType(position);
            if (type == DataSource.TYPE_WAYPOINT) {
                Waypoint waypoint = ((WaypointDataSource) mDataSource).cursorToWaypoint(cursor);
                waypoints.add(waypoint);
            } else if (type == DataSource.TYPE_TRACK) {
                Track track = ((TrackDataSource) mDataSource).cursorToTrack(cursor);
                tracks.add(track);
            } else if (type == DataSource.TYPE_ROUTE) {
                Route route = ((RouteDataSource) mDataSource).cursorToRoute(cursor);
                routes.add(route);
            }
        }
    }
}
 
Example 6
Source File: AddSsidDialog.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
private ArrayList<String> getSelectedSSIDs() {
    ArrayList<String> selectedSSIDs = new ArrayList<>();

    // manual
    String manualSsid = editText_ssid.getText().toString().trim();
    if (!TextUtils.isEmpty(manualSsid)) {
        selectedSSIDs.add(manualSsid);
    }

    // available networks
    int len = listView.getCount();
    SparseBooleanArray checked = listView.getCheckedItemPositions();
    for (int i = 0; i < len; i++) {
        if (checked.get(i)) {
            String item = ssids.get(i);
            /* do whatever you want with the checked item */
            selectedSSIDs.add(item);
        }
    }

    return selectedSSIDs;
}
 
Example 7
Source File: LovelyChoiceDialog.java    From LovelyDialog with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onClick(View v) {
    if (adaptee != null) {
        SparseBooleanArray checkedItemPositions = choicesList.getCheckedItemPositions();
        List<T> selectedItems = new ArrayList<>(checkedItemPositions.size());
        List<Integer> selectedPositions = new ArrayList<>(checkedItemPositions.size());
        ListAdapter adapter = choicesList.getAdapter();
        for (int index = 0; index < adapter.getCount(); index++) {
            if (checkedItemPositions.get(index)) {
                selectedPositions.add(index);
                selectedItems.add((T) adapter.getItem(index));
            }
        }
        adaptee.onItemsSelected(selectedPositions, selectedItems);
    }
    dismiss();
}
 
Example 8
Source File: ManageGroupActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    SparseBooleanArray positions = null;
    ArrayList<String> checkedIdstrs = null;
    int itemId = item.getItemId();
    if (itemId == R.id.menu_modify_group_name) {
        positions = getListView().getCheckedItemPositions();
        checkedIdstrs = new ArrayList<String>();
        String oriName = null;
        for (int i = 0; i < positions.size(); i++) {
            if (positions.get(positions.keyAt(i))) {
                oriName = group.getLists().get(positions.keyAt(i)).getName();
                checkedIdstrs.add(group.getLists().get(positions.keyAt(i)).getIdstr());
            }
        }
        ModifyGroupDialog modifyGroupDialog = new ModifyGroupDialog(oriName, checkedIdstrs.get(0));
        modifyGroupDialog.setTargetFragment(ManageGroupFragment.this, 0);
        modifyGroupDialog.show(getFragmentManager(), "");
        mode.finish();
        return true;
    } else if (itemId == R.id.menu_remove) {
        positions = getListView().getCheckedItemPositions();
        checkedIdstrs = new ArrayList<String>();
        for (int i = 0; i < positions.size(); i++) {
            if (positions.get(positions.keyAt(i))) {
                checkedIdstrs.add(group.getLists().get(positions.keyAt(i)).getIdstr());
            }
        }
        RemoveGroupDialog removeGroupDialog = new RemoveGroupDialog(checkedIdstrs);
        removeGroupDialog.setTargetFragment(ManageGroupFragment.this, 0);
        removeGroupDialog.show(getFragmentManager(), "");
        mode.finish();
        return true;
    }
    return false;
}
 
Example 9
Source File: BlobDescriptorListFragment.java    From aard2-android with GNU General Public License v3.0 5 votes vote down vote up
protected void deleteSelectedItems() {
    SparseBooleanArray checkedItems = getListView().getCheckedItemPositions();
    for (int i = checkedItems.size() - 1; i > -1; --i) {
        int position = checkedItems.keyAt(i);
        boolean checked = checkedItems.get(position);
        if (checked) {
            getDescriptorList().remove(position);
        }
     }
}
 
Example 10
Source File: FavArticleFragment.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private ArrayList<ArticleFav> getDeletedArticles() {
	SparseBooleanArray array = mListView.getChoicePostions();
	int headers = mListView.getRefreshableView().getHeaderViewsCount();
	int count = mAdapter.getCount();
	ArrayList<ArticleFav> articles = new ArrayList<ArticleFav>();
	for (int i = headers; i < count + headers; i++) {
		if (array.get(i)) {
			ArticleFav article = (ArticleFav) mAdapter.getItem(i-headers);
			articles.add(article);
		}
	}
	return articles;
}
 
Example 11
Source File: ExpandableTextView.java    From social-app-android with Apache License 2.0 5 votes vote down vote up
public void setText(@Nullable CharSequence text, @NonNull SparseBooleanArray collapsedStatus, int position) {
    mCollapsedStatus = collapsedStatus;
    mPosition = position;
    boolean isCollapsed = collapsedStatus.get(position, true);
    clearAnimation();
    mCollapsed = isCollapsed;
    mButton.setText(mCollapsed ? mExpandText : mCollapseText);
    setText(text);
    getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
    requestLayout();
}
 
Example 12
Source File: WeekAdapter.java    From TimeTable with GNU General Public License v3.0 5 votes vote down vote up
private void hidePopUpMenu(ViewHolder holder) {
    SparseBooleanArray checkedItems = mListView.getCheckedItemPositions();
    if (checkedItems.size() > 0) {
        for (int i = 0; i < checkedItems.size(); i++) {
            int key = checkedItems.keyAt(i);
            if (checkedItems.get(key)) {
                holder.popup.setVisibility(View.INVISIBLE);
                }
        }
    } else {
        holder.popup.setVisibility(View.VISIBLE);
    }
}
 
Example 13
Source File: HomeworksAdapter.java    From TimeTable with GNU General Public License v3.0 5 votes vote down vote up
private void hidePopUpMenu(ViewHolder holder) {
    SparseBooleanArray checkedItems = mListView.getCheckedItemPositions();
    if (checkedItems.size() > 0) {
        for (int i = 0; i < checkedItems.size(); i++) {
            int key = checkedItems.keyAt(i);
            if (checkedItems.get(key)) {
                holder.popup.setVisibility(View.INVISIBLE);
            }
        }
    } else {
        holder.popup.setVisibility(View.VISIBLE);
    }
}
 
Example 14
Source File: ExamsAdapter.java    From TimeTable with GNU General Public License v3.0 5 votes vote down vote up
private void hidePopUpMenu(ViewHolder holder) {
    SparseBooleanArray checkedItems = mListView.getCheckedItemPositions();
    if (checkedItems.size() > 0) {
        for (int i = 0; i < checkedItems.size(); i++) {
            int key = checkedItems.keyAt(i);
            if (checkedItems.get(key)) {
                holder.popup.setVisibility(View.INVISIBLE);
            }
        }
    } else {
        holder.popup.setVisibility(View.VISIBLE);
    }
}
 
Example 15
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 16
Source File: FavThreadFragment.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private ArrayList<Thread> getDeletedThreads() {
	SparseBooleanArray array = mListView.getChoicePostions();
	int headers = mListView.getRefreshableView().getHeaderViewsCount();
	int count = mAdapter.getCount();
	ArrayList<Thread> threads = new ArrayList<Thread>();
	for (int i = headers; i < count + headers; i++) {
		if (array.get(i)) {
			Thread thread = (Thread) mAdapter.getItem(i-headers);
			threads.add(thread);
		}
	}
	return threads;
}
 
Example 17
Source File: ManageGroupActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    SparseBooleanArray positions = null;
    ArrayList<String> checkedIdstrs = null;
    int itemId = item.getItemId();
    if (itemId == R.id.menu_modify_group_name) {
        positions = getListView().getCheckedItemPositions();
        checkedIdstrs = new ArrayList<String>();
        String oriName = null;
        for (int i = 0; i < positions.size(); i++) {
            if (positions.get(positions.keyAt(i))) {
                oriName = group.getLists().get(positions.keyAt(i)).getName();
                checkedIdstrs.add(group.getLists().get(positions.keyAt(i)).getIdstr());
            }
        }
        ModifyGroupDialog modifyGroupDialog = new ModifyGroupDialog(oriName, checkedIdstrs.get(0));
        modifyGroupDialog.setTargetFragment(ManageGroupFragment.this, 0);
        modifyGroupDialog.show(getFragmentManager(), "");
        mode.finish();
        return true;
    } else if (itemId == R.id.menu_remove) {
        positions = getListView().getCheckedItemPositions();
        checkedIdstrs = new ArrayList<String>();
        for (int i = 0; i < positions.size(); i++) {
            if (positions.get(positions.keyAt(i))) {
                checkedIdstrs.add(group.getLists().get(positions.keyAt(i)).getIdstr());
            }
        }
        RemoveGroupDialog removeGroupDialog = new RemoveGroupDialog(checkedIdstrs);
        removeGroupDialog.setTargetFragment(ManageGroupFragment.this, 0);
        removeGroupDialog.show(getFragmentManager(), "");
        mode.finish();
        return true;
    }
    return false;
}
 
Example 18
Source File: ListHostsFragment.java    From hosts-editor-android with Apache License 2.0 5 votes vote down vote up
private Host[] getSelectedItems() {
    List<Host> items = new ArrayList<>();

    int len = mListView.getCount();
    SparseBooleanArray checked = mListView.getCheckedItemPositions();
    for (int i = 0; i < len; i++) {
        if (checked.get(i)) {
            items.add(mAdapter.getItem(i));
        }
    }
    return items.toArray(new Host[items.size()]);
}
 
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;
}