android.util.SparseBooleanArray Java Examples

The following examples show how to use android.util.SparseBooleanArray. 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 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 #2
Source File: TsExtractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(
    @Mode int mode,
    TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0);
  trackIds = new SparseBooleanArray();
  trackPids = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  durationReader = new TsDurationReader();
  pcrPid = -1;
  resetPayloadReaders();
}
 
Example #3
Source File: DragSortListView.java    From chromadoze with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Use this when an item has been deleted, to move the check state of all
 * following items up one step. 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.
 * 
 * See also further comments on {@link #moveCheckState(int, int)}.
 * 
 * @param position
 */
public void removeCheckState(int position) {
    SparseBooleanArray cip = getCheckedItemPositions();

    if (cip.size() == 0)
        return;
    int[] runStart = new int[cip.size()];
    int[] runEnd = new int[cip.size()];
    int rangeStart = position;
    int rangeEnd = cip.keyAt(cip.size() - 1) + 1;
    int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd);
    for (int i = 0; i != runCount; i++) {
        if (!(runStart[i] == position || (runEnd[i] < runStart[i] && runEnd[i] > position))) {
            // Only set a new check mark in front of this run if it does
            // not contain the deleted position. If it does, we only need
            // to make it one check mark shorter at the end.
            setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd),
                    true);
        }
        setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false);
    }
}
 
Example #4
Source File: DragSortListView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * Use this when an item has been deleted, to move the check state of all
 * following items up one step. 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 android.widget.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.
 * 
 * See also further comments on {@link #moveCheckState(int, int)}.
 * 
 * @param position
 */
public void removeCheckState(int position) {
    SparseBooleanArray cip = getCheckedItemPositions();

    if (cip.size() == 0)
        return;
    int[] runStart = new int[cip.size()];
    int[] runEnd = new int[cip.size()];
    int rangeStart = position;
    int rangeEnd = cip.keyAt(cip.size() - 1) + 1;
    int runCount = buildRunList(cip, rangeStart, rangeEnd, runStart, runEnd);
    for (int i = 0; i != runCount; i++) {
        if (!(runStart[i] == position || (runEnd[i] < runStart[i] && runEnd[i] > position))) {
            // Only set a new check mark in front of this run if it does
            // not contain the deleted position. If it does, we only need
            // to make it one check mark shorter at the end.
            setItemChecked(rotate(runStart[i], -1, rangeStart, rangeEnd), true);
        }
        setItemChecked(rotate(runEnd[i], -1, rangeStart, rangeEnd), false);
    }
}
 
Example #5
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 #6
Source File: RequestFragment.java    From candybar with Apache License 2.0 6 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    resetRecyclerViewPadding(newConfig.orientation);
    if (mAsyncTask != null) return;

    int[] positions = mManager.findFirstVisibleItemPositions(null);

    SparseBooleanArray selectedItems = mAdapter.getSelectedItemsArray();
    ViewHelper.resetSpanCount(mRecyclerView,
            getActivity().getResources().getInteger(R.integer.request_column_count));

    mAdapter = new RequestAdapter(getActivity(),
            CandyBarMainActivity.sMissedApps,
            mManager.getSpanCount());
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setSelectedItemsArray(selectedItems);

    if (positions.length > 0)
        mRecyclerView.scrollToPosition(positions[0]);
}
 
Example #7
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private Parameters() {
  this(
      /* selectionOverrides= */ new SparseArray<>(),
      /* rendererDisabledFlags= */ new SparseBooleanArray(),
      /* preferredAudioLanguage= */ null,
      /* preferredTextLanguage= */ null,
      /* selectUndeterminedTextLanguage= */ false,
      /* disabledTextTrackSelectionFlags= */ 0,
      /* forceLowestBitrate= */ false,
      /* allowMixedMimeAdaptiveness= */ false,
      /* allowNonSeamlessAdaptiveness= */ true,
      /* maxVideoWidth= */ Integer.MAX_VALUE,
      /* maxVideoHeight= */ Integer.MAX_VALUE,
      /* maxVideoBitrate= */ Integer.MAX_VALUE,
      /* exceedVideoConstraintsIfNecessary= */ true,
      /* exceedRendererCapabilitiesIfNecessary= */ true,
      /* viewportWidth= */ Integer.MAX_VALUE,
      /* viewportHeight= */ Integer.MAX_VALUE,
      /* viewportOrientationMayChange= */ true,
      /* tunnelingAudioSessionId= */ C.AUDIO_SESSION_ID_UNSET);
}
 
Example #8
Source File: MultiSelectionUtil.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    mListener.onDestroyActionMode(actionMode);
    // Clear all the checked items
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    if (checkedPositions != null) {
        for (int i = 0; i < checkedPositions.size(); i++) {
            mListView.setItemChecked(checkedPositions.keyAt(i), false);
        }
    }
    // Restore the original onItemClickListener
    mListView.setOnItemClickListener(mOldItemClickListener);
    // Clear the Action Mode
    mActionMode = null;
    // Reset the ListView's Choice Mode
    mListView.post(mSetChoiceModeNoneRunnable);
}
 
Example #9
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 #10
Source File: DeviceIdleJobsController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public DeviceIdleJobsController(JobSchedulerService service) {
    super(service);

    mHandler = new DeviceIdleJobsDelayHandler(mContext.getMainLooper());
    // Register for device idle mode changes
    mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    mLocalDeviceIdleController =
            LocalServices.getService(DeviceIdleController.LocalService.class);
    mDeviceIdleWhitelistAppIds = mLocalDeviceIdleController.getPowerSaveWhitelistUserAppIds();
    mPowerSaveTempWhitelistAppIds =
            mLocalDeviceIdleController.getPowerSaveTempWhitelistAppIds();
    mDeviceIdleUpdateFunctor = new DeviceIdleUpdateFunctor();
    mAllowInIdleJobs = new ArraySet<>();
    mForegroundUids = new SparseBooleanArray();
    final IntentFilter filter = new IntentFilter();
    filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
    filter.addAction(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED);
    filter.addAction(PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED);
    filter.addAction(PowerManager.ACTION_POWER_SAVE_TEMP_WHITELIST_CHANGED);
    mContext.registerReceiverAsUser(
            mBroadcastReceiver, UserHandle.ALL, filter, null, null);
}
 
Example #11
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 #12
Source File: TsExtractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param mode Mode for the extractor. One of {@link #MODE_MULTI_PMT}, {@link #MODE_SINGLE_PMT}
 *     and {@link #MODE_HLS}.
 * @param timestampAdjuster A timestamp adjuster for offsetting and scaling sample timestamps.
 * @param payloadReaderFactory Factory for injecting a custom set of payload readers.
 */
public TsExtractor(
    @Mode int mode,
    TimestampAdjuster timestampAdjuster,
    TsPayloadReader.Factory payloadReaderFactory) {
  this.payloadReaderFactory = Assertions.checkNotNull(payloadReaderFactory);
  this.mode = mode;
  if (mode == MODE_SINGLE_PMT || mode == MODE_HLS) {
    timestampAdjusters = Collections.singletonList(timestampAdjuster);
  } else {
    timestampAdjusters = new ArrayList<>();
    timestampAdjusters.add(timestampAdjuster);
  }
  tsPacketBuffer = new ParsableByteArray(new byte[BUFFER_SIZE], 0);
  trackIds = new SparseBooleanArray();
  trackPids = new SparseBooleanArray();
  tsPayloadReaders = new SparseArray<>();
  continuityCounters = new SparseIntArray();
  durationReader = new TsDurationReader();
  pcrPid = -1;
  resetPayloadReaders();
}
 
Example #13
Source File: NotifyFragment.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 #14
Source File: DynamicListView.java    From Kore with Apache License 2.0 6 votes vote down vote up
/**
 * When swapping items the checked item positions in the list may need to be updated
 * @param originalPosition
 * @param newPosition
 */
private void updateCheckedItemPositions(int originalPosition, int newPosition) {
    switch (getChoiceMode()) {
        case CHOICE_MODE_SINGLE:
            int checkPos = getCheckedItemPosition();
            if (checkPos == newPosition) {
                setItemChecked(originalPosition, true);
            } else if (checkPos == originalPosition) {
                setItemChecked(newPosition, false);
            }
            break;
        case CHOICE_MODE_MULTIPLE:
            SparseBooleanArray checkedItems = getCheckedItemPositions();
            setItemChecked(originalPosition, checkedItems.get(newPosition));
            setItemChecked(newPosition, checkedItems.get(originalPosition));
    }
}
 
Example #15
Source File: NotesFragment.java    From multi-copy with Apache License 2.0 6 votes vote down vote up
public void deleteRows(){
        //get Selected items
        SparseBooleanArray selected = notesAdapter.getmSelectedItems();

        //loop through selected items
        for (int i = (selected.size()-1) ;i >=0 ; i--){
            if (selected.valueAt(i)){
                //If the current id is selected remove the item via key
                deleteFromNoteRealm(selected.keyAt(i));
                notesAdapter.notifyDataSetChanged();
             }
        }

//        Toast.makeText(getContext(), selected.size() + " items deleted", Toast.LENGTH_SHORT).show();
        Snackbar snackbar = Snackbar.make(recyclerView,selected.size() + " Notes deleted",Snackbar.LENGTH_SHORT);
        snackbar.show();
        actionMode.finish();

    }
 
Example #16
Source File: MultipleChoiceFragment.java    From WizardPager with Apache License 2.0 5 votes vote down vote up
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    ArrayList<String> selections = new ArrayList<String>();
    for (int i = 0; i < checkedPositions.size(); i++) {
        if (checkedPositions.valueAt(i)) {
            selections.add(getListAdapter().getItem(checkedPositions.keyAt(i)).toString());
        }
    }

    mPage.getData().putStringArrayList(Page.SIMPLE_DATA_KEY, selections);
    mPage.notifyDataChanged();
}
 
Example #17
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 #18
Source File: AuthenticatorActivity.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the position of the one and only checked item in the provided list in multiple selection
 * mode.
 *
 * @return {@code 0}-based position.
 * @throws IllegalStateException if the list is not in multiple selection mode, or if the number
 *     of checked items is not {@code 1}.
 */
@TargetApi(11)
private static int getMultiSelectListSingleCheckedItemPosition(AbsListView list) {
  Preconditions.checkState(list.getCheckedItemCount() == 1);
  SparseBooleanArray checkedItemPositions = list.getCheckedItemPositions();
  Preconditions.checkState(checkedItemPositions != null);
  for (int i = 0, len = list.getCount(); i < len; i++) {
    boolean itemChecked = checkedItemPositions.get(i);
    if (itemChecked) {
      return i;
    }
  }

  throw new IllegalStateException("No items checked");
}
 
Example #19
Source File: NonParcelRepository.java    From parceler with Apache License 2.0 5 votes vote down vote up
private NonParcelRepository() {
    //private singleton constructor
    parcelableCollectionFactories.put(Collection.class, new CollectionParcelableFactory());
    parcelableCollectionFactories.put(List.class, new ListParcelableFactory());
    parcelableCollectionFactories.put(ArrayList.class, new ListParcelableFactory());
    parcelableCollectionFactories.put(Set.class, new SetParcelableFactory());
    parcelableCollectionFactories.put(HashSet.class, new SetParcelableFactory());
    parcelableCollectionFactories.put(TreeSet.class, new TreeSetParcelableFactory());
    parcelableCollectionFactories.put(SparseArray.class, new SparseArrayParcelableFactory());
    parcelableCollectionFactories.put(Map.class, new MapParcelableFactory());
    parcelableCollectionFactories.put(HashMap.class, new MapParcelableFactory());
    parcelableCollectionFactories.put(TreeMap.class, new TreeMapParcelableFactory());
    parcelableCollectionFactories.put(Integer.class, new IntegerParcelableFactory());
    parcelableCollectionFactories.put(Long.class, new LongParcelableFactory());
    parcelableCollectionFactories.put(Double.class, new DoubleParcelableFactory());
    parcelableCollectionFactories.put(Float.class, new FloatParcelableFactory());
    parcelableCollectionFactories.put(Byte.class, new ByteParcelableFactory());
    parcelableCollectionFactories.put(String.class, new StringParcelableFactory());
    parcelableCollectionFactories.put(Character.class, new CharacterParcelableFactory());
    parcelableCollectionFactories.put(Boolean.class, new BooleanParcelableFactory());
    parcelableCollectionFactories.put(byte[].class, new ByteArrayParcelableFactory());
    parcelableCollectionFactories.put(char[].class, new CharArrayParcelableFactory());
    parcelableCollectionFactories.put(boolean[].class, new BooleanArrayParcelableFactory());
    parcelableCollectionFactories.put(IBinder.class, new IBinderParcelableFactory());
    parcelableCollectionFactories.put(Bundle.class, new BundleParcelableFactory());
    parcelableCollectionFactories.put(SparseBooleanArray.class, new SparseBooleanArrayParcelableFactory());
    parcelableCollectionFactories.put(LinkedList.class, new LinkedListParcelableFactory());
    parcelableCollectionFactories.put(LinkedHashMap.class, new LinkedHashMapParcelableFactory());
    parcelableCollectionFactories.put(SortedMap.class, new TreeMapParcelableFactory());
    parcelableCollectionFactories.put(SortedSet.class, new TreeSetParcelableFactory());
    parcelableCollectionFactories.put(LinkedHashSet.class, new LinkedHashSetParcelableFactory());

}
 
Example #20
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean areRendererDisabledFlagsEqual(
    SparseBooleanArray first, SparseBooleanArray second) {
  int firstSize = first.size();
  if (second.size() != firstSize) {
    return false;
  }
  // Only true values are put into rendererDisabledFlags, so we don't need to compare values.
  for (int indexInFirst = 0; indexInFirst < firstSize; indexInFirst++) {
    if (second.indexOfKey(first.keyAt(indexInFirst)) < 0) {
      return false;
    }
  }
  return true;
}
 
Example #21
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private Parameters() {
  this(
      // Video
      /* maxVideoWidth= */ Integer.MAX_VALUE,
      /* maxVideoHeight= */ Integer.MAX_VALUE,
      /* maxVideoFrameRate= */ Integer.MAX_VALUE,
      /* maxVideoBitrate= */ Integer.MAX_VALUE,
      /* exceedVideoConstraintsIfNecessary= */ true,
      /* allowVideoMixedMimeTypeAdaptiveness= */ false,
      /* allowVideoNonSeamlessAdaptiveness= */ true,
      /* viewportWidth= */ Integer.MAX_VALUE,
      /* viewportHeight= */ Integer.MAX_VALUE,
      /* viewportOrientationMayChange= */ true,
      // Audio
      TrackSelectionParameters.DEFAULT.preferredAudioLanguage,
      /* maxAudioChannelCount= */ Integer.MAX_VALUE,
      /* maxAudioBitrate= */ Integer.MAX_VALUE,
      /* exceedAudioConstraintsIfNecessary= */ true,
      /* allowAudioMixedMimeTypeAdaptiveness= */ false,
      /* allowAudioMixedSampleRateAdaptiveness= */ false,
      /* allowAudioMixedChannelCountAdaptiveness= */ false,
      // Text
      TrackSelectionParameters.DEFAULT.preferredTextLanguage,
      TrackSelectionParameters.DEFAULT.preferredTextRoleFlags,
      TrackSelectionParameters.DEFAULT.selectUndeterminedTextLanguage,
      TrackSelectionParameters.DEFAULT.disabledTextTrackSelectionFlags,
      // General
      /* forceLowestBitrate= */ false,
      /* forceHighestSupportedBitrate= */ false,
      /* exceedRendererCapabilitiesIfNecessary= */ true,
      /* tunnelingAudioSessionId= */ C.AUDIO_SESSION_ID_UNSET,
      new SparseArray<>(),
      new SparseBooleanArray());
}
 
Example #22
Source File: ExpandableTextView.java    From ExpandableTextView 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;
    mExpandIndicatorController.changeState(mCollapsed);
    setText(text);
}
 
Example #23
Source File: SettingsActivity.java    From AppOpsX with MIT License 5 votes vote down vote up
private void saveChoice(SparseBooleanArray choiceResult) {
  StringBuilder sb = new StringBuilder();
  int size = choiceResult.size();
  for (int i = 0; i < size; i++) {
    if (choiceResult.get(i)) {
      sb.append(i).append(',');
    }
  }
  String s = sb.toString();
  if (!TextUtils.isEmpty(s)) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    sp.edit().putString("auto_perm_templete", s).apply();
  }
}
 
Example #24
Source File: DragSortListView.java    From DongWeather with Apache License 2.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 #25
Source File: Parcel.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void readSparseBooleanArrayInternal(SparseBooleanArray outVal, int N) {
    while (N > 0) {
        int key = readInt();
        boolean value = this.readByte() == 1;
        //Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
        outVal.append(key, value);
        N--;
    }
}
 
Example #26
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 #27
Source File: UserChoosePage.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
private void resetChoices() {
    final SparseBooleanArray sba = this.mListView.getCheckedItemPositions();
    for (int i = 0; i < sba.size(); i++) {
        this.mCursorAdapter.setItemChecked(sba.keyAt(i), false);
    }
    this.mListView.clearChoices();
}
 
Example #28
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 #29
Source File: RefreshListView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 删除选中item
 */
public void deleteChoices() {
    SparseBooleanArray array = getRefreshableView().getCheckedItemPositions();
    mAdapter.deleteChoice(array, getRefreshableView().getHeaderViewsCount());
    mAdapter.notifyDataSetChanged();
    clearChoices();
}
 
Example #30
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];
}