当前位置: 首页>>代码示例>>Java>>正文


Java SparseBooleanArray.valueAt方法代码示例

本文整理汇总了Java中android.util.SparseBooleanArray.valueAt方法的典型用法代码示例。如果您正苦于以下问题:Java SparseBooleanArray.valueAt方法的具体用法?Java SparseBooleanArray.valueAt怎么用?Java SparseBooleanArray.valueAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.util.SparseBooleanArray的用法示例。


在下文中一共展示了SparseBooleanArray.valueAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIds

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
public ArrayMap<Integer, long[]> getIds() {
    ArrayMap<Integer, long[]> arrayMap = new ArrayMap<>();
    if (choiceMode == ListView.CHOICE_MODE_MULTIPLE) {
        for (Map.Entry<Integer, SparseBooleanArray> entry : multipleIds.entrySet()) {
            List<Integer> l = new ArrayList<>();
            SparseBooleanArray ids = entry.getValue();
            for (int i = 0; i < ids.size(); i++) {
                if (ids.valueAt(i)) {
                    l.add(ids.keyAt(i));
                }
            }
            long[] _ids = new long[l.size()];
            for (int i = 0; i < l.size(); i++) {
                _ids[i] = l.get(i);
            }
            arrayMap.put(entry.getKey(), _ids);
        }
    }
    return arrayMap;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:21,代码来源:ExpandableListViewCheckAdapter.java

示例2: onItemClick

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
@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();
    }
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:23,代码来源:MultiSelectionUtil.java

示例3: onSaveInstanceState

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // Get the SetGame
    SetGame game = mActionsListener.getSetGame();

    SparseBooleanArray checkedItemPositions = getCheckedItemPositions();
    int positionIndex = 0;
    // Loop through SparseBooleanArray and grab the positions that are checked
    for (int i = 0; i < checkedItemPositions.size(); i++) {
        if (checkedItemPositions.valueAt(i)) {
            mCheckedPositions[positionIndex] = checkedItemPositions.keyAt(i);
            positionIndex++;
        }
    }

    // Bundle objects
    outState.putParcelable(getString(R.string.bundle_key_game), Parcels.wrap(game));
    outState.putIntArray(getString(R.string.bundle_key_checked_positions), mCheckedPositions);
    outState.putInt(getString(R.string.bundle_key_checked_count), mCheckedCount);
}
 
开发者ID:jaysondc,项目名称:TripleTap,代码行数:23,代码来源:GameFragment.java

示例4: deleteRows

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
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();

    }
 
开发者ID:Rishabhk07,项目名称:multi-copy,代码行数:20,代码来源:NotesFragment.java

示例5: saveInstanceState

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
public boolean saveInstanceState(Bundle outBundle) {
    SparseBooleanArray checkedPositions = mListView.getCheckedItemPositions();
    if (mActionMode != null && checkedPositions != null) {
        ArrayList<Integer> positions = new ArrayList<Integer>();
        for (int i = 0; i < checkedPositions.size(); i++) {
            if (checkedPositions.valueAt(i)) {
                int position = checkedPositions.keyAt(i);
                positions.add(position);
            }
        }

        outBundle.putIntegerArrayList(getStateKey(), positions);
        return true;
    }
    return false;
}
 
开发者ID:ChessCom,项目名称:android-chessclock,代码行数:17,代码来源:MultiSelectionUtil.java

示例6: findFirstSetIndex

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
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;
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:10,代码来源:DragSortListView.java

示例7: onActionItemClicked

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();
    switch (menuItem.getItemId()) {
        case R.id.delete_all_action:
            //SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();
            // Перебираем с конца, чтобы не нарушать порядок нумерации в списке
            for (int i = (sparseBooleanArray.size() - 1); i >= 0; i--) {
                if (sparseBooleanArray.valueAt(i)) {
                    parentActivity.notes.remove(sparseBooleanArray.keyAt(i));
                }
            }
            actionMode.finish();
            parentActivity.adapter.notifyDataSetChanged();
            parentActivity.listView.smoothScrollToPosition(0);
            Toast.makeText(parentActivity, R.string.deleted_successfully_toast, Toast.LENGTH_LONG).show();
            return true;
        case R.id.copy_all_action:
            StringBuilder textToCopy = new StringBuilder("");
            String label = "Notes text";
            for (int i = 0; i < sparseBooleanArray.size(); i++) {
                if (sparseBooleanArray.valueAt(i)) {
                    textToCopy.append(parentActivity.notes.get(sparseBooleanArray.keyAt(i)).getText());
                    textToCopy.append("\n");
                }
            }
            ClipboardManager clipboard = (ClipboardManager) parentActivity.getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(label, textToCopy.toString());
            clipboard.setPrimaryClip(clip);
            actionMode.finish();
            Toast.makeText(parentActivity, R.string.copied_to_clipboard_toast, Toast.LENGTH_LONG).show();
            return true;
        default:
            return false;
    }
}
 
开发者ID:coffeeplanter,项目名称:SimpleNotes,代码行数:37,代码来源:MultiChoiceImplementation.java

示例8: getCheckedItemIds

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
public long[] getCheckedItemIds() {
    SparseBooleanArray ids = adapterCheckLin.getCheckedItemIds();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < ids.size(); i++) {
        if (ids.valueAt(i)) {
            list.add(ids.keyAt(i));
        }
    }
    long[] _ids = new long[list.size()];
    for (int i = 0; i < list.size(); i++) {
        _ids[i] = list.get(i);
    }
    return _ids;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:15,代码来源:FragmentListView.java

示例9: getCheckedItemIds

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
public static long[] getCheckedItemIds(ListView listview) {
    List<Integer> list = new ArrayList<>();
    //listview.getCheckedItemPositions(); 为触发过选择的item ,选中 为true 取消false
    SparseBooleanArray sp = listview.getCheckedItemPositions();
    for (int i = 0; i < sp.size(); i++) {
        if (sp.valueAt(i)) {
            list.add(sp.keyAt(i));
        }
    }
    long[] ids = new long[list.size()];
    for (int i = 0; i < list.size(); i++) {
        ids[i] = list.get(i);
    }
    return ids;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:16,代码来源:CheckLayout.java

示例10: copySelectedNotes

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
public void copySelectedNotes(SparseBooleanArray checkedIndices, BaseAdapter notesAdapter, String destination) {
    for (int i = 0; i < checkedIndices.size(); i++) {
        if (checkedIndices.valueAt(i)) {
            File file = (File) notesAdapter.getItem(checkedIndices.keyAt(i));
            copyFile(file, destination);
        }
    }
}
 
开发者ID:gsantner,项目名称:markor,代码行数:9,代码来源:MarkorSingleton.java

示例11: getCheckedIds

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
public static TreeSet<Long> getCheckedIds(ListView listView) {
    TreeSet<Long> ids = new TreeSet<>();

    SparseBooleanArray checked = listView.getCheckedItemPositions();

    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i)) {
            long id = listView.getItemIdAtPosition(checked.keyAt(i));
            ids.add(id);
        }
    }

    return ids;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:15,代码来源:ListViewUtils.java

示例12: onSetCardClicked

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
/**
 * This is called by the presenter whenever a SET card is clicked by the user.
 * If 3 cards are selected those indices are sent to the presenter
 * who will check if they are a valid set.
 */
@Override
public void onSetCardClicked() {

    mCheckedCount = getCheckedItemCount();

    // If we have 3 items selected, check if they are a set
    if (mCheckedCount == 3) {
        SparseBooleanArray checkedItemPositions = getCheckedItemPositions();

        int positionIndex = 0;

        // Loop through SparseBooleanArray and grab the 3 positions that are checked
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i)) {
                mCheckedPositions[positionIndex] = checkedItemPositions.keyAt(i);
                positionIndex++;
            }
        }

        // Submit the set instances to the presenter
        mActionsListener.onSubmitSet(
                mCheckedPositions[0],
                mCheckedPositions[1],
                mCheckedPositions[2]);

        Log.d(LOG_TAG, String.format(
                "Submitted set at positions %d, %d, %d",
                mCheckedPositions[0],
                mCheckedPositions[1],
                mCheckedPositions[2]));
    }
}
 
开发者ID:jaysondc,项目名称:TripleTap,代码行数:38,代码来源:GameFragment.java

示例13: buildRunList

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
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;
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:49,代码来源:DragSortListView.java

示例14: onActionItemClicked

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
@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;
	}
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:80,代码来源:DirectoryFragment.java

示例15: buildRunList

import android.util.SparseBooleanArray; //导入方法依赖的package包/类
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;
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:49,代码来源:DragSortListView.java


注:本文中的android.util.SparseBooleanArray.valueAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。