Example usage for android.os Bundle EMPTY

List of usage examples for android.os Bundle EMPTY

Introduction

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

Prototype

Bundle EMPTY

To view the source code for android.os Bundle EMPTY.

Click Source Link

Usage

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

/**
 * The application can be started from the following entry points:
 * <ul>//  w ww  .  j  av a 2 s .c  om
 *     <li>Launcher: you tap on the Gmail icon in the launcher. This is what most users think of
 *         as Starting the app?.</li>
 *     <li>Shortcut: Users can make a shortcut to take them directly to a label.</li>
 *     <li>Widget: Shows the contents of a synced label, and allows:
 *     <ul>
 *         <li>Viewing the list (tapping on the title)</li>
 *         <li>Composing a new message (tapping on the new message icon in the title. This
 *         launches the {@link ComposeActivity}.
 *         </li>
 *         <li>Viewing a single message (tapping on a list element)</li>
 *     </ul>
 *
 *     </li>
 *     <li>Tapping on a notification:
 *     <ul>
 *         <li>Shows message list if more than one message</li>
 *         <li>Shows the conversation if the notification is for a single message</li>
 *     </ul>
 *     </li>
 *     <li>...and most importantly, the activity life cycle can tear down the application and
 *     restart it:
 *     <ul>
 *         <li>Rotate the application: it is destroyed and recreated.</li>
 *         <li>Navigate away, and return from recent applications.</li>
 *     </ul>
 *     </li>
 *     <li>Add a new account: fires off an intent to add an account,
 *     and returns in {@link #onActivityResult(int, int, android.content.Intent)} .</li>
 *     <li>Re-authenticate your account: again returns in onActivityResult().</li>
 *     <li>Composing can happen from many entry points: third party applications fire off an
 *     intent to compose email, and launch directly into the {@link ComposeActivity}
 *     .</li>
 * </ul>
 * {@inheritDoc}
 */
@SuppressLint("NewApi")
@Override
public boolean onCreate(Bundle savedState) {
    initializeActionBar();
    initializeDevLoggingService();
    // Allow shortcut keys to function for the ActionBar and menus.
    mActivity.setDefaultKeyMode(Activity.DEFAULT_KEYS_SHORTCUT);
    mResolver = mActivity.getContentResolver();
    mNewEmailReceiver = new SuppressNotificationReceiver();
    mRecentFolderList.initialize(mActivity);
    mVeiledMatcher.initialize(this);

    mFloatingComposeButton = mActivity.findViewById(R.id.compose_button);

    //TS: ke.ma 2015-03-12 EMAIL BUGFIX-947440 ADD_S
    mFloatingComposeButton.setElevation(8);
    mFloatingComposeButton.setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            // TODO Auto-generated method stub
            outline.setOval(0, 0, view.getWidth(), view.getWidth());
        }
    });
    //TS: ke.ma 2015-03-12 EMAIL BUGFIX-947440 ADD_E
    mFloatingComposeButton.setOnClickListener(this);

    if (isDrawerEnabled()) {
        mDrawerToggle = new ActionBarDrawerToggle(mActivity, mDrawerContainer,
                //                    false,
                //                    R.drawable.ic_drawer,
                R.string.drawer_open, R.string.drawer_close);
        mDrawerContainer.setDrawerListener(mDrawerListener);
        mDrawerContainer.setDrawerShadow(mContext.getResources().getDrawable(R.drawable.drawer_shadow),
                Gravity.START);

        mDrawerToggle.setDrawerIndicatorEnabled(isDrawerEnabled());
    } else {
        final ActionBar ab = mActivity.getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.ic_drawer);
        ab.setHomeActionContentDescription(R.string.drawer_open);
        ab.setDisplayHomeAsUpEnabled(true);
    }

    // All the individual UI components listen for ViewMode changes. This
    // simplifies the amount of logic in the AbstractActivityController, but increases the
    // possibility of timing-related bugs.
    mViewMode.addListener(this);
    mPagerController = new ConversationPagerController(mActivity, this);
    mToastBar = findActionableToastBar(mActivity);
    attachActionBar();

    mDrawIdler.setRootView(mActivity.getWindow().getDecorView());

    final Intent intent = mActivity.getIntent();

    // Immediately handle a clean launch with intent, and any state restoration
    // that does not rely on restored fragments or loader data
    // any state restoration that relies on those can be done later in
    // onRestoreInstanceState, once fragments are up and loader data is re-delivered
    if (savedState != null) {
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S
        // restore check status for star toggle
        mCheckStatus = savedState.getBoolean(BUNDLE_CHECK_STATUS_KEY, false);
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E
        /// TCT: restore global search tag.
        if (savedState.containsKey(SAVED_GLOBAL_SEARCH)) {
            mGlobalSearch = savedState.getBoolean(SAVED_GLOBAL_SEARCH);
            LogUtils.logFeature(LogTag.SEARCH_TAG, "onCreate restore mGlobalSearch [%s] ", mGlobalSearch);
        }
        if (savedState.containsKey(SAVED_ACCOUNT)) {
            setAccount((Account) savedState.getParcelable(SAVED_ACCOUNT));
        }
        if (savedState.containsKey(SAVED_FOLDER)) {
            final Folder folder = savedState.getParcelable(SAVED_FOLDER);
            /**
             * TCT: Restore the local search or global search instance:
             * 1. Restore the ConversationListContext from Bundle.
             * 2. Restore query if in global search mode.
             * 3. Update Local Search UI (ActionBarView)
             * @{
             */
            final Bundle bundle = savedState.getParcelable(SAVED_LOCAL_SEARCH);
            if (bundle != null) {
                final ConversationListContext convListContext = ConversationListContext.forBundle(bundle);
                mConvListContext = convListContext;
                LogUtils.logFeature(LogTag.SEARCH_TAG,
                        "onCreate restore ConverationListContext from saved instance [%s] ", mConvListContext);
            }
            String query = mConvListContext != null ? mConvListContext.getSearchQuery() : null;
            if (TextUtils.isEmpty(query) && mGlobalSearch) {
                query = intent.getStringExtra(SearchManager.QUERY);
                mConvListContext.setLocalSearch(true);
                mConvListContext.setSearchQueryText(query);
                LogUtils.logFeature(LogTag.SEARCH_TAG, "onCreate restore global search query [%s]",
                        mConvListContext);
            }
            setListContext(folder, query);
            if (mConvListContext.isLocalSearch()) {
                LogUtils.logFeature(LogTag.SEARCH_TAG, "[Local Search] Enter and execute local search [%s]",
                        query);
                mActionBarController.expandSearch(query, mConvListContext.getSearchField());
            }
            /** @} */
        }
        if (savedState.containsKey(SAVED_ACTION)) {
            mDialogAction = savedState.getInt(SAVED_ACTION);
        }
        mDialogFromSelectedSet = savedState.getBoolean(SAVED_ACTION_FROM_SELECTED, false);
        mViewMode.handleRestore(savedState);
    } else if (intent != null) {
        handleIntent(intent);
    }
    // Create the accounts loader; this loads the account switch spinner.
    mActivity.getLoaderManager().initLoader(LOADER_ACCOUNT_CURSOR, Bundle.EMPTY, mAccountCallbacks);
    return true;
}

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

/**
 * Set the account, and carry out all the account-related changes that rely on this.
 * @param account new account to set to.
 *//*www  .  ja  v a 2s.  com*/
private void setAccount(Account account) {
    if (account == null) {
        LogUtils.w(LOG_TAG, new Error(), "AAC ignoring null (presumably invalid) account restoration");
        return;
    }
    LogUtils.d(LOG_TAG, "AbstractActivityController.setAccount(): account = %s", account.uri);
    mAccount = account;
    // Only change AAC state here. Do *not* modify any other object's state. The object
    // should listen on account changes.
    restartOptionalLoader(LOADER_RECENT_FOLDERS, mFolderCallbacks, Bundle.EMPTY);
    mActivity.invalidateOptionsMenu();
    disableNotificationsOnAccountChange(mAccount);
    restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    // The Mail instance can be null during test runs.
    final MailAppProvider instance = MailAppProvider.getInstance();
    if (instance != null) {
        instance.setLastViewedAccount(mAccount.uri.toString());
    }
    if (account.settings == null) {
        LogUtils.w(LOG_TAG, new Error(), "AAC ignoring account with null settings.");
        return;
    }
    mAccountObservers.notifyChanged();
    perhapsEnterWaitMode();
}

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

/**
 * Set the account, and carry out all the account-related changes that rely on this.
 * @param account new account to set to.
 *///  w  ww  .ja v a2  s  .  c  o m
private void setAccount(Account account) {
    if (account == null) {
        LogUtils.w(LOG_TAG, new Error(), "AAC ignoring null (presumably invalid) account restoration");
        return;
    }
    LogUtils.d(LOG_TAG, "AbstractActivityController.setAccount(): account = %s", account.uri);
    mAccount = account;

    Analytics.getInstance().setEmail(account.getEmailAddress(), account.getType());

    // Only change AAC state here. Do *not* modify any other object's state. The object
    // should listen on account changes.
    restartOptionalLoader(LOADER_RECENT_FOLDERS, mFolderCallbacks, Bundle.EMPTY);
    mActivity.invalidateOptionsMenu();
    disableNotificationsOnAccountChange(mAccount);
    restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    // The Mail instance can be null during test runs.
    final MailAppProvider instance = MailAppProvider.getInstance();
    if (instance != null) {
        instance.setLastViewedAccount(mAccount.uri.toString());
    }
    if (account.settings == null) {
        LogUtils.w(LOG_TAG, new Error(), "AAC ignoring account with null settings.");
        return;
    }
    mAccountObservers.notifyChanged();
    perhapsEnterWaitMode();
}

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.
 *///  w  w w .j  a  v  a2s.com
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.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.
 *//*w  w w.  j  av a 2  s.co  m*/
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().setEmail(mAccount.getEmailAddress(), mAccount.getType());
            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 = 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;
        }

        // Check if we should load all conversations instead of using
        // the default behavior which loads an initial subset.
        mIgnoreInitialConversationLimit = intent.getBooleanExtra(Utils.EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT,
                false);

        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);
            mSearchViewController.saveRecentQuery(query);
            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.tct.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 w  w  w  . j a  v a2s.co m*/
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 = 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;
            //TS: junwei-xu 2014-1-5 EMAIL BUGFIX_879468 ADD_S
        } else if (intent.getData() != null) {
            folderUri = intent.getData();
            //TS: junwei-xu 2014-1-5 EMAIL BUGFIX_879468 ADD_E
        } 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;
        }

        // Check if we should load all conversations instead of using
        // the default behavior which loads an initial subset.
        mIgnoreInitialConversationLimit = intent.getBooleanExtra(Utils.EXTRA_IGNORE_INITIAL_CONVERSATION_LIMIT,
                false);

        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;
            //TS: zheng.zou 2015-03-18 EMAIL BUGFIX_744708 ADD_S
            mToastBar.hide(false, false);
            //TS: zheng.zou 2015-03-18 EMAIL BUGFIX_744708 ADD_E
            // 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();
            }
            /** TCT: init the list context for remote search, except folder. @{ */
            // use a UNINITIALIZED folder temporarily. need update when finish search load.
            Folder folder = Folder.newUnsafeInstance();
            mConvListContext = ConversationListContext.forSearchQuery(mAccount, folder, query);
            mConvListContext
                    .setSearchField(mActivity.getIntent().getStringExtra(SearchParams.BUNDLE_QUERY_FIELD));
            /** @} */
        } else {
            /** TCT: The action is search but no extra account means it's a global search. @{ */
            mGlobalSearch = true;
            LogUtils.logFeature(LogTag.SEARCH_TAG, "Handle ACTION_SEARCH , is mGlobalSearch [%s]",
                    mGlobalSearch);
            // reload conbined inbox folder if needed.
            if (mAccount != null && (mFolder == null || !mFolder.isInitialized())) {
                Bundle args = new Bundle();
                LogUtils.logFeature(LogTag.SEARCH_TAG, " GlobalSearch but without Folder, reload inbox again.");
                args.putParcelable(Utils.EXTRA_FOLDER_URI, mAccount.settings.defaultInbox);
                restartOptionalLoader(LOADER_FIRST_FOLDER, mFolderCallbacks, args);
            }
            /** @} */
        }
    }
    if (mAccount != null) {
        restartOptionalLoader(LOADER_ACCOUNT_UPDATE_CURSOR, mAccountCallbacks, Bundle.EMPTY);
    }
}

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

private void initAttachmentsFromIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from  w  w w  . j  av a 2 s. c  om*/
    if (extras == null) {
        extras = Bundle.EMPTY;
    }
    final String action = intent.getAction();
    if (!mAttachmentsChanged) {
        long totalSize = 0;
        if (extras.containsKey(EXTRA_ATTACHMENTS)) {
            String[] uris = (String[]) extras.getSerializable(EXTRA_ATTACHMENTS);
            for (String uriString : uris) {
                final Uri uri = Uri.parse(uriString);
                long size = 0;
                try {
                    if (handleSpecialAttachmentUri(uri)) {
                        continue;
                    }

                    final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                    //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S
                    if (a == null) {
                        continue;
                    }
                    //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E
                    size = mAttachmentsView.addAttachment(mAccount, a, true);//TS: yanhua.chen 2015-6-8 EMAIL CR_996908 MOD

                    Analytics.getInstance().sendEvent("send_intent_attachment",
                            Utils.normalizeMimeType(a.getContentType()), null, size);

                } catch (AttachmentFailureException e) {
                    LogUtils.e(LOG_TAG, e, "Error adding attachment");
                    showAttachmentTooBigToast(e.getErrorRes());
                }
                totalSize += size;
            }
        }
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            if (!PermissionUtil.checkAndRequestPermissionForResult(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    PermissionUtil.REQ_CODE_PERMISSION_ADD_ATTACHMENT)) {
                return;
            }
            if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
                final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
                ArrayList<Attachment> attachments = new ArrayList<Attachment>();
                for (Uri uri : uris) {
                    if (uri == null) {
                        continue;
                    }
                    try {
                        if (handleSpecialAttachmentUri(uri)) {
                            continue;
                        }

                        final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                        //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S
                        if (a == null) {
                            continue;
                        }
                        //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E
                        attachments.add(a);

                        Analytics.getInstance().sendEvent("send_intent_attachment",
                                Utils.normalizeMimeType(a.getContentType()), null, a.size);

                    } catch (AttachmentFailureException e) {
                        LogUtils.e(LOG_TAG, e, "Error adding attachment");
                        String maxSize = AttachmentUtils.convertToHumanReadableSize(getApplicationContext(),
                                mAccount.settings.getMaxAttachmentSize());
                        showErrorToast(getString(R.string.generic_attachment_problem, maxSize));
                    }
                }
                // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_S
                totalSize += addAttachments(attachments, false);
                // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_E
            } else {
                final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
                if (uri != null) {
                    long size = 0;
                    //[BUGFIX]-Modified-BEGIN by TCTNJ.wenlu.wu,12/03/2014,PR-857886
                    if (!handleSpecialAttachmentUri(uri)) {

                        new AsyncTask<Void, Void, Void>() {
                            @Override
                            protected Void doInBackground(Void... params) {
                                try {
                                    Attachment mAttachment = mAttachmentsView.generateLocalAttachment(uri);
                                    android.os.Message msg = new android.os.Message();
                                    msg.what = 1001;
                                    msg.obj = mAttachment;
                                    mHandler.sendMessage(msg);
                                } catch (AttachmentFailureException e) {
                                    LogUtils.e(LOG_TAG, e, "Error adding attachment");
                                    showAttachmentTooBigToast(e.getErrorRes());
                                }
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void result) {

                            }
                        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    //[BUGFIX]-Modified-END by TCTNJ.wenlu.wu,12/03/2014,PR-857886

                    totalSize += size;
                }
            }
        }

        if (totalSize > 0) {
            mAttachmentsChanged = true;
            updateSaveUi();

            Analytics.getInstance().sendEvent("send_intent_with_attachments",
                    Integer.toString(getAttachments().size()), null, totalSize);
        }
    }
}

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

private int getShareAttachmentSize(Intent intent) {
    Bundle extras = intent.getExtras();//from  w  ww.  ja va  2 s .com
    if (extras == null) {
        extras = Bundle.EMPTY;
    }
    final String action = intent.getAction();
    int totalSize = 0;
    if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
        ArrayList<Attachment> attachments = new ArrayList<Attachment>();
        for (Uri uri : uris) {
            if (uri == null) {
                continue;
            }
            try {
                if (handleSpecialAttachmentUri(uri)) {
                    continue;
                }

                final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S
                if (a == null) {
                    continue;
                }
                //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E
                attachments.add(a);

                Analytics.getInstance().sendEvent("send_intent_attachment",
                        Utils.normalizeMimeType(a.getContentType()), null, a.size);

            } catch (AttachmentFailureException e) {
                LogUtils.e(LOG_TAG, e, "Error adding attachment");
                String maxSize = AttachmentUtils.convertToHumanReadableSize(getApplicationContext(),
                        mAccount.settings.getMaxAttachmentSize());
                showErrorToast(getString(R.string.generic_attachment_problem, maxSize));
            }
        }
        // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_S
        totalSize += addAttachments(attachments, false);
        // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_E
    } else {
        final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
        if (uri != null) {
            long size = 0;
            //[BUGFIX]-Modified-BEGIN by TCTNJ.wenlu.wu,12/03/2014,PR-857886
            if (!handleSpecialAttachmentUri(uri)) {

                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        try {
                            Attachment mAttachment = mAttachmentsView.generateLocalAttachment(uri);
                            android.os.Message msg = new android.os.Message();
                            msg.what = ADD_ATTACHMENT_MSG;
                            msg.obj = mAttachment;
                            mHandler.sendMessage(msg);
                        } catch (AttachmentFailureException e) {
                            LogUtils.e(LOG_TAG, e, "Error adding attachment");
                            // TS: jian.xu 2016-01-11 EMAIL BUGFIX-1307962 MOD_S
                            //Note: show toast must be on ui thread.
                            android.os.Message errorMsg = new android.os.Message();
                            errorMsg.what = ADD_ATTACHMENT_MSG_ERROR;
                            errorMsg.obj = e.getErrorRes();
                            mHandler.sendMessage(errorMsg);
                            //showAttachmentTooBigToast(e.getErrorRes());
                            // TS: jian.xu 2016-01-11 EMAIL BUGFIX-1307962 MOD_E
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void result) {

                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            //[BUGFIX]-Modified-END by TCTNJ.wenlu.wu,12/03/2014,PR-857886

            totalSize += size;
        }
    }
    return totalSize;
}

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

/**
 * Loads the preference that tells whether the welcome tour should be displayed,
 * and calls the callback with this value.
 * For this to function, the account must have been synced.
 */// w  w  w .j  a  v a 2  s  . c om
private void perhapsStartWelcomeTour() {
    new AsyncTask<Void, Void, Boolean>() {
        @Override
        protected Boolean doInBackground(Void... params) {
            if (mActivity.wasLatestWelcomeTourShownOnDeviceForAllAccounts()) {
                // No need to go through the WelcomeStateLoader machinery.
                return false;
            }
            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {
                if (mAccount != null && mAccount.isAccountReady()) {
                    LoaderManager.LoaderCallbacks<?> welcomeLoaderCallbacks = mActivity.getWelcomeCallbacks();
                    if (welcomeLoaderCallbacks != null) {
                        // The callback is responsible for showing the tour when appropriate.
                        mActivity.getLoaderManager().initLoader(LOADER_WELCOME_TOUR_ACCOUNTS, Bundle.EMPTY,
                                welcomeLoaderCallbacks);
                    }
                }
            }
        }
    }.execute();
}