Example usage for android.util SparseBooleanArray get

List of usage examples for android.util SparseBooleanArray get

Introduction

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

Prototype

public boolean get(int key) 

Source Link

Document

Gets the boolean mapped from the specified key, or false if no such mapping has been made.

Usage

From source file:com.shinymayhem.radiopresets.FragmentStations.java

private int getSelectedPosition() {
    SparseBooleanArray positions = mListView.getCheckedItemPositions();
    int position = -1;
    for (int i = 0; i < mListView.getCount(); i++) {
        boolean selected = positions.get(i);
        if (selected) {
            position = i;//from  w w  w . jav a  2 s .  c  om
        }
    }
    return position;
}

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

/**
 * Valid the Group Name/*  w w w.  jav  a 2s  .c  o m*/
 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com
 * @return void
 */
private void okAction() {
    if (et_GroupName.getText() == null || et_GroupName.getText().toString().trim().length() == 0) {
        Msg.alertMsg(this, getString(R.string.BChat_MustFillGroupName));
    } else {
        SparseBooleanArray itemsChecked = lv_Contacts.getCheckedItemPositions();
        if (itemsChecked.size() == 0) {
            Msg.alertMsg(this, getString(R.string.BChat_MustFillGroupName));
        } else {
            //   Create Request
            SyncRequest_BC request = new SyncRequest_BC(null, String.valueOf(Env.getAD_User_ID()), null,
                    et_GroupName.getText().toString(), null, null, true);
            for (int i = 0; i < itemsChecked.size(); i++) {
                boolean selected = itemsChecked.get(i);
                if (selected) {
                    DisplayBChatContactItem contact = m_ContactAdapter.getItem(i);
                    request.addUser(new Invited(contact.getRecord_ID(), MQTTDefaultValues.STATUS_CREATED));
                }
            }
            //   Add Local User
            request.addUser(new Invited(Env.getAD_User_ID(), MQTTDefaultValues.STATUS_CREATED));
            //   Save Request
            BCMessageHandle.getInstance(this).sendRequest(request);
            //   Add Param
            Intent intent = getIntent();
            intent.putExtra("SPS_BC_Request_UUID", request.getSPS_BC_Request_UUID());
            setResult(Activity.RESULT_OK, intent);
            finish();
        }
    }
}

From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java

private Event getFirstCheckedItem() {
    if (getListView().getCheckedItemCount() != 1) {
        return null;
    }/*from w  ww  .  j a v a2  s.co  m*/

    SparseBooleanArray checkedItemPositions = getListView().getCheckedItemPositions();
    for (int i = 0; i < getListAdapter().getCount(); i++) {
        if (checkedItemPositions.get(i)) {
            return (Event) getListAdapter().getItem(i);
        }
    }
    return null;
}

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  ww  w .j a  va  2 s .  c  o 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:com.chalmers.feedlr.activity.FeedActivity.java

public void createFeed(View button) {

    // Animate switch to main view
    toggleSettingsView(null);/*from ww  w .j  av a  2  s  . c  o m*/

    // Extract new feed title
    EditText titleEditText = (EditText) userListLayout.findViewById(R.id.create_feed_action_bar_title);
    String feedTitle = titleEditText.getText().toString();
    Feed feed = new Feed(feedTitle);

    // Extract new feed users
    SparseBooleanArray checked = userListView.getCheckedItemPositions();
    ArrayList<Integer> userIDs = new ArrayList<Integer>();

    UserAdapter adapter = (UserAdapter) userListView.getAdapter();

    Cursor c;
    for (int i = 0; i < adapter.getCount(); i++) {
        if (checked.get(i)) {
            c = (Cursor) adapter.getItem(i);
            userIDs.add(c.getInt(c.getColumnIndex(DatabaseHelper.USER_COLUMN_USERID)));
        }
    }

    // Save user list as a feed in database
    db.addFeed(feed);
    long feed_id = db.getFeed_id(feed);
    for (Integer i : userIDs)
        db.addFeedUserBridge(feed_id, i);
    Log.i(getClass().getName(), "Added feed \"" + feed.getTitle() + "\" with " + userIDs.size() + " users.");

    // Hide keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(titleEditText.getWindowToken(), 0);

    // Animate switch to new feed view
    this.feedAdapter.addFeed(feed);
    feedViewSwiper.setCurrentItem(adapter.getCount());
    feedTitleTextView.setText(feed.getTitle());

    // Remove the createFeedView
    View v = settingsViewFlipper.getCurrentView();
    settingsViewFlipper.showPrevious();
    settingsViewFlipper.removeView(v);
    userListLayout = null;
    userListView = null;

    // Check overlay
    updateOverlay();
}

From source file:com.battlelancer.seriesguide.ui.dialogs.ManageListsDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View layout = inflater.inflate(R.layout.dialog_manage_lists, container, false);

    // buttons// w  ww.ja  va 2 s  .  c  o m
    Button dontAddButton = (Button) layout.findViewById(R.id.buttonNegative);
    dontAddButton.setText(android.R.string.cancel);
    dontAddButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    Button addButton = (Button) layout.findViewById(R.id.buttonPositive);
    addButton.setText(android.R.string.ok);
    addButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // add item to selected lists
            int itemTvdbId = getArguments().getInt(InitBundle.INT_ITEM_TVDB_ID);
            int itemType = getArguments().getInt(InitBundle.INT_ITEM_TYPE);
            SparseBooleanArray checkedLists = mAdapter.getCheckedPositions();

            final ArrayList<ContentProviderOperation> batch = new ArrayList<>();

            for (int position = 0; position < mAdapter.getCount(); position++) {
                final Cursor listEntry = (Cursor) mAdapter.getItem(position);

                boolean wasListChecked = !TextUtils.isEmpty(listEntry.getString(ListsQuery.LIST_ITEM_ID));
                boolean isListChecked = checkedLists.get(position);

                String listId = listEntry.getString(ListsQuery.LIST_ID);
                String listItemId = ListItems.generateListItemId(itemTvdbId, itemType, listId);

                if (wasListChecked && !isListChecked) {
                    // remove from list
                    batch.add(
                            ContentProviderOperation.newDelete(ListItems.buildListItemUri(listItemId)).build());
                } else if (!wasListChecked && isListChecked) {
                    // add to list
                    ContentValues values = new ContentValues();
                    values.put(ListItems.LIST_ITEM_ID, listItemId);
                    values.put(ListItems.ITEM_REF_ID, itemTvdbId);
                    values.put(ListItems.TYPE, itemType);
                    values.put(Lists.LIST_ID, listId);
                    batch.add(ContentProviderOperation.newInsert(ListItems.CONTENT_URI).withValues(values)
                            .build());
                }
            }

            // apply ops
            try {
                DBUtils.applyInSmallBatches(getActivity(), batch);
            } catch (OperationApplicationException e) {
                Timber.e(e, "Applying list changes failed");
            }

            getActivity().getContentResolver().notifyChange(ListItems.CONTENT_WITH_DETAILS_URI, null);

            dismiss();
        }
    });

    // lists list
    mListView = (ListView) layout.findViewById(R.id.list);
    /*
     * As using CHOICE_MODE_MULTIPLE does not seem to work before Jelly
     * Bean, do everything ourselves.
     */
    mListView.setOnItemClickListener(this);

    return layout;
}

From source file:org.kontalk.ui.GroupInfoFragment.java

private void readdUser(final SparseBooleanArray checked) {
    List<String> users = new LinkedList<>();
    for (int i = 0, c = mMembersAdapter.getCount(); i < c; ++i) {
        if (checked.get(i)) {
            GroupMembersAdapter.GroupMember member = (GroupMembersAdapter.GroupMember) mMembersAdapter
                    .getItem(i);/*from w ww  .j  a  v  a 2  s  . c  o m*/
            if (!Authenticator.isSelfJID(getContext(), member.contact.getJID())) {
                users.add(member.contact.getJID());
            }
        }
    }

    if (users.size() > 0) {
        mConversation.addUsers(users.toArray(new String[users.size()]));
    }

    getActivity().finish();
}

From source file:com.battlelancer.seriesguide.ui.dialogs.ListsDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View layout = inflater.inflate(R.layout.list_dialog, null);

    // buttons//from   ww  w  . ja v  a2s  .co  m
    Button dontAddButton = (Button) layout.findViewById(R.id.buttonNegative);
    dontAddButton.setText(android.R.string.cancel);
    dontAddButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    Button addButton = (Button) layout.findViewById(R.id.buttonPositive);
    addButton.setText(android.R.string.ok);
    addButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // add item to selected lists
            String itemId = getArguments().getString("itemid");
            int itemType = getArguments().getInt("itemtype");
            SparseBooleanArray checkedLists = mAdapter.getCheckedPositions();

            final ArrayList<ContentProviderOperation> batch = com.uwetrottmann.androidutils.Lists
                    .newArrayList();

            for (int position = 0; position < mAdapter.getCount(); position++) {
                final Cursor listEntry = (Cursor) mAdapter.getItem(position);

                boolean wasListChecked = !TextUtils.isEmpty(listEntry.getString(ListsQuery.LIST_ITEM_ID));
                boolean isListChecked = checkedLists.get(position);

                String listId = listEntry.getString(ListsQuery.LIST_ID);
                String listItemId = ListItems.generateListItemId(itemId, itemType, listId);

                if (wasListChecked && !isListChecked) {
                    // remove from list
                    batch.add(
                            ContentProviderOperation.newDelete(ListItems.buildListItemUri(listItemId)).build());
                } else if (!wasListChecked && isListChecked) {
                    // add to list
                    ContentValues values = new ContentValues();
                    values.put(ListItems.LIST_ITEM_ID, listItemId);
                    values.put(ListItems.ITEM_REF_ID, itemId);
                    values.put(ListItems.TYPE, itemType);
                    values.put(Lists.LIST_ID, listId);
                    batch.add(ContentProviderOperation.newInsert(ListItems.CONTENT_URI).withValues(values)
                            .build());
                }
            }

            // apply ops
            try {
                DBUtils.applyInSmallBatches(getActivity(), batch);
            } catch (OperationApplicationException e) {
                Timber.e("Applying list changes failed", e);
            }

            getActivity().getContentResolver().notifyChange(ListItems.CONTENT_WITH_DETAILS_URI, null);

            dismiss();
        }
    });

    // lists list
    mListView = (ListView) layout.findViewById(R.id.list);
    /*
     * As using CHOICE_MODE_MULTIPLE does not seem to work before Jelly
     * Bean, do everything ourselves.
     */
    mListView.setOnItemClickListener(this);

    return layout;
}

From source file:org.kontalk.ui.GroupInfoFragment.java

private void removeSelectedUsers(final SparseBooleanArray checked) {
    boolean removingSelf = false;
    List<String> users = new LinkedList<>();
    for (int i = 0, c = mMembersAdapter.getCount(); i < c; ++i) {
        if (checked.get(i)) {
            GroupMembersAdapter.GroupMember member = (GroupMembersAdapter.GroupMember) mMembersAdapter
                    .getItem(i);// www  . java2  s  . co  m
            if (Authenticator.isSelfJID(getContext(), member.contact.getJID())) {
                removingSelf = true;
            } else {
                users.add(member.contact.getJID());
            }
        }
    }

    if (users.size() > 0) {
        mConversation.removeUsers(users.toArray(new String[users.size()]));
        reload();
    }

    if (removingSelf)
        confirmLeave();
}

From source file:com.sumatone.cloud.securecloud.Fragments.UploadFragment.java

private void selectAcps() {
    final CharSequence[] items = RegisterActivity.ROLES;
    int level = PreferenceManager.getDefaultSharedPreferences(getActivity()).getInt("level", 7);
    int levelBelowThisUser = searchLastLevel(RegisterActivity.LEVELS, level);
    final CharSequence[] filterItems = Arrays.copyOfRange(items, levelBelowThisUser + 1, items.length);

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Who can download the file?");
    builder.setMultiChoiceItems(filterItems, null, null);

    final List<AccessControlPolicy> tempList = new ArrayList<AccessControlPolicy>();

    builder.setPositiveButton("Next", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            switch (state) {
            case 0:
                SparseBooleanArray CheCked = ((AlertDialog) dialog).getListView().getCheckedItemPositions();
                acpsArray = new JSONArray();
                for (int i = 0; i < CheCked.size(); i++) {
                    if (CheCked.get(i) == true) {
                        List<String> actionList = new ArrayList<String>();
                        actionList.add("download");
                        tempList.add(new AccessControlPolicy(filterItems[i].toString(), actionList));
                        /*JSONObject object = new JSONObject();
                        try {/*ww  w .jav a 2  s .  c om*/
                            object.put(String.valueOf(RegisterActivity.LEVELS[i]), "download");
                            acpsArray.put(object);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }*/
                    }
                }
                state = 1;
                builder.setTitle("Who can delete the file?");
                builder.setMultiChoiceItems(filterItems, null, null);
                builder.create().show();

                //encryptAndUpload();
                break;
            case 1:
                CheCked = ((AlertDialog) dialog).getListView().getCheckedItemPositions();
                acpsArray = new JSONArray();
                for (int i = 0; i < CheCked.size(); i++) {
                    if (CheCked.get(i) == true) {
                        for (int j = 0; j < tempList.size(); j++) {
                            if (tempList.get(j).getRole().equals(filterItems[i].toString())) {
                                tempList.get(j).getActions().add("delete");
                                break;
                            }
                        }
                        /*JSONObject object = new JSONObject();
                        try {
                            object.put(String.valueOf(RegisterActivity.LEVELS[i]), "download");
                            acpsArray.put(object);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }*/
                    }
                }
                state = 2;
                builder.setTitle("Who can update the file?");
                builder.setMultiChoiceItems(filterItems, null, null);
                builder.create().show();
                break;
            case 2:
                state = 0;
                CheCked = ((AlertDialog) dialog).getListView().getCheckedItemPositions();
                acpsArray = new JSONArray();
                for (int i = 0; i < CheCked.size(); i++) {
                    if (CheCked.get(i) == true) {
                        for (int j = 0; j < tempList.size(); j++) {
                            if (tempList.get(j).getRole().equals(filterItems[i].toString())) {
                                tempList.get(j).getActions().add("update");
                                break;
                            }
                        }
                        /*JSONObject object = new JSONObject();
                        try {
                            object.put(String.valueOf(RegisterActivity.LEVELS[i]), "download");
                            acpsArray.put(object);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }*/
                    }
                }
                formPolicyConfigurations(tempList);
                break;
            default:
            }
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    builder.create().show();
}