示例#1
0
  private void initChat() {
    if (dialog.getType() == QBDialogType.GROUP) {
      chat = new GroupChatImpl(this);
      progressBar.setVisibility(View.VISIBLE);
      joinGroupChat();

    } else if (dialog.getType() == QBDialogType.PRIVATE) {
      Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog);
      chat = new PrivateChatImpl(this, opponentID);
      loadChatHistory();
    }
  }
示例#2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    Intent intent = getIntent();
    dialog = (QBDialog) intent.getSerializableExtra(EXTRA_DIALOG);

    messagesContainer = (ListView) findViewById(R.id.messagesContainer);
    messageEditText = (EditText) findViewById(R.id.messageEdit);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    companionLabel = (TextView) findViewById(R.id.companionLabel);

    container = (RelativeLayout) findViewById(R.id.container);
    if (dialog.getType() == QBDialogType.GROUP) {
      TextView meLabel = (TextView) findViewById(R.id.meLabel);
      container.removeView(meLabel);
      container.removeView(companionLabel);
    } else if (dialog.getType() == QBDialogType.PRIVATE) {
      Integer opponentID = ChatService.getInstance().getOpponentIDForPrivateDialog(dialog);
      companionLabel.setText(
          ChatService.getInstance().getDialogsUsers().get(opponentID).getLogin());
    }

    sendButton = (Button) findViewById(R.id.chatSendButton);
    sendButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String messageText = messageEditText.getText().toString();
            if (!TextUtils.isEmpty(messageText)) {
              sendChatMessage(messageText);
            }
          }
        });

    keyboardHandleLayout = (KeyboardHandleRelativeLayout) findViewById(R.id.sizeNotifierLayout);
    keyboardHandleLayout.listener = this;
    stickersFrame = findViewById(R.id.frame);
    stickerButton = (ImageView) findViewById(R.id.stickers_button);

    stickerButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (isStickersFrameVisible) {
              showKeyboard();
              stickerButton.setImageResource(R.drawable.ic_action_insert_emoticon);
            } else {
              if (keyboardHandleLayout.isKeyboardVisible()) {
                keyboardHandleLayout.hideKeyboard(
                    ChatActivity.this,
                    new KeyboardHandleRelativeLayout.OnKeyboardHideCallback() {
                      @Override
                      public void onKeyboardHide() {
                        stickerButton.setImageResource(R.drawable.ic_action_keyboard);
                        setStickersFrameVisible(true);
                      }
                    });
              } else {
                stickerButton.setImageResource(R.drawable.ic_action_keyboard);
                setStickersFrameVisible(true);
              }
            }
          }
        });
    updateStickersFrameParams();
    stickersFragment = (StickersFragment) getSupportFragmentManager().findFragmentById(R.id.frame);
    if (stickersFragment == null) {
      stickersFragment =
          new StickersFragment.Builder()
              .setStickerPlaceholderColorFilterRes(android.R.color.darker_gray)
              .build();
      getSupportFragmentManager().beginTransaction().replace(R.id.frame, stickersFragment).commit();
    }
    stickersFragment.setOnStickerSelectedListener(stickerSelectedListener);
    stickersFragment.setOnEmojiBackspaceClickListener(
        new OnEmojiBackspaceClickListener() {
          @Override
          public void onEmojiBackspaceClicked() {
            KeyEvent event =
                new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
            messageEditText.dispatchKeyEvent(event);
          }
        });
    setStickersFrameVisible(isStickersFrameVisible);

    if (isSessionActive()) {
      initChat();
    }

    ChatService.getInstance().addConnectionListener(chatConnectionListener);
  }
示例#3
0
  @Override
  protected void onDestroy() {
    super.onDestroy();

    ChatService.getInstance().removeConnectionListener(chatConnectionListener);
  }