Example usage for android.util SparseBooleanArray size

List of usage examples for android.util SparseBooleanArray size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of key-value mappings that this SparseBooleanArray currently stores.

Usage

From source file:com.serenegiant.aceparrot.MediaFragment.java

/**
 * ???//from w w  w.j  a v a  2s  . c o m
 * @return
 */
private ARMediaObject[] getSelectedMedias() {
    ARMediaObject[] result = null;
    if (mMediaListView != null) {
        final SparseBooleanArray ids = mMediaListView.getCheckedItemPositions();
        final int n = ids != null ? ids.size() : 0;
        if (n > 0) {
            final List<ARMediaObject> list = new ArrayList<ARMediaObject>();
            for (int i = 0; i < n; i++) {
                if (ids.valueAt(i)) {
                    final Object obj = mMediaListView.getItemAtPosition(ids.keyAt(i));
                    if (obj instanceof ARMediaObject) {
                        list.add((ARMediaObject) obj);
                    }
                }
            }
            final int m = list.size();
            if (m > 0) {
                result = new ARMediaObject[m];
                list.toArray(result);
            }
        }
    }
    return result;
}

From source file:de.qspool.clementineremote.ui.fragments.GlobalSearchFragment.java

@SuppressLint({ "InlinedApi", "NewApi" })
@Override// w  ww  . j  ava  2 s  . c o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_global_search, container, false);

    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.global_search_refresh_layout);
    mEmptyView = (SwipeRefreshLayout) view.findViewById(R.id.global_search_empty);

    mSwipeRefreshLayout.setColorSchemeResources(R.color.orange);
    mEmptyView.setColorSchemeResources(R.color.orange);
    mSwipeRefreshLayout.setEnabled(true);
    mEmptyView.setEnabled(true);

    mEmptyText = (TextView) view.findViewById(R.id.global_search_empty_txt);
    mList = (ListView) view.findViewById(R.id.global_search);

    mList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SongSelectItem item = mAdapters.getLast().getItem(position);

            if (item.getLevel() == mMaxLevels - 1) {
                Message msg = Message.obtain();
                LinkedList<ClementineRemoteProtocolBuffer.SongMetadata> songs = new LinkedList<>();
                songs.add(GlobalSearchManager.getInstance().getRequest().getSongFromUrl(item.getUrl()));
                msg.obj = ClementineMessageFactory
                        .buildInsertSongs(App.Clementine.getPlaylistManager().getActivePlaylistId(), songs);
                App.ClementineConnection.mHandler.sendMessage(msg);

                String text = getActivity().getResources().getQuantityString(R.plurals.songs_added, 1, 1);
                Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
            } else {
                GlobalSearchQuery globalSearchQuery = new GlobalSearchQuery(getActivity(), mQueryId);
                globalSearchQuery.openDatabase();
                globalSearchQuery.setLevel(mAdapters.size());
                globalSearchQuery.setSelection(item.getSelection());
                mAdapters.add(new DynamicSongQueryAdapter(getActivity(), globalSearchQuery));
                showList();
            }
        }
    });
    mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override
        public boolean onActionItemClicked(ActionMode mode, android.view.MenuItem item) {
            SparseBooleanArray checkedPositions = mList.getCheckedItemPositions();
            final LinkedList<SongSelectItem> selectedItems = new LinkedList<>();

            for (int i = 0; i < checkedPositions.size(); ++i) {
                int position = checkedPositions.keyAt(i);
                if (checkedPositions.valueAt(i)) {
                    selectedItems.add(mAdapters.getLast().getItem(position));
                }
            }

            for (SongSelectItem songItem : selectedItems) {
                OnSongSelectFinishedListener listener;

                switch (item.getItemId()) {
                case R.id.global_search_context_add:

                    listener = new OnSongSelectFinishedListener() {
                        @Override
                        public void OnSongSelectFinished(LinkedList<SongSelectItem> l) {
                            addSongsToPlaylist(l);
                        }
                    };

                    break;
                default:
                    return false;
                }
                queryItems(songItem, listener);
            }
            mode.finish();
            return true;
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.global_search_context_menu, menu);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow()
                        .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey_cab_status));
            }

            return true;
        }

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

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getActivity().getWindow()
                        .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.actionbar_dark));
            }
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
        }
    });

    GlobalSearchManager.getInstance().addOnGlobalSearchResponseListerner(this);

    setHasOptionsMenu(true);

    mActionBar.setTitle("");
    mActionBar.setSubtitle("/");

    return view;
}

From source file:com.conferenceengineer.android.iosched.ui.SessionsFragment.java

private List<Integer> getCheckedSessionPositions() {
    List<Integer> checkedSessionPositions = new ArrayList<Integer>();
    ListView listView = getListView();
    if (listView == null) {
        return checkedSessionPositions;
    }//from w ww .ja v a 2  s . c om

    SparseBooleanArray checkedPositionsBool = listView.getCheckedItemPositions();
    for (int i = 0; i < checkedPositionsBool.size(); i++) {
        if (checkedPositionsBool.valueAt(i)) {
            checkedSessionPositions.add(checkedPositionsBool.keyAt(i));
        }
    }

    return checkedSessionPositions;
}

From source file:org.dvbviewer.controller.ui.fragments.TimerList.java

@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
        SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
        Log.i(RecordingList.class.getSimpleName(), "items selected: " + checkedPositions.size());
        if (checkedPositions != null && checkedPositions.size() > 0) {
            int size = checkedPositions.size();
            TimerDeleter deleter = new TimerDeleter(TimerList.this);
            List<Timer> timers = new ArrayList<Timer>();
            for (int i = 0; i < size; i++) {
                if (checkedPositions.valueAt(i)) {
                    timers.add(mAdapter.getItem(checkedPositions.keyAt(i)));
                }//from   ww  w.  j  a  va 2s  .  c om
            }
            Timer[] array = new Timer[timers.size()];
            deleter.execute(timers.toArray(array));
        }
        mode.finish();
        break;

    case DialogInterface.BUTTON_NEGATIVE:
        // No button clicked
        break;
    }
}

From source file:org.totschnig.myexpenses.fragment.TemplatesList.java

@Override
protected void configureMenu11(Menu menu, int count, AbsListView lv) {
    super.configureMenu11(menu, count, lv);
    switch (lv.getId()) {
    case R.id.list:
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        boolean hasForeignExchangeTransfer = false, hasPlan = false;
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i) && isForeignExchangeTransfer(checkedItemPositions.keyAt(i))) {
                hasForeignExchangeTransfer = true;
                break;
            }/*w w w  .  j a  va  2 s . c o m*/
        }
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i) && isPlan(checkedItemPositions.keyAt(i))) {
                hasPlan = true;
                break;
            }
        }
        configureMenuInternal(menu, count, hasForeignExchangeTransfer, hasPlan);
        break;
    case R.id.calendar_gridview:
        requirePlanMonthFragment().configureMenu11(menu, count, lv);
    }
}

From source file:com.btmura.android.reddit.app.NavigationFragment.java

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    int count = getListView().getCheckedItemCount();
    boolean aboutItemVisible = count == 1;
    boolean shareItemsVisible = count == 1;
    boolean deleteItemVisible = true;

    SparseBooleanArray checked = getListView().getCheckedItemPositions();
    int size = checked.size();
    for (int i = 0; i < size; i++) {
        if (checked.valueAt(i)) {
            int position = checked.keyAt(i);
            int adapterIndex = mergeAdapter.getAdapterIndex(position);
            switch (adapterIndex) {
            case ADAPTER_ACCOUNTS:
            case ADAPTER_PLACES:
                aboutItemVisible = shareItemsVisible = deleteItemVisible = false;
                break;

            case ADAPTER_SUBREDDITS:
                int adapterPosition = mergeAdapter.getAdapterPosition(position);
                String subreddit = subredditAdapter.getName(adapterPosition);
                boolean hasSidebar = Subreddits.hasSidebar(subreddit);
                aboutItemVisible &= hasSidebar;
                shareItemsVisible &= hasSidebar;
                deleteItemVisible &= hasSidebar;
                break;
            }// ww  w  .  j a  v a  2s  .co m
        }
    }

    if (aboutItemVisible || shareItemsVisible || deleteItemVisible) {
        prepareMode(mode, count);
        prepareAddItem(menu);
        prepareAboutItem(menu, aboutItemVisible);
        prepareDeleteItem(menu, deleteItemVisible);
        prepareShareItems(menu, shareItemsVisible);
    } else {
        mode.finish();
    }

    return true;
}

From source file:com.github.jvanhie.discogsscrobbler.ReleaseListFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setSelection() {
    mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setSelector(R.drawable.track_selector);
    mList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override/*from   w ww .  j  a  va  2s .c  o  m*/
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = getActivity().getMenuInflater();
            inflater.inflate(R.menu.list_cab, menu);
            return true;
        }

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

        @Override
        public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {
            SparseBooleanArray checkedItems = mList.getCheckedItemPositions();
            final List<Release> releases = new ArrayList<Release>();
            if (checkedItems != null) {
                for (int i = 0; i < checkedItems.size(); i++) {
                    if (checkedItems.valueAt(i)) {
                        releases.add((Release) mList.getAdapter().getItem(checkedItems.keyAt(i)));
                    }
                }
            }
            switch (item.getItemId()) {
            case R.id.reload_release:
                mCallbacks.setRefreshVisible(true);
                mDiscogs.refreshReleases(releases, new Discogs.DiscogsWaiter() {
                    @Override
                    public void onResult(boolean success) {
                        if (success) {
                            Toast.makeText(getActivity(), "reloaded releases", Toast.LENGTH_SHORT).show();
                            loadList();
                        } else {
                            Toast.makeText(getActivity(), "Failed to reload requested releases!",
                                    Toast.LENGTH_SHORT).show();
                        }
                        mCallbacks.setRefreshVisible(false);
                    }
                });
                mode.finish();
                break;
            case R.id.delete_release:
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                // Add the buttons
                builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User clicked OK button
                        mCallbacks.setRefreshVisible(true);
                        mDiscogs.removeReleases(releases, new Discogs.DiscogsWaiter() {
                            @Override
                            public void onResult(boolean success) {
                                if (success) {
                                    Toast.makeText(getActivity(), "Removed selected releases",
                                            Toast.LENGTH_SHORT).show();
                                    loadList();
                                } else {
                                    Toast.makeText(getActivity(), "Failed to remove selected releases!",
                                            Toast.LENGTH_SHORT).show();
                                }
                                mCallbacks.setRefreshVisible(false);
                            }
                        });
                        mode.finish();
                    }
                });
                builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mode.finish();
                    }
                });
                builder.setTitle(R.string.delete_releases_title).setMessage(R.string.delete_releases_message);
                AlertDialog dialog = builder.create();
                dialog.show();
                break;
            case R.id.cancel_selection:
                mode.finish();
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {

        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(mList.getCheckedItemCount() + " releases selected");

        }

    });
}

From source file:com.btmura.android.reddit.app.NavigationFragment.java

private String[] getCheckedSubreddits() {
    ListView lv = getListView();//from   w  w w. j  a  va2s . co m
    SparseBooleanArray checked = lv.getCheckedItemPositions();
    String[] subreddits = new String[lv.getCheckedItemCount()];

    int size = checked.size();
    int j = 0;
    for (int i = 0; i < size; i++) {
        if (checked.valueAt(i)) {
            int position = checked.keyAt(i);
            int adapterPosition = mergeAdapter.getAdapterPosition(position);
            subreddits[j++] = subredditAdapter.getName(adapterPosition);
        }
    }

    return subreddits;
}

From source file:org.dvbviewer.controller.ui.fragments.RecordingList.java

@Override
public void onClick(DialogInterface dialog, int which) {
    switch (which) {
    case DialogInterface.BUTTON_POSITIVE:
        Log.i(RecordingList.class.getSimpleName(), "onClick");
        SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
        Log.i(RecordingList.class.getSimpleName(), "items selected: " + checkedPositions.size());
        if (checkedPositions != null && checkedPositions.size() > 0) {

            int size = checkedPositions.size();
            RecordingDeleter deleter = new RecordingDeleter(this);
            List<Recording> recordings = new ArrayList<Recording>();
            for (int i = 0; i < size; i++) {
                if (checkedPositions.valueAt(i)) {
                    recordings.add(mAdapter.getItem(checkedPositions.keyAt(i)));
                }//from   w w  w . j a  v a 2  s  . c o  m
            }
            Recording[] array = new Recording[recordings.size()];
            deleter.execute(recordings.toArray(array));
        }
        mode.finish();
        break;

    case DialogInterface.BUTTON_NEGATIVE:
        // No button clicked
        break;
    }
}

From source file:org.tigase.mobile.bookmarks.BookmarksActivity.java

@TargetApi(11)
private void initializeContextActions() {

    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

        private Bookmark getBookmarkFromFlatPosition(int pos) {
            long packed = listView.getExpandableListPosition(pos);
            int child = ExpandableListView.getPackedPositionChild(packed);
            int group = ExpandableListView.getPackedPositionGroup(packed);

            return (Bookmark) adapter.getChild(group, child);
        }//from   w  w  w  .j  a v  a 2s  .com

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            SparseBooleanArray selection = listView.getCheckedItemPositions();

            if (item.getItemId() == R.id.edit) {
                for (int i = 0; i < selection.size(); i++) {
                    if (selection.valueAt(i)) {
                        int pos = selection.keyAt(i);

                        Bookmark bookmark = getBookmarkFromFlatPosition(pos);
                        editItem(bookmark);
                    }
                }
                mode.finish(); // Action picked, so close the CAB
                return true;
            } else if (item.getItemId() == R.id.remove) {
                List<Bookmark> items = new ArrayList<Bookmark>();
                for (int i = 0; i < selection.size(); i++) {
                    if (selection.valueAt(i)) {
                        int pos = selection.keyAt(i);

                        Bookmark bookmark = getBookmarkFromFlatPosition(pos);
                        if (bookmark != null) {
                            items.add(bookmark);
                        }
                    }
                }
                removeItems(items);
                mode.finish();
                return true;
            } else {
                return false;
            }

        }

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

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            Menu menu = mode.getMenu();
            for (int i = 0; i < menu.size(); i++) {
                MenuItem mi = menu.getItem(i);
                if (mi.getItemId() == R.id.edit) {
                    mi.setVisible(listView.getCheckedItemCount() < 2);
                }
            }
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            // TODO Auto-generated method stub
            return true;
        }

    });
}