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.bt.download.android.gui.activities.AudioPlayerActivity.java

/**
 * Checks whether the passed intent contains a playback request,
 * and starts playback if that's the case
 *//*w w w  .  j av  a  2  s . c om*/
private void startPlayback() {
    Intent intent = getIntent();

    if (intent == null || mService == null) {
        return;
    }

    Uri uri = intent.getData();
    String mimeType = intent.getType();
    boolean handled = false;

    if (uri != null && uri.toString().length() > 0) {
        MusicUtils.playFile(this, uri);
        handled = true;
    } else if (Playlists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "playlistId", "playlist", -1);
        if (id >= 0) {
            MusicUtils.playPlaylist(this, id);
            handled = true;
        }
    } else if (Albums.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "albumId", "album", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playAlbum(this, id, position);
            handled = true;
        }
    } else if (Artists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "artistId", "artist", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playArtist(this, id, position);
            handled = true;
        }
    }

    if (handled) {
        // Make sure to process intent only once
        setIntent(new Intent());
        // Refresh the queue
        ((QueueFragment) mPagerAdapter.getFragment(0)).refreshQueue();
    }
}

From source file:alaindc.crowdroid.SensorsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (action.equals(Constants.INTENT_START_SENSORS)) {

            // Init throughput taken
            SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putBoolean(Constants.THROUGHPUT_TAKEN, false);
            editor.commit();// w  ww  . j a  v a 2 s  . c  om

            // Configure sensors and eventlistener
            mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
            List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensorList) {
                if (Constants.isInMonitoredSensors(sensor.getType()))
                    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
            }

            // TODO STUB: Comment this in release
            for (int type : Constants.STUBBED_MONITORED_SENSORS) {
                stub_onSensorChanged(type);
            }

        }

        if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) {
            // Configure amplitude and start TEST
            amplitudeTask = new GetAmplitudeTask(this);
            amplitudeTask.getData();
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) {
            double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1);

            if (amplitude > 0) {
                SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude));
                editor.commit();

                // Update view
                Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
                senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA,
                        "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: "
                                + Double.toString(amplitude));
                LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent);
            }

            int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE);

            // Set the alarms for next sensing of amplitude
            alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
            Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class);
            intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

            // TIMEOUT for another monitoring of audio
            int seconds = 30; // TODO: De-hardcode this
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
                    alarmIntent);

        }
    }
}

From source file:app.view.chat.ChatActivity.java

/**
 * onActivityResult/*  w w w .j  a va  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)));
            if (copyMsg.getType() == EMMessage.Type.IMAGE) {
                ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody();
                // ???
                clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl());
            } else {
                // 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_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, "????", Toast.LENGTH_SHORT).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.cleverzone.zhizhi.capture.CaptureActivity.java

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

    // historyManager must be initialized here to update the history preference
    //        historyManager = new HistoryManager(this);
    //        historyManager.trimHistory();

    // 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  ww w .j av a2s.  co  m*/
    lastResult = null;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    //        if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
    //            setRequestedOrientation(getCurrentOrientation());
    //        } else {
    //            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    //        }
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

    resetStatusView();

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

    inactivityTimer.onResume();

    Intent intent = getIntent();

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

    source = IntentSource.NONE;
    sourceUrl = null;
    //        scanFromWebPageManager = null;
    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);
                }
            }

            if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
                int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
                if (cameraId >= 0) {
                    cameraManager.setManualCameraId(cameraId);
                }
            }

            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);

    }

    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);
    }
}

From source file:activities.PaintActivity.java

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

    switch (requestCode) {
    case PaintUtility.CAMERA_PIC_REQUEST:
    case PaintUtility.LIBRARY_PIC_REQUEST:

        int orientation = ExifInterface.ORIENTATION_UNDEFINED;
        if (data != null) {
            orientation = data.getIntExtra(MediaStore.Images.ImageColumns.ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
        }//ww  w .  jav  a  2  s.  co m
        Uri imageUri = PaintUtility.getPhotoUri(this, requestCode, resultCode, data);
        this.painter.closedCamera();

        if (imageUri != null) {
            this.painter.loadCompressedImage(imageUri, requestCode == PaintUtility.CAMERA_PIC_REQUEST,
                    orientation);
        }
        setDefaultToolMode();
        break;
    case RS_CODE_SHARE_FB:
        deleteTempImage();
        FlurryAgent.logEvent(FLURRY_EV_SHARE_FB);

        break;
    case RS_CODE_SHARE_GMAIL:
        deleteTempImage();
        FlurryAgent.logEvent(FLURRY_EV_SHARE_EMAIL);

        break;
    case RS_CODE_SHARE_TWITTER:
        deleteTempImage();
        //en caso de que si haya compartido
        if (resultCode == -1)
            FlurryAgent.logEvent(FLURRY_EV_SHARE_TWITTER);

        break;
    }

}

From source file:com.sdspikes.fireworks.FireworksActivity.java

private void handleSelectPlayersResult(int response, Intent data) {
    if (response != Activity.RESULT_OK) {
        Log.w(TAG, "*** select players UI cancelled, " + response);
        switchToMainScreen();/*  ww  w.  j  a v  a  2s .  c o  m*/
        return;
    }

    Log.d(TAG, "Select players UI succeeded.");

    // get the invitee list
    final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
    Log.d(TAG, "Invitee count: " + invitees.size());

    // get the automatch criteria
    Bundle autoMatchCriteria = null;
    int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
    int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
    if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
        autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        Log.d(TAG, "Automatch criteria: " + autoMatchCriteria);
    }

    // create the room
    Log.d(TAG, "Creating room...");
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
    rtmConfigBuilder.addPlayersToInvite(invitees);
    rtmConfigBuilder.setMessageReceivedListener(this);
    rtmConfigBuilder.setRoomStatusUpdateListener(this);
    if (autoMatchCriteria != null) {
        rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
    }
    switchToScreen(R.id.screen_wait);
    keepScreenOn();
    resetGameVars();
    Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build());
    Log.d(TAG, "Room created, waiting for it to be ready...");
}

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

/**
 * onActivityResult/*from www  .j av a2 s .  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)));
            if (copyMsg.getType() == EMMessage.Type.IMAGE) {
                ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody();
                // ???
                clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl());
            } else {
                // 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_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 st4 = getResources().getString(R.string.unable_to_get_loaction);
                Toast.makeText(this, st4, 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:net.oschina.app.v2.activity.zxing.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();
    // historyManager must be initialized here to update the history preference
    // historyManager = new HistoryManager(this);
    // historyManager.trimHistory();

    // 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  a  2  s.  c o m*/
    lastResult = null;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
        //setRequestedOrientation(getCurrentOrientation());
    } else {
        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    }

    resetStatusView();

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

    inactivityTimer.onResume();

    Intent intent = getIntent();

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

    source = IntentSource.NONE;
    sourceUrl = null;
    scanFromWebPageManager = null;
    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);
                }
            }

            if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
                int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
                if (cameraId >= 0) {
                    cameraManager.setManualCameraId(cameraId);
                }
            }

            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);
    }

    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);
    }
}

From source file:com.blueshit.activity.ChatActivity.java

/**
 * onActivityResult/*from w  ww  .ja v a 2s. 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_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, 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:com.hichinaschool.flashcards.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  ww  .j a  va 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();
        }

    });
}