use of im.actor.sdk.view.emoji.keyboard.KeyboardStatusListener in project actor-platform by actorapp.
the class InputBarFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View res = inflater.inflate(R.layout.fragment_inputbar, container, false);
res.setBackgroundColor(style.getMainBackgroundColor());
//
// Message Body
//
messageEditText = (BarEditText) res.findViewById(R.id.et_message);
messageEditText.setTextColor(style.getTextPrimaryColor());
messageEditText.setHintTextColor(style.getTextHintColor());
// Hardware keyboard events
messageEditText.setOnKeyListener((view, keycode, keyEvent) -> {
if (messenger().isSendByEnterEnabled()) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keycode == KeyEvent.KEYCODE_ENTER) {
onSendButtonPressed();
return true;
}
}
return false;
});
// Software keyboard events
messageEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_SEND) {
onSendButtonPressed();
return true;
}
if (i == EditorInfo.IME_ACTION_DONE) {
onSendButtonPressed();
return true;
}
if (messenger().isSendByEnterEnabled()) {
if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
onSendButtonPressed();
return true;
}
}
return false;
});
messageEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
onBeforeTextChanged(charSequence, i, i1, i2);
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
InputBarFragment.this.onTextChanged(charSequence, i, i1, i2);
}
@Override
public void afterTextChanged(Editable editable) {
onAfterTextChanged(editable);
}
});
messageEditText.addSelectionListener((start, length) -> {
InputBarFragment.this.onSelectionChanged(start, length);
});
messageEditText.setOnFocusChangeListener((v, hasFocus) -> {
Fragment parent = getParentFragment();
if (parent instanceof InputBarCallback) {
((InputBarCallback) parent).onTextFocusChanged(hasFocus);
}
});
//
// Send Button
//
sendButton = (TintImageView) res.findViewById(R.id.ib_send);
sendButton.setResource(R.drawable.conv_send);
sendButton.setOnClickListener(v -> {
onSendButtonPressed();
});
//
// Attach Button
//
attachButton = (ImageButton) res.findViewById(R.id.ib_attach);
attachButton.setOnClickListener(v -> {
onAttachButtonClicked();
});
//
// Emoji keyboard
//
emojiButton = (ImageView) res.findViewById(R.id.ib_emoji);
emojiButton.setOnClickListener(v -> emojiKeyboard.toggle());
emojiKeyboard = getEmojiKeyboard();
emojiKeyboard.setOnStickerClickListener(sticker -> {
Fragment parent = getParentFragment();
if (parent instanceof InputBarCallback) {
((InputBarCallback) parent).onStickerSent(sticker);
}
});
emojiKeyboard.setKeyboardStatusListener(new KeyboardStatusListener() {
@Override
public void onDismiss() {
emojiButton.setImageResource(R.drawable.ic_emoji);
}
@Override
public void onShow() {
emojiButton.setImageResource(R.drawable.ic_keyboard);
}
});
//
// Audio
//
audioContainer = res.findViewById(R.id.audioContainer);
audioTimer = (TextView) res.findViewById(R.id.audioTimer);
audioSlide = res.findViewById(R.id.audioSlide);
recordPoint = res.findViewById(R.id.record_point);
audioButton = (ImageView) res.findViewById(R.id.record_btn);
audioButton.setVisibility(View.VISIBLE);
audioButton.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (!isAudioVisible) {
showAudio();
slideStart = (int) event.getX();
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (isAudioVisible) {
hideAudio(false);
}
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (isAudioVisible) {
int slide = slideStart - (int) event.getX();
if (slide < 0) {
slide = 0;
}
if (slide > SLIDE_LIMIT) {
hideAudio(true);
} else {
slideAudio(slide);
}
}
}
return true;
});
return res;
}
Aggregations