Example usage for android.os Bundle putParcelable

List of usage examples for android.os Bundle putParcelable

Introduction

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

Prototype

public void putParcelable(@Nullable String key, @Nullable Parcelable value) 

Source Link

Document

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

Usage

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Use the {@link ContentResolver#call} method to send or save the message.
 *
 * If this was successful, this method will return an non-null Bundle instance
 *//*from   w w  w.j  a v a  2  s .com*/
private static Bundle callAccountSendSaveMethod(final ContentResolver resolver, final Account account,
        final String method, final SendOrSaveMessage sendOrSaveMessage) {
    // Copy all of the values from the content values to the bundle
    final Bundle methodExtras = new Bundle(sendOrSaveMessage.mValues.size());
    final Set<Entry<String, Object>> valueSet = sendOrSaveMessage.mValues.valueSet();

    for (Entry<String, Object> entry : valueSet) {
        final Object entryValue = entry.getValue();
        final String key = entry.getKey();
        if (entryValue instanceof String) {
            methodExtras.putString(key, (String) entryValue);
        } else if (entryValue instanceof Boolean) {
            methodExtras.putBoolean(key, (Boolean) entryValue);
        } else if (entryValue instanceof Integer) {
            methodExtras.putInt(key, (Integer) entryValue);
        } else if (entryValue instanceof Long) {
            methodExtras.putLong(key, (Long) entryValue);
        } else {
            LogUtils.wtf(LOG_TAG, "Unexpected object type: %s", entryValue.getClass().getName());
        }
    }

    // If the SendOrSaveMessage has some opened fds, add them to the bundle
    final Bundle fdMap = sendOrSaveMessage.attachmentFds();
    if (fdMap != null) {
        methodExtras.putParcelable(UIProvider.SendOrSaveMethodParamKeys.OPENED_FD_MAP, fdMap);
    }

    return resolver.call(account.uri, method, account.uri.toString(), methodExtras);
}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Sets the current folder if it is different from the object provided here. This method does
 * NOT notify the folder observers that a change has happened. Observers are notified when we
 * get an updated folder from the loaders, which will happen as a consequence of this method
 * (since this method starts/restarts the loaders).
 * @param folder The folder to assign//from w ww .  j av a 2  s. c  om
 */
private void updateFolder(Folder folder) {
    if (folder == null || !folder.isInitialized()) {
        LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder);
        return;
    }
    if (folder.equals(mFolder)) {
        LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder);
        return;
    }
    final boolean wasNull = mFolder == null;
    LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name);
    final LoaderManager lm = mActivity.getLoaderManager();
    // updateFolder is called from AAC.onLoadFinished() on folder changes.  We need to
    // ensure that the folder is different from the previous folder before marking the
    // folder changed.
    setHasFolderChanged(folder);
    mFolder = folder;

    // We do not need to notify folder observers yet. Instead we start the loaders and
    // when the load finishes, we will get an updated folder. Then, we notify the
    // folderObservers in onLoadFinished.
    mActionBarView.setFolder(mFolder);

    // Only when we switch from one folder to another do we want to restart the
    // folder and conversation list loaders (to trigger onCreateLoader).
    // The first time this runs when the activity is [re-]initialized, we want to re-use the
    // previous loader's instance and data upon configuration change (e.g. rotation).
    // If there was not already an instance of the loader, init it.
    if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) {
        lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    } else {
        lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    }
    if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) {
        // If there was an existing folder AND we have changed
        // folders, we want to restart the loader to get the information
        // for the newly selected folder
        lm.destroyLoader(LOADER_CONVERSATION_LIST);
    }
    final Bundle args = new Bundle(2);
    args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}

From source file:com.chen.mail.ui.AbstractActivityController.java

@Override
public void onSaveInstanceState(Bundle outState) {
    mViewMode.handleSaveInstanceState(outState);
    if (mAccount != null) {
        outState.putParcelable(SAVED_ACCOUNT, mAccount);
    }/*from  w w w .  ja  va 2 s  .c  o  m*/
    if (mFolder != null) {
        outState.putParcelable(SAVED_FOLDER, mFolder);
    }
    // If this is a search activity, let's store the search query term as well.
    if (ConversationListContext.isSearchResult(mConvListContext)) {
        outState.putString(SAVED_QUERY, mConvListContext.searchQuery);
    }
    if (mCurrentConversation != null && mViewMode.isConversationMode()) {
        outState.putParcelable(SAVED_CONVERSATION, mCurrentConversation);
    }
    if (!mSelectedSet.isEmpty()) {
        outState.putParcelable(SAVED_SELECTED_SET, mSelectedSet);
    }
    if (mToastBar.getVisibility() == View.VISIBLE) {
        outState.putParcelable(SAVED_TOAST_BAR_OP, mToastBar.getOperation());
    }
    final ConversationListFragment convListFragment = getConversationListFragment();
    if (convListFragment != null) {
        convListFragment.getAnimatedAdapter().onSaveInstanceState(outState);
    }
    // If there is a dialog being shown, save the state so we can create a listener for it.
    if (mDialogAction != -1) {
        outState.putInt(SAVED_ACTION, mDialogAction);
        outState.putBoolean(SAVED_ACTION_FROM_SELECTED, mDialogFromSelectedSet);
    }
    if (mDetachedConvUri != null) {
        outState.putParcelable(SAVED_DETACHED_CONV_URI, mDetachedConvUri);
    }

    outState.putParcelable(SAVED_HIERARCHICAL_FOLDER, mFolderListFolder);
    mSafeToModifyFragments = false;

    outState.putParcelable(SAVED_INBOX_KEY, mInbox);

    outState.putBundle(SAVED_CONVERSATION_LIST_SCROLL_POSITIONS, mConversationListScrollPositions);
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * Sets the current folder if it is different from the object provided here. This method does
 * NOT notify the folder observers that a change has happened. Observers are notified when we
 * get an updated folder from the loaders, which will happen as a consequence of this method
 * (since this method starts/restarts the loaders).
 * @param folder The folder to assign//from w  ww.  j a v  a  2  s.c  o  m
 */
private void updateFolder(Folder folder) {
    if (folder == null || !folder.isInitialized()) {
        LogUtils.e(LOG_TAG, new Error(), "AAC.setFolder(%s): Bad input", folder);
        return;
    }
    if (folder.equals(mFolder)) {
        LogUtils.d(LOG_TAG, "AAC.setFolder(%s): Input matches mFolder", folder);
        return;
    }
    final boolean wasNull = mFolder == null;
    LogUtils.d(LOG_TAG, "AbstractActivityController.setFolder(%s)", folder.name);
    final LoaderManager lm = mActivity.getLoaderManager();
    // updateFolder is called from AAC.onLoadFinished() on folder changes.  We need to
    // ensure that the folder is different from the previous folder before marking the
    // folder changed.
    setHasFolderChanged(folder);
    mFolder = folder;

    // We do not need to notify folder observers yet. Instead we start the loaders and
    // when the load finishes, we will get an updated folder. Then, we notify the
    // folderObservers in onLoadFinished.
    mActionBarController.setFolder(mFolder);

    // Only when we switch from one folder to another do we want to restart the
    // folder and conversation list loaders (to trigger onCreateLoader).
    // The first time this runs when the activity is [re-]initialized, we want to re-use the
    // previous loader's instance and data upon configuration change (e.g. rotation).
    // If there was not already an instance of the loader, init it.
    if (lm.getLoader(LOADER_FOLDER_CURSOR) == null) {
        lm.initLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    } else {
        lm.restartLoader(LOADER_FOLDER_CURSOR, Bundle.EMPTY, mFolderCallbacks);
    }
    if (!wasNull && lm.getLoader(LOADER_CONVERSATION_LIST) != null) {
        // If there was an existing folder AND we have changed
        // folders, we want to restart the loader to get the information
        // for the newly selected folder
        lm.destroyLoader(LOADER_CONVERSATION_LIST);
    }
    final Bundle args = new Bundle(2);
    args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    args.putParcelable(BUNDLE_FOLDER_KEY, mFolder);
    args.putBoolean(BUNDLE_IGNORE_INITIAL_CONVERSATION_LIMIT_KEY, mIgnoreInitialConversationLimit);
    mIgnoreInitialConversationLimit = false;
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}

From source file:com.android.mail.ui.AbstractActivityController.java

/**
 * Load the conversation list early for the given folder. This happens when some UI element
 * (usually the drawer) instructs the controller that an account change or folder change is
 * imminent. While the UI element is animating, the controller can preload the conversation
 * list for the default inbox of the account provided here or to the folder provided here.
 *
 * @param nextAccount The account which the app will switch to shortly, possibly null.
 * @param nextFolder The folder which the app will switch to shortly, possibly null.
 *//*from w  ww.j a  v  a2s . c o m*/
protected void preloadConvList(Account nextAccount, Folder nextFolder) {
    // Fire off the conversation list loader for this account already with a fake
    // listener.
    final Bundle args = new Bundle(2);
    if (nextAccount != null) {
        args.putParcelable(BUNDLE_ACCOUNT_KEY, nextAccount);
    } else {
        args.putParcelable(BUNDLE_ACCOUNT_KEY, mAccount);
    }
    if (nextFolder != null) {
        args.putParcelable(BUNDLE_FOLDER_KEY, nextFolder);
    } else {
        LogUtils.e(LOG_TAG, new Error(), "AAC.preloadConvList(): Got an empty folder");
    }
    mFolder = null;
    final LoaderManager lm = mActivity.getLoaderManager();
    lm.destroyLoader(LOADER_CONVERSATION_LIST);
    lm.initLoader(LOADER_CONVERSATION_LIST, args, mListCursorCallbacks);
}

From source file:com.android.mail.ui.AbstractActivityController.java

@Override
public void onSaveInstanceState(Bundle outState) {
    mViewMode.handleSaveInstanceState(outState);
    if (mAccount != null) {
        outState.putParcelable(SAVED_ACCOUNT, mAccount);
    }/*from   ww w.j av  a 2  s.c  o  m*/
    if (mFolder != null) {
        outState.putParcelable(SAVED_FOLDER, mFolder);
    }
    // If this is a search activity, let's store the search query term as well.
    if (ConversationListContext.isSearchResult(mConvListContext)) {
        outState.putString(SAVED_QUERY, mConvListContext.searchQuery);
    }
    if (mCurrentConversation != null && mViewMode.isConversationMode()) {
        outState.putParcelable(SAVED_CONVERSATION, mCurrentConversation);
    }
    if (!mCheckedSet.isEmpty()) {
        outState.putParcelable(SAVED_SELECTED_SET, mCheckedSet);
    }
    if (mToastBar.getVisibility() == View.VISIBLE) {
        outState.putParcelable(SAVED_TOAST_BAR_OP, mToastBar.getOperation());
    }
    final ConversationListFragment convListFragment = getConversationListFragment();
    if (convListFragment != null) {
        convListFragment.getAnimatedAdapter().onSaveInstanceState(outState);
    }
    // If there is a dialog being shown, save the state so we can create a listener for it.
    if (mDialogAction != -1) {
        outState.putInt(SAVED_ACTION, mDialogAction);
        outState.putBoolean(SAVED_ACTION_FROM_SELECTED, mDialogFromSelectedSet);
    }
    if (mDetachedConvUri != null) {
        outState.putParcelable(SAVED_DETACHED_CONV_URI, mDetachedConvUri);
    }

    outState.putParcelable(SAVED_HIERARCHICAL_FOLDER, mFolderListFolder);
    mSafeToModifyFragments = false;

    outState.putParcelable(SAVED_INBOX_KEY, mInbox);

    outState.putBundle(SAVED_CONVERSATION_LIST_SCROLL_POSITIONS, mConversationListScrollPositions);

    mSearchViewController.saveState(outState);
}

From source file:com.android.mail.compose.ComposeActivity.java

/**
 * Opens {@link ParcelFileDescriptor} for each of the attachments.  This method must be
 * called before the ComposeActivity finishes.
 * Note: The caller is responsible for closing these file descriptors.
 *///  w ww. j a va2 s. c  o  m
private static Bundle initializeAttachmentFds(final Context context, final List<Attachment> attachments) {
    if (attachments == null || attachments.size() == 0) {
        return null;
    }

    final Bundle result = new Bundle(attachments.size());
    final ContentResolver resolver = context.getContentResolver();

    for (Attachment attachment : attachments) {
        if (attachment == null || Utils.isEmpty(attachment.contentUri)) {
            continue;
        }

        ParcelFileDescriptor fileDescriptor;
        try {
            fileDescriptor = resolver.openFileDescriptor(attachment.contentUri, "r");
        } catch (FileNotFoundException e) {
            LogUtils.e(LOG_TAG, e, "Exception attempting to open attachment");
            fileDescriptor = null;
        } catch (SecurityException e) {
            // We have encountered a security exception when attempting to open the file
            // specified by the content uri.  If the attachment has been cached, this
            // isn't a problem, as even through the original permission may have been
            // revoked, we have cached the file.  This will happen when saving/sending
            // a previously saved draft.
            // TODO(markwei): Expose whether the attachment has been cached through the
            // attachment object.  This would allow us to limit when the log is made, as
            // if the attachment has been cached, this really isn't an error
            LogUtils.e(LOG_TAG, e, "Security Exception attempting to open attachment");
            // Just set the file descriptor to null, as the underlying provider needs
            // to handle the file descriptor not being set.
            fileDescriptor = null;
        }

        if (fileDescriptor != null) {
            result.putParcelable(attachment.contentUri.toString(), fileDescriptor);
        }
    }

    return result;
}

From source file:com.android.launcher2.Launcher.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
    super.onSaveInstanceState(outState);

    outState.putInt(RUNTIME_STATE, mState.ordinal());
    // We close any open folder since it will not be re-opened, and we need to make sure
    // this state is reflected.
    closeFolder();//from  w  ww  .j  a  v  a  2  s .  co  m

    if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 && mWaitingForResult) {
        outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
        outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
    }

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

    // Save the current AppsCustomize tab
    if (mAppsCustomizeTabHost != null) {
        String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag();
        if (currentTabTag != null) {
            outState.putString("apps_customize_currentTab", currentTabTag);
        }
        int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
        outState.putInt("apps_customize_currentIndex", currentIndex);
    }
}

From source file:com.chen.mail.ui.AbstractActivityController.java

/**
 * Handle an intent to open the app. This method is called only when there is no saved state,
 * so we need to set state that wasn't set before. It is correct to change the viewmode here
 * since it has not been previously set.
 *
 * This method is called for a subset of the reasons mentioned in
 * {@link #onCreate(android.os.Bundle)}. Notably, this is called when launching the app from
 * notifications, widgets, and shortcuts.
 * @param intent intent passed to the activity.
 *//*from   ww  w  .j  av a  2s  .  c om*/
private void handleIntent(Intent intent) {
    LogUtils.d(LOG_TAG, "IN AAC.handleIntent. action=%s", intent.getAction());
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            setAccount(Account.newinstance(intent.getStringExtra(Utils.EXTRA_ACCOUNT)));
        }
        if (mAccount == null) {
            return;
        }
        final boolean isConversationMode = intent.hasExtra(Utils.EXTRA_CONVERSATION);

        if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
            Analytics.getInstance().setCustomDimension(Analytics.CD_INDEX_ACCOUNT_TYPE,
                    AnalyticsUtils.getAccountTypeForAccount(mAccount.getEmailAddress()));
            Analytics.getInstance().sendEvent("notification_click",
                    isConversationMode ? "conversation" : "conversation_list", null, 0);
        }

        if (isConversationMode && mViewMode.getMode() == ViewMode.UNKNOWN) {
            mViewMode.enterConversationMode();
        } else {
            mViewMode.enterConversationListMode();
        }
        // Put the folder and conversation, and ask the loader to create this folder.
        final Bundle args = new Bundle();

        final Uri folderUri;
        if (intent.hasExtra(Utils.EXTRA_FOLDER_URI)) {
            folderUri = (Uri) intent.getParcelableExtra(Utils.EXTRA_FOLDER_URI);
        } else if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
            final Folder folder = Folder.fromString(intent.getStringExtra(Utils.EXTRA_FOLDER));
            folderUri = folder.folderUri.fullUri;
        } else {
            final Bundle extras = intent.getExtras();
            LogUtils.d(LOG_TAG, "Couldn't find a folder URI in the extras: %s",
                    extras == null ? "null" : extras.toString());
            folderUri = mAccount.settings.defaultInbox;
        }

        args.putParcelable(Utils.EXTRA_FOLDER_URI, folderUri);
        args.putParcelable(Utils.EXTRA_CONVERSATION, intent.getParcelableExtra(Utils.EXTRA_CONVERSATION));
        restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
    } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        if (intent.hasExtra(Utils.EXTRA_ACCOUNT)) {
            mHaveSearchResults = false;
            // Save this search query for future suggestions.
            final String query = intent.getStringExtra(SearchManager.QUERY);
            final String authority = mContext.getString(R.string.suggestions_authority);
            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mContext, authority,
                    SuggestionsProvider.MODE);
            suggestions.saveRecentQuery(query, null);
            setAccount((Account) intent.getParcelableExtra(Utils.EXTRA_ACCOUNT));
            fetchSearchFolder(intent);
            if (shouldEnterSearchConvMode()) {
                mViewMode.enterSearchResultsConversationMode();
            } else {
                mViewMode.enterSearchResultsListMode();
            }
        } else {
            LogUtils.e(LOG_TAG, "Missing account extra from search intent.  Finishing");
            mActivity.finish();
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

From source file:com.android.mail.compose.ComposeActivity.java

private void saveState(Bundle state) {
    // We have no accounts so there is nothing to compose, and therefore, nothing to save.
    if (mAccounts == null || mAccounts.length == 0) {
        return;/*from  ww  w .  j  a  v  a2s.  c  o  m*/
    }
    // The framework is happy to save and restore the selection but only if it also saves and
    // restores the contents of the edit text. That's a lot of text to put in a bundle so we do
    // this manually.
    View focus = getCurrentFocus();
    if (focus != null && focus instanceof EditText) {
        EditText focusEditText = (EditText) focus;
        state.putInt(EXTRA_FOCUS_SELECTION_START, focusEditText.getSelectionStart());
        state.putInt(EXTRA_FOCUS_SELECTION_END, focusEditText.getSelectionEnd());
    }

    final List<ReplyFromAccount> replyFromAccounts = mFromSpinner.getReplyFromAccounts();
    final int selectedPos = mFromSpinner.getSelectedItemPosition();
    final ReplyFromAccount selectedReplyFromAccount = (replyFromAccounts != null && replyFromAccounts.size() > 0
            && replyFromAccounts.size() > selectedPos) ? replyFromAccounts.get(selectedPos) : null;
    if (selectedReplyFromAccount != null) {
        state.putString(EXTRA_SELECTED_REPLY_FROM_ACCOUNT, selectedReplyFromAccount.serialize().toString());
        state.putParcelable(Utils.EXTRA_ACCOUNT, selectedReplyFromAccount.account);
    } else {
        state.putParcelable(Utils.EXTRA_ACCOUNT, mAccount);
    }

    if (mDraftId == UIProvider.INVALID_MESSAGE_ID && mRequestId != 0) {
        // We don't have a draft id, and we have a request id,
        // save the request id.
        state.putInt(EXTRA_REQUEST_ID, mRequestId);
    }

    // We want to restore the current mode after a pause
    // or rotation.
    int mode = getMode();
    state.putInt(EXTRA_ACTION, mode);

    final Message message = createMessage(selectedReplyFromAccount, mRefMessage, mode,
            removeComposingSpans(mBodyView.getText()));
    if (mDraft != null) {
        message.id = mDraft.id;
        message.serverId = mDraft.serverId;
        message.uri = mDraft.uri;
    }
    state.putParcelable(EXTRA_MESSAGE, message);

    if (mRefMessage != null) {
        state.putParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE, mRefMessage);
    } else if (message.appendRefMessageContent) {
        // If we have no ref message but should be appending
        // ref message content, we have orphaned quoted text. Save it.
        state.putCharSequence(EXTRA_QUOTED_TEXT, mQuotedTextView.getQuotedTextIfIncluded());
    }
    state.putBoolean(EXTRA_SHOW_CC, mCcBccView.isCcVisible());
    state.putBoolean(EXTRA_SHOW_BCC, mCcBccView.isBccVisible());
    state.putBoolean(EXTRA_RESPONDED_INLINE, mRespondedInline);
    state.putBoolean(EXTRA_SAVE_ENABLED, mSave != null && mSave.isEnabled());
    state.putParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS, mAttachmentsView.getAttachmentPreviews());

    state.putParcelable(EXTRA_VALUES, mExtraValues);

    state.putBoolean(EXTRA_TEXT_CHANGED, mTextChanged);
    // On configuration changes, we don't actually need to parse the body html ourselves because
    // the framework can correctly restore the body EditText to its exact original state.
    state.putBoolean(EXTRA_SKIP_PARSING_BODY, isChangingConfigurations());
}