Example usage for android.os Bundle getBoolean

List of usage examples for android.os Bundle getBoolean

Introduction

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

Prototype

public boolean getBoolean(String key, boolean defaultValue) 

Source Link

Document

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

Usage

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

/**
 * The application can be started from the following entry points:
 * <ul>//  w  w w  .  j a v a2  s  .  co  m
 *     <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}
 */
@Override
public void 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);
    mFloatingComposeButton.setOnClickListener(this);

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

        // Disable default drawer indicator as we are setting the drawer indicator icons.
        // TODO(shahrk): Once we can disable/enable drawer animation, go back to using
        // drawer indicators.
        mDrawerToggle.setDrawerIndicatorEnabled(false);
        mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_menu_wht_24dp);
    } else {
        final ActionBar ab = mActivity.getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.ic_menu_wht_24dp);
        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();

    mSearchViewController = new MaterialSearchViewController(mActivity, this, intent, savedState);
    addConversationListLayoutListener(mSearchViewController);

    // 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) {
        if (savedState.containsKey(SAVED_ACCOUNT)) {
            setAccount((Account) savedState.getParcelable(SAVED_ACCOUNT));
        }
        if (savedState.containsKey(SAVED_FOLDER)) {
            final Folder folder = savedState.getParcelable(SAVED_FOLDER);
            final String query = savedState.getString(SAVED_QUERY, null);
            setListContext(folder, query);
        }
        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);
}

From source file:com.android.gallery3d.app.PhotoPage.java

@Override
public void onCreate(Bundle data, Bundle restoreState) {
    super.onCreate(data, restoreState);
    mActionBar = mActivity.getGalleryActionBar();
    mSelectionManager = new SelectionManager(mActivity, false);
    mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager);

    mPhotoView = new PhotoView(mActivity);
    mPhotoView.setListener(this);
    mRootPane.addComponent(mPhotoView);// www  . j  a v  a 2 s  .  co m
    mApplication = (GalleryApp) ((Activity) mActivity).getApplication();
    mOrientationManager = mActivity.getOrientationManager();
    mActivity.getGLRoot().setOrientationSource(mOrientationManager);

    mHandler = new SynchronizedHandler(mActivity.getGLRoot()) {
        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
            case MSG_HIDE_BARS: {
                /// M: [BUG.MODIFY] @{
                /* hideBars(); */
                if (mIsActive) {
                    hideBars();
                } else {
                    Log.i(TAG, "<mHandler.MSG_HIDE_BARS> mIsActive = " + mIsActive + ", not hideBars");
                }
                /// @}
                break;
            }
            case MSG_REFRESH_BOTTOM_CONTROLS: {
                if (mCurrentPhoto == message.obj && mBottomControls != null) {
                    mIsPanorama = message.arg1 == 1;
                    mIsPanorama360 = message.arg2 == 1;
                    mBottomControls.refresh();
                    fresh(mBottomControls.getContainerVisibility());
                }
                break;
            }
            case MSG_ON_FULL_SCREEN_CHANGED: {
                if (mAppBridge != null) {
                    mAppBridge.onFullScreenChanged(message.arg1 == 1);
                }
                break;
            }
            case MSG_UPDATE_ACTION_BAR: {
                updateBars();
                break;
            }
            case MSG_WANT_BARS: {
                wantBars();
                break;
            }
            case MSG_UNFREEZE_GLROOT: {
                mActivity.getGLRoot().unfreeze();
                break;
            }
            case MSG_UPDATE_DEFERRED: {
                long nextUpdate = mDeferUpdateUntil - SystemClock.uptimeMillis();
                if (nextUpdate <= 0) {
                    mDeferredUpdateWaiting = false;
                    updateUIForCurrentPhoto();
                } else {
                    mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, nextUpdate);
                }
                break;
            }
            case MSG_ON_CAMERA_CENTER: {
                mSkipUpdateCurrentPhoto = false;
                boolean stayedOnCamera = false;
                if (!mPhotoView.getFilmMode()) {
                    stayedOnCamera = true;
                } else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff
                        && mMediaSet.getMediaItemCount() > 1) {
                    mPhotoView.switchToImage(1);
                } else {
                    if (mAppBridge != null)
                        mPhotoView.setFilmMode(false);
                    stayedOnCamera = true;
                }

                if (stayedOnCamera) {
                    if (mAppBridge == null && mMediaSet.getTotalMediaItemCount() > 1) {
                        launchCamera();
                        /// M: [FEATURE.ADD] @{
                        mPhotoView.stopUpdateEngineData();
                        /// @}
                        /* We got here by swiping from photo 1 to the
                           placeholder, so make it be the thing that
                           is in focus when the user presses back from
                           the camera app */
                        mPhotoView.switchToImage(1);
                    } else {
                        updateBars();
                        /// M: [BUG.MODIFY] getMediaItem(0) may be null, fix JE @{
                        /*updateCurrentPhoto(mModel.getMediaItem(0));*/
                        MediaItem photo = mModel.getMediaItem(0);
                        if (photo != null) {
                            updateCurrentPhoto(photo);
                        }
                        /// @}
                    }
                }
                break;
            }
            case MSG_ON_PICTURE_CENTER: {
                if (!mPhotoView.getFilmMode() && mCurrentPhoto != null
                        && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) {
                    /// M: [BUG.MODIFY] @{
                    /*mPhotoView.setFilmMode(true);*/
                    showEmptyAlbumToast(Toast.LENGTH_SHORT);
                    /// @}
                }
                break;
            }
            case MSG_REFRESH_IMAGE: {
                final MediaItem photo = mCurrentPhoto;
                mCurrentPhoto = null;
                updateCurrentPhoto(photo);
                break;
            }
            case MSG_UPDATE_PHOTO_UI: {
                updateUIForCurrentPhoto();
                break;
            }
            case MSG_UPDATE_SHARE_URI: {
                /// M: [BUG.ADD] @{
                // never update share uri when PhotoPage is not active
                if (!mIsActive) {
                    break;
                }
                /// @}
                /// M: [BUG.MARK] @{
                // No matter what message.obj is, we update share intent for current photo
                /* if (mCurrentPhoto == message.obj) {*/
                /// @}
                boolean isPanorama360 = message.arg1 != 0;
                Uri contentUri = mCurrentPhoto.getContentUri();
                Intent panoramaIntent = null;
                if (isPanorama360) {
                    panoramaIntent = createSharePanoramaIntent(contentUri);
                }
                Intent shareIntent = createShareIntent(mCurrentPhoto);

                mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this);
                setNfcBeamPushUri(contentUri);
                /// M: [BUG.MARK] @{
                // }
                /// @}
                break;
            }
            case MSG_UPDATE_PANORAMA_UI: {
                if (mCurrentPhoto == message.obj) {
                    boolean isPanorama360 = message.arg1 != 0;
                    updatePanoramaUI(isPanorama360);
                }
                break;
            }
            default:
                throw new AssertionError(message.what);
            }
        }
    };

    mSetPathString = data.getString(KEY_MEDIA_SET_PATH);
    /// M: [FEATURE.ADD] [Camera independent from Gallery] @{
    mLaunchFromCamera = data.getBoolean(KEY_LAUNCH_FROM_CAMERA, false);
    /// @}
    /// M: [BUG.MODIFY] @{
    // if there is mSetPathString, view is not read only, enable edit
    /*mReadOnlyView = data.getBoolean(KEY_READONLY);*/
    mReadOnlyView = data.getBoolean(KEY_READONLY) && (mSetPathString == null || mSetPathString.equals(""));
    Log.i(TAG, "<onCreate> mSetPathString = " + mSetPathString + ", mReadOnlyView = " + mReadOnlyView);
    /// @}
    mOriginalSetPathString = mSetPathString;
    setupNfcBeamPush();
    String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH);
    Path itemPath = itemPathString != null ? Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) : null;
    mTreatBackAsUp = data.getBoolean(KEY_TREAT_BACK_AS_UP, false);
    mStartInFilmstrip = data.getBoolean(KEY_START_IN_FILMSTRIP, false);
    boolean inCameraRoll = data.getBoolean(KEY_IN_CAMERA_ROLL, false);
    mCurrentIndex = data.getInt(KEY_INDEX_HINT, 0);
    if (mSetPathString != null) {
        mShowSpinner = true;
        /// M: [FEATURE.ADD] [Camera independent from Gallery] @{
        // Launch from secure camera
        if (!mSetPathString.equals("/local/all/0") && SecureSource.isSecurePath(mSetPathString)) {
            Log.d(TAG, "<onCreate> secure album");
            mFlags |= FLAG_SHOW_WHEN_LOCKED;
            mSecureAlbum = (SecureAlbum) mActivity.getDataManager().getMediaSet(mSetPathString);
            mSecureAlbum.clearAll();
            ArrayList<String> secureAlbum = (ArrayList<String>) data.getSerializable(SECURE_ALBUM);
            if (secureAlbum != null) {
                int albumCount = secureAlbum.size();
                Log.d(TAG, "<onCreate> albumCount " + albumCount);
                for (int i = 0; i < albumCount; i++) {
                    try {
                        String[] albumItem = secureAlbum.get(i).split("\\+");
                        int albumItemSize = albumItem.length;
                        Log.d(TAG, "<onCreate> albumItemSize " + albumItemSize);
                        if (albumItemSize == 2) {
                            int id = Integer.parseInt(albumItem[0].trim());
                            boolean isVideo = Boolean.parseBoolean(albumItem[1].trim());
                            Log.d(TAG, "<onCreate> secure item : id " + id + ", isVideo " + isVideo);
                            mSecureAlbum.addMediaItem(isVideo, id);
                        }
                    } catch (NullPointerException ex) {
                        Log.e(TAG, "<onCreate> exception " + ex);
                    } catch (PatternSyntaxException ex) {
                        Log.e(TAG, "<onCreate> exception " + ex);
                    } catch (NumberFormatException ex) {
                        Log.e(TAG, "<onCreate> exception " + ex);
                    }
                }
            }
            mShowSpinner = false;
            mSetPathString = "/filter/empty/{" + mSetPathString + "}";
            mSetPathString = "/combo/item/{" + mSetPathString + "}";
        }
        /// @}
        mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE);
        if (mAppBridge != null) {
            mShowBars = false;
            mHasCameraScreennailOrPlaceholder = true;
            mAppBridge.setServer(this);

            // Get the ScreenNail from AppBridge and register it.
            int id = SnailSource.newId();
            Path screenNailSetPath = SnailSource.getSetPath(id);
            Path screenNailItemPath = SnailSource.getItemPath(id);
            mScreenNailSet = (SnailAlbum) mActivity.getDataManager().getMediaObject(screenNailSetPath);
            mScreenNailItem = (SnailItem) mActivity.getDataManager().getMediaObject(screenNailItemPath);
            mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());

            if (data.getBoolean(KEY_SHOW_WHEN_LOCKED, false)) {
                // Set the flag to be on top of the lock screen.
                mFlags |= FLAG_SHOW_WHEN_LOCKED;
            }
            // Don't display "empty album" action item for capture intents.
            if (!mSetPathString.equals("/local/all/0")) {
                // Check if the path is a secure album.
                if (SecureSource.isSecurePath(mSetPathString)) {
                    mSecureAlbum = (SecureAlbum) mActivity.getDataManager().getMediaSet(mSetPathString);
                    mShowSpinner = false;
                }
                mSetPathString = "/filter/empty/{" + mSetPathString + "}";
            }

            // Combine the original MediaSet with the one for ScreenNail
            // from AppBridge.
            mSetPathString = "/combo/item/{" + screenNailSetPath + "," + mSetPathString + "}";

            // Start from the screen nail.
            itemPath = screenNailItemPath;
            /// M: [FEATURE.MARK] [Camera independent from Gallery] @{
            // After camera is removed from gallery, modify the behavior as below:
            // When view the first image in camera folder, slide to left,
            // there is no place holder of camera, and it can not launch camera too.
            /*} else if (inCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) {
                  mSetPathString = "/combo/item/{" + FilterSource.FILTER_CAMERA_SHORTCUT +
              "," + mSetPathString + "}";
                  mCurrentIndex++;
                  mHasCameraScreennailOrPlaceholder = true;*/
            /// @}
            /// M: [FEATURE.ADD] [Camera independent from Gallery] @{
            // When launch from camera, and not from secure camera, we show empty item
            // after delete all images.
        } else if (mLaunchFromCamera && mSecureAlbum == null) {
            mSetPathString = "/filter/empty/{" + mSetPathString + "}";
            Log.i(TAG, "<onCreate> launch from camera, not secure, mSetPathString = " + mSetPathString);
            /// @}
        }

        MediaSet originalSet = mActivity.getDataManager().getMediaSet(mSetPathString);
        if (mHasCameraScreennailOrPlaceholder && originalSet instanceof ComboAlbum) {
            // Use the name of the camera album rather than the default
            // ComboAlbum behavior
            ((ComboAlbum) originalSet).useNameOfChild(1);
        }
        /// M: [BUG.ADD] @{
        // tell PhotoView whether this album is cluster
        if (originalSet != null && originalSet instanceof ClusterAlbum) {
            mPhotoView.setIsCluster(true);
        } else {
            mPhotoView.setIsCluster(false);
        }
        /// @}
        mSelectionManager.setSourceMediaSet(originalSet);
        mSetPathString = "/filter/delete/{" + mSetPathString + "}";
        mMediaSet = (FilterDeleteSet) mActivity.getDataManager().getMediaSet(mSetPathString);
        if (mMediaSet == null) {
            Log.w(TAG, "failed to restore " + mSetPathString);
        }
        if (itemPath == null) {
            int mediaItemCount = mMediaSet.getMediaItemCount();
            if (mediaItemCount > 0) {
                if (mCurrentIndex >= mediaItemCount)
                    mCurrentIndex = 0;
                itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1).get(0).getPath();
            } else {
                // Bail out, PhotoPage can't load on an empty album
                return;
            }
        }
        PhotoDataAdapter pda = new PhotoDataAdapter(mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex,
                mAppBridge == null ? -1 : 0, mAppBridge == null ? false : mAppBridge.isPanorama(),
                mAppBridge == null ? false : mAppBridge.isStaticCamera());
        mModel = pda;
        mPhotoView.setModel(mModel);

        pda.setDataListener(new PhotoDataAdapter.DataListener() {

            @Override
            public void onPhotoChanged(int index, Path item) {
                int oldIndex = mCurrentIndex;
                mCurrentIndex = index;
                if (mHasCameraScreennailOrPlaceholder) {
                    if (mCurrentIndex > 0) {
                        mSkipUpdateCurrentPhoto = false;
                    }

                    /// M: [FEATURE.MODIFY] @{
                    /*if (oldIndex == 0 && mCurrentIndex > 0
                     && !mPhotoView.getFilmMode()) {
                     mPhotoView.setFilmMode(true);*/
                    if (oldIndex == 0 && mCurrentIndex > 0) {
                        onActionBarAllowed(true);
                        mPhotoView.setFilmMode(false);
                        /// @}
                        if (mAppBridge != null) {
                            UsageStatistics.onEvent("CameraToFilmstrip", UsageStatistics.TRANSITION_SWIPE,
                                    null);
                        }
                    } else if (oldIndex == 2 && mCurrentIndex == 1) {
                        mCameraSwitchCutoff = SystemClock.uptimeMillis() + CAMERA_SWITCH_CUTOFF_THRESHOLD_MS;
                        mPhotoView.stopScrolling();
                    } else if (oldIndex >= 1 && mCurrentIndex == 0) {
                        mPhotoView.setWantPictureCenterCallbacks(true);
                        mSkipUpdateCurrentPhoto = true;
                    }
                }
                if (!mSkipUpdateCurrentPhoto) {
                    if (item != null) {
                        MediaItem photo = mModel.getMediaItem(0);
                        if (photo != null)
                            updateCurrentPhoto(photo);
                    }
                    updateBars();
                }
                // Reset the timeout for the bars after a swipe
                /// M: [DEBUG.ADD] @{
                Log.i(TAG, "<onPhotoChanged> refreshHidingMessage");
                /// @}
                refreshHidingMessage();
            }

            @Override
            public void onLoadingFinished(boolean loadingFailed) {
                /// M: [BUG.ADD] @{
                mLoadingFinished = true;
                // Refresh bottom controls when data loading done
                refreshBottomControlsWhenReady();
                /// @}
                if (!mModel.isEmpty()) {
                    MediaItem photo = mModel.getMediaItem(0);
                    if (photo != null)
                        updateCurrentPhoto(photo);
                } else if (mIsActive) {
                    // We only want to finish the PhotoPage if there is no
                    // deletion that the user can undo.
                    if (mMediaSet.getNumberOfDeletions() == 0) {
                        /// M: [BUG.ADD] pause PhotoView before finish PhotoPage @{
                        mPhotoView.pause();
                        /// @}
                        mActivity.getStateManager().finishState(PhotoPage.this);
                    }
                }
            }

            @Override
            public void onLoadingStarted() {
                /// M: [BUG.ADD] @{
                mLoadingFinished = false;
                /// @}
            }
        });
    } else {
        // Get default media set by the URI
        MediaItem mediaItem = (MediaItem) mActivity.getDataManager().getMediaObject(itemPath);
        /// M: [BUG.ADD] fix JE when mediaItem is deleted@{
        if (mediaItem == null) {
            Toast.makeText(((Activity) mActivity), R.string.no_such_item, Toast.LENGTH_LONG).show();
            mPhotoView.pause();
            mActivity.getStateManager().finishState(this);
            return;
        }
        /// @}
        /// M: [BUG.ADD] @{
        // no PhotoDataAdapter style loading in SinglePhotoDataAdapter
        mLoadingFinished = true;
        /// @}
        mModel = new SinglePhotoDataAdapter(mActivity, mPhotoView, mediaItem);
        mPhotoView.setModel(mModel);
        updateCurrentPhoto(mediaItem);
        mShowSpinner = false;
    }

    mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1);
    RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity)
            .findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root);
    if (galleryRoot != null) {
        if (mSecureAlbum == null) {
            mBottomControls = new PhotoPageBottomControls(this, mActivity, galleryRoot);
        }
    }
    /// M: [BUG.MODIFY] set change listener to current GLRootView @{
    // onResume also need to set this listener, so modify it.
    /*((GLRootView) mActivity.getGLRoot()).setOnSystemUiVisibilityChangeListener(
        new View.OnSystemUiVisibilityChangeListener() {
        @Override
            public void onSystemUiVisibilityChange(int visibility) {
                int diff = mLastSystemUiVis ^ visibility;
                mLastSystemUiVis = visibility;
                if ((diff & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0
                        && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    /// M: [BUG.MODIFY] Don't need show bars in camera preview. @{
                    /*showBars();*/
    /*wantBars();
    /// @}
    }
    }
    });*/
    setOnSystemUiVisibilityChangeListener();
    /// @}
    /// M: [FEATURE.ADD] VTSP: share as video @{
    initAnimatedContentSharer();
    /// @}
    /// M: [FEATURE.ADD] add backward controller for layer @{
    mPhotoView.setBackwardControllerForLayerManager(mBackwardContollerForLayer);
    /// @}
}