Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeResource.

Prototype

public static Bitmap decodeResource(Resources res, int id) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:bikebadger.RideFragment.java

private void updateUI() {

    boolean trackingLocations = mRideManager.isTrackingLocations();
    boolean trackingThisRun = mRideManager.isTrackingRun(mRide);
    boolean mRunNotNull = mRide != null;
    String msg = "";

    Log.d(Constants.APP.TAG, "RideFragment::updateUI");
    if (trackingLocations)
        Log.d(Constants.APP.TAG, "trackingLocations=" + trackingLocations);
    else/*  ww  w  .  j  a v a 2  s.co  m*/
        Log.d(Constants.APP.TAG, "trackingLocations is FALSE");
    if (trackingThisRun)
        Log.d(Constants.APP.TAG, "trackingThisRun=" + trackingThisRun);
    else
        Log.d(Constants.APP.TAG, "trackingThisRun is FALSE");

    if (mRunNotNull)
        Log.d(Constants.APP.TAG, "mRide is NOT null!");
    else
        Log.d(Constants.APP.TAG, "mRide is NULL!");

    if (mRide != null) {
        mStartedTextView.setText(mRide.getStartDate().toString());
    }

    int durationSeconds = 0;

    if (mRide != null && mLastLocation != null) {
        Log.d(Constants.APP.TAG, "mRide != null && mLastLocation != null");
        mMessagebarView.setTextColor(Color.WHITE);
        //String msg = "mRide != null && mLastLocation != null";
        double bearing1 = mLastLocation.getBearing();
        double bearing2 = mRideManager.mClosestBearing;
        double bearingDif = bearing2 - bearing1;
        if (mRideManager.mClosestWaypoint != null) {
            Log.d(Constants.APP.TAG, "mRideManager.mClosestWaypoint != null");

            if (mRideManager.mClosestWaypoint.IsTriggered()) {
                mMessagebarView.setTextColor(Color.RED);
                msg = "\"" + mRideManager.mClosestWaypoint.getName() + "\"";
                msg += " (Active)";
                Bitmap activeBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_triggered);
                mArrowView.setImageBitmap(activeBitmap);
            } else {
                mMessagebarView.setTextColor(Color.WHITE);
                msg = "\"" + mRideManager.mClosestWaypoint.getName() + "\"";
                msg += " at ";
                msg += Formatter.FormatDistanceMiles(mRideManager.mClosestDistance);
                //msg += " ft";
                //msg += " (" + Formatter.FormatDecimal(bearing1) + "->";
                // msg += Formatter.FormatDecimal(bearing2) + ":" + Formatter.FormatDecimal(bearingDif);
                // Point the arrow to the bearing of the closest waypoint...
                Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_white);
                Matrix matrix = new Matrix();
                matrix.postRotate((float) (bearingDif));
                final int width = myBitmap.getWidth();
                final int height = myBitmap.getHeight();
                Log.d(Constants.APP.TAG, "myBitmap.getWidth=" + myBitmap.getWidth() + "myBitmap.getHeight="
                        + myBitmap.getHeight());
                Bitmap rotatedBitmap = Bitmap.createBitmap(myBitmap, 0, 0, width, height, matrix, true);
                mArrowView.setImageBitmap(rotatedBitmap);
            }
        }

        // set the top message line
        mMessagebarView.setText(msg);

        durationSeconds = mRide.StopwatchSeconds();
        mSpeedTextView.setText(Formatter.FormatDecimal(mLastLocation.getSpeed() * Ride.METERS_TO_MILES));
        mTargetSpeedTextView.setText(Formatter.FormatDecimal(mRide.GetTargetAvgSpeed()));
        mAverageSpeedTextView.setText(Formatter.FormatDecimal(mRide.GetAverageSpeed()));
        mDurationTextView.setText(Formatter.FormatDuration(durationSeconds));

    } else if (mRide == null && mLastLocation == null) {
        Log.d(Constants.APP.TAG, "mRide == null && mLastLocation == null");
        mTargetSpeedTextView.setText(Formatter.FormatDecimal(mRideManager.GetDefaultTargetAvgSpeed()));

        mMessagebarView.setTextColor(Color.WHITE);
        if (mRideManager.WaypointsLoaded()) {
            mMessagebarView.setText("\"" + mRideManager.GetGPXFileName() + "\" loaded ("
                    + mRideManager.mWaypoints.size() + ")");
        }
    } else if (mRide != null && mLastLocation == null) { // mLastLocation is null
        mMessagebarView.setTextColor(Color.RED);
        mMessagebarView.setText("Waiting on GPS...");
    } else if (mRide == null && mLastLocation != null) {
        Log.d(Constants.APP.TAG, "mRide == null && mLastLocation != null");
    }

    if (!trackingThisRun) {
        mStartStopButton.setBackgroundResource(R.drawable.ic_button_white_play);
        mStartStopButton.setOnClickListener(mPlayButtonClickListener);
    }

    if (trackingThisRun) {
        mStartStopButton.setBackgroundResource(R.drawable.ic_button_white_pause);
        mStartStopButton.setOnClickListener(mPauseButtonClickListener);
    }

    //mStartButton.setEnabled(!started);
    mResetButton.setEnabled(trackingLocations && trackingThisRun);
    mWaypointButton.setEnabled(trackingLocations);
    //mTargetEditButton.setEnabled(trackingLocations && trackingThisRun);
}

From source file:co.shunya.gita.player.MusicService.java

/**
 * Updates the notification./*w  w  w  . j ava  2  s . co m*/
 */
void updateNotification(String text, int rsdId) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.gopinathji);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setAutoCancel(false).setSmallIcon(rsdId).setLargeIcon(icon)
            .setContentTitle(getString(R.string.app_name_reader)).setContentText(text).setOngoing(true);
    builder.setContentIntent(pi);
    issueNotification(builder);
}

From source file:cmu.cconfs.instantMessage.activities.ChatActivity.java

/**
 * onActivityResult/*from  ww  w.ja  v  a 2  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)));
            // 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) { // ??
            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, 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE
                || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION
                || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

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

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

/**
 * onActivityResult/*from w  w w.  ja va 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)));
            // 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) { // ??
            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_LONG).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.bofsoft.laio.laiovehiclegps.Fragment.BaiduMapFragment.java

private void addOverlay(GPSInfoData gpsInfoData) {//marker ?? ?
    LatLng llA = new LatLng(gpsInfoData.Latitude, gpsInfoData.Longitude);
    // GPSGPS??????
    CoordinateConverter converter = new CoordinateConverter();
    converter.from(CoordinateConverter.CoordType.GPS);
    // sourceLatLng???
    converter.coord(llA);/*from ww  w .ja va2 s .com*/
    //        desLatLng = converter.convert();
    LatLng tmpLL = converter.convert();

    View v_temp = LayoutInflater.from(getActivity()).inflate(R.layout.map_marker, null);//
    TextView tv_temp = (TextView) v_temp.findViewById(R.id.tv_marker);//?textview
    ImageView img_temp = (ImageView) v_temp.findViewById(R.id.iv_marker);//?imageview
    tv_temp.setText(gpsInfoData.License);//?
    if (gpsInfoData.Status == 0) {
        img_temp.setImageResource(imgIds[0]);//marker
        bitmap = BitmapFactory.decodeResource(getResources(), imgIds[0]);
    } else {
        img_temp.setImageResource(imgIds[2]);//marker
        bitmap = BitmapFactory.decodeResource(getResources(), imgIds[2]);
    }
    Matrix matrix = new Matrix();
    img_temp.setScaleType(ImageView.ScaleType.MATRIX); //required
    matrix.postScale(1, 1);
    //ImageViewImage
    int dw = bitmap.getWidth();
    int dh = bitmap.getHeight();
    matrix.postRotate((float) gpsInfoData.Direction, (float) dw / 2, (float) dh / 2);//
    img_temp.setImageMatrix(matrix);
    bd_temp = BitmapDescriptorFactory.fromView(v_temp);//?marker
    MarkerOptions oo = new MarkerOptions().position(tmpLL).icon(bd_temp).anchor(0.5f, 1.0f).zIndex(15);
    Marker mMarkerA = (Marker) (mBaiduMap.addOverlay(oo));
    Bundle bundle = new Bundle();
    bundle.putString("License", gpsInfoData.getLicense());
    mMarkerA.setExtraInfo(bundle);
}

From source file:co.shunya.gita.player.MusicService.java

/**
 * Configures service as a foreground service. A foreground service is a service that's doing
 * something the user is actively aware of (such as playing music), and must appear to the
 * user as a notification. That's why we create the notification here.
 *///www.  ja v  a  2 s. c  om
void setUpAsForeground(String text) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.gopinathji);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setAutoCancel(false).setSmallIcon(R.drawable.ic_stat_playing).setLargeIcon(icon)
            .setContentTitle(getString(R.string.app_name_reader)).setContentText(text).setOngoing(true)
            .setContentIntent(pi);
    issueNotification(builder);
    startForeground(NOTIFICATION_ID, mNotification);
}

From source file:cn.hbm.superwechat.activity.ChatActivity.java

/**
 * onActivityResult/*from   w w  w  .j a 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)));
            // 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) { // ??
            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();
        }
    }
}

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

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

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

            break;

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

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

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

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

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

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

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

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

From source file:cn.gen.superwechat.activity.ChatActivity.java

/**
 * onActivityResult/*from  w ww.ja  va  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.refreshSeekTo(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

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

            break;

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

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

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

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

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

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

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                toggleMore(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                String st = getResources().getString(cn.gen.superwechat.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();
        }
    }
}