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.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++;/*  ww  w.  j  a v a2 s . c o m*/
        }
    }

    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: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);//from   w w w  .  j  a v  a  2 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: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  ww  w . j a  v a2 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:com.android.contacts.SimImportFragment.java

private void importCurrentSelections() {
    final SparseBooleanArray checked = mListView.getCheckedItemPositions();
    final ArrayList<SimContact> importableContacts = new ArrayList<>(checked.size());
    for (int i = 0; i < checked.size(); i++) {
        // It's possible for existing contacts to be "checked" but we only want to import the
        // ones that don't already exist
        if (checked.valueAt(i) && !mAdapter.existsInCurrentAccount(i)) {
            importableContacts.add(mAdapter.getItem(checked.keyAt(i)));
        }/*  www. ja v  a  2s.co m*/
    }
    SimImportService.startImport(getContext(), mSubscriptionId, importableContacts,
            mAccountHeaderPresenter.getCurrentAccount());
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category_list);
    mContext = this;
    mMessageHelper = new MessageHelper(mContext);
    mRequestMethods = new RequestMethods(mContext);
    mSharedPref = new SharedPreferencesMethods(mContext);
    mCurrentUser = new ListUser(CategoryListActivity.this);

    //Google Analytics Tracker
    ((ListApplication) getApplication()).getTracker(ListApplication.TrackerName.GLOBAL_TRACKER);

    //Set List Adapter
    mGridView = (GridView) findViewById(R.id.categoryGrid);
    adapter = new CategoryListAdapter(this, mCategoryList);

    //Set up Helper Message if new user
    if (!mSharedPref.getCategoryHelperViewed()) {

        //UI Elements
        final View helperMessage = findViewById(R.id.category_helper_message);
        ImageButton helperCloseButton = (ImageButton) findViewById(R.id.helper_close_button);

        helperCloseButton.setOnClickListener(new View.OnClickListener() {
            @Override/*from w  w w .  java 2 s .co  m*/
            public void onClick(View v) {
                helperMessage.setVisibility(View.GONE);
                mSharedPref.setCategoryHelperViewed(true);
            }
        });

        helperMessage.setVisibility(View.VISIBLE);
    }

    //Get Categories
    mRequestMethods.getCategories(new RequestMethods.ResponseCallback() {
        @Override
        public void onSuccess(JSONArray response) {
            Log.v(TAG, "> getCategories > onSuccess: " + response);
            mCategoryData = response;

            //Get users pre-selected categories
            if (!(mCurrentUser.isTempUser())) {
                //If user is logged in, request any pre-selected categories
                mRequestMethods.getUserCategories(new RequestMethods.ResponseCallback() {
                    @Override
                    public void onSuccess(JSONArray response) {
                        Log.v(TAG, "> getUserCategories > onSuccess " + response.toString());

                        //Create list of category ids
                        if (response.length() > 0) {
                            //Get array of catIds
                            for (int i = 0; i < response.length(); i++) {
                                try {
                                    JSONObject singleCat = response.getJSONObject(i);
                                    mUserCategories.add(i, singleCat.getInt("categoryid"));
                                    Log.v("USERCATS", "add: " + singleCat.getInt("categoryid"));
                                } catch (JSONException e) {
                                    Log.e(TAG, e.getMessage());
                                }
                            }
                            Log.v(TAG, "users category list: " + mUserCategories.toString());
                        }
                        updateList();
                    } //onSuccess

                    @Override
                    public void onFail(VolleyError error) {
                        Log.v(TAG, "> getUserCategories > onFail " + error.toString());
                        mMessageHelper.showDialog(mContext, getString(R.string.error_title),
                                getString(R.string.error_message));
                    }
                });
            } else {

                JSONArray tempUserCategories = mSharedPref.getCategorySharedPreference();

                if (tempUserCategories != null && tempUserCategories.length() > 0) {
                    //Convert to list + add to mUserCategories
                    for (int i = 0; i < tempUserCategories.length(); i++) {
                        try {
                            mUserCategories.add(i, tempUserCategories.getInt(i));
                            Log.v(TAG, " TEMPUSER CATEGORIES: " + mUserCategories.toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                updateList();
            }
        } //onSuccess

        @Override
        public void onFail(VolleyError error) {
            Log.d(TAG, "> getCategories > onFail: " + error.getMessage());
            mMessageHelper.showDialog(mContext, getString(R.string.error_title),
                    getString(R.string.error_message));
        }
    });

    //When Category is tapped
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //ImageView checkmarkView = (ImageView)view.findViewById(R.id.checkmark);
            CheckableRelativeLayout checkableLayout = (CheckableRelativeLayout) view
                    .findViewById(R.id.checkable_layout);
            ImageView checkIcon = (ImageView) view.findViewById(R.id.category_checkmark);
            TextView categoryNameLabel = (TextView) view.findViewById(R.id.category_title);

            //Get item clicked + its category id
            CategoryListItem item = (CategoryListItem) mGridView.getItemAtPosition(position);
            String catId = String.valueOf(item.getCategoryID());

            if (mGridView.isItemChecked(position)) {
                checkableLayout.getBackground().setAlpha(128);
                checkIcon.setVisibility(View.VISIBLE);
                categoryNameLabel.setTextColor(getResources().getColor(R.color.secondary_text_material_dark));
                item.setCategoryChecked(true);
                mRequestMethods.addCategory(catId);
                //Log.v(TAG, "ADDED " + catId);
            } else {
                checkableLayout.getBackground().setAlpha(255);
                checkIcon.setVisibility(View.GONE);
                categoryNameLabel
                        .setTextColor(getResources().getColor(R.color.primary_text_default_material_dark));
                item.setCategoryChecked(false);
                mRequestMethods.removeCategory(catId);
                //Log.v(TAG, "REMOVED " + catId);
            }
            //Count how many items are checked: if at least 3, show done button
            SparseBooleanArray positions = mGridView.getCheckedItemPositions();
            int length = positions.size();
            int ItemsChecked = 0;
            if (positions.size() > 0) {
                for (int i = 0; i < length; i++) {
                    if (positions.get(positions.keyAt(i))) {
                        ItemsChecked++;
                    }
                }
            }
            if (ItemsChecked >= 1) {
                MenuItem doneButton = menu.findItem(R.id.action_done);
                doneButton.setVisible(true);
            } else {
                MenuItem doneButton = menu.findItem(R.id.action_done);
                doneButton.setVisible(false);
            }
        }
    }); //setOnItemClickListener

}

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);//from   w w w .  j  a v  a  2 s .c om
        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;
}

From source file:org.dvbviewer.controller.ui.base.BaseListFragment.java

/**
 * Gets the checked item count.//from  w  w  w.  j  av  a  2 s  . com
 *
 * @return the checked item count
 * @author RayBa
 * @date 07.04.2013
 */
public int getCheckedItemCount() {
    SparseBooleanArray checkedPositions = getListView().getCheckedItemPositions();
    int count = 0;
    int size = checkedPositions.size();
    if (checkedPositions != null && size > 0) {
        for (int i = 0; i < size; i++) {
            if (checkedPositions.valueAt(i)) {
                count++;
            }
        }
    }
    return count;
}

From source file:org.mariotaku.twidere.fragment.support.DraftsFragment.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   w  ww.  j  av  a 2s.  co m*/
        f.show(getChildFragmentManager(), "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;
}

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

private void uploadSelectedRecords() {

    boolean allDrafts = true;
    SparseBooleanArray selected = getListView().getCheckedItemPositions();
    int count = countSelected();
    int index = 0;
    int[] recordIds = new int[count];
    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;
                if (record.getStatus() != Record.Status.DRAFT) {
                    allDrafts = false;/* ww  w .jav  a 2s . c o  m*/
                }
                recordIds[index++] = record.getId();
            }
        }
    }

    if (allDrafts) {
        showDraftsError();
    } else {
        Intent intent = new Intent(getActivity(), UploadService.class);
        intent.putExtra(UploadService.RECORD_IDS_EXTRA, recordIds);
        getActivity().startService(intent);
    }
    finishActionMode();
}

From source file:org.mariotaku.twidere.fragment.DraftsFragment.java

@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.delete: {
        final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment();
        final Bundle args = new Bundle();
        args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds());
        f.setArguments(args);//ww w  .  jav a 2s .  co  m
        f.show(getChildFragmentManager(), "delete_drafts_confirm");
        break;
    }
    case R.id.send: {
        final Cursor c = mAdapter.getCursor();
        if (c == null || c.isClosed())
            return false;
        final SparseBooleanArray checked = mListView.getCheckedItemPositions();
        final List<Draft> list = new ArrayList<>();
        final DraftCursorIndices indices = new DraftCursorIndices(c);
        for (int i = 0, j = checked.size(); i < j; i++) {
            if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) {
                list.add(indices.newObject(c));
            }
        }
        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;
}