Example usage for android.os Bundle putLongArray

List of usage examples for android.os Bundle putLongArray

Introduction

In this page you can find the example usage for android.os Bundle putLongArray.

Prototype

public void putLongArray(@Nullable String key, @Nullable long[] value) 

Source Link

Document

Inserts a long array value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:org.opendatakit.common.android.utilities.AndroidUtils.java

public static Bundle convertToBundle(JSONObject valueMap, final MacroStringExpander expander)
        throws JSONException {
    Bundle b = new Bundle();
    @SuppressWarnings("unchecked")
    Iterator<String> cur = valueMap.keys();
    while (cur.hasNext()) {
        String key = cur.next();/* w w  w.j a va  2s .  c  o m*/
        if (!valueMap.isNull(key)) {
            Object o = valueMap.get(key);
            if (o instanceof JSONObject) {
                Bundle be = convertToBundle((JSONObject) o, expander);
                b.putBundle(key, be);
            } else if (o instanceof JSONArray) {
                JSONArray a = (JSONArray) o;
                // only non-empty arrays are written into the Bundle
                // first non-null element defines data type
                // for the array
                Object oe = null;
                for (int j = 0; j < a.length(); ++j) {
                    if (!a.isNull(j)) {
                        oe = a.get(j);
                        break;
                    }
                }
                if (oe != null) {
                    if (oe instanceof JSONObject) {
                        Bundle[] va = new Bundle[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = null;
                            } else {
                                va[j] = convertToBundle((JSONObject) a.getJSONObject(j), expander);
                            }
                        }
                        b.putParcelableArray(key, va);
                    } else if (oe instanceof JSONArray) {
                        throw new JSONException("Unable to convert nested arrays");
                    } else if (oe instanceof String) {
                        String[] va = new String[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = null;
                            } else {
                                va[j] = a.getString(j);
                            }
                        }
                        b.putStringArray(key, va);
                    } else if (oe instanceof Boolean) {
                        boolean[] va = new boolean[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = false;
                            } else {
                                va[j] = a.getBoolean(j);
                            }
                        }
                        b.putBooleanArray(key, va);
                    } else if (oe instanceof Integer) {
                        int[] va = new int[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = 0;
                            } else {
                                va[j] = a.getInt(j);
                            }
                        }
                        b.putIntArray(key, va);
                    } else if (oe instanceof Long) {
                        long[] va = new long[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = 0;
                            } else {
                                va[j] = a.getLong(j);
                            }
                        }
                        b.putLongArray(key, va);
                    } else if (oe instanceof Double) {
                        double[] va = new double[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = Double.NaN;
                            } else {
                                va[j] = a.getDouble(j);
                            }
                        }
                        b.putDoubleArray(key, va);
                    }
                }
            } else if (o instanceof String) {
                String v = valueMap.getString(key);
                if (expander != null) {
                    v = expander.expandString(v);
                }
                b.putString(key, v);
            } else if (o instanceof Boolean) {
                b.putBoolean(key, valueMap.getBoolean(key));
            } else if (o instanceof Integer) {
                b.putInt(key, valueMap.getInt(key));
            } else if (o instanceof Long) {
                b.putLong(key, valueMap.getLong(key));
            } else if (o instanceof Double) {
                b.putDouble(key, valueMap.getDouble(key));
            }
        }
    }
    return b;
}

From source file:com.facebook.LegacyTokenHelper.java

private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
        bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        boolean[] array = new boolean[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getBoolean(i);
        }/*  w w w  . j  a v a 2  s  . co  m*/
        bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
        bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        byte[] array = new byte[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (byte) jsonArray.getInt(i);
        }
        bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
        bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        short[] array = new short[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (short) jsonArray.getInt(i);
        }
        bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
        bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int[] array = new int[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getInt(i);
        }
        bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
        bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        long[] array = new long[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getLong(i);
        }
        bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
        bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        float[] array = new float[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) jsonArray.getDouble(i);
        }
        bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
        bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        double[] array = new double[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getDouble(i);
        }
        bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
        String charString = json.getString(JSON_VALUE);
        if (charString != null && charString.length() == 1) {
            bundle.putChar(key, charString.charAt(0));
        }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        char[] array = new char[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            String charString = jsonArray.getString(i);
            if (charString != null && charString.length() == 1) {
                array[i] = charString.charAt(0);
            }
        }
        bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
        bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int numStrings = jsonArray.length();
        ArrayList<String> stringList = new ArrayList<String>(numStrings);
        for (int i = 0; i < numStrings; i++) {
            Object jsonStringValue = jsonArray.get(i);
            stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
        }
        bundle.putStringArrayList(key, stringList);
    } else if (valueType.equals(TYPE_ENUM)) {
        try {
            String enumType = json.getString(JSON_VALUE_ENUM_TYPE);
            @SuppressWarnings({ "unchecked", "rawtypes" })
            Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType);
            @SuppressWarnings("unchecked")
            Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE));
            bundle.putSerializable(key, enumValue);
        } catch (ClassNotFoundException e) {
        } catch (IllegalArgumentException e) {
        }
    }
}

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

private boolean processIntent(Intent intent) {
    boolean isDeepLink = false;

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        /* Do a search by name, launched from the quick search */
        String query = intent.getStringExtra(SearchManager.QUERY);
        Bundle args = new Bundle();
        SearchCriteria sc = new SearchCriteria();
        sc.name = query;/* www .  j ava 2 s .  co  m*/
        args.putSerializable(SearchViewFragment.CRITERIA, sc);
        selectItem(R.string.main_card_search, args, false,
                true); /* Don't clear backstack, do force the intent */

    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        boolean shouldSelectItem = true;

        Uri data = intent.getData();
        Bundle args = new Bundle();
        assert data != null;

        boolean shouldClearFragmentStack = true; /* Clear backstack for deep links */
        if (data.getAuthority().toLowerCase().contains("gatherer.wizards")) {
            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                String queryParam;
                if ((queryParam = data.getQueryParameter("multiverseid")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByMultiverseId(Long.parseLong(queryParam),
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else if ((queryParam = data.getQueryParameter("name")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByName(queryParam,
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            true, database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else {
                    throw new Exception("Not Found");
                }
            } catch (Exception e) {
                /* empty cursor, just return */
                ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                this.finish();
                shouldSelectItem = false;
            } finally {
                DatabaseManager.getInstance(this, false).closeDatabase(false);
            }
        } else if (data.getAuthority().contains("CardSearchProvider")) {
            /* User clicked a card in the quick search autocomplete, jump right to it */
            args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                    new long[] { Long.parseLong(data.getLastPathSegment()) });
            shouldClearFragmentStack = false; /* Don't clear backstack for search intents */
        } else {
            /* User clicked a deep link, jump to the card(s) */
            isDeepLink = true;

            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                Cursor cursor = null;
                boolean screenLaunched = false;
                if (data.getScheme().toLowerCase().equals("card")
                        && data.getAuthority().toLowerCase().equals("multiverseid")) {
                    if (data.getLastPathSegment() == null) {
                        /* Home screen deep link */
                        launchHomeScreen();
                        screenLaunched = true;
                        shouldSelectItem = false;
                    } else {
                        try {
                            /* Don't clear the fragment stack for internal links (thanks Meld cards) */
                            if (data.getPathSegments().contains("internal")) {
                                shouldClearFragmentStack = false;
                            }
                            cursor = CardDbAdapter.fetchCardByMultiverseId(
                                    Long.parseLong(data.getLastPathSegment()),
                                    new String[] {
                                            CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                                    database);
                        } catch (NumberFormatException e) {
                            cursor = null;
                        }
                    }
                }

                if (cursor != null) {
                    if (cursor.getCount() != 0) {
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    } else {
                        /* empty cursor, just return */
                        ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                        this.finish();
                        shouldSelectItem = false;
                    }
                    cursor.close();
                } else if (!screenLaunched) {
                    /* null cursor, just return */
                    ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                    this.finish();
                    shouldSelectItem = false;
                }
            } catch (FamiliarDbException e) {
                e.printStackTrace();
            }
            DatabaseManager.getInstance(this, false).closeDatabase(false);
        }
        args.putInt(CardViewPagerFragment.STARTING_CARD_POSITION, 0);
        if (shouldSelectItem) {
            selectItem(R.string.main_card_search, args, shouldClearFragmentStack, true);
        }
    } else if (ACTION_ROUND_TIMER.equals(intent.getAction())) {
        selectItem(R.string.main_timer, null, true, false);
    } else if (ACTION_CARD_SEARCH.equals(intent.getAction())) {
        selectItem(R.string.main_card_search, null, true, false);
    } else if (ACTION_LIFE.equals(intent.getAction())) {
        selectItem(R.string.main_life_counter, null, true, false);
    } else if (ACTION_DICE.equals(intent.getAction())) {
        selectItem(R.string.main_dice, null, true, false);
    } else if (ACTION_TRADE.equals(intent.getAction())) {
        selectItem(R.string.main_trade, null, true, false);
    } else if (ACTION_MANA.equals(intent.getAction())) {
        selectItem(R.string.main_mana_pool, null, true, false);
    } else if (ACTION_WISH.equals(intent.getAction())) {
        selectItem(R.string.main_wishlist, null, true, false);
    } else if (ACTION_RULES.equals(intent.getAction())) {
        selectItem(R.string.main_rules, null, true, false);
    } else if (ACTION_JUDGE.equals(intent.getAction())) {
        selectItem(R.string.main_judges_corner, null, true, false);
    } else if (ACTION_MOJHOSTO.equals(intent.getAction())) {
        selectItem(R.string.main_mojhosto, null, true, false);
    } else if (ACTION_PROFILE.equals(intent.getAction())) {
        selectItem(R.string.main_profile, null, true, false);
    } else if (ACTION_DECKLIST.equals(intent.getAction())) {
        selectItem(R.string.main_decklist, null, true, false);
    } else if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        /* App launched as regular, show the default fragment if there isn't one already */
        if (getSupportFragmentManager().getFragments() == null) {
            launchHomeScreen();
        }
    } else {
        /* Some unknown intent, just finish */
        finish();
    }

    mDrawerList.setItemChecked(mCurrentFrag, true);
    return isDeepLink;
}

From source file:io.jawg.osmcontributor.ui.fragments.MapFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
    outState.putParcelable(LOCATION, mapboxMap.getCameraPosition().target);
    outState.putFloat(ZOOM_LEVEL, getZoomLevel());
    outState.putInt(CREATION_MODE, mapMode.ordinal());
    outState.putLong(POI_TYPE_ID, poiTypeSelected == null ? -1 : poiTypeSelected.getId());
    outState.putDouble(LEVEL, currentLevel);
    outState.putBoolean(DISPLAY_OPEN_NOTES, displayOpenNotes);
    outState.putBoolean(DISPLAY_CLOSED_NOTES, displayClosedNotes);

    int markerType = markerSelected == null ? LocationMarkerView.MarkerType.NONE.ordinal()
            : markerSelected.getType().ordinal();
    outState.putInt(MARKER_TYPE, markerType);

    if (markerSelected != null) {
        switch (markerSelected.getType()) {
        case POI:
            markerSelectedId = ((Poi) markerSelected.getRelatedObject()).getId();
            break;
        case NODE_REF:
            markerSelectedId = ((PoiNodeRef) markerSelected.getRelatedObject()).getId();
            break;
        case NOTE:
            markerSelectedId = ((Note) markerSelected.getRelatedObject()).getId();
            break;
        }/*ww w.j a  va  2 s.c om*/
    } else {
        markerSelectedId = -1L;
    }
    outState.putLong(SELECTED_MARKER_ID, markerSelectedId);

    long[] hidden = new long[poiTypeHidden.size()];
    int index = 0;

    for (Long value : poiTypeHidden) {
        hidden[index] = value;
        index++;
    }

    outState.putLongArray(HIDDEN_POI_TYPE, hidden);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    // ADW: If we leave the menu open, on restoration it will try to auto
    // find//from  ww  w.  ja va 2 s . c om
    // the ocupied cells. But this could happed before the workspace is
    // fully loaded,
    // so it can cause a NPE cause of the way we load the desktop
    // columns/rows count.
    // I prefer to just close it than diggin the code to make it load
    // later...
    // Accepting patches :-)
    closeOptionsMenu();
    super.onSaveInstanceState(outState);

    outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
    if (mWorkspace != null) {
        final ArrayList<PersonaFolder> personaFolders = mWorkspace.getOpenFolders();
        if (personaFolders.size() > 0) {
            final int count = personaFolders.size();
            long[] ids = new long[count];
            for (int i = 0; i < count; i++) {
                final PersonaFolderInfo info = personaFolders.get(i).getInfo();
                ids[i] = info.id;
            }
            outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
        }
    }
    final boolean isConfigurationChange = getChangingConfigurations() != 0;

    // When the drawer is opened and we are saving the state because of a
    // configuration change
    if (allAppsOpen && isConfigurationChange) {
        outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
    }
    if (mDockBar != null && mDockBar.isOpen()) {
        outState.putBoolean(RUNTIME_STATE_DOCKBAR, true);
    }
    if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
        final PersonaCellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
        final PersonaCellLayout layout = (PersonaCellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);

        outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
        outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
        outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS, layout.getOccupiedCells());
    }

    if (mFolderInfo != null && mWaitingForResult) {
        outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
        outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
    }
}