Example #1
0
  private LinphoneChatMessage getMessageForId(int id) {
    for (LinphoneChatMessage message : chatRoom.getHistory()) {
      if (message.getStorageId() == id) {
        return message;
      }
    }

    return null;
  }
  private String saveImage(Bitmap bm, int id, LinphoneChatMessage message) {
    try {
      String path = Environment.getExternalStorageDirectory().toString();
      if (!path.endsWith("/")) path += "/";
      path += "Pictures/";
      File directory = new File(path);
      directory.mkdirs();

      String filename = getString(R.string.picture_name_format).replace("%s", String.valueOf(id));
      File file = new File(path, filename);

      OutputStream fOut = null;
      fOut = new FileOutputStream(file);

      bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
      fOut.flush();
      fOut.close();

      if (useLinphoneMessageStorage) {
        // Update url path in liblinphone database
        if (message == null) {
          LinphoneChatMessage[] history = chatRoom.getHistory();
          for (LinphoneChatMessage msg : history) {
            if (msg.getStorageId() == id) {
              message = msg;
              break;
            }
          }
        }
        message.setExternalBodyUrl(path + filename);
        chatRoom.updateUrl(message);
      }

      MediaStore.Images.Media.insertImage(
          getActivity().getContentResolver(),
          file.getAbsolutePath(),
          file.getName(),
          file.getName());
      return file.getAbsolutePath();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Example #3
0
 public void dispayMessageList() {
   adapter = new ChatMessageAdapter(getActivity(), chatRoom.getHistory());
   messagesList.setAdapter(adapter);
   adapter.notifyDataSetChanged();
 }
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = null;

      if (convertView != null) {
        view = convertView;
      } else {
        view = mInflater.inflate(R.layout.chatlist_cell, parent, false);
      }
      String contact;
      boolean isDraft = false;
      if (position >= mDrafts.size()) {
        contact = mConversations.get(position - mDrafts.size());
      } else {
        contact = mDrafts.get(position);
        isDraft = true;
      }
      view.setTag(contact);
      int unreadMessagesCount =
          LinphoneActivity.instance().getChatStorage().getUnreadMessageCount(contact);

      LinphoneAddress address;
      try {
        address = LinphoneCoreFactory.instance().createLinphoneAddress(contact);
      } catch (LinphoneCoreException e) {
        Log.e("Chat view cannot parse address", e);
        return view;
      }
      LinphoneUtils.findUriPictureOfContactAndSetDisplayName(
          address, view.getContext().getContentResolver());

      String message = "";
      if (useNativeAPI) {
        LinphoneChatRoom chatRoom = LinphoneManager.getLc().getOrCreateChatRoom(contact);
        LinphoneChatMessage[] history = chatRoom.getHistory(20);
        if (history != null && history.length > 0) {
          for (int i = history.length - 1; i >= 0; i--) {
            LinphoneChatMessage msg = history[i];
            if (msg.getText() != null && msg.getText().length() > 0) {
              message = msg.getText();
              break;
            }
          }
        }
      } else {
        List<ChatMessage> messages = LinphoneActivity.instance().getChatMessages(contact);
        if (messages != null && messages.size() > 0) {
          int iterator = messages.size() - 1;
          ChatMessage lastMessage = null;

          while (iterator >= 0) {
            lastMessage = messages.get(iterator);
            if (lastMessage.getMessage() == null) {
              iterator--;
            } else {
              iterator = -1;
            }
          }
          message =
              (lastMessage == null || lastMessage.getMessage() == null)
                  ? ""
                  : lastMessage.getMessage();
        }
      }
      TextView lastMessageView = (TextView) view.findViewById(R.id.lastMessage);
      lastMessageView.setText(message);

      TextView sipUri = (TextView) view.findViewById(R.id.sipUri);
      sipUri.setSelected(true); // For animation

      if (getResources().getBoolean(R.bool.only_display_username_if_unknown)
          && address.getDisplayName() != null
          && LinphoneUtils.isSipAddress(address.getDisplayName())) {
        address.setDisplayName(LinphoneUtils.getUsernameFromAddress(address.getDisplayName()));
      } else if (getResources().getBoolean(R.bool.only_display_username_if_unknown)
          && LinphoneUtils.isSipAddress(contact)) {
        contact = LinphoneUtils.getUsernameFromAddress(contact);
      }

      sipUri.setText(address.getDisplayName() == null ? contact : address.getDisplayName());
      if (isDraft) {
        view.findViewById(R.id.draft).setVisibility(View.VISIBLE);
      }

      ImageView delete = (ImageView) view.findViewById(R.id.delete);
      TextView unreadMessages = (TextView) view.findViewById(R.id.unreadMessages);

      if (unreadMessagesCount > 0) {
        unreadMessages.setVisibility(View.VISIBLE);
        unreadMessages.setText(String.valueOf(unreadMessagesCount));
      } else {
        unreadMessages.setVisibility(View.GONE);
      }

      if (isEditMode) {
        delete.setVisibility(View.VISIBLE);
      } else {
        delete.setVisibility(View.INVISIBLE);
      }

      return view;
    }
 public void dispayMessageList() {
   adapter = new ChatMessageAdapter(this.getActivity(), chatRoom.getHistory());
   messagesList.setAdapter(adapter);
 }