Example usage for android.util SparseBooleanArray put

List of usage examples for android.util SparseBooleanArray put

Introduction

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

Prototype

public void put(int key, boolean value) 

Source Link

Document

Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.

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 w w .j a v  a  2 s.  c  o m
}

From source file:Main.java

public static SparseBooleanArray cloneSBArray(SparseBooleanArray arr) {
    try {//w w w  .j  a va  2  s  .  c  o m
        return arr.clone();
    } catch (Exception e) {
        // Happens when using HC - should clone manually
        int size = arr.size();
        SparseBooleanArray clone = new SparseBooleanArray();
        for (int i = 0; i < size; i++) {
            if (arr.get(arr.keyAt(i))) {
                clone.put(arr.keyAt(i), true);
            }
        }
        return clone;
    }
}

From source file:org.kontalk.util.SystemUtils.java

/**
 * Provides clone functionality for the {@link SparseBooleanArray}.
 * See https://code.google.com/p/android/issues/detail?id=39242
 *//*w w  w.ja v  a2  s. c  o  m*/
public static SparseBooleanArray cloneSparseBooleanArray(SparseBooleanArray array) {
    final SparseBooleanArray clone = new SparseBooleanArray();

    synchronized (array) {
        final int size = array.size();
        for (int i = 0; i < size; i++) {
            int key = array.keyAt(i);
            clone.put(key, array.get(key));
        }
    }

    return clone;
}

From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java

@SuppressWarnings("boxing")
public static void handleRecurrence(final FragmentActivity activity, final Task task, final boolean isDue,
        final ExecInterface callback) {
    final FragmentManager fm = activity.getSupportFragmentManager();
    Optional<Recurring> recurringOptional = isDue ? task.getRecurrence() : task.getRecurringReminder();
    boolean isExact = false;
    if (recurringOptional.isPresent()) {
        Recurring recurring = recurringOptional.get();
        isExact = recurring.isExact();/*from w w  w  .ja va 2  s. co  m*/
        Log.d(TAG, "exact: " + isExact);
        if (recurring.getDerivedFrom().isPresent()) {
            final Optional<Recurring> master = Recurring.get(recurring.getDerivedFrom().get());
            if (master.isPresent()) {
                recurring = master.get();
            }
        }
    }
    final RecurrencePickerDialog rp = RecurrencePickerDialog.newInstance(new OnRecurrenceSetListener() {
        @Override
        public void onCustomRecurrenceSetInterval(final boolean isDue, final int intervalYears,
                final int intervalMonths, final int intervalDays, final int intervalHours,
                final int intervalMinutes, @NonNull final Optional<Calendar> startDate,
                @NonNull final Optional<Calendar> endDate, final boolean isExact) {
            final Recurring r = Recurring.newRecurring("", intervalMinutes, intervalHours, intervalDays,
                    intervalMonths, intervalYears, isDue, startDate, endDate, true, isExact,
                    new SparseBooleanArray());
            setRecurence(task, isDue, r.getId(), callback);
        }

        @Override
        public void onCustomRecurrenceSetWeekdays(final boolean isDue, @NonNull final List<Integer> weekdays,
                @NonNull final Optional<Calendar> startDate, @NonNull final Optional<Calendar> endDate,
                final boolean isExact) {
            final SparseBooleanArray weekdaysArray = new SparseBooleanArray();
            for (final int day : weekdays) {
                weekdaysArray.put(day, true);
            }
            final Recurring r = Recurring.newRecurring("", 0, 0, 0, 0, 0, isDue, startDate, endDate, true,
                    isExact, weekdaysArray);
            setRecurence(task, isDue, r.getId(), callback);
        }

        @Override
        public void onNoRecurrenceSet() {
            setRecurence(task, isDue, -1, callback);
        }

        @Override
        public void onRecurrenceSet(final Recurring r) {
            setRecurence(task, isDue, r.getId(), callback);
        }
    }, recurringOptional, isDue, MirakelCommonPreferences.isDark(), isExact);
    rp.show(fm, "reccurence");
}

From source file:android.databinding.ViewDataBinding.java

/** @hide */
protected static void setTo(SparseBooleanArray list, int index, boolean value) {
    if (list == null || index < 0 || index >= list.size()) {
        return;/* w w  w . j av  a2s.  c  om*/
    }
    list.put(index, value);
}

From source file:org.akop.crosswords.fragment.BaseFragment.java

protected void readSparseBooleanArray(Bundle bundle, String prefix, SparseBooleanArray array) {
    int keys[] = bundle.getIntArray(prefix + "_keys");
    boolean values[] = bundle.getBooleanArray(prefix + "_values");

    if (keys != null && values != null) {
        for (int i = 0, n = keys.length; i < n; i++) {
            array.put(keys[i], values[i]);
        }//w  w w .  jav  a 2  s .c  o  m
    }
}

From source file:com.github.jobs.ui.dialog.RemoveServicesDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final ArrayList<Parcelable> services = getArguments().getParcelableArrayList(ARG_SERVICES);
    CharSequence[] items = new CharSequence[services.size()];
    for (int i = 0, servicesSize = services.size(); i < servicesSize; i++) {
        TemplateService service = (TemplateService) services.get(i);
        items[i] = getString(R.string.service_list_item, service.getType(), service.getData());
    }/*from www . j a  va2s.  com*/
    final SparseBooleanArray checked = new SparseBooleanArray();
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.title_remove_services)
            .setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    checked.put(which, isChecked);
                }
            }).setPositiveButton(R.string.remove_selected_services, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // get a list of the services to delete
                    ArrayList<TemplateService> toRemove = new ArrayList<TemplateService>();
                    for (int i = 0; i < checked.size(); i++) {
                        if (checked.valueAt(i)) {
                            int index = checked.keyAt(i);
                            toRemove.add((TemplateService) services.get(index));
                        }
                    }
                    // fire service deletion
                    FragmentActivity activity = getActivity();
                    if (activity instanceof EditTemplateActivity) {
                        EditTemplateActivity editTemplateActivity = (EditTemplateActivity) activity;
                        editTemplateActivity.removeServices(toRemove);
                    }
                }
            }).setNegativeButton(R.string.cancel, null).create();
}

From source file:com.rc.droid_stalker.components.NetworkStats.java

/**
 * Return list of unique UIDs known by this data structure.
 *//*from   w ww .j  a  v  a  2  s .co  m*/
public int[] getUniqueUids() {
    final SparseBooleanArray uids = new SparseBooleanArray();
    for (int uid : this.uid) {
        uids.put(uid, true);
    }

    final int size = uids.size();
    final int[] result = new int[size];
    for (int i = 0; i < size; i++) {
        result[i] = uids.keyAt(i);
    }
    return result;
}

From source file:org.mariotaku.twidere.activity.AccountSelectorActivity.java

@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
    mAdapter.swapCursor(cursor);//  ww  w .  ja v a  2s . co m
    final SparseBooleanArray checked = new SparseBooleanArray();
    cursor.moveToFirst();
    if (mSelectedIds.size() == 0) {
        if (mAllowSelectNone)
            return;
        while (!cursor.isAfterLast()) {
            final boolean is_activated = cursor
                    .getInt(cursor.getColumnIndexOrThrow(Accounts.IS_ACTIVATED)) == 1;
            final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID));
            if (is_activated) {
                mSelectedIds.add(user_id);
            }
            mAdapter.setItemChecked(cursor.getPosition(), is_activated);
            cursor.moveToNext();
        }
    } else {
        while (!cursor.isAfterLast()) {
            final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID));
            if (mSelectedIds.contains(user_id)) {
                checked.put(cursor.getPosition(), true);
                mAdapter.setItemChecked(cursor.getPosition(), true);
            }
            cursor.moveToNext();
        }
    }
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

private static void fillSeparatorsSparseArray(SparseBooleanArray sparseBooleanArray, char[] chars) {
    sparseBooleanArray.clear();//from   w w w . ja v a  2s. co m
    for (char separator : chars)
        sparseBooleanArray.put(separator, true);
}