Exemplo n.º 1
0
  private void initView() {
    View view = LayoutInflater.from(context).inflate(R.layout.reply_widget, null);

    bottomContainer = (LinearLayout) view.findViewById(R.id.reply_widget_bottom_container);
    actionContainer = (LinearLayout) view.findViewById(R.id.reply_widget_action_container);

    addButton = (ImageView) view.findViewById(R.id.reply_widget_add_button);
    addEmojiButton = (ImageView) view.findViewById(R.id.reply_widget_emoji_button);
    addImageButton = (ImageView) view.findViewById(R.id.reply_add_image_button);
    recyclerView = (RecyclerView) view.findViewById(R.id.reply_widget_image_listview);

    submitButton = (ImageView) view.findViewById(R.id.reply_widget_submit_button);
    emojiconEditText = (EmojiconEditText) view.findViewById(R.id.reply_widget_edittext);
    hasDotImageView = (ImageView) view.findViewById(R.id.reply_widget_has_dot);
    final View rootView = view.findViewById(R.id.reply_widget_root_view);

    // Give the topmost view of your activity layout hierarchy. This will be used to measure soft
    // keyboard height
    final EmojiconsPopup popup = new EmojiconsPopup(rootView, context);

    // Will automatically set size according to the soft keyboard size
    popup.setSizeForSoftKeyboard();

    // If the emoji popup is dismissed, change addEmojiButton to smiley icon
    popup.setOnDismissListener(
        new PopupWindow.OnDismissListener() {

          @Override
          public void onDismiss() {
            changeEmojiKeyboardIcon(addEmojiButton, R.mipmap.expression);
          }
        });

    // If the text keyboard closes, also dismiss the emoji popup
    popup.setOnSoftKeyboardOpenCloseListener(
        new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {

          @Override
          public void onKeyboardOpen(int keyBoardHeight) {}

          @Override
          public void onKeyboardClose() {
            if (popup.isShowing()) popup.dismiss();
          }
        });

    // On emoji clicked, add it to edittext
    popup.setOnEmojiconClickedListener(
        new EmojiconGridView.OnEmojiconClickedListener() {

          @Override
          public void onEmojiconClicked(Emojicon emojicon) {
            if (emojiconEditText == null || emojicon == null) {
              return;
            }

            int start = emojiconEditText.getSelectionStart();
            int end = emojiconEditText.getSelectionEnd();
            if (start < 0) {
              emojiconEditText.append(emojicon.getEmoji());
            } else {
              emojiconEditText
                  .getText()
                  .replace(
                      Math.min(start, end),
                      Math.max(start, end),
                      emojicon.getEmoji(),
                      0,
                      emojicon.getEmoji().length());
            }
          }
        });

    // On backspace clicked, emulate the KEYCODE_DEL key event
    popup.setOnEmojiconBackspaceClickedListener(
        new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {

          @Override
          public void onEmojiconBackspaceClicked(View v) {
            KeyEvent event =
                new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
            emojiconEditText.dispatchKeyEvent(event);
          }
        });

    addButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            hideSoftKeyboard(emojiconEditText);
            switchActionContainer();
          }
        });

    // To toggle between text keyboard and emoji keyboard keyboard(Popup)
    addEmojiButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            bottomContainer.setVisibility(View.GONE);

            // If popup is not showing => emoji keyboard is not visible, we need to show it
            if (!popup.isShowing()) {

              // If keyboard is visible, simply show the emoji popup
              if (popup.isKeyBoardOpen()) {
                popup.showAtBottom();
                changeEmojiKeyboardIcon(addEmojiButton, R.mipmap.ic_action_keyboard);
              }

              // else, open the text keyboard first and immediately after that show the emoji popup
              else {
                emojiconEditText.setFocusableInTouchMode(true);
                emojiconEditText.requestFocus();
                popup.showAtBottomPending();
                final InputMethodManager inputMethodManager =
                    (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.showSoftInput(
                    emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
                changeEmojiKeyboardIcon(addEmojiButton, R.mipmap.ic_action_keyboard);
              }
            }

            // If popup is showing, simply dismiss it to show the undelying text keyboard
            else {
              popup.dismiss();
            }
          }
        });

    // On submit, add the edittext text to listview and clear the edittext
    submitButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            String newText = emojiconEditText.getText().toString();

            if (replyWidgetListener != null) {
              replyWidgetListener.onCommit(newText);
            }
          }
        });

    emojiconEditText.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            boolean isKeyBoardShow = showSoftKeyboard(emojiconEditText);
            if (isKeyBoardShow) {
              hideActionContainer();
            }
            return false;
          }
        });

    addImageButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            initImageList();
            gotoSelectImage();
          }
        });

    contentContainer.addView(view);
  }
Exemplo n.º 2
0
 public void clean() {
   if (emojiconEditText != null) {
     emojiconEditText.setText("");
   }
 }
Exemplo n.º 3
0
 public void resetHint() {
   emojiconEditText.setText("");
   emojiconEditText.setHint(R.string.we_speek);
 }
Exemplo n.º 4
0
 public void setHint(String hint) {
   emojiconEditText.setText("");
   emojiconEditText.setHint(hint);
 }
Exemplo n.º 5
0
 public void setText(String text) {
   emojiconEditText.setText(text);
   emojiconEditText.setSelection(text.length());
 }
Exemplo n.º 6
0
 public String getText() {
   return emojiconEditText.getText().toString();
 }