List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:com.ccxt.whl.activity.ChatActivity.java
/** * onActivityResult *//* www.j av a2 s. com*/ 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, "????", 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 (requestCode == REQUEST_CODE_ADD_TO_CONTACT) { // ? EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); String sendstr = data.getStringExtra("edittext"); if (CommonUtils.isNullOrEmpty(sendstr)) { sendstr = ""; } //addUserToBlacklist(deleteMsg.getFrom()); addContact(deleteMsg.getFrom(), sendstr); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } } }
From source file:com.MustacheMonitor.MustacheMonitor.StacheCam.java
/** * Called when the camera view exits./*from w w w . ja v a2 s. co m*/ * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; // If CAMERA if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = null; Uri uri = null; // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } // If sending filename back else if (destType == FILE_URI) { if (!this.saveToPhotoAlbum) { uri = Uri.fromFile( new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg")); } else { uri = getUriFromMediaStore(); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) { writeUncompressedImage(uri); this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { exifPath = FileUtils.getRealPathFromURI(uri, this.cordova); } else { exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); } } // Send Uri back to JavaScript for viewing image this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); bitmap = null; } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { if (resultCode == Activity.RESULT_OK) { Uri uri = intent.getData(); // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { // This is a special case to just return the path as no scaling, // rotating or compression needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && destType == FILE_URI && !this.correctOrientation) { this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } else { // Get the path to the image. Makes loading so much easier. String imagePath = FileUtils.getRealPathFromURI(uri, this.cordova); Log.d(LOG_TAG, "Real path = " + imagePath); // If we don't have a valid image so quit. if (imagePath == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retreive path to picture!"); return; } Bitmap bitmap = getScaledBitmap(imagePath); if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova.getActivity().getContentResolver().query(intent.getData(), cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } } // If sending base64 image back if (destType == DATA_URL) { this.processPicture(bitmap); } // If sending filename back else if (destType == FILE_URI) { // Do we need to scale the returned file if (this.targetHeight > 0 && this.targetWidth > 0) { try { // Create an ExifHelper to save the exif data that is lost during compression String resizePath = DirectoryManager .getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg"; ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(resizePath); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } OutputStream os = new FileOutputStream(resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); } // The resized image is cached by the app in order to get around this and not have to delete you // application cache I'm adding the current system time to the end of the file url. this.success( new PluginResult(PluginResult.Status.OK, ("file://" + resizePath + "?" + System.currentTimeMillis())), this.callbackId); } catch (Exception e) { e.printStackTrace(); this.failPicture("Error retrieving image."); } } else { this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId); } } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); } } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:com.fullteem.yueba.app.ui.ChatActivity.java
/** * onActivityResult/*ww w. j ava 2 s. co m*/ */ @Override 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 = (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 = 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, "????", 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 = 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.ieeton.agency.activity.ChatActivity.java
/** * onActivityResult// www . j a va 2 s .c o m */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Utils.logd("requestCode:" + requestCode); Utils.logd("resultCode:" + resultCode); 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, "????", 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 (requestCode == REQUEST_CODE_GROUP_DETAIL) { adapter.refresh(); } else if (requestCode == REQUEST_CODE_QUICK_REPLY) { String content = data.getStringExtra(EXTRA_QUICK_REPLY); Utils.logd("content:" + content); sendText(content); } else if (conversation.getMsgCount() > 0) { adapter.refresh(); setResult(RESULT_OK); } } }
From source file:com.irccloud.android.activity.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { if (buffer != null) { if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK) { if (imageCaptureURI != null) { if (!NetworkConnection.getInstance().uploadsAvailable() || PreferenceManager.getDefaultSharedPreferences(this) .getString("image_service", "IRCCloud").equals("imgur")) { new ImgurRefreshTask(imageCaptureURI).execute((Void) null); } else { fileUploadTask = new FileUploadTask(imageCaptureURI, this); fileUploadTask.execute((Void) null); }/* w w w . j a v a 2 s . co m*/ if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("keep_photos", false) && imageCaptureURI.toString().startsWith("file://")) { ContentValues image = new ContentValues(); image.put(MediaStore.Images.Media.DATA, imageCaptureURI.toString().substring(7)); getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, image); } } } else if (requestCode == REQUEST_PHOTO && resultCode == RESULT_OK) { Uri selectedImage = imageReturnedIntent.getData(); if (selectedImage != null) { if (!NetworkConnection.getInstance().uploadsAvailable() || PreferenceManager.getDefaultSharedPreferences(this) .getString("image_service", "IRCCloud").equals("imgur")) { new ImgurRefreshTask(selectedImage).execute((Void) null); } else { fileUploadTask = new FileUploadTask(selectedImage, this); fileUploadTask.execute((Void) null); } } } else if (requestCode == REQUEST_DOCUMENT && resultCode == RESULT_OK) { Uri selectedFile = imageReturnedIntent.getData(); if (selectedFile != null) { fileUploadTask = new FileUploadTask(selectedFile, this); fileUploadTask.execute((Void) null); } } else if (requestCode == REQUEST_UPLOADS && resultCode == RESULT_OK) { buffer.draft = ""; messageTxt.setText(""); } else if (requestCode == REQUEST_PASTEBIN) { if (resultCode == RESULT_OK) { pastebinResult = imageReturnedIntent; } else if (resultCode == RESULT_CANCELED) { buffer.draft = imageReturnedIntent.getStringExtra("paste_contents"); messageTxt.setText(buffer.draft); } } } }
From source file:edu.mit.viral.shen.DroidFish.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case RESULT_SETTINGS: handlePrefsChange();//from ww w.j av a2 s . c o m break; case RESULT_EDITBOARD: if (resultCode == RESULT_OK) { try { String fen = data.getAction(); startPosition = fen; ctrl.setData(fen); ctrl.setFENOrPGN(fen); mDatabase.updateStartFen(fen, game_number); ctrl.setFENOrPGN(fen); setBoardFlip(false); } catch (ChessParseError e) { } } break; case RESULT_LOAD_PGN: if (resultCode == RESULT_OK) { try { String pgn = data.getAction(); int modeNr = ctrl.getGameMode().getModeNr(); if ((modeNr != GameMode.ANALYSIS) && (modeNr != GameMode.EDIT_GAME)) newGameMode(GameMode.EDIT_GAME); ctrl.setFENOrPGN(pgn); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; case RESULT_SELECT_SCID: if (resultCode == RESULT_OK) { String pathName = data.getAction(); if (pathName != null) { Editor editor = settings.edit(); editor.putString("currentScidFile", pathName); editor.putInt("currFT", FT_SCID); editor.commit(); Intent i = new Intent(DroidFish.this, LoadScid.class); i.setAction("edu.mit.viral.shen.loadScid"); i.putExtra("edu.mit.viral.shen.pathname", pathName); startActivityForResult(i, RESULT_LOAD_PGN); } } break; case RESULT_OI_PGN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadPGNFromFile(pathName); } break; case RESULT_OI_PGN_SAVE: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) { if ((pathName.length() > 0) && !pathName.contains(".")) pathName += ".pgn"; savePGNToFile(pathName, false); } } break; case RESULT_OI_FEN_LOAD: if (resultCode == RESULT_OK) { String pathName = getFilePathFromUri(data.getData()); if (pathName != null) loadFENFromFile(pathName); } break; case RESULT_GET_FEN: if (resultCode == RESULT_OK) { String fen = data.getStringExtra(Intent.EXTRA_TEXT); if (fen == null) { String pathName = getFilePathFromUri(data.getData()); loadFENFromFile(pathName); } setFenHelper(fen); } break; case RESULT_LOAD_FEN: if (resultCode == RESULT_OK) { String fen = data.getAction(); setFenHelper(fen); } break; } }
From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java
/** * Called when the camera view exits.//w ww . j a v a 2 s .c om * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; // If CAMERA if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { // Create an ExifHelper to save the exif data that is lost during compression ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(getTempDirectoryPath() + "/.Pic.jpg"); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = null; Uri uri = null; // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (bitmap == null) { // Try to get the bitmap from intent. bitmap = (Bitmap) intent.getExtras().get("data"); } // Double-check the bitmap. if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } this.processPicture(bitmap); checkForDuplicateImage(DATA_URL); } // If sending filename back else if (destType == FILE_URI || destType == NATIVE_URI) { if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); //Just because we have a media URI doesn't mean we have a real file, we need to make it uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); } else { uri = Uri.fromFile( new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); } // If all this is true we shouldn't compress the image. if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && !this.correctOrientation) { writeUncompressedImage(uri); this.callbackContext.success(uri.toString()); } else { bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { exifPath = FileHelper.getRealPath(uri, this.cordova); } else { exifPath = uri.getPath(); } exif.createOutFile(exifPath); exif.writeExifData(); } } // Send Uri back to JavaScript for viewing image this.callbackContext.success(uri.toString()); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); bitmap = null; } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { if (resultCode == Activity.RESULT_OK) { Uri uri = intent.getData(); // If you ask for video or all media type you will automatically get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { this.callbackContext.success(uri.toString()); } else { // This is a special case to just return the path as no scaling, // rotating, nor compressing needs to be done if (this.targetHeight == -1 && this.targetWidth == -1 && (destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) { this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); // Get the path to the image. Makes loading so much easier. String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } Bitmap bitmap = null; try { bitmap = getScaledBitmap(uriString); } catch (IOException e) { e.printStackTrace(); } if (bitmap == null) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to create bitmap!"); return; } if (this.correctOrientation) { rotate = getImageOrientation(uri); if (rotate != 0) { // Matrix matrix = new Matrix(); // matrix.setRotate(rotate); // bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); RotateTask r = new RotateTask(bitmap, srcType, destType, rotate, intent); r.execute(); return; } } returnImageToProcess(bitmap, srcType, destType, intent, rotate); } } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:com.irccloud.android.activity.MainActivity.java
private void setFromIntent(Intent intent) { launchBid = -1;//from w ww. jav a 2s.c om 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:cn.yunluosoft.tonglou.activity.ChatActivity.java
/** * onActivityResult/*from w w w . ja v a 2s . co m*/ */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 8226 && resultCode == RESULT_OK) { String s = data.getStringExtra("name"); if (!ToosUtils.isStringEmpty(s)) { messageInfo.receiverNickName = s; toChatUsername = messageInfo.receiverImUserName; // toChatUsername = getIntent().getStringExtra("userId"); ((TextView) findViewById(R.id.title_title)).setText(messageInfo.receiverNickName); } } 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(), 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) { // ?? loading(); // 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(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(); } } }