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.t2.compassionMeditation.MeditationActivity.java

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

    switch (requestCode) {
    case BioZenConstants.END_SESSION_ACTIVITY:
        if (data != null) {
            int action = data.getIntExtra(BioZenConstants.END_SESSION_ACTIVITY_RESULT,
                    BioZenConstants.END_SESSION_RESTART);

            switch (action) {

            default:
            case BioZenConstants.END_SESSION_RESTART:
                break;

            case BioZenConstants.END_SESSION_SAVE:
                EndAndSaveSession(data);
                break;

            case BioZenConstants.END_SESSION_QUIT:
                if (mLogFile != null)
                    mLogFile.delete();/*from   w  w  w. ja v  a 2  s  .c o  m*/
                Analytics.onEndSession(this);
                finish();
                break;
            }
        } else {
            if (mLogFile != null)
                mLogFile.delete();
            Analytics.onEndSession(this);
            finish();
        }

        break;
    }
}

From source file:com.ieeton.user.activity.ChatActivity.java

/**
 * onActivityResult/*from w  w  w  . ja v a  2  s  . c  o  m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
            // ((TextMessageBody) copyMsg.getBody()).getMessage()));
            clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refresh();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                Toast.makeText(this, "????", 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VOICE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_PICTURE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_LOCATION) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }
    }
}

From source file:com.honglang.zxing.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    // resultView = findViewById(R.id.result_view);
    statusView = (TextView) findViewById(R.id.status_view);

    handler = null;//from  w w w. ja  v  a 2 s. com
    lastResult = null;

    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
    }

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    Intent intent = getIntent();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
            && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();
        String dataString = intent.getDataString();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result
            // to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
            decodeHints = DecodeHintManager.parseDecodeHints(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }

            String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
            if (customPromptMessage != null) {
                statusView.setText(customPromptMessage);
            }

        } else if (dataString != null && dataString.contains("http://www.google")
                && dataString.contains("/m/products/scan")) {

            // Scan only products and send the result to mobile Product
            // Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

        } else if (isZXingURL(dataString)) {

            // Scan formats requested in query string (all formats if none
            // specified).
            // If a return URL is specified, send the results there.
            // Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(dataString);
            // scanFromWebPageManager = new
            // ScanFromWebPageManager(inputUri);
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);
            // Allow a sub-set of the hints to be specified by the caller.
            decodeHints = DecodeHintManager.parseDecodeHints(inputUri);

        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}

From source file:com.vanco.abplayer.BiliVideoViewActivity.java

private void parseIntent(Intent i) {
    //      Uri dat = IntentHelper.getIntentUri(i);
    //      if (dat == null)
    //         resultFinish(RESULT_FAILED);
    ///*from   w w  w  . j  a  v  a  2s.co m*/
    //      String datString = dat.toString();
    //      if (!datString.equals(dat.toString()))
    //         dat = Uri.parse(datString);
    //
    //      mUri = dat;
    //      danmakuPath = "http://comment.bilibili.com/"+i.getStringExtra("CID")+".xml";
    //        Logger.d(danmakuPath);
    av = i.getStringExtra("av");
    page = i.getStringExtra("page");
    Logger.d("----->" + av + "/" + page);

    mNeedLock = i.getBooleanExtra("lockScreen", false);
    mDisplayName = i.getStringExtra("displayName");
    mFromStart = i.getBooleanExtra("fromStart", false);
    mSaveUri = i.getBooleanExtra("saveUri", true);
    mStartPos = i.getFloatExtra("startPosition", -1.0f);
    mLoopCount = i.getIntExtra("loopCount", 1);
    mParentId = i.getIntExtra("parentId", 0);
    mSubPath = i.getStringExtra("subPath");
    mSubShown = i.getBooleanExtra("subShown", true);
    mIsHWCodec = i.getBooleanExtra("hwCodec", false);
    Log.i("L: %b, N: %s, S: %b, P: %f, LP: %d", mNeedLock, mDisplayName, mFromStart, mStartPos, mLoopCount);
}

From source file:com.ichi2.anki.CardEditor.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(AnkiDroidApp.TAG, "CardEditor: onCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    Intent intent = getIntent();
    if (savedInstanceState != null) {
        mCaller = savedInstanceState.getInt("caller");
        mAddNote = savedInstanceState.getBoolean("addFact");
    } else {//from   w  w  w  .  java  2 s .  c o  m
        mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER);
        if (mCaller == CALLER_NOCALLER) {
            String action = intent.getAction();
            if (action != null && (ACTION_CREATE_FLASHCARD.equals(action)
                    || ACTION_CREATE_FLASHCARD_SEND.equals(action))) {
                mCaller = CALLER_INDICLASH;
            }
        }
    }
    Log.i(AnkiDroidApp.TAG, "CardEditor: caller: " + mCaller);

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());

    if (mCaller == CALLER_INDICLASH && preferences.getBoolean("intentAdditionInstantAdd", false)) {
        // save information without showing card editor
        fetchIntentInformation(intent);
        MetaDB.saveIntentInformation(CardEditor.this, Utils.joinFields(mSourceText));
        Themes.showThemedToast(CardEditor.this, getResources().getString(R.string.app_name) + ": "
                + getResources().getString(R.string.CardEditorLaterMessage), false);
        finish();
        return;
    }

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }

    registerExternalStorageListener();

    View mainView = getLayoutInflater().inflate(R.layout.card_editor, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setContentStyle(mainView, Themes.CALLER_CARD_EDITOR);

    mFieldsLayoutContainer = (LinearLayout) findViewById(R.id.CardEditorEditFieldsLayout);

    mSave = (Button) findViewById(R.id.CardEditorSaveButton);
    mCancel = (Button) findViewById(R.id.CardEditorCancelButton);
    mLater = (Button) findViewById(R.id.CardEditorLaterButton);
    mDeckButton = (TextView) findViewById(R.id.CardEditorDeckText);
    mModelButton = (TextView) findViewById(R.id.CardEditorModelText);
    mTagsButton = (TextView) findViewById(R.id.CardEditorTagText);
    mSwapButton = (Button) findViewById(R.id.CardEditorSwapButton);
    mSwapButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            swapText(false);
        }
    });

    mAedictIntent = false;

    switch (mCaller) {
    case CALLER_NOCALLER:
        Log.i(AnkiDroidApp.TAG, "CardEditor: no caller could be identified, closing");
        finish();
        return;

    case CALLER_REVIEWER:
        mCurrentEditedCard = Reviewer.getEditorCard();
        if (mCurrentEditedCard == null) {
            finish();
            return;
        }
        mEditorNote = mCurrentEditedCard.note();
        mAddNote = false;
        break;

    case CALLER_STUDYOPTIONS:
    case CALLER_DECKPICKER:
        mAddNote = true;
        break;

    case CALLER_BIGWIDGET_EDIT:
        // Card widgetCard = AnkiDroidWidgetBig.getCard();
        // if (widgetCard == null) {
        // finish();
        // return;
        // }
        // mEditorNote = widgetCard.getFact();
        // mAddNote = false;
        break;

    case CALLER_BIGWIDGET_ADD:
        mAddNote = true;
        break;

    case CALLER_CARDBROWSER_EDIT:
        mCurrentEditedCard = CardBrowser.sCardBrowserCard;
        if (mCurrentEditedCard == null) {
            finish();
            return;
        }
        mEditorNote = mCurrentEditedCard.note();
        mAddNote = false;
        break;

    case CALLER_CARDBROWSER_ADD:
        mAddNote = true;
        break;

    case CALLER_CARDEDITOR:
        mAddNote = true;
        break;

    case CALLER_CARDEDITOR_INTENT_ADD:
        mAddNote = true;
        break;

    case CALLER_INDICLASH:
        fetchIntentInformation(intent);
        if (mSourceText == null) {
            finish();
            return;
        }
        if (mSourceText[0].equals("Aedict Notepad") && addFromAedict(mSourceText[1])) {
            finish();
            return;
        }
        mAddNote = true;
        break;
    }

    setNote(mEditorNote);

    if (mAddNote) {
        setTitle(R.string.cardeditor_title_add_note);
        // set information transferred by intent
        String contents = null;
        if (mSourceText != null) {
            if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) {
                contents = mSourceText[1].replaceFirst("\\[", "\u001f");
                contents = contents.substring(0, contents.length() - 1);
            } else {
                mEditFields.get(0).setText(mSourceText[0]);
                mEditFields.get(1).setText(mSourceText[1]);
            }
        } else {
            contents = intent.getStringExtra(EXTRA_CONTENTS);
        }
        if (contents != null) {
            setEditFieldTexts(contents);
        }

        LinearLayout modelButton = ((LinearLayout) findViewById(R.id.CardEditorModelButton));
        modelButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_MODEL_SELECT);
            }
        });
        modelButton.setVisibility(View.VISIBLE);
        mSave.setText(getResources().getString(R.string.add));
        mCancel.setText(getResources().getString(R.string.close));

        mLater.setVisibility(View.VISIBLE);
        mLater.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = getFieldsText();
                if (content.length() > mEditFields.size() - 1) {
                    MetaDB.saveIntentInformation(CardEditor.this, content);
                    populateEditFields();
                    mSourceText = null;
                    Themes.showThemedToast(CardEditor.this,
                            getResources().getString(R.string.CardEditorLaterMessage), false);
                }
                if (mCaller == CALLER_INDICLASH || mCaller == CALLER_CARDEDITOR_INTENT_ADD) {
                    closeCardEditor();
                }
            }
        });
    } else {
        setTitle(R.string.cardeditor_title_edit_card);
        mSwapButton.setVisibility(View.GONE);
        mSwapButton = (Button) findViewById(R.id.CardEditorLaterButton);
        mSwapButton.setVisibility(View.VISIBLE);
        mSwapButton.setText(getResources().getString(R.string.fact_adder_swap));
        mSwapButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                swapText(false);
            }
        });
    }

    ((LinearLayout) findViewById(R.id.CardEditorDeckButton)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DIALOG_DECK_SELECT);
        }
    });

    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);
    // if Arabic reshaping is enabled, disable the Save button to avoid
    // saving the reshaped string to the deck
    if (mPrefFixArabic && !mAddNote) {
        mSave.setEnabled(false);
    }

    ((LinearLayout) findViewById(R.id.CardEditorTagButton)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_TAGS_SELECT);
        }
    });

    mSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (duplicateCheck(true)) {
                return;
            }
            boolean modified = false;
            for (FieldEditText f : mEditFields) {
                modified = modified | f.updateField();
            }
            if (mAddNote) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, mSaveFactHandler,
                        new DeckTask.TaskData(mEditorNote));
            } else {
                // added tag?
                for (String t : mCurrentTags) {
                    modified = modified || !mEditorNote.hasTag(t);
                }
                // removed tag?
                modified = modified || mEditorNote.getTags().size() > mCurrentTags.size();
                // changed did?
                boolean changedDid = mCurrentEditedCard.getDid() != mCurrentDid;
                modified = modified || changedDid;
                if (modified) {
                    mEditorNote.setTags(mCurrentTags);
                    // set did for card
                    if (changedDid) {
                        mCurrentEditedCard.setDid(mCurrentDid);
                    }
                    mChanged = true;
                }
                closeCardEditor();
                // if (mCaller == CALLER_BIGWIDGET_EDIT) {
                // // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT,
                // // mSaveFactHandler, new
                // // DeckTask.TaskData(Reviewer.UPDATE_CARD_SHOW_QUESTION,
                // // mDeck, AnkiDroidWidgetBig.getCard()));
                // } else if (!mCardReset) {
                // // Only send result to save if something was actually
                // // changed
                // if (mModified) {
                // setResult(RESULT_OK);
                // } else {
                // setResult(RESULT_CANCELED);
                // }
                // closeCardEditor();
                // }

            }
        }
    });

    mCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            closeCardEditor();
        }

    });
}

From source file:cn.ucai.yizhesale.activity.ChatActivity.java

/**
 * onActivityResult/*  w  ww  .ja  v a2s  . c om*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
            // ((TextMessageBody) copyMsg.getBody()).getMessage()));
            clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refreshSeekTo(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        case RESULT_CODE_FORWARD: // ??
            EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
            Intent intent = new Intent(this, ForwardMessageActivity.class);
            intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
            startActivity(intent);

            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(),
                            cn.ucai.yizhesale.R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                toggleMore(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                String st = getResources().getString(cn.ucai.yizhesale.R.string.unable_to_get_loaction);
                Toast.makeText(this, st, Toast.LENGTH_SHORT).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE
                || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION
                || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }
    }
}

From source file:cn.kangeqiu.kq.activity.ChatActivity.java

/**
 * onActivityResult/*w  ww  . j a  va2s.  c o m*/
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
            // ((TextMessageBody) copyMsg.getBody()).getMessage()));
            clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refresh();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        case RESULT_CODE_FORWARD: // ??
            EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
            Intent intent = new Intent(this, ForwardMessageActivity.class);
            intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
            startActivity(intent);

            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_CREATE_GUESS) {
            if (data != null) {

                try {
                    sendJingcai(
                            match.getJSONObject("team1").getString("name") + "VS"
                                    + match.getJSONObject("team2").getString("name"),
                            "isGuess", data.getStringExtra("id") + "," + data.getStringExtra("price"));
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                // Toast.makeText(ChatActivity.this,
                // data.getStringExtra("id"), Toast.LENGTH_SHORT)
                // .show();
            }
        } else if (requestCode == REQUEST_CODE_CREATE_BRAG) {
            if (data != null) {

                sendJingcai("??", "isBrag", data.getStringExtra("id"));

            }
        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                String st = getResources().getString(R.string.unable_to_get_loaction);
                Toast.makeText(this, st, 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE
                || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION
                || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }
    }
}

From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    resultView = findViewById(R.id.result_view);
    statusView = (TextView) findViewById(R.id.status_view);

    handler = null;/*from   w  w w. j a v  a2s .  c  om*/
    lastResult = null;

    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    beepManager.updatePrefs();

    inactivityTimer.onResume();

    Intent intent = getIntent();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
            && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();
        String dataString = intent.getDataString();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result
            // to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }

            String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
            if (customPromptMessage != null) {
                statusView.setText(customPromptMessage);
            }

        } else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX)
                && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

            // Scan only products and send the result to mobile Product
            // Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

        } else if (isZXingURL(dataString)) {

            // Scan formats requested in query string (all formats if none
            // specified).
            // If a return URL is specified, send the results there.
            // Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(sourceUrl);
            returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM);
            returnRaw = inputUri.getQueryParameter(RAW_PARAM) != null;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);

        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}