Beispiel #1
0
 private void setStickersFrameVisible(boolean isVisible) {
   stickersFrame.setVisibility(isVisible ? View.VISIBLE : View.GONE);
   isStickersFrameVisible = isVisible;
   if (stickersFrame.getHeight() != vc908.stickerfactory.utils.KeyboardUtils.getKeyboardHeight()) {
     updateStickersFrameParams();
   }
   final int padding =
       isVisible ? vc908.stickerfactory.utils.KeyboardUtils.getKeyboardHeight() : 0;
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
     keyboardHandleLayout.post(
         new Runnable() {
           @Override
           public void run() {
             setContentBottomPadding(padding);
             scrollDown();
           }
         });
   } else {
     setContentBottomPadding(padding);
   }
   scrollDown();
 }
Beispiel #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);
  }