Exemplo n.º 1
0
  @Override
  public synchronized void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
    final LinphoneChatMessage finalMessage = msg;
    final String finalImage = finalMessage.getExternalBodyUrl();
    final State finalState = state;
    if (LinphoneActivity.isInstanciated() && state != State.InProgress) {
      if (finalMessage != null && !finalMessage.equals("")) {
        LinphoneActivity.instance()
            .onMessageStateChanged(sipUri, finalMessage.getText(), finalState.toInt());
      } else if (finalImage != null && !finalImage.equals("")) {
        if (latestImageMessages != null && latestImageMessages.containsValue(finalImage)) {
          int id = -1;
          for (int key : latestImageMessages.keySet()) {
            String object = latestImageMessages.get(key);
            if (object.equals(finalImage)) {
              id = key;
              break;
            }
          }
          if (id != -1) {
            LinphoneActivity.instance().onImageMessageStateChanged(sipUri, id, finalState.toInt());
          }
        }
      }

      if (lastSentMessagesBubbles != null && lastSentMessagesBubbles.size() > 0) {
        for (BubbleChat bubble : lastSentMessagesBubbles) {
          if (bubble.getNativeMessageObject() == finalMessage) {
            bubble.updateStatusView(finalState);
          }
        }
      }
      adapter.notifyDataSetChanged();
    }
  }
Exemplo n.º 2
0
  @Override
  public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
    if (LinphoneActivity.isInstanciated() && state != LinphoneChatMessage.State.InProgress) {
      if (msg != null) {
        LinphoneActivity.instance().onMessageStateChanged(sipUri, msg.getText(), state.toInt());
      }
      invalidate();
    }

    if (state == State.FileTransferDone) {
      if (mDownloadedImageStream != null) {
        byte[] bytes = mDownloadedImageStream.toByteArray();
        Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, mDownloadedImageStreamSize);

        String path = msg.getExternalBodyUrl();
        String fileName = path.substring(path.lastIndexOf("/") + 1);
        String url =
            MediaStore.Images.Media.insertImage(
                getActivity().getContentResolver(), bm, fileName, null);
        if (url != null) {
          msg.setAppData(url);
        }

        mDownloadedImageStream = null;
        mDownloadedImageStreamSize = 0;
      } else if (mUploadingImageStream != null) {
        mUploadingImageStream = null;
      }
    }

    if (state == State.FileTransferDone || state == State.FileTransferError) {
      uploadLayout.setVisibility(View.GONE);
      textLayout.setVisibility(View.VISIBLE);
      progressBar.setProgress(0);
      currentMessageInFileTransferUploadState = null;
    }
    invalidate();
  }