Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

In this page you can find the example usage for android.content Intent getIntExtra.

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.nit.vicky.DeckPicker.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    mDontSaveOnStop = false;// ww w  .j  av a  2  s. c  o m
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
        addNote();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (AnkiDroidApp.setLanguage(newLanguage)) {
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
    case LOCATION_CONNECTION_FAILURE_RESOLUTION_REQUEST:
        // If the result code is Activity.RESULT_OK, try to connect again
        switch (resultCode) {
        case Activity.RESULT_OK:
            // Try the request again
            // TODO - check google developers documentation again
            // and implement it correctly
        }/*from   ww w .ja v  a 2 s  . c o m*/

        break;
    case SEARCH_POI_ACTIVITY_RESULT:
        if (resultCode == Activity.RESULT_OK) {
            // search activity finished OK
            if (data == null)
                return;
            // PoisModel poi_to = (PoisModel)
            // data.getSerializableExtra("pmodel");
            // startNavigationTask(poi_to);

            IPoisClass place = (IPoisClass) data.getSerializableExtra("ianyplace");
            handleSearchPlaceSelection(place);

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // CANCELLED
            if (data == null)
                return;
            String msg = (String) data.getSerializableExtra("message");
            if (msg != null)
                Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
        }
        break;
    case SELECT_PLACE_ACTIVITY_RESULT:
        if (resultCode == Activity.RESULT_OK) {
            if (data == null)
                return;

            String fpf = data.getStringExtra("floor_plan_path");
            if (fpf == null) {
                Toast.makeText(getBaseContext(), "You haven't selected both building and floor...!",
                        Toast.LENGTH_SHORT).show();
                return;
            }

            try {
                BuildingModel b = mAnyplaceCache.getSpinnerBuildings().get(data.getIntExtra("bmodel", 0));
                FloorModel f = b.getFloors().get(data.getIntExtra("fmodel", 0));
                selectPlaceActivityResult(b, f);
            } catch (Exception ex) {
                Toast.makeText(getBaseContext(), "You haven't selected both building and floor...!",
                        Toast.LENGTH_SHORT).show();
            }

        } else if (resultCode == Activity.RESULT_CANCELED) {
            // CANCELLED
            if (data == null)
                return;
            String msg = (String) data.getSerializableExtra("message");
            if (msg != null)
                Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();
        }
        break;
    case PREFERENCES_ACTIVITY_RESULT:
        if (resultCode == RESULT_OK) {
            AnyplacePrefs.Action result = (Action) data.getSerializableExtra("action");

            switch (result) {
            case REFRESH_BUILDING:

                if (!userData.isFloorSelected()) {
                    Toast.makeText(getBaseContext(), "Load a map before performing this action!",
                            Toast.LENGTH_SHORT).show();
                    break;
                }

                if (progressBar.getVisibility() == View.VISIBLE) {
                    Toast.makeText(getBaseContext(), "Building Loading in progress. Please Wait!",
                            Toast.LENGTH_SHORT).show();
                    break;
                }

                try {

                    final BuildingModel b = userData.getSelectedBuilding();
                    // clear_floorplans
                    File floorsRoot = new File(AnyplaceUtils.getFloorPlansRootFolder(this), b.buid);
                    // clear radiomaps
                    File radiomapsRoot = AnyplaceUtils.getRadioMapsRootFolder(this);
                    final String[] radiomaps = radiomapsRoot.list(new FilenameFilter() {

                        @Override
                        public boolean accept(File dir, String filename) {
                            if (filename.startsWith(b.buid))
                                return true;
                            else
                                return false;
                        }
                    });
                    for (int i = 0; i < radiomaps.length; i++) {
                        radiomaps[i] = radiomapsRoot.getAbsolutePath() + File.separator + radiomaps[i];
                    }

                    floorSelector.Stop();
                    disableAnyplaceTracker();
                    DeleteFolderBackgroundTask task = new DeleteFolderBackgroundTask(
                            new DeleteFolderBackgroundTask.DeleteFolderBackgroundTaskListener() {

                                @Override
                                public void onSuccess() {

                                    // clear any markers that might have already
                                    // been added to the map
                                    visiblePois.clearAll();
                                    // clear and resets the cached POIS inside
                                    // AnyplaceCache
                                    mAnyplaceCache.setPois(new HashMap<String, PoisModel>(), "");
                                    mAnyplaceCache.fetchAllFloorsRadiomapReset();

                                    bypassSelectBuildingActivity(b, b.getSelectedFloor());

                                }
                            }, UnifiedNavigationActivity.this, true);
                    task.setFiles(floorsRoot);
                    task.setFiles(radiomaps);
                    task.execute();
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
            break;
        }
        break;
    }
}

From source file:com.hichinaschool.flashcards.anki.DeckPicker.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    mDontSaveOnStop = false;//from ww w  . j  a  va 2s .c om
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (AnkiDroidApp.setLanguage(newLanguage)) {
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

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

@Override
protected void onStateResult(int requestCode, int resultCode, Intent data) {
    /// M: [BUG.ADD] mark we are not starting video player, to re-enable toggleBars() @{
    mIsStartingVideoPlayer = false;//from  w  w  w  .  j ava 2  s  . c om
    /// @}
    /// M: [FEATURE.ADD] @{
    if (mExtActivityResultListener != null) {
        mExtActivityResultListener.onActivityResult(requestCode, resultCode, data);
        mExtActivityResultListener = null;
    }
    /// @}
    /// M: [BUG.MODIFY] @{
    /*if (resultCode == Activity.RESULT_CANCELED) {*/
    if (resultCode == Activity.RESULT_CANCELED && requestCode != REQUEST_PLAY_VIDEO) {
        /// @}
        // This is a reset, not a canceled
        return;
    }
    mRecenterCameraOnResume = false;
    switch (requestCode) {
    case REQUEST_EDIT:
        setCurrentPhotoByIntentEx(data);
        break;
    /// M: [FEATURE.ADD] SlideVideo @{
    case REQUEST_TRIM:
        if (data != null) {
            redirectCurrentMedia(data.getData(), false);
        }
        break;
    /// @}
    case REQUEST_CROP:
        if (resultCode == Activity.RESULT_OK) {
            setCurrentPhotoByIntentEx(data);
        }
        break;
    case REQUEST_CROP_PICASA: {
        if (resultCode == Activity.RESULT_OK) {
            Context context = mActivity.getAndroidContext();
            String message = context.getString(R.string.crop_saved,
                    context.getString(R.string.folder_edited_online_photos));
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
        break;
    }
    case REQUEST_SLIDESHOW: {
        if (data == null)
            break;
        String path = data.getStringExtra(SlideshowPage.KEY_ITEM_PATH);
        int index = data.getIntExtra(SlideshowPage.KEY_PHOTO_INDEX, 0);
        if (path != null) {
            mModel.setCurrentPhoto(Path.fromString(path), index);
        }
        break;
    }
    /// M: [FEATURE.ADD] added for Stereo feature.@{
    case BottomControlLayer.REQUEST_REFOCUS:
    case BottomControlLayer.REQUEST_FANCY_COLOR:
    case BottomControlLayer.REQUEST_BACKGROUND:
    case BottomControlLayer.REQUEST_COPY_PAST:
        if (resultCode == Activity.RESULT_OK) {
            setRefocusCurrentPhotoByIntent(data);
        }
        break;
    /// @}
    }
}

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

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    // Reset the startActivity waiting flag
    mWaitingForResult = false;// w  ww  .j  av a 2  s.  c o  m

    if (requestCode == REQUEST_BIND_APPWIDGET) {
        int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (resultCode == RESULT_CANCELED) {
            completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
        } else if (resultCode == RESULT_OK) {
            addAppWidgetImpl(appWidgetId, mPendingAddInfo, null, mPendingAddWidgetInfo);
        }
        return;
    } else if (requestCode == REQUEST_PICK_WALLPAPER) {
        if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
            mWorkspace.exitOverviewMode(false);
        }
        return;
    }

    boolean delayExitSpringLoadedMode = false;
    boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || requestCode == REQUEST_CREATE_APPWIDGET);

    // We have special handling for widgets
    if (isWidgetDrop) {
        int appWidgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
        if (appWidgetId < 0) {
            Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\"
                    + "widget configuration activity.");
            completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
            mWorkspace.stripEmptyScreens();
        } else {
            completeTwoStageWidgetDrop(resultCode, appWidgetId);
        }
        return;
    }

    // The pattern used here is that a user PICKs a specific application,
    // which, depending on the target, might need to CREATE the actual target.

    // For example, the user would PICK_SHORTCUT for "Music playlist", and we
    // launch over to the Music app to actually CREATE_SHORTCUT.
    if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
        final PendingAddArguments args = new PendingAddArguments();
        args.requestCode = requestCode;
        args.intent = data;
        args.container = mPendingAddInfo.container;
        args.screenId = mPendingAddInfo.screenId;
        args.cellX = mPendingAddInfo.cellX;
        args.cellY = mPendingAddInfo.cellY;
        if (isWorkspaceLocked()) {
            sPendingAddList.add(args);
        } else {
            delayExitSpringLoadedMode = completeAdd(args);
        }
    } else if (resultCode == RESULT_CANCELED) {
        mWorkspace.stripEmptyScreens();
    }
    mDragLayer.clearAnimatedView();
    // Exit spring loaded mode if necessary after cancelling the configuration of a widget
    exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode, null);
}

From source file:com.irccloud.android.activity.MainActivity.java

private void setFromIntent(Intent intent) {
    launchBid = -1;// w  ww.j a  v  a2s. c o  m
    launchURI = null;

    if (NetworkConnection.getInstance().ready)
        setIntent(new Intent(this, MainActivity.class));

    if (intent.hasExtra("bid")) {
        int new_bid = intent.getIntExtra("bid", 0);
        if (NetworkConnection.getInstance().ready
                && NetworkConnection.getInstance().getState() == NetworkConnection.STATE_CONNECTED
                && BuffersDataSource.getInstance().getBuffer(new_bid) == null) {
            Crashlytics.log(Log.WARN, "IRCCloud", "Invalid bid requested by launch intent: " + new_bid);
            Notifications.getInstance().deleteNotificationsForBid(new_bid);
            if (excludeBIDTask != null)
                excludeBIDTask.cancel(true);
            excludeBIDTask = new ExcludeBIDTask();
            excludeBIDTask.execute(new_bid);
            return;
        } else if (BuffersDataSource.getInstance().getBuffer(new_bid) != null) {
            Crashlytics.log(Log.DEBUG, "IRCCloud", "Found BID, switching buffers");
            if (buffer != null && buffer.bid != new_bid)
                backStack.add(0, buffer.bid);
            buffer = BuffersDataSource.getInstance().getBuffer(new_bid);
            server = ServersDataSource.getInstance().getServer(buffer.cid);
        } else {
            Crashlytics.log(Log.DEBUG, "IRCCloud", "BID not found, will try after reconnecting");
            launchBid = new_bid;
        }
    }

    if (intent.getData() != null && intent.getData().getScheme() != null
            && intent.getData().getScheme().startsWith("irc")) {
        if (open_uri(intent.getData())) {
            return;
        } else {
            launchURI = intent.getData();
            buffer = null;
            server = null;
        }
    } else if (intent.hasExtra("cid")) {
        if (buffer == null) {
            buffer = BuffersDataSource.getInstance().getBufferByName(intent.getIntExtra("cid", 0),
                    intent.getStringExtra("name"));
            if (buffer != null) {
                server = ServersDataSource.getInstance().getServer(intent.getIntExtra("cid", 0));
            }
        }
    }

    if (buffer == null) {
        server = null;
    } else {
        if (intent.hasExtra(Intent.EXTRA_STREAM)) {
            String type = getContentResolver().getType((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
            if (type != null && type.startsWith("image/")
                    && (!NetworkConnection.getInstance().uploadsAvailable()
                            || PreferenceManager.getDefaultSharedPreferences(this)
                                    .getString("image_service", "IRCCloud").equals("imgur"))) {
                new ImgurRefreshTask((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM)).execute((Void) null);
            } else {
                fileUploadTask = new FileUploadTask((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM), this);
                fileUploadTask.execute((Void) null);
            }
        }

        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            if (intent.hasExtra(Intent.EXTRA_SUBJECT))
                buffer.draft = intent.getStringExtra(Intent.EXTRA_SUBJECT) + " ("
                        + intent.getStringExtra(Intent.EXTRA_TEXT) + ")";
            else
                buffer.draft = intent.getStringExtra(Intent.EXTRA_TEXT);
        }
    }

    if (buffer == null) {
        launchBid = intent.getIntExtra("bid", -1);
    } else {
        onBufferSelected(buffer.bid);
    }
}

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

private void finishCreate() {
    final Bundle savedState = mInnerSavedState;
    findViews();/*from  w  w  w.  j a  v a 2s. c o m*/
    final Intent intent = getIntent();
    final Message message;
    final ArrayList<AttachmentPreview> previews;
    mShowQuotedText = false;
    final CharSequence quotedText;
    int action;
    // Check for any of the possibly supplied accounts.;
    final Account account;
    if (hadSavedInstanceStateMessage(savedState)) {
        action = savedState.getInt(EXTRA_ACTION, COMPOSE);
        account = savedState.getParcelable(Utils.EXTRA_ACCOUNT);
        message = savedState.getParcelable(EXTRA_MESSAGE);

        previews = savedState.getParcelableArrayList(EXTRA_ATTACHMENT_PREVIEWS);
        mRefMessage = savedState.getParcelable(EXTRA_IN_REFERENCE_TO_MESSAGE);
        quotedText = savedState.getCharSequence(EXTRA_QUOTED_TEXT);

        mExtraValues = savedState.getParcelable(EXTRA_VALUES);

        // Get the draft id from the request id if there is one.
        if (savedState.containsKey(EXTRA_REQUEST_ID)) {
            final int requestId = savedState.getInt(EXTRA_REQUEST_ID);
            if (sRequestMessageIdMap.containsKey(requestId)) {
                synchronized (mDraftLock) {
                    mDraftId = sRequestMessageIdMap.get(requestId);
                }
            }
        }
    } else {
        account = obtainAccount(intent);
        action = intent.getIntExtra(EXTRA_ACTION, COMPOSE);
        // Initialize the message from the message in the intent
        message = intent.getParcelableExtra(ORIGINAL_DRAFT_MESSAGE);
        previews = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENT_PREVIEWS);
        mRefMessage = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE);
        mRefMessageUri = intent.getParcelableExtra(EXTRA_IN_REFERENCE_TO_MESSAGE_URI);
        quotedText = null;

        if (Analytics.isLoggable()) {
            if (intent.getBooleanExtra(Utils.EXTRA_FROM_NOTIFICATION, false)) {
                Analytics.getInstance().sendEvent("notification_action", "compose", getActionString(action), 0);
            }
        }
    }
    mAttachmentsView.setAttachmentPreviews(previews);

    setAccount(account);
    if (mAccount == null) {
        return;
    }

    initRecipients();

    // Clear the notification and mark the conversation as seen, if necessary
    final Folder notificationFolder = intent.getParcelableExtra(EXTRA_NOTIFICATION_FOLDER);

    if (notificationFolder != null) {
        final Uri conversationUri = intent.getParcelableExtra(EXTRA_NOTIFICATION_CONVERSATION);
        Intent actionIntent;
        if (conversationUri != null) {
            actionIntent = new Intent(MailIntentService.ACTION_RESEND_NOTIFICATIONS_WEAR);
            actionIntent.putExtra(Utils.EXTRA_CONVERSATION, conversationUri);
        } else {
            actionIntent = new Intent(MailIntentService.ACTION_CLEAR_NEW_MAIL_NOTIFICATIONS);
            actionIntent.setData(Utils.appendVersionQueryParameter(this, notificationFolder.folderUri.fullUri));
        }
        actionIntent.setPackage(getPackageName());
        actionIntent.putExtra(Utils.EXTRA_ACCOUNT, account);
        actionIntent.putExtra(Utils.EXTRA_FOLDER, notificationFolder);

        startService(actionIntent);
    }

    if (intent.getBooleanExtra(EXTRA_FROM_EMAIL_TASK, false)) {
        mLaunchedFromEmail = true;
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        final Uri dataUri = intent.getData();
        if (dataUri != null) {
            final String dataScheme = intent.getData().getScheme();
            final String accountScheme = mAccount.composeIntentUri.getScheme();
            mLaunchedFromEmail = TextUtils.equals(dataScheme, accountScheme);
        }
    }

    if (mRefMessageUri != null) {
        mShowQuotedText = true;
        mComposeMode = action;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            String wearReply = null;
            if (remoteInput != null) {
                LogUtils.d(LOG_TAG, "Got remote input from new api");
                CharSequence input = remoteInput.getCharSequence(NotificationActionUtils.WEAR_REPLY_INPUT);
                if (input != null) {
                    wearReply = input.toString();
                }
            } else {
                // TODO: remove after legacy code has been removed.
                LogUtils.d(LOG_TAG, "No remote input from new api, falling back to compatibility mode");
                ClipData clipData = intent.getClipData();
                if (clipData != null && LEGACY_WEAR_EXTRA.equals(clipData.getDescription().getLabel())) {
                    Bundle extras = clipData.getItemAt(0).getIntent().getExtras();
                    if (extras != null) {
                        wearReply = extras.getString(NotificationActionUtils.WEAR_REPLY_INPUT);
                    }
                }
            }

            if (!TextUtils.isEmpty(wearReply)) {
                createWearReplyTask(this, mRefMessageUri, UIProvider.MESSAGE_PROJECTION, mComposeMode,
                        wearReply).execute();
                finish();
                return;
            } else {
                LogUtils.w(LOG_TAG, "remote input string is null");
            }
        }

        getLoaderManager().initLoader(INIT_DRAFT_USING_REFERENCE_MESSAGE, null, this);
        return;
    } else if (message != null && action != EDIT_DRAFT) {
        initFromDraftMessage(message);
        initQuotedTextFromRefMessage(mRefMessage, action);
        mShowQuotedText = message.appendRefMessageContent;
        // if we should be showing quoted text but mRefMessage is null
        // and we have some quotedText, display that
        if (mShowQuotedText && mRefMessage == null) {
            if (quotedText != null) {
                initQuotedText(quotedText, false /* shouldQuoteText */);
            } else if (mExtraValues != null) {
                initExtraValues(mExtraValues);
                return;
            }
        }
    } else if (action == EDIT_DRAFT) {
        if (message == null) {
            throw new IllegalStateException("Message must not be null to edit draft");
        }
        initFromDraftMessage(message);
        // Update the action to the draft type of the previous draft
        switch (message.draftType) {
        case UIProvider.DraftType.REPLY:
            action = REPLY;
            break;
        case UIProvider.DraftType.REPLY_ALL:
            action = REPLY_ALL;
            break;
        case UIProvider.DraftType.FORWARD:
            action = FORWARD;
            break;
        case UIProvider.DraftType.COMPOSE:
        default:
            action = COMPOSE;
            break;
        }
        LogUtils.d(LOG_TAG, "Previous draft had action type: %d", action);

        mShowQuotedText = message.appendRefMessageContent;
        if (message.refMessageUri != null) {
            // If we're editing an existing draft that was in reference to an existing message,
            // still need to load that original message since we might need to refer to the
            // original sender and recipients if user switches "reply <-> reply-all".
            mRefMessageUri = message.refMessageUri;
            mComposeMode = action;
            getLoaderManager().initLoader(REFERENCE_MESSAGE_LOADER, null, this);
            return;
        }
    } else if ((action == REPLY || action == REPLY_ALL || action == FORWARD)) {
        if (mRefMessage != null) {
            initFromRefMessage(action);
            mShowQuotedText = true;
        }
    } else {
        if (initFromExtras(intent)) {
            return;
        }
    }

    mComposeMode = action;
    finishSetup(action, intent, savedState);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void configureOrAddAppWidget(Intent data) {
    int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (appWidget.configure != null) {
        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidget.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

        startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
    } else {//from  ww w.j  a va 2s  . c  om
        // Otherwise just add it
        onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@SuppressWarnings("unused")
void addAppWidget(final Intent data) {
    // TODO: catch bad widget exception when sent
    int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
    /*//from   w w  w . j  a v a2  s .  c  om
     * if (SEARCH_WIDGET.equals(customWidget)) { // We don't need this any
     * more, since this isn't a real app widget.
     * mAppWidgetHost.deleteAppWidgetId(appWidgetId); // add the search
     * widget addSearch(); } else {
     */
    AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

    try {
        Bundle metadata = getPackageManager().getReceiverInfo(appWidget.provider,
                PackageManager.GET_META_DATA).metaData;
        if (metadata != null) {
            if (metadata.containsKey(PersonaLauncherMetadata.Requirements.APIVersion)) {
                int requiredApiVersion = metadata.getInt(PersonaLauncherMetadata.Requirements.APIVersion);
                if (requiredApiVersion > PersonaLauncherMetadata.CurrentAPIVersion) {
                    onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_CANCELED, data);
                    // Show a nice toast here to tell the user why the
                    // widget is rejected.
                    new AlertDialog.Builder(this).setTitle(R.string.adw_version).setCancelable(true)
                            .setIcon(R.drawable.pr_app_icon)
                            .setPositiveButton(getString(android.R.string.ok), null)
                            .setMessage(getString(R.string.scrollable_api_required)).create().show();
                    return;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException expt) {
        // No Metadata available... then it is all OK...
    }
    configureOrAddAppWidget(data);
}

From source file:com.av.remusic.service.MediaService.java

private void handleCommandIntent(Intent intent) {
    final String action = intent.getAction();
    final String command = SERVICECMD.equals(action) ? intent.getStringExtra(CMDNAME) : null;

    if (D)//  w w w  .ja va2  s  .c  om
        Log.d(TAG, "handleCommandIntent: action = " + action + ", command = " + command);

    if (CMDNEXT.equals(command) || NEXT_ACTION.equals(action)) {
        gotoNext(true);
    } else if (CMDPREVIOUS.equals(command) || PREVIOUS_ACTION.equals(action)
            || PREVIOUS_FORCE_ACTION.equals(action)) {
        prev(PREVIOUS_FORCE_ACTION.equals(action));
    } else if (CMDTOGGLEPAUSE.equals(command) || TOGGLEPAUSE_ACTION.equals(action)) {
        if (isPlaying()) {
            pause();
            mPausedByTransientLossOfFocus = false;
        } else {
            play();
        }
    } else if (CMDPAUSE.equals(command) || PAUSE_ACTION.equals(action)) {
        pause();
        mPausedByTransientLossOfFocus = false;
    } else if (CMDPLAY.equals(command)) {
        play();
    } else if (CMDSTOP.equals(command) || STOP_ACTION.equals(action)) {
        pause();
        mPausedByTransientLossOfFocus = false;
        seek(0);
        releaseServiceUiAndStop();
    } else if (REPEAT_ACTION.equals(action)) {
        cycleRepeat();
    } else if (SHUFFLE_ACTION.equals(action)) {
        cycleShuffle();
    } else if (TRY_GET_TRACKINFO.equals(action)) {
        getLrc(mPlaylist.get(mPlayPos).mId);
    } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {

        if (isPlaying() && !mIsLocked) {
            Intent lockscreen = new Intent(this, LockActivity.class);
            lockscreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(lockscreen);
        }
    } else if (LOCK_SCREEN.equals(action)) {
        mIsLocked = intent.getBooleanExtra("islock", true);
        L.D(D, TAG, "isloced = " + mIsLocked);
    } else if (SEND_PROGRESS.equals(action)) {
        if (isPlaying() && !mIsSending) {
            mPlayerHandler.post(sendDuration);
            mIsSending = true;
        } else if (!isPlaying()) {
            mPlayerHandler.removeCallbacks(sendDuration);
            mIsSending = false;
        }

    } else if (SETQUEUE.equals(action)) {
        Log.e("playab", "action");
        setQueuePosition(intent.getIntExtra("position", 0));
    }
}