Example usage for android.util SparseBooleanArray keyAt

List of usage examples for android.util SparseBooleanArray keyAt

Introduction

In this page you can find the example usage for android.util SparseBooleanArray keyAt.

Prototype

public int keyAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the key from the indexth key-value mapping that this SparseBooleanArray stores.

Usage

From source file:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java

private int countSelected() {

    int count = 0;
    SparseBooleanArray selected = getListView().getCheckedItemPositions();
    for (int i = 0; i < selected.size(); i++) {
        // Ignore the first item as it is help text.
        if (selected.keyAt(i) > 0) {
            if (selected.valueAt(i)) {
                count++;/* w  ww.jav  a  2 s  .  c  o  m*/
            }
        }
    }
    return count;
}

From source file:co.juliansuarez.libwizardpager.wizard.ui.MultipleChoiceFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    ArrayList<String> selections = new ArrayList<String>();
    ArrayList<Choice> choices = new ArrayList<Choice>();

    Boolean skipNextPage = false;
    for (int i = 0; i < checkedPositions.size(); i++) {
        if (checkedPositions.valueAt(i)) {
            String item = getListAdapter().getItem(checkedPositions.keyAt(i)).toString();
            selections.add(item);//from  ww  w  .  java 2 s .  c  o  m

            Choice c = mPage.getChoice(item);
            choices.add(c);

            if (c.skipNextPage()) {
                skipNextPage = true;
            }
        }
    }
    mPage.getData().putBoolean(Page.SKIP_NEXT_PAGE, skipNextPage);
    mPage.getData().putParcelableArrayList(Page.CHOICE_DATA_KEY, choices);
    mPage.getData().putStringArrayList(Page.SIMPLE_DATA_KEY, selections);
    mPage.notifyDataChanged();
}

From source file:com.android.contacts.SimImportFragment.java

private void updateToolbarWithCurrentSelections() {
    // The ListView keeps checked state for items that are disabled but we only want  to
    // consider items that don't exist in the current account when updating the toolbar
    int importableCount = 0;
    final SparseBooleanArray checked = mListView.getCheckedItemPositions();
    for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i) && !mAdapter.existsInCurrentAccount(checked.keyAt(i))) {
            importableCount++;//from  ww  w.  ja  v  a2s  .c  om
        }
    }

    if (importableCount == 0) {
        mImportButton.setVisibility(View.GONE);
        mToolbar.setTitle(R.string.sim_import_title_none_selected);
    } else {
        mToolbar.setTitle(String.valueOf(importableCount));
        mImportButton.setVisibility(View.VISIBLE);
    }
}

From source file:au.org.ala.fielddata.mobile.ViewSavedRecordsActivity.java

private void deleteSelectedRecords() {
    RecordDAO recordDao = new RecordDAO(getActivity());
    SparseBooleanArray selected = getListView().getCheckedItemPositions();
    int deleteCount = 0;
    for (int i = 0; i < selected.size(); i++) {
        // Ignore the first item as it is help text.
        if (selected.keyAt(i) > 0) {

            if (selected.valueAt(i) == true) {
                Record record = ((RecordView) getListAdapter().getItem(selected.keyAt(i))).record;
                recordDao.delete(Record.class, record.getId());
                deleteCount++;/*from w w  w .j  av  a 2s .com*/
            }
        }
    }
    if (deleteCount > 0) {
        String message = "%d records deleted";
        if (deleteCount == 1) {
            message = "%d record deleted";
        }
        Toast.makeText(getActivity(), String.format(message, deleteCount), Toast.LENGTH_SHORT).show();

    }

    finishActionMode();

    reload();

}

From source file:com.example.android.bluetoothchat.DeviceListActivity.java

private void connect() {
    // ????/*from   www .j  a va 2 s  .c o  m*/
    mBtAdapter.cancelDiscovery();

    // ???MAC address??, ???View???17?char ?
    //        ArrayList<String> address = new ArrayList<>();
    SparseBooleanArray checkeditempositions = pairedListView.getCheckedItemPositions();
    String[] address = new String[pairedListView.getCheckedItemCount()];

    for (int i = 0; i < pairedListView.getCount(); i++) {
        if (checkeditempositions.get(i) == true) {
            //???(????)????????
            int key = checkeditempositions.keyAt(i);
            String info = pairedListView.getItemAtPosition(key).toString();
            //                address.add(info.substring(info.length() - 17));
            address[i] = info.substring(info.length() - 17);
        }
    }

    //        for(int i=0; i<address.size();i++)
    //        Toast.makeText(this, i +"?"+ address.get(i),Toast.LENGTH_SHORT).show();

    for (int i = 0; i < address.length; i++)
        Toast.makeText(this, i + "?" + address[i], Toast.LENGTH_SHORT).show();

    // IntentMAC address?
    //        Intent intent = new Intent();
    //        intent.putStringArrayListExtra(EXTRA_DEVICE_ADDRESS, address);

    // result????
    //        setResult(Activity.RESULT_OK, intent);
    finish();
}

From source file:com.lithidsw.wallbox.app.randomizer.RandomizerFrag.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    fa = super.getActivity();
    mUtils = new Utils(fa);
    menuHelper = new MenuHelper(fa);
    ll = (LinearLayout) inflater.inflate(R.layout.randomizer_frag, container, false);
    prefs = fa.getSharedPreferences(C.PREF, Context.MODE_PRIVATE);

    adapter = new RandomizerGridAdapter(fa, mGalItems);
    mGridView = (GridView) ll.findViewById(R.id.grid_view);
    mTextView = (TextView) ll.findViewById(R.id.no_content);
    mProgressBar = (ProgressBar) ll.findViewById(R.id.progress);
    mGridView.setAdapter(adapter);/*  w  ww  .  j  a  v a2 s . co m*/

    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {

        }

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            actionMode.setTitle("Choose threads");
            mRemoveList.clear();
            MenuInflater inflater = actionMode.getMenuInflater();
            inflater.inflate(R.menu.randomizer_selection_menu, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            final SparseBooleanArray checked = mGridView.getCheckedItemPositions();
            switch (menuItem.getItemId()) {
            case R.id.action_delete:
                int size = checked.size();
                for (int i = 0; i < size; i++) {
                    int key = checked.keyAt(i);
                    boolean value = checked.get(key);
                    if (value) {
                        new TableHelper(fa).deleteSinglePaper(mGalItems.get(key)[1]);
                    }
                }
                actionMode.finish();
                new GalLoader().execute();
                break;
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {

        }
    });
    setHasOptionsMenu(true);

    if (!prefs.getBoolean(C.PREF_RANDOMIZER_FIRST_RUN_MAIN, false)) {
        prefs.edit().putBoolean(C.PREF_RANDOMIZER_FIRST_RUN_MAIN, true).commit();
        String title = getResources().getString(R.string.main_title_randomize);
        String message = getResources().getString(R.string.randomizer_description);
        new CustomDialogs().openFirstDialog(fa, title, message);
    }
    return ll;
}

From source file:org.creativecommons.thelist.activities.CategoryListActivity.java

public void saveUserCategories() {
    SparseBooleanArray positions = mGridView.getCheckedItemPositions();
    int length = positions.size();
    //Array of user selected categories
    List<Integer> userCategories = new ArrayList<>();

    for (int i = 0; i < length; i++) {
        int itemPosition = positions.keyAt(i);
        boolean value = positions.get(itemPosition);

        if (value) {
            CategoryListItem catItem = (CategoryListItem) mGridView.getItemAtPosition(itemPosition);
            int catId = catItem.getCategoryID();
            userCategories.add(catId);//from  w  ww .  j a v a  2s.c om
            Log.v(TAG, "ITEM ADDED");
        }
    }

    Intent intent;

    if (mCurrentUser.isTempUser()) { //TEMP USER
        //Save user categories to shared preferences
        mSharedPref.saveSharedPreference(SharedPreferencesMethods.CATEGORY_PREFERENCE_KEY,
                userCategories.toString());

        if (mSharedPref.getUserItemCount() == 0) {
            intent = new Intent(CategoryListActivity.this, RandomActivity.class);
            startActivity(intent);
        } else {
            intent = new Intent(CategoryListActivity.this, DrawerActivity.class);
            startActivity(intent);
        }
    } else {
        intent = new Intent(CategoryListActivity.this, DrawerActivity.class);
        startActivity(intent);
    }
}

From source file:org.spinsuite.bchat.view.FV_ThreadIndex.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override/* ww  w.jav  a  2 s .co  m*/
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            // Capture total checked items
            final int checkedCount = getListView().getCheckedItemCount();
            // Set the CAB title according to total checked items
            mode.setTitle(checkedCount + " " + getString(R.string.BChat_Selected));
            // Calls toggleSelection method from ListViewAdapter Class
            m_Adapter.toggleSelection(position);

        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_delete:
                SparseBooleanArray selectedItems = m_Adapter.getSelectedItems();
                String[] ids = new String[selectedItems.size()];
                for (int i = (selectedItems.size() - 1); i >= 0; i--) {
                    if (selectedItems.valueAt(i)) {
                        DisplayBChatThreadListItem selectedItem = m_Adapter.getItem(selectedItems.keyAt(i));
                        //   Add Value
                        ids[i] = selectedItem.getSPS_BC_Request_UUID();
                        //   Remove Item
                        m_Adapter.remove(selectedItem);
                    }
                }
                //   Delete Records in DB
                if (ids.length > 0) {
                    BCMessageHandle.getInstance(m_ctx).deleteRequest(ids);
                }
                mode.finish();
                return true;
            default:
                return false;
            }
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.bc_thread_list_selected, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            m_Adapter.removeSelection();
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

    });
}

From source file:de.vanita5.twittnuker.activity.support.DraftsActivity.java

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_DELETE: {
        final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment();
        final Bundle args = new Bundle();
        args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds());
        f.setArguments(args);/*from   www. j ava 2 s.c o m*/
        f.show(getSupportFragmentManager(), "delete_drafts_confirm");
        break;
    }
    case MENU_SEND: {
        final Cursor c = mAdapter.getCursor();
        if (c == null || c.isClosed())
            return false;
        final SparseBooleanArray checked = mListView.getCheckedItemPositions();
        final List<DraftItem> list = new ArrayList<DraftItem>();
        final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c);
        for (int i = 0, j = checked.size(); i < j; i++) {
            if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) {
                list.add(new DraftItem(c, indices));
            }
        }
        if (sendDrafts(list)) {
            final Where where = Where.in(new Column(Drafts._ID),
                    new RawItemArray(mListView.getCheckedItemIds()));
            mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null);
        }
        break;
    }
    default: {
        return false;
    }
    }
    mode.finish();
    return true;
}

From source file:org.getlantern.firetweet.activity.support.DraftsActivity.java

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_DELETE: {
        final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment();
        final Bundle args = new Bundle();
        args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds());
        f.setArguments(args);// w  w  w. j  a  v  a 2 s  .co  m
        f.show(getSupportFragmentManager(), "delete_drafts_confirm");
        break;
    }
    case MENU_SEND: {
        final Cursor c = mAdapter.getCursor();
        if (c == null || c.isClosed())
            return false;
        final SparseBooleanArray checked = mListView.getCheckedItemPositions();
        final List<DraftItem> list = new ArrayList<>();
        final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c);
        for (int i = 0, j = checked.size(); i < j; i++) {
            if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) {
                list.add(new DraftItem(c, indices));
            }
        }
        if (sendDrafts(list)) {
            final Expression where = Expression.in(new Column(Drafts._ID),
                    new RawItemArray(mListView.getCheckedItemIds()));
            mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null);
        }
        break;
    }
    default: {
        return false;
    }
    }
    mode.finish();
    return true;
}