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.mariotaku.twidere.activity.support.ComposeActivity.java

@Override
public void onSaveInstanceState(final Bundle outState) {
    outState.putLongArray(EXTRA_ACCOUNT_IDS, mAccountsAdapter.getSelectedAccountIds());
    outState.putParcelableArrayList(EXTRA_MEDIA, new ArrayList<Parcelable>(getMediaList()));
    outState.putBoolean(EXTRA_IS_POSSIBLY_SENSITIVE, mIsPossiblySensitive);
    outState.putParcelable(EXTRA_STATUS, mInReplyToStatus);
    outState.putLong(EXTRA_STATUS_ID, mInReplyToStatusId);
    outState.putParcelable(EXTRA_USER, mMentionUser);
    outState.putParcelable(EXTRA_DRAFT, mDraftItem);
    outState.putBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS, mShouldSaveAccounts);
    outState.putString(EXTRA_ORIGINAL_TEXT, mOriginalText);
    super.onSaveInstanceState(outState);
}

From source file:com.android.deskclock.AlarmClockFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putLong(KEY_EXPANDED_ID, mAdapter.getExpandedId());
    outState.putLongArray(KEY_REPEAT_CHECKED_IDS, mAdapter.getRepeatArray());
    outState.putLongArray(KEY_SELECTED_ALARMS, mAdapter.getSelectedAlarmsArray());
    outState.putBundle(KEY_RINGTONE_TITLE_CACHE, mRingtoneTitleCache);
    outState.putParcelable(KEY_DELETED_ALARM, mDeletedAlarm);
    outState.putBoolean(KEY_UNDO_SHOWING, mUndoShowing);
    outState.putBundle(KEY_PREVIOUS_DAY_MAP, mAdapter.getPreviousDaysOfWeekMap());
    outState.putParcelable(KEY_SELECTED_ALARM, mSelectedAlarm);
}

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

@Override
public void onSaveInstanceState(final Bundle outState) {
    mText = parseString(mEditText.getText());
    outState.putLongArray(INTENT_KEY_IDS, mAccountIds);
    outState.putString(INTENT_KEY_TEXT, mText);
    outState.putLong(INTENT_KEY_IN_REPLY_TO_ID, mInReplyToStatusId);
    outState.putString(INTENT_KEY_IN_REPLY_TO_NAME, mInReplyToName);
    outState.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, mInReplyToScreenName);
    outState.putBoolean(INTENT_KEY_IS_QUOTE, mIsQuote);
    outState.putBoolean(INTENT_KEY_IS_IMAGE_ATTACHED, mIsImageAttached);
    outState.putBoolean(INTENT_KEY_IS_PHOTO_ATTACHED, mIsPhotoAttached);
    outState.putParcelable(INTENT_KEY_IMAGE_URI, mImageUri);
    outState.putBoolean(INTENT_KEY_CONTENT_MODIFIED, mContentModified);
    outState.putBoolean(INTENT_KEY_IS_POSSIBLY_SENSITIVE, mIsPossiblySensitive);
    super.onSaveInstanceState(outState);
}

From source file:com.android.music.MediaPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    badSymptoms.saveMenu("menu", item.toString());

    Intent intent;//  w w w .j  a  v a2 s .co  m
    try {
        switch (item.getItemId()) {
        case GOTO_START:
            intent = new Intent();
            intent.setClass(this, MusicBrowserActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
            break;
        case USE_AS_RINGTONE: {
            // Set the system setting to make this the current ringtone
            if (mService != null) {
                MusicUtils.setRingtone(this, mService.getAudioId());
            }
            return true;
        }
        case PARTY_SHUFFLE:
            MusicUtils.togglePartyShuffle();
            setShuffleButtonImage();
            break;

        case NEW_PLAYLIST: {
            intent = new Intent();
            intent.setClass(this, CreatePlaylist.class);
            startActivityForResult(intent, NEW_PLAYLIST);
            return true;
        }

        case PLAYLIST_SELECTED: {
            long[] list = new long[1];
            list[0] = MusicUtils.getCurrentAudioId();
            long playlist = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(this, list, playlist);
            return true;
        }

        case DELETE_ITEM: {
            if (mService != null) {
                long[] list = new long[1];
                list[0] = MusicUtils.getCurrentAudioId();
                Bundle b = new Bundle();
                String f;
                if (android.os.Environment.isExternalStorageRemovable()) {
                    f = getString(R.string.delete_song_desc, mService.getTrackName());
                } else {
                    f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName());
                }
                b.putString("description", f);
                b.putLongArray("items", list);
                intent = new Intent();
                intent.setClass(this, DeleteItems.class);
                intent.putExtras(b);
                startActivityForResult(intent, -1);
            }
            return true;
        }

        case EFFECTS_PANEL: {
            Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
            i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mService.getAudioSessionId());
            startActivityForResult(i, EFFECTS_PANEL);
            return true;
        }
        }
    } catch (RemoteException ex) {
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.music.TrackBrowserFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case PLAY_SELECTION: {
        // play the track
        int position = mSelectedPosition;
        MusicUtils.playAll(getActivity(), mTrackCursor, position);
        return true;
    }//w w w  .  jav a 2s.  c om

    case QUEUE: {
        long[] list = new long[] { mSelectedId };
        MusicUtils.addToCurrentPlaylist(getActivity(), list);
        return true;
    }

    case NEW_PLAYLIST: {
        Intent intent = new Intent();
        intent.setClass(getActivity(), CreatePlaylist.class);
        startActivityForResult(intent, NEW_PLAYLIST);
        return true;
    }

    case PLAYLIST_SELECTED: {
        long[] list = new long[] { mSelectedId };
        long playlist = item.getIntent().getLongExtra("playlist", 0);
        MusicUtils.addToPlaylist(getActivity(), list, playlist);
        return true;
    }

    case USE_AS_RINGTONE:
        // Set the system setting to make this the current ringtone
        MusicUtils.setRingtone(getActivity(), mSelectedId);
        return true;

    case DELETE_ITEM: {
        long[] list = new long[1];
        list[0] = (int) mSelectedId;
        Bundle b = new Bundle();
        String f;
        if (android.os.Environment.isExternalStorageRemovable()) {
            f = getString(R.string.delete_song_desc);
        } else {
            f = getString(R.string.delete_song_desc_nosdcard);
        }
        String desc = String.format(f, mCurrentTrackName);
        b.putString("description", desc);
        b.putLongArray("items", list);
        Intent intent = new Intent();
        intent.setClass(getActivity(), DeleteItems.class);
        intent.putExtras(b);
        startActivityForResult(intent, -1);
        return true;
    }

    case REMOVE:
        removePlaylistItem(mSelectedPosition);
        return true;

    case SEARCH:
        doSearch();
        return true;
    }
    return super.onContextItemSelected(item);
}

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

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case MENU_HOME: {
        final String text = mEditText != null ? parseString(mEditText.getText()) : null;
        if (mContentModified && !isNullOrEmpty(text)) {
            mUnsavedTweetDialogFragment = (DialogFragment) Fragment.instantiate(this,
                    UnsavedTweetDialogFragment.class.getName());
            final Bundle args = new Bundle();
            args.putBoolean(INTENT_KEY_IS_NAVIGATE_UP, true);
            mUnsavedTweetDialogFragment.setArguments(args);
            mUnsavedTweetDialogFragment.show(getSupportFragmentManager(), "unsaved_tweet");
        } else {/* www. j a  v a 2 s.  c  om*/
            NavUtils.navigateUpFromSameTask(this);
        }
        break;
    }
    case MENU_SEND: {
        send();
        break;
    }
    case MENU_SELECT_ACCOUNT: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        final Bundle bundle = new Bundle();
        bundle.putBoolean(INTENT_KEY_ACTIVATED_ONLY, true);
        bundle.putLongArray(INTENT_KEY_IDS, mAccountIds);
        intent.putExtras(bundle);
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;/*from ww  w  .java 2 s . com*/
    try {
        switch (item.getItemId()) {
        case GOTO_START:
            intent = new Intent();
            intent.setClass(this, MusicBrowserActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
            break;
        case USE_AS_RINGTONE: {
            // Set the system setting to make this the current ringtone
            if (mService != null) {
                MusicUtils.setRingtone(this, mService.getAudioId());
            }
            return true;
        }
        case PARTY_SHUFFLE:
            MusicUtils.togglePartyShuffle();
            setShuffleButtonImage();
            break;

        case NEW_PLAYLIST: {
            intent = new Intent();
            intent.setClass(this, CreatePlaylist.class);
            startActivityForResult(intent, NEW_PLAYLIST);
            return true;
        }

        case PLAYLIST_SELECTED: {
            long[] list = new long[1];
            list[0] = MusicUtils.getCurrentAudioId();
            long playlist = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(this, list, playlist);
            return true;
        }

        case DELETE_ITEM: {
            if (mService != null) {
                long[] list = new long[1];
                list[0] = MusicUtils.getCurrentAudioId();
                Bundle b = new Bundle();
                String f;
                if (android.os.Environment.isExternalStorageRemovable()) {
                    f = getString(R.string.delete_song_desc, mService.getTrackName());
                } else {
                    f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName());
                }
                b.putString("description", f);
                b.putLongArray("items", list);
                intent = new Intent();
                intent.setClass(this, DeleteItems.class);
                intent.putExtras(b);
                startActivityForResult(intent, -1);
            }
            return true;
        }

        case EFFECTS_PANEL: {
            Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
            i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mService.getAudioSessionId());
            startActivityForResult(i, EFFECTS_PANEL);
            return true;
        }
        }
    } catch (RemoteException ex) {
    }
    return super.onOptionsItemSelected(item);
}

From source file:saphion.fragments.alarm.AlarmFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putLongArray(KEY_EXPANDED_IDS, mAdapter.getExpandedArray());
    outState.putLongArray(KEY_REPEAT_CHECKED_IDS, mAdapter.getRepeatArray());
    outState.putLongArray(KEY_SELECTED_ALARMS, mAdapter.getSelectedAlarmsArray());
    outState.putBundle(KEY_RINGTONE_TITLE_CACHE, mRingtoneTitleCache);
    outState.putParcelable(KEY_DELETED_ALARM, mDeletedAlarm);
    outState.putBoolean(KEY_UNDO_SHOWING, mUndoShowing);
    outState.putBundle(KEY_PREVIOUS_DAY_MAP, mAdapter.getPreviousDaysOfWeekMap());
    outState.putParcelable(KEY_SELECTED_ALARM, mSelectedAlarm);
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

private static void putNestedJSONObject(JSONObject jsonObject, Bundle bundle) throws JSONException {
    JSONArray names = jsonObject.names();
    for (int i = 0; i < names.length(); i++) {
        String name = names.getString(i);
        Object data = jsonObject.get(name);
        if (data == null) {
            continue;
        }//from   w  w w.  j  av  a 2s .  com
        if (data instanceof Integer) {
            bundle.putInt(name, ((Integer) data).intValue());
        }
        if (data instanceof Float) {
            bundle.putFloat(name, ((Float) data).floatValue());
        }
        if (data instanceof Double) {
            bundle.putDouble(name, ((Double) data).doubleValue());
        }
        if (data instanceof Long) {
            bundle.putLong(name, ((Long) data).longValue());
        }
        if (data instanceof String) {
            bundle.putString(name, (String) data);
        }
        if (data instanceof Boolean) {
            bundle.putBoolean(name, ((Boolean) data).booleanValue());
        }
        // Nested JSONObject
        if (data instanceof JSONObject) {
            Bundle nestedBundle = new Bundle();
            bundle.putBundle(name, nestedBundle);
            putNestedJSONObject((JSONObject) data, nestedBundle);
        }
        // Nested JSONArray. Doesn't support mixed types in single array
        if (data instanceof JSONArray) {
            // Empty array. No way to tell what type of data to pass on, so skipping
            if (((JSONArray) data).length() == 0) {
                Log.e("Empty array not supported in nested JSONObject, skipping");
                continue;
            }
            // Integer
            if (((JSONArray) data).get(0) instanceof Integer) {
                int[] integerArrayData = new int[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    integerArrayData[j] = ((JSONArray) data).getInt(j);
                }
                bundle.putIntArray(name, integerArrayData);
            }
            // Double
            if (((JSONArray) data).get(0) instanceof Double) {
                double[] doubleArrayData = new double[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    doubleArrayData[j] = ((JSONArray) data).getDouble(j);
                }
                bundle.putDoubleArray(name, doubleArrayData);
            }
            // Long
            if (((JSONArray) data).get(0) instanceof Long) {
                long[] longArrayData = new long[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    longArrayData[j] = ((JSONArray) data).getLong(j);
                }
                bundle.putLongArray(name, longArrayData);
            }
            // String
            if (((JSONArray) data).get(0) instanceof String) {
                String[] stringArrayData = new String[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    stringArrayData[j] = ((JSONArray) data).getString(j);
                }
                bundle.putStringArray(name, stringArrayData);
            }
            // Boolean
            if (((JSONArray) data).get(0) instanceof Boolean) {
                boolean[] booleanArrayData = new boolean[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    booleanArrayData[j] = ((JSONArray) data).getBoolean(j);
                }
                bundle.putBooleanArray(name, booleanArrayData);
            }
        }
    }
}

From source file:com.facebook.SharedPreferencesTokenCache.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);
        }//from  w  w  w.  ja v a2 s.  c  o  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);
    }
}