示例#1
0
  public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
    this.sipUri = newSipUri;
    this.displayName = displayName;
    this.pictureUri = pictureUri;

    if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) {
      ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage();
      if (chatStorage.getDraft(sipUri) == null) {
        chatStorage.saveDraft(sipUri, message.getText().toString());
      } else {
        chatStorage.updateDraft(sipUri, message.getText().toString());
      }
    } else if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
    }

    if (LinphoneActivity.isInstanciated()) {
      String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
      if (draft == null) draft = "";
      message.setText(draft);
    }

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    displayChatHeader(displayName, pictureUri);
    dispayMessageList();
  }
  public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
    if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) {
      ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage();
      if (chatStorage.getDraft(sipUri) == null) {
        chatStorage.saveDraft(sipUri, message.getText().toString());
      } else {
        chatStorage.updateDraft(sipUri, message.getText().toString());
      }
    } else if (LinphoneActivity.isInstanciated()) {
      LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
    }

    sipUri = newSipUri;
    if (LinphoneActivity.isInstanciated()) {
      String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
      if (draft == null) draft = "";
      message.setText(draft);
    }

    displayChatHeader(displayName, pictureUri);
    displayMessages();
  }
示例#3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;
    View view = inflater.inflate(R.layout.chat, container, false);

    // Retain the fragment across configuration changes
    setRetainInstance(true);

    // Retrieve parameter from intent
    sipUri = getArguments().getString("SipUri");
    displayName = getArguments().getString("DisplayName");
    pictureUri = getArguments().getString("PictureUri");

    // Initialize UI
    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);
    messagesList = (ListView) view.findViewById(R.id.chatMessageList);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);
    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    topBar = (LinearLayout) view.findViewById(R.id.topbar);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
    remoteComposing.setVisibility(View.GONE);

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    uploadLayout.setVisibility(View.GONE);

    displayChatHeader(displayName, pictureUri);

    // Manage multiline
    message = (EditText) view.findViewById(R.id.message);
    if (!getResources().getBoolean(R.bool.allow_chat_multiline)) {
      message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
      message.setMaxLines(1);
    }

    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
      sendImage.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              pickImage();
            }
          });
    } else {
      sendImage.setEnabled(false);
    }

    back = (TextView) view.findViewById(R.id.back);
    if (back != null) {
      back.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              getActivity().finish();
            }
          });
    }

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (currentMessageInFileTransferUploadState != null) {
              uploadLayout.setVisibility(View.GONE);
              textLayout.setVisibility(View.VISIBLE);
              progressBar.setProgress(0);
              currentMessageInFileTransferUploadState.cancelFileTransfer();
              currentMessageInFileTransferUploadState = null;
            }
          }
        });

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    mListener =
        new LinphoneCoreListenerBase() {
          @Override
          public void messageReceived(
              LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
            LinphoneAddress from = cr.getPeerAddress();
            if (from.asStringUriOnly().equals(sipUri)) {
              invalidate();
            }
          }

          @Override
          public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom room) {
            if (chatRoom != null
                && room != null
                && chatRoom
                    .getPeerAddress()
                    .asStringUriOnly()
                    .equals(room.getPeerAddress().asStringUriOnly())) {
              remoteComposing.setVisibility(
                  chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
            }
          }
        };

    textWatcher =
        new TextWatcher() {
          public void afterTextChanged(Editable arg0) {}

          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

          public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
              sendMessage.setEnabled(false);
            } else {
              if (chatRoom != null) chatRoom.compose();
              sendMessage.setEnabled(true);
            }
          }
        };

    // Force hide keyboard
    getActivity()
        .getWindow()
        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    return view;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    sipUri = getArguments().getString("SipUri");
    String displayName = getArguments().getString("DisplayName");
    String pictureUri = getArguments().getString("PictureUri");

    view = inflater.inflate(R.layout.chat, container, false);

    useLinphoneMessageStorage = getResources().getBoolean(R.bool.use_linphone_chat_storage);

    contactName = (TextView) view.findViewById(R.id.contactName);
    contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture);

    sendMessage = (TextView) view.findViewById(R.id.sendMessage);
    sendMessage.setOnClickListener(this);

    remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
    remoteComposing.setVisibility(View.GONE);

    messagesList = (ListView) view.findViewById(R.id.chatMessageList);

    message = (EditText) view.findViewById(R.id.message);
    if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
      message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
      message.setMaxLines(1);
    }

    uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
    uploadLayout.setVisibility(View.GONE);
    textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);

    progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
    sendImage = (TextView) view.findViewById(R.id.sendPicture);
    if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
      registerForContextMenu(sendImage);
      sendImage.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              pickImage();
            }
          });
    } else {
      sendImage.setEnabled(false);
    }

    cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload);
    cancelUpload.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            uploadThread.interrupt();
            uploadLayout.setVisibility(View.GONE);
            textLayout.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
          }
        });

    LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
    if (lc != null) {
      chatRoom = lc.getOrCreateChatRoom(sipUri);
      // Only works if using liblinphone storage
      chatRoom.markAsRead();
    }

    displayChatHeader(displayName, pictureUri);

    uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();

    textWatcher =
        new TextWatcher() {
          public void afterTextChanged(Editable arg0) {}

          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

          public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            if (message.getText().toString().equals("")) {
              sendMessage.setEnabled(false);
            } else {
              if (chatRoom != null) chatRoom.compose();
              sendMessage.setEnabled(true);
            }
          }
        };

    // Force hide keyboard
    if (LinphoneActivity.isInstanciated()) {
      InputMethodManager imm =
          (InputMethodManager)
              LinphoneActivity.instance().getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    // Workaround for SGS3 issue
    if (savedInstanceState != null) {
      fileToUploadPath = savedInstanceState.getString("fileToUploadPath");
      imageToUpload = savedInstanceState.getParcelable("imageToUpload");
    }
    if (fileToUploadPath != null || imageToUpload != null) {
      sendImage.post(
          new Runnable() {
            @Override
            public void run() {
              sendImage.showContextMenu();
            }
          });
    }

    return view;
  }