Example usage for android.media ThumbnailUtils createVideoThumbnail

List of usage examples for android.media ThumbnailUtils createVideoThumbnail

Introduction

In this page you can find the example usage for android.media ThumbnailUtils createVideoThumbnail.

Prototype

public static Bitmap createVideoThumbnail(String filePath, int kind) 

Source Link

Document

Create a video thumbnail for a video.

Usage

From source file:com.cw.litenote.util.video.UtilVideo.java

static BitmapDrawable getBitmapDrawableByPath(Activity mAct, String picPathStr) {
    String path = Uri.parse(picPathStr).getPath();
    Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(path,
            MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
    BitmapDrawable bitmapDrawable = new BitmapDrawable(mAct.getResources(), bmThumbnail);
    return bitmapDrawable;
}

From source file:com.pavlospt.rxfile.RxFile.java

public static Observable<Bitmap> getVideoThumbnail(final String filePath) {
    return Observable.fromCallable(new Func0<Bitmap>() {
        @Override// ww w . j  av a  2  s. com
        public Bitmap call() {
            return ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.MINI_KIND);
        }
    });
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static void DownloadFromUrl(final String media, final String messageId, final Context ctx,
        final ImageView container, final Object object, final String timelineId, final String localId,
        final Long fileSize) {

    new AsyncTask<Void, Void, Boolean>() {
        private boolean retry = true;
        private Bitmap imageDownloaded;
        private BroadcastReceiver mDownloadCancelReceiver;
        private HttpGet job;
        private AccountManager am;
        private Account account;
        private String authToken;

        @Override//from w  w w .j  a va  2 s.  c  om
        protected void onPreExecute() {
            IntentFilter downloadFilter = new IntentFilter(ConstantKeys.BROADCAST_CANCEL_PROCESS);
            mDownloadCancelReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String localIdToClose = (String) intent.getExtras().get(ConstantKeys.LOCALID);
                    if (localId.equals(localIdToClose)) {
                        try {
                            job.abort();
                        } catch (Exception e) {
                            log.debug("The process was canceled");
                        }
                        cancel(false);
                    }
                }
            };

            // registering our receiver
            ctx.getApplicationContext().registerReceiver(mDownloadCancelReceiver, downloadFilter);
        }

        @Override
        protected void onCancelled() {
            File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG);
            File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP);

            if (file1.exists()) {
                file1.delete();
            }
            if (file2.exists()) {
                file2.delete();
            }

            file1 = null;
            file2 = null;
            System.gc();
            try {
                ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver);
            } catch (Exception e) {
                log.debug("Receriver unregister from another code");
            }

            for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) {
                if (AppUtils.getlistOfDownload().get(i).equals(localId)) {
                    AppUtils.getlistOfDownload().remove(i);
                }
            }

            DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId, 100);

            Intent intent = new Intent();
            intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH);
            intent.putExtra(ConstantKeys.LOCALID, localId);
            ctx.sendBroadcast(intent);

            if (object != null) {
                ((ProgressDialog) object).dismiss();
            }
        }

        @Override
        protected Boolean doInBackground(Void... params) {
            try {
                File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG);
                File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP);
                // firt we are goint to search the local files
                if ((!file1.exists()) && (!file2.exists())) {
                    account = AccountUtils.getAccount(ctx.getApplicationContext(), false);
                    am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE);
                    authToken = ConstantKeys.STRING_DEFAULT;
                    authToken = am.blockingGetAuthToken(account, ctx.getString(R.string.account_type), true);

                    MessagingClientService messageService = new MessagingClientService(
                            ctx.getApplicationContext());

                    URL urlObj = new URL(Preferences.getServerProtocol(ctx), Preferences.getServerAddress(ctx),
                            Preferences.getServerPort(ctx), ctx.getString(R.string.url_get_content));

                    String url = ConstantKeys.STRING_DEFAULT;
                    url = Uri.parse(urlObj.toString()).buildUpon().build().toString() + timelineId + "/"
                            + messageId + "/" + "content";

                    job = new HttpGet(url);
                    // first, get free space
                    FreeUpSpace(ctx, fileSize);
                    messageService.getContent(authToken, media, messageId, timelineId, localId, false, false,
                            fileSize, job);
                }

                if (file1.exists()) {
                    imageDownloaded = decodeSampledBitmapFromPath(file1.getAbsolutePath(), 200, 200);
                } else if (file2.exists()) {
                    imageDownloaded = ThumbnailUtils.createVideoThumbnail(file2.getAbsolutePath(),
                            MediaStore.Images.Thumbnails.MINI_KIND);
                }

                if (imageDownloaded == null) {
                    return false;
                }
                return true;
            } catch (Exception e) {
                deleteFiles();
                return false;
            }
        }

        @Override
        protected void onPostExecute(Boolean result) {
            // We have the media
            try {
                ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver);
            } catch (Exception e) {
                log.debug("Receiver was closed on cancel");
            }

            if (!(localId.contains(ConstantKeys.AVATAR))) {
                for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) {
                    if (AppUtils.getlistOfDownload().get(i).equals(localId)) {
                        AppUtils.getlistOfDownload().remove(i);
                    }
                }

                DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId,
                        100);

                Intent intent = new Intent();
                intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH);
                intent.putExtra(ConstantKeys.LOCALID, localId);
                ctx.sendBroadcast(intent);
            }

            if (object != null) {
                ((ProgressDialog) object).dismiss();
            }

            // Now the only container could be the avatar in edit screen
            if (container != null) {
                if (imageDownloaded != null) {
                    container.setImageBitmap(imageDownloaded);
                } else {
                    deleteFiles();
                    imageDownloaded = decodeSampledBitmapFromResource(ctx.getResources(),
                            R.drawable.ic_error_loading, 200, 200);
                    container.setImageBitmap(imageDownloaded);
                    Toast.makeText(ctx.getApplicationContext(),
                            ctx.getApplicationContext().getText(R.string.donwload_fail), Toast.LENGTH_SHORT)
                            .show();
                }
            } else {
                showMedia(localId, ctx, (ProgressDialog) object);
            }

        }

        private void deleteFiles() {
            File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG);
            File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP);
            if (file1.exists()) {
                file1.delete();
            }
            if (file2.exists()) {
                file2.delete();
            }
        }

    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.pavlospt.rxfile.RxFile.java

public static Observable<Bitmap> getVideoThumbnailFromPathWithKind(final String path, final int kind) {
    return Observable.defer(new Func0<Observable<Bitmap>>() {
        @Override/*from   www.j ava  2s.  co  m*/
        public Observable<Bitmap> call() {
            return Observable.just(ThumbnailUtils.createVideoThumbnail(path, kind));
        }
    });
}

From source file:com.chute.android.photopickerplus.ui.activity.ServicesActivity.java

@SuppressLint("NewApi")
@Override//from w  w w .j  a va  2  s.c om
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK
            && resultCode != AuthenticationActivity.RESULT_DIFFERENT_CHUTE_USER_AUTHENTICATED) {
        return;
    }
    if (requestCode == AuthenticationFactory.AUTHENTICATION_REQUEST_CODE) {
        if (data != null) {
            String newSessionToken = data.getExtras()
                    .getString(AuthenticationActivity.INTENT_DIFFERENT_CHUTE_USER_TOKEN);
            String previousSessionToken = TokenAuthenticationProvider.getInstance().getToken();
            if (!newSessionToken.equals(previousSessionToken)) {
                CurrentUserAccountsRequest request = new CurrentUserAccountsRequest(getApplicationContext(),
                        new AccountsCallback());
                request.getClient().setAuthentication(new CustomAuthenticationProvider(newSessionToken));
                request.executeAsync();
            }
        } else {
            GCAccounts.allUserAccounts(getApplicationContext(), new AccountsCallback()).executeAsync();
        }
        return;
    }

    if (requestCode == PhotosIntentWrapper.ACTIVITY_FOR_RESULT_STREAM_KEY) {
        finish();
        return;
    }
    if (requestCode == Constants.CAMERA_PIC_REQUEST) {
        String path = "";
        File tempFile = AppUtil.getTempImageFile(getApplicationContext());
        if (AppUtil.hasImageCaptureBug() == false && tempFile.length() > 0) {
            try {
                android.provider.MediaStore.Images.Media.insertImage(getContentResolver(),
                        tempFile.getAbsolutePath(), null, null);
                tempFile.delete();
                path = MediaDAO.getLastPhotoFromCameraPhotos(getApplicationContext()).toString();
            } catch (FileNotFoundException e) {
                ALog.d("", e);
            }
        } else {
            ALog.e("Bug " + data.getData().getPath());
            path = Uri.fromFile(new File(AppUtil.getPath(getApplicationContext(), data.getData()))).toString();
        }
        final AssetModel model = new AssetModel();
        model.setThumbnail(path);
        model.setUrl(path);
        model.setType(MediaType.IMAGE.name().toLowerCase());
        ArrayList<AssetModel> mediaCollection = new ArrayList<AssetModel>();
        mediaCollection.add(model);
        setResult(Activity.RESULT_OK,
                new Intent().putExtra(PhotosIntentWrapper.KEY_PHOTO_COLLECTION, mediaCollection));
        finish();
    }
    if (requestCode == Constants.CAMERA_VIDEO_REQUEST) {
        Uri uriVideo = data.getData();
        File file = new File(uriVideo.getPath());

        Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(),
                MediaStore.Images.Thumbnails.MINI_KIND);

        final AssetModel model = new AssetModel();
        model.setThumbnail(AppUtil.getImagePath(getApplicationContext(), thumbnail));
        model.setVideoUrl(uriVideo.toString());
        model.setUrl(AppUtil.getImagePath(getApplicationContext(), thumbnail));
        model.setType(MediaType.VIDEO.name().toLowerCase());
        ArrayList<AssetModel> mediaCollection = new ArrayList<AssetModel>();
        mediaCollection.add(model);
        setResult(Activity.RESULT_OK,
                new Intent().putExtra(PhotosIntentWrapper.KEY_PHOTO_COLLECTION, mediaCollection));
        finish();
    }

}

From source file:com.applozic.mobicommons.file.FileUtils.java

public static Bitmap getPreview(String filePath, int reqWidth, int reqHeight, boolean enabled,
        String mimeType) {//from w w  w .j  a  v a  2  s. co m

    if (mimeType.startsWith("video")) {
        return ThumbnailUtils.createVideoThumbnail(filePath, 1);
    }
    return getPreview(filePath, reqWidth, reqHeight);
}

From source file:com.xxjwd.chat.ChatActivity.java

 /**
 * onActivityResult//ww w.  j av  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: // ??
         ChatMessage copyMsg = ((ChatMessage) 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: // ?
         ChatMessage deleteMsg = (ChatMessage) 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: // ??
         ChatMessage forwardMsg = (ChatMessage) 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) {
         // ?
         ChatManager.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(ChatFileUtil.getInstance(this).getChatFilePath(FileType.Picture), "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) {
               ChatLog.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) { // ???
         ChatMessage deleteMsg = (ChatMessage) 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.runye.express.chat.activity.ChatActivity.java

/**
 * /*from   ww  w . ja  v a  2s .  c o 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)));
            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 = 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 = 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) {

            Uri videoUri = data.getData();
            String[] proj = { MediaStore.Images.Media.DATA, MediaStore.Video.Media.DURATION };
            try {
                Cursor cursor = getContentResolver().query(videoUri, proj, null, null, null);
                if (cursor != null) {
                    if (cursor.moveToFirst()) {
                        int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                        int duration = cursor
                                .getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
                        String videoPath = cursor.getString(index);
                        Bitmap 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.chat_app_panel_video_icon);
                        }
                        File videoFile = new File(videoPath);
                        System.out.println("length:" + videoFile.length());
                        // ???5M
                        if (videoFile.length() > 1024 * 1024 * 5) {
                            Toast.makeText(this, "??5M?", Toast.LENGTH_SHORT).show();
                            return;
                        }

                        // get the thumb image file
                        File file = new File(PathUtil.getInstance().getVideoPath(), "th" + videoFile.getName());
                        try {
                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
                            bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(file));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        sendVideo(videoPath, file.getAbsolutePath(), duration);
                    }
                } else {
                    File videoFile = new File(videoUri.getPath());
                    Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoFile.getAbsolutePath(), 3);
                    if (bitmap == null) {
                        EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                        bitmap = BitmapFactory.decodeResource(getResources(),
                                R.drawable.chat_app_panel_video_icon);
                    }

                    System.out.println("length:" + videoFile.length());
                    // ???5M
                    if (videoFile.length() > 1024 * 1024 * 5) {
                        Toast.makeText(this, "??5M?", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    // get the thumb image file
                    File file = new File(PathUtil.getInstance().getVideoPath(), "th" + videoFile.getName());
                    try {
                        if (!file.getParentFile().exists()) {
                            file.getParentFile().mkdirs();
                        }
                        bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(file));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    sendVideo(videoFile.getAbsolutePath(), file.getAbsolutePath(), 0);

                }

            } catch (Exception e) {
                System.out.println("exception:" + e.getMessage());
            }

        } else if (requestCode == REQUEST_CODE_CAMERA_VIDEO) {
            if (videoFile != null && videoFile.exists()) {
                // ?
                String thumbPath = com.easemob.util.ImageUtils.saveVideoThumb(videoFile, 120, 120,
                        Thumbnails.MINI_KIND);
                sendVideo(videoFile.getAbsolutePath(), thumbPath, 1);
            }
        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null)
                    sendPicByUri(selectedImage);
            }
        } 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) {
            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 (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            EMChatManager.getInstance().getConversation(toChatUsername);
            adapter.refresh();
        }
    }
}

From source file:com.interestfriend.activity.FeedBackActivity.java

/**
 * onActivityResult//from  w  w w.  ja v a  2 s . co  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, "", 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.easemob.ui.ChatActivity.java

/**
 * onActivityResult/*from  w w  w  . j a  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)));
            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_CAMERA_VIDEO) {
            if (videoFile != null && videoFile.exists()) {
                // ?
                String thumbPath = com.easemob.util.ImageUtils.saveVideoThumb(videoFile, 120, 120,
                        Thumbnails.MINI_KIND);
                sendVideo(videoFile.getAbsolutePath(), thumbPath, 1);
            }
        } 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 (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            EMChatManager.getInstance().getConversation(toChatUsername);
            adapter.refresh();
        }
    }
}