Example usage for android.os Bundle putParcelableArray

List of usage examples for android.os Bundle putParcelableArray

Introduction

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

Prototype

public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) 

Source Link

Document

Inserts an array of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:de.spiritcroc.ownlog.ui.fragment.LogItemEditFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(KEY_ADD_ITEM, mAddItem);
    outState.putBoolean(KEY_TEMPORARY_EXISTENCE, mTemporaryExistence);
    outState.putString(KEY_INIT_TITLE, mInitTitle);
    outState.putString(KEY_SET_TITLE, mEditLogTitle.getText().toString());
    outState.putString(KEY_INIT_CONTENT, mInitContent);
    outState.putString(KEY_SET_CONTENT, mEditLogContent.getText().toString());
    outState.putLong(KEY_INIT_TIME, mInitTime);
    outState.putLong(KEY_SET_TIME, mTime.getTimeInMillis());
    outState.putParcelableArray(KEY_INIT_TAGS, mInitTags.toArray(new TagItem[mInitTags.size()]));
    outState.putParcelableArray(KEY_SET_TAGS, mSetTags.toArray(new TagItem[mSetTags.size()]));
    outState.putParcelableArray(KEY_AVAILABLE_TAGS, mAvailableTags.toArray(new TagItem[mAvailableTags.size()]));
}

From source file:net.alexjf.tmm.fragments.ImmedTransactionStatsFragment.java

private void updateCurrentTransactionSet() {
    if (adapter == null || catPercentageAdapter == null) {
        return;//from w w  w.  ja v a2s. c o m
    }

    if (adapter.getCount() == 0 && catPercentageAdapter.getCount() == 0) {
        return;
    }

    if (categoryStatsTask != null) {
        return;
    }

    Utils.preventOrientationChanges(getActivity());

    String strLoading = getActivity().getResources().getString(R.string.analyzing_stats);

    categoryStatsTask = new AsyncTaskWithProgressDialog<ImmediateTransactionAdapter>(getActivity(),
            TASK_CATEGORYSTATS, strLoading) {
        // TODO: Make this more efficient by already getting all the
        // data from the database
        @Override
        protected Bundle doInBackground(ImmediateTransactionAdapter... args) {
            List<ImmediateTransaction> currentTransactionSet = new LinkedList<ImmediateTransaction>();
            Utils.fromAdapterToList(adapter, currentTransactionSet);
            currentFilter.applyInPlace(currentTransactionSet);

            Map<Category, Double> perCategoryValues = new HashMap<Category, Double>();

            double totalValue = 0;
            CurrencyUnit currency = null;

            for (ImmediateTransaction transaction : currentTransactionSet) {
                try {
                    transaction.load();
                    Category cat = transaction.getCategory();
                    cat.load();

                    Money transactionValue = transaction.getValue();

                    if (currency == null) {
                        currency = transactionValue.getCurrencyUnit();
                    }

                    double transactionValueDouble = transactionValue.abs().getAmount().doubleValue();

                    Double existingValue = perCategoryValues.get(cat);

                    totalValue += transactionValueDouble;

                    if (existingValue != null) {
                        transactionValueDouble += existingValue;
                    }

                    perCategoryValues.put(cat, transactionValueDouble);
                } catch (DatabaseException e) {
                    setThrowable(e);
                    return null;
                }
            }

            Bundle bundle = new Bundle();
            int size = perCategoryValues.size();
            Category[] categories = new Category[size];
            double[] values = new double[size];

            List<Entry<Category, Double>> catValues = new ArrayList<Entry<Category, Double>>(
                    perCategoryValues.entrySet());
            Collections.sort(catValues, new Comparator<Entry<Category, Double>>() {
                @Override
                public int compare(Map.Entry<Category, Double> arg0, Map.Entry<Category, Double> arg1) {
                    return arg0.getValue().compareTo(arg1.getValue());
                }

                ;
            });

            int i = 0;
            for (Entry<Category, Double> catValue : catValues) {
                categories[i] = catValue.getKey();
                values[i] = catValue.getValue();
                i++;
            }

            if (currency != null) {
                bundle.putString(KEY_CURRENCY, currency.getCurrencyCode());
            }
            bundle.putParcelableArray(KEY_CATEGORIES, categories);
            bundle.putDoubleArray(KEY_VALUES, values);
            bundle.putDouble(KEY_TOTALVALUE, totalValue);

            return bundle;
        }

        ;
    };

    categoryStatsTask.setResultListener(this);
    categoryStatsTask.execute(adapter);
}

From source file:androidx.media.MediaBrowserServiceCompat.java

void performSearch(final String query, Bundle extras, ConnectionRecord connection,
        final ResultReceiver receiver) {
    final Result<List<MediaBrowserCompat.MediaItem>> result = new Result<List<MediaBrowserCompat.MediaItem>>(
            query) {//  w ww. ja va2s  .c o m
        @Override
        void onResultSent(List<MediaBrowserCompat.MediaItem> items) {
            if ((getFlags() & RESULT_FLAG_ON_SEARCH_NOT_IMPLEMENTED) != 0 || items == null) {
                receiver.send(RESULT_ERROR, null);
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putParcelableArray(KEY_SEARCH_RESULTS, items.toArray(new MediaBrowserCompat.MediaItem[0]));
            receiver.send(RESULT_OK, bundle);
        }
    };

    mCurConnection = connection;
    onSearch(query, extras, result);
    mCurConnection = null;

    if (!result.isDone()) {
        throw new IllegalStateException(
                "onSearch must call detach() or sendResult()" + " before returning for query=" + query);
    }
}

From source file:info.icefilms.icestream.browse.BrowseFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    // Call base class method
    super.onSaveInstanceState(outState);

    // Save the stop parcel and other settings and lists
    outState.putParcelable("StopParcel", new StopParcel(this));
    outState.putBoolean("InitialConnection", mInitialConnection);
    outState.putParcelableArrayList("Heading1Items", mHeadingItems[0]);
    outState.putParcelableArrayList("Heading2Items", mHeadingItems[1]);
    outState.putParcelableArrayList("Heading3Items", mHeadingItems[2]);
    outState.putParcelableArrayList("ListItems", mListItems);
    outState.putParcelableArray("CurrentState", mCurrentState.toArray(new State[0]));
}

From source file:androidx.media.MediaController2.java

/**
 * Sets the playlist.//  ww w  .j  a  va2  s .c om
 * <p>
 * Even when the playlist is successfully set, use the playlist returned from
 * {@link #getPlaylist()} for playlist APIs such as {@link #skipToPlaylistItem(MediaItem2)}.
 * Otherwise the session in the remote process can't distinguish between media items.
 *
 * @param list playlist
 * @param metadata metadata of the playlist
 * @see #getPlaylist()
 * @see ControllerCallback#onPlaylistChanged
 */
public void setPlaylist(@NonNull List<MediaItem2> list, @Nullable MediaMetadata2 metadata) {
    if (list == null) {
        throw new IllegalArgumentException("list shouldn't be null");
    }
    Bundle args = new Bundle();
    args.putParcelableArray(ARGUMENT_PLAYLIST, MediaUtils2.toMediaItem2ParcelableArray(list));
    args.putBundle(ARGUMENT_PLAYLIST_METADATA, metadata == null ? null : metadata.toBundle());
    sendCommand(COMMAND_CODE_PLAYLIST_SET_LIST, args);
}

From source file:androidx.media.MediaSession2StubImplBase.java

private void connect(Bundle extras, final ResultReceiver cb) {
    final ControllerInfo controllerInfo = createControllerInfo(extras);
    mSession.getCallbackExecutor().execute(new Runnable() {
        @Override/* w  w  w.  j  a v a2  s .  c  om*/
        public void run() {
            if (mSession.isClosed()) {
                return;
            }
            synchronized (mLock) {
                // Keep connecting controllers.
                // This helps sessions to call APIs in the onConnect()
                // (e.g. setCustomLayout()) instead of pending them.
                mConnectingControllers.add(controllerInfo.getId());
            }
            SessionCommandGroup2 allowedCommands = mSession.getCallback().onConnect(mSession.getInstance(),
                    controllerInfo);
            // Don't reject connection for the request from trusted app.
            // Otherwise server will fail to retrieve session's information to dispatch
            // media keys to.
            boolean accept = allowedCommands != null || controllerInfo.isTrusted();
            if (accept) {
                if (DEBUG) {
                    Log.d(TAG, "Accepting connection, controllerInfo=" + controllerInfo + " allowedCommands="
                            + allowedCommands);
                }
                if (allowedCommands == null) {
                    // For trusted apps, send non-null allowed commands to keep
                    // connection.
                    allowedCommands = new SessionCommandGroup2();
                }
                synchronized (mLock) {
                    mConnectingControllers.remove(controllerInfo.getId());
                    mControllers.put(controllerInfo.getId(), controllerInfo);
                    mAllowedCommandGroupMap.put(controllerInfo, allowedCommands);
                }
                // If connection is accepted, notify the current state to the
                // controller. It's needed because we cannot call synchronous calls
                // between session/controller.
                // Note: We're doing this after the onConnectionChanged(), but there's
                //       no guarantee that events here are notified after the
                //       onConnected() because IMediaController2 is oneway (i.e. async
                //       call) and Stub will use thread poll for incoming calls.
                final Bundle resultData = new Bundle();
                resultData.putBundle(ARGUMENT_ALLOWED_COMMANDS, allowedCommands.toBundle());
                resultData.putInt(ARGUMENT_PLAYER_STATE, mSession.getPlayerState());
                resultData.putInt(ARGUMENT_BUFFERING_STATE, mSession.getBufferingState());
                resultData.putParcelable(ARGUMENT_PLAYBACK_STATE_COMPAT, mSession.getPlaybackStateCompat());
                resultData.putInt(ARGUMENT_REPEAT_MODE, mSession.getRepeatMode());
                resultData.putInt(ARGUMENT_SHUFFLE_MODE, mSession.getShuffleMode());
                final List<MediaItem2> playlist = allowedCommands.hasCommand(COMMAND_CODE_PLAYLIST_GET_LIST)
                        ? mSession.getPlaylist()
                        : null;
                if (playlist != null) {
                    resultData.putParcelableArray(ARGUMENT_PLAYLIST,
                            MediaUtils2.toMediaItem2ParcelableArray(playlist));
                }
                final MediaItem2 currentMediaItem = allowedCommands.hasCommand(
                        COMMAND_CODE_PLAYLIST_GET_CURRENT_MEDIA_ITEM) ? mSession.getCurrentMediaItem() : null;
                if (currentMediaItem != null) {
                    resultData.putBundle(ARGUMENT_MEDIA_ITEM, currentMediaItem.toBundle());
                }
                resultData.putBundle(ARGUMENT_PLAYBACK_INFO, mSession.getPlaybackInfo().toBundle());
                final MediaMetadata2 playlistMetadata = mSession.getPlaylistMetadata();
                if (playlistMetadata != null) {
                    resultData.putBundle(ARGUMENT_PLAYLIST_METADATA, playlistMetadata.toBundle());
                }
                // Double check if session is still there, because close() can be
                // called in another thread.
                if (mSession.isClosed()) {
                    return;
                }
                cb.send(CONNECT_RESULT_CONNECTED, resultData);
            } else {
                synchronized (mLock) {
                    mConnectingControllers.remove(controllerInfo.getId());
                }
                if (DEBUG) {
                    Log.d(TAG, "Rejecting connection, controllerInfo=" + controllerInfo);
                }
                cb.send(CONNECT_RESULT_DISCONNECTED, null);
            }
        }
    });
}

From source file:li.barter.http.HttpResponseParser.java

/**
 * @param response parsing google book api response
 * @return/*from  w  ww . j  a  v  a  2  s .  c  om*/
 */
private ResponseInfo parseGoogleBookSuggestionsResponse(final String response) throws JSONException {

    final ResponseInfo responseInfo = new ResponseInfo();
    final Bundle responseBundle = new Bundle(1);

    final JSONObject bookInfoObject = new JSONObject(response);
    final JSONArray searchResults = JsonUtils.readJSONArray(bookInfoObject, HttpConstants.ITEMS, false, false);
    Suggestion[] suggestion = new Suggestion[searchResults.length()];
    for (int i = 0; i < searchResults.length(); i++) {
        String id, name, imageUrl;

        JSONObject bookInfo = JsonUtils.readJSONObject(searchResults, i, false, false);

        id = JsonUtils.readString(bookInfo, HttpConstants.ID, false, false);

        JSONObject volumeInfo = JsonUtils.readJSONObject(bookInfo, HttpConstants.VOLUMEINFO, false, false);
        name = JsonUtils.readString(volumeInfo, HttpConstants.TITLE, false, false);

        try {
            JSONObject imageLinks = JsonUtils.readJSONObject(volumeInfo, HttpConstants.IMAGELINKS, false,
                    false);
            imageUrl = JsonUtils.readString(imageLinks, HttpConstants.THUMBNAIL, false, false);
        } catch (Exception e) {
            imageUrl = "";
        }

        suggestion[i] = new Suggestion();
        suggestion[i].id = id;
        suggestion[i].name = name;
        suggestion[i].imageUrl = imageUrl;

    }
    responseBundle.putParcelableArray(HttpConstants.RESULTS, suggestion);
    responseInfo.responseBundle = responseBundle;
    return responseInfo;
}

From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    if (mTimePicker != null) {
        outState.putParcelable(KEY_INITIAL_TIME, mTimePicker.getTime());
        outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
        outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
        outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
        if (mInKbMode) {
            outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
        }// w w w  . ja  v  a2s . c o m
        outState.putString(KEY_TITLE, mTitle);
        outState.putBoolean(KEY_THEME_DARK, mThemeDark);
        outState.putBoolean(KEY_THEME_DARK_CHANGED, mThemeDarkChanged);
        outState.putInt(KEY_ACCENT, mAccentColor);
        outState.putBoolean(KEY_VIBRATE, mVibrate);
        outState.putBoolean(KEY_DISMISS, mDismissOnPause);
        outState.putParcelableArray(KEY_SELECTABLE_TIMES, mSelectableTimes);
        outState.putParcelable(KEY_MIN_TIME, mMinTime);
        outState.putParcelable(KEY_MAX_TIME, mMaxTime);
        outState.putBoolean(KEY_ENABLE_SECONDS, mEnableSeconds);
        outState.putInt(KEY_OK_RESID, mOkResid);
        outState.putString(KEY_OK_STRING, mOkString);
        outState.putInt(KEY_CANCEL_RESID, mCancelResid);
        outState.putString(KEY_CANCEL_STRING, mCancelString);
    }
}

From source file:com.jarklee.materialdatetimepicker.time.TimePickerDialog.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    if (mTimePicker != null) {
        outState.putParcelable(KEY_INITIAL_TIME, mTimePicker.getTime());
        outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
        outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
        outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
        if (mInKbMode) {
            outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
        }//  w  w  w. j  av a2s . co  m
        outState.putString(KEY_TITLE, mTitle);
        outState.putBoolean(KEY_THEME_DARK, mThemeDark);
        outState.putBoolean(KEY_THEME_DARK_CHANGED, mThemeDarkChanged);
        outState.putInt(KEY_ACCENT, mAccentColor);
        outState.putBoolean(KEY_VIBRATE, mVibrate);
        outState.putBoolean(KEY_DISMISS, mDismissOnPause);
        outState.putParcelableArray(KEY_SELECTABLE_TIMES, mSelectableTimes);
        outState.putParcelable(KEY_MIN_TIME, mMinTime);
        outState.putParcelable(KEY_MAX_TIME, mMaxTime);
        outState.putBoolean(KEY_ENABLE_SECONDS, mEnableSeconds);
        outState.putBoolean(KEY_ENABLE_MINUTES, mEnableMinutes);
        outState.putInt(KEY_OK_RESID, mOkResid);
        outState.putString(KEY_OK_STRING, mOkString);
        outState.putInt(KEY_CANCEL_RESID, mCancelResid);
        outState.putString(KEY_CANCEL_STRING, mCancelString);
    }
}

From source file:com.customdatepicker.time.TimePickerDialog.java

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    if (mTimePicker != null) {
        outState.putParcelable(KEY_INITIAL_TIME, mTimePicker.getTime());
        outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
        outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
        outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
        if (mInKbMode) {
            outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
        }/* w ww . j  av a 2  s .c  o  m*/
        outState.putString(KEY_TITLE, mTitle);
        outState.putBoolean(KEY_THEME_DARK, mThemeDark);
        outState.putBoolean(KEY_THEME_DARK_CHANGED, mThemeDarkChanged);
        outState.putInt(KEY_ACCENT, mAccentColor);
        outState.putBoolean(KEY_VIBRATE, mVibrate);
        outState.putBoolean(KEY_DISMISS, mDismissOnPause);
        outState.putParcelableArray(KEY_SELECTABLE_TIMES, mSelectableTimes);
        outState.putParcelable(KEY_MIN_TIME, mMinTime);
        outState.putParcelable(KEY_MAX_TIME, mMaxTime);
        outState.putBoolean(KEY_ENABLE_SECONDS, mEnableSeconds);
        outState.putBoolean(KEY_ENABLE_MINUTES, mEnableMinutes);
        outState.putInt(KEY_OK_RESID, mOkResid);
        outState.putString(KEY_OK_STRING, mOkString);
        outState.putInt(KEY_OK_COLOR, mOkColor);
        outState.putInt(KEY_CANCEL_RESID, mCancelResid);
        outState.putString(KEY_CANCEL_STRING, mCancelString);
        outState.putInt(KEY_CANCEL_COLOR, mCancelColor);
        outState.putSerializable(KEY_VERSION, mVersion);
    }
}