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, boolean valueIfKeyNotFound) 

Source Link

Document

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

Usage

From source file:Main.java

public static void swap(SparseBooleanArray booleanArray, int x, int p, boolean defaultValue) {
    boolean value = booleanArray.get(x, defaultValue);
    booleanArray.put(x, booleanArray.get(p, defaultValue));
    booleanArray.put(p, value);//  w  ww.ja  va 2 s.c o  m
}

From source file:Main.java

public static <T> ArrayList<T> getIfTrue(T[] items, SparseBooleanArray booleanArray) {
    final ArrayList<T> values = new ArrayList<>();
    for (int i = 0; i < items.length; i++) {
        if (booleanArray.get(i, false)) {
            values.add(items[i]);//from   ww w  .j  a v a  2 s.  c o  m
        }
    }
    return values;
}

From source file:com.dwdesign.tweetings.activity.SelectAccountActivity.java

@Override
public void onItemClick(final AdapterView<?> adapter, final View view, final int position, final long id) {
    if (mCursor == null || mCursor.isClosed())
        return;//  w  ww. j ava 2  s.c  o m
    final int choise_mode = mListView.getChoiceMode();
    if (choise_mode == ListView.CHOICE_MODE_NONE)
        return;

    final SparseBooleanArray checkedpositions = mListView.getCheckedItemPositions();
    final boolean checked = checkedpositions.get(position, false);
    mCursor.moveToPosition(position);
    final long user_id = mCursor.getLong(mCursor.getColumnIndexOrThrow(Accounts.USER_ID));
    if (!checked) {
        if (mActivatedUsersId.contains(user_id)) {
            mActivatedUsersId.remove(user_id);
        }
    } else if (!mActivatedUsersId.contains(user_id)) {
        mActivatedUsersId.add(user_id);
    }
}

From source file:org.mariotaku.twidere.extension.timescape.ExtensionSettingsActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (mCursor == null || mCursor.isClosed())
        return;// w w w.j  a va2  s.  com

    final SparseBooleanArray checkedpositions = mListView.getCheckedItemPositions();
    final boolean checked = checkedpositions.get(position, false);
    mCursor.moveToPosition(position);
    final long user_id = mCursor.getLong(mCursor.getColumnIndex(Accounts.USER_ID));
    if (!checked) {
        if (mSelectedIds.contains(user_id)) {
            mSelectedIds.remove(user_id);
        }
    } else if (!mSelectedIds.contains(user_id)) {
        mSelectedIds.add(user_id);
    }
    final SharedPreferences.Editor editor = mPreferences.edit();
    editor.putString(PREFERENCE_KEY_SELECTED_IDS, ListUtils.buildString(mSelectedIds, ',', false));
    editor.commit();

    insertOrUpdatePlugin(this, mSelectedIds.size() > 0 ? ConfigState.CONFIGURED : ConfigState.NOT_CONFIGURED);
    final Application application = getApplication();
    if (application instanceof ExtensionApplication) {
        ((ExtensionApplication) application).loadStatuses();
    }
}

From source file:com.andremion.louvre.sample.MediaTypeFilterDialog.java

@NonNull
private String[] parseToArray(@NonNull SparseBooleanArray selectedTypes) {
    List<String> selectedTypeList = new ArrayList<>();
    for (int i = 0; i < selectedTypes.size(); i++) {
        int key = selectedTypes.keyAt(i);
        if (selectedTypes.get(key, false)) {
            selectedTypeList.add(Louvre.IMAGE_TYPES[key]);
        }/*from   w w w. j a v a 2 s .  c  om*/
    }
    String[] array = new String[selectedTypeList.size()];
    selectedTypeList.toArray(array);
    return array;
}

From source file:com.irccloud.android.fragment.SpamFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context ctx = getActivity();
    if (ctx == null)
        return null;

    if (server == null && savedInstanceState != null && savedInstanceState.containsKey("cid"))
        server = ServersList.getInstance().getServer(savedInstanceState.getInt("cid"));

    if (server == null)
        throw new IllegalArgumentException("invalid CID");

    if (buffers == null && savedInstanceState != null && savedInstanceState.containsKey("buffers")) {
        buffers = (ArrayList<Buffer>) savedInstanceState.getSerializable("buffers");
    } else {//  w  w  w  .ja  v  a 2 s.  com
        buffers = new ArrayList<>();
        for (Buffer b : BuffersList.getInstance().getBuffersForServer(server.getCid())) {
            if (b.getArchived() == 0 && b.getType().equals("conversation"))
                buffers.add(b);
        }
    }

    ArrayList<String> itemsList = new ArrayList<>();
    for (Buffer b : buffers) {
        itemsList.add(b.getName());
    }

    if (buffersToRemove == null && savedInstanceState != null
            && savedInstanceState.containsKey("buffersToRemove")) {
        buffersToRemove = (ArrayList<Buffer>) savedInstanceState.getSerializable("buffersToRemove");
    } else {
        buffersToRemove = new ArrayList<>(buffers);
    }

    CharSequence[] items = itemsList.toArray(new CharSequence[itemsList.size()]);
    LayoutInflater inflater = LayoutInflater.from(ctx);
    View v = inflater.inflate(R.layout.dialog_spam, null);
    listView = v.findViewById(android.R.id.list);
    listView.setAdapter(new ArrayAdapter<>(ctx, R.layout.row_spam, items));

    for (int i = 0; i < buffers.size(); i++) {
        listView.setItemChecked(i, buffersToRemove.contains(buffers.get(i)));
    }

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            SparseBooleanArray checked = listView.getCheckedItemPositions();
            buffersToRemove.clear();
            for (int i = 0; i < buffers.size(); i++) {
                if (checked.get(i, false))
                    buffersToRemove.add(buffers.get(i));
            }
        }
    });

    return new AlertDialog.Builder(ctx).setView(v)
            .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    for (Buffer b : buffersToRemove) {
                        NetworkConnection.getInstance().deleteBuffer(b.getCid(), b.getBid());
                    }

                    new AlertDialog.Builder(ctx)
                            .setTitle(server.getName() + " (" + server.getHostname() + ":" + (server.getPort())
                                    + ")")
                            .setMessage(buffersToRemove.size() + " conversations were deleted")
                            .setNegativeButton("Close", null).show();
                }
            }).setNegativeButton("Cancel", null).create();
}

From source file:com.findme.views.ExpandableTextView.java

public void setText(CharSequence text, SparseBooleanArray collapsedStatus, int position) {
    mCollapsedStatus = collapsedStatus;//from  w ww . j  av a  2s. c  om
    mPosition = position;
    boolean isCollapsed = collapsedStatus.get(position, true);
    clearAnimation();
    mCollapsed = isCollapsed;
    mButton.setImageDrawable(mCollapsed ? mExpandDrawable : mCollapseDrawable);
    setText(text);
    getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
    requestLayout();
}

From source file:com.akalipetis.action_mode_list_fragment.ActionModeListFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public int calculateCheckedItems() {
    ListView l = getListView();//  w  ww. j  a v  a 2 s .c o  m
    if (Build.VERSION.SDK_INT >= 11)
        return l.getCheckedItemCount();
    SparseBooleanArray checkedItems = l.getCheckedItemPositions();
    if (checkedItems == null)
        return 0;
    int cnt = 0;
    for (int i = 0, lim = checkedItems.size(); i < lim; ++i) {
        int key = checkedItems.keyAt(i);
        if (checkedItems.get(key, false))
            cnt++;
    }
    return cnt;
}

From source file:com.akalipetis.fragment.ActionModeListFragment.java

public int calculateCheckedItems() {
    ListView l = getListView();/*from  w w  w .  ja v  a  2s.c om*/
    if (Build.VERSION.SDK_INT >= 11)
        return l.getCheckedItemCount();
    SparseBooleanArray checkedItems = l.getCheckedItemPositions();
    if (checkedItems == null)
        return 0;
    int cnt = 0;
    for (int i = 0, lim = checkedItems.size(); i < lim; ++i) {
        int key = checkedItems.keyAt(i);
        if (checkedItems.get(key, false))
            cnt++;
    }
    return cnt;
}

From source file:es.ugr.swad.swadroid.modules.tests.TestsMake.java

/**
 * Function to set the tags that will be present in the test
 *//*from  w  w w  .  jav  a2  s  .  c  om*/
private void setTags() {
    ListView checkBoxesList = (ListView) findViewById(R.id.testTagsList);
    TagsArrayAdapter tagsAdapter = (TagsArrayAdapter) checkBoxesList.getAdapter();
    int childsCount = checkBoxesList.getCount();
    SparseBooleanArray checkedItems = checkBoxesList.getCheckedItemPositions();
    tagsList = new ArrayList<TestTag>();

    //If "All tags" item checked, add the whole list to the list of selected tags
    if (checkedItems.get(0, false)) {
        tagsList.add(new TestTag(0, null, "all", 0));

        //If "All tags" item is not checked, add the selected items to the list of selected tags
    } else {
        for (int i = 0; i < childsCount; i++) {
            if (checkedItems.get(i, false)) {
                tagsList.add(tagsAdapter.getItem(i));
            }
        }
    }

    if (isDebuggable) {
        Log.d(TAG, "tagsList=" + tagsList.toString());
    }

    //If no tags selected, show a message to notice user
    if (tagsList.isEmpty()) {
        Toast.makeText(getApplicationContext(), R.string.testNoTagsSelectedMsg, Toast.LENGTH_LONG).show();

        //If any tag is selected, show the answer types selection screen
    } else {
        selectAnswerTypes();
    }
}