2015-05-03 13:48:36 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x
|
2015-05-03 13:48:36 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2016-01-11 18:19:48 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2015-05-03 13:48:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Components;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.content.Context;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.os.Build;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.InputFilter;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.style.ImageSpan;
|
|
|
|
import android.util.TypedValue;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.view.ActionMode;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.KeyEvent;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.widget.EditText;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.widget.FrameLayout;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.Emoji;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.R;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
public class PhotoViewerCaptionEnterView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate, SizeNotifierFrameLayoutPhoto.SizeNotifierFrameLayoutPhotoDelegate {
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public interface PhotoViewerCaptionEnterViewDelegate {
|
|
|
|
void onCaptionEnter();
|
2015-06-29 19:12:11 +02:00
|
|
|
void onTextChanged(CharSequence text);
|
2015-05-03 13:48:36 +02:00
|
|
|
void onWindowSizeChanged(int size);
|
|
|
|
}
|
|
|
|
|
|
|
|
private EditText messageEditText;
|
|
|
|
private ImageView emojiButton;
|
|
|
|
private EmojiView emojiView;
|
2015-06-29 19:12:11 +02:00
|
|
|
private SizeNotifierFrameLayoutPhoto sizeNotifierLayout;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
private ActionMode currentActionMode;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatorSet runningAnimation;
|
|
|
|
private AnimatorSet runningAnimation2;
|
|
|
|
private ObjectAnimator runningAnimationAudio;
|
2015-05-03 13:48:36 +02:00
|
|
|
private int runningAnimationType;
|
|
|
|
private int audioInterfaceState;
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private int lastSizeChangeValue1;
|
|
|
|
private boolean lastSizeChangeValue2;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private int keyboardHeight;
|
|
|
|
private int keyboardHeightLand;
|
|
|
|
private boolean keyboardVisible;
|
2015-06-29 19:12:11 +02:00
|
|
|
private int emojiPadding;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
private boolean innerTextChange;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private PhotoViewerCaptionEnterViewDelegate delegate;
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
private View windowView;
|
|
|
|
|
|
|
|
public PhotoViewerCaptionEnterView(Context context, SizeNotifierFrameLayoutPhoto parent, final View window) {
|
2015-05-03 13:48:36 +02:00
|
|
|
super(context);
|
|
|
|
setBackgroundColor(0x7f000000);
|
|
|
|
setFocusable(true);
|
|
|
|
setFocusableInTouchMode(true);
|
2016-04-22 15:49:00 +02:00
|
|
|
windowView = window;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
sizeNotifierLayout = parent;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
LinearLayout textFieldContainer = new LinearLayout(context);
|
|
|
|
textFieldContainer.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
addView(textFieldContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 2, 0, 0, 0));
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
2015-05-03 13:48:36 +02:00
|
|
|
textFieldContainer.addView(frameLayout, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1.0f));
|
|
|
|
|
|
|
|
emojiButton = new ImageView(context);
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_smile_w);
|
|
|
|
emojiButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
|
emojiButton.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(1), 0, 0);
|
|
|
|
frameLayout.addView(emojiButton, LayoutHelper.createFrame(48, 48, Gravity.BOTTOM | Gravity.LEFT));
|
|
|
|
emojiButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!isPopupShowing()) {
|
|
|
|
showPopup(1);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
openKeyboardInternal();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
messageEditText = new EditText(context) {
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
try {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
} catch (Exception e) {
|
|
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(51));
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-04-22 15:49:00 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
messageEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
currentActionMode = mode;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
fixActionMode(mode);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
if (currentActionMode == mode) {
|
|
|
|
currentActionMode = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messageEditText.setCustomInsertionActionModeCallback(new ActionMode.Callback() {
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
currentActionMode = mode;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
fixActionMode(mode);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
if (currentActionMode == mode) {
|
|
|
|
currentActionMode = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
messageEditText.setHint(LocaleController.getString("AddCaption", R.string.AddCaption));
|
2016-03-06 02:49:31 +01:00
|
|
|
messageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
|
|
|
messageEditText.setInputType(messageEditText.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
2015-05-03 13:48:36 +02:00
|
|
|
messageEditText.setMaxLines(4);
|
2015-06-29 19:12:11 +02:00
|
|
|
messageEditText.setHorizontallyScrolling(false);
|
2015-05-03 13:48:36 +02:00
|
|
|
messageEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
messageEditText.setGravity(Gravity.BOTTOM);
|
|
|
|
messageEditText.setPadding(0, AndroidUtilities.dp(11), 0, AndroidUtilities.dp(12));
|
|
|
|
messageEditText.setBackgroundDrawable(null);
|
|
|
|
AndroidUtilities.clearCursorDrawable(messageEditText);
|
|
|
|
messageEditText.setTextColor(0xffffffff);
|
|
|
|
messageEditText.setHintTextColor(0xb2ffffff);
|
|
|
|
InputFilter[] inputFilters = new InputFilter[1];
|
2016-03-06 02:49:31 +01:00
|
|
|
inputFilters[0] = new InputFilter.LengthFilter(200);
|
2015-05-03 13:48:36 +02:00
|
|
|
messageEditText.setFilters(inputFilters);
|
|
|
|
frameLayout.addView(messageEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 52, 0, 6, 0));
|
|
|
|
messageEditText.setOnKeyListener(new OnKeyListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onKey(View view, int i, KeyEvent keyEvent) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (i == KeyEvent.KEYCODE_BACK) {
|
|
|
|
if (hideActionMode()) {
|
|
|
|
return true;
|
|
|
|
} else if (!keyboardVisible && isPopupShowing()) {
|
|
|
|
if (keyEvent.getAction() == 1) {
|
|
|
|
showPopup(0);
|
|
|
|
}
|
|
|
|
return true;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
messageEditText.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (isPopupShowing()) {
|
|
|
|
showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-03-06 02:49:31 +01:00
|
|
|
/*messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (i == EditorInfo.IME_ACTION_DONE || i == EditorInfo.IME_ACTION_NEXT) {
|
2015-05-03 13:48:36 +02:00
|
|
|
delegate.onCaptionEnter();
|
|
|
|
return true;
|
2016-03-06 02:49:31 +01:00
|
|
|
} else
|
|
|
|
if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
2015-05-03 13:48:36 +02:00
|
|
|
delegate.onCaptionEnter();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
});*/
|
2015-05-03 13:48:36 +02:00
|
|
|
messageEditText.addTextChangedListener(new TextWatcher() {
|
2015-07-22 20:56:37 +02:00
|
|
|
boolean processChange = false;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
|
2015-07-22 20:56:37 +02:00
|
|
|
if (innerTextChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (delegate != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
delegate.onTextChanged(charSequence);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
|
|
|
|
if (before != count && (count - before) > 1) {
|
|
|
|
processChange = true;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
2015-07-22 20:56:37 +02:00
|
|
|
if (innerTextChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (processChange) {
|
|
|
|
ImageSpan[] spans = editable.getSpans(0, editable.length(), ImageSpan.class);
|
|
|
|
for (int i = 0; i < spans.length; i++) {
|
|
|
|
editable.removeSpan(spans[i]);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
|
|
|
processChange = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public boolean hideActionMode() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23 && currentActionMode != null) {
|
|
|
|
currentActionMode.finish();
|
|
|
|
currentActionMode = null;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private void fixActionMode(ActionMode mode) {
|
|
|
|
try {
|
|
|
|
Class classActionMode = Class.forName("com.android.internal.view.FloatingActionMode");
|
|
|
|
Field fieldToolbar = classActionMode.getDeclaredField("mFloatingToolbar");
|
|
|
|
fieldToolbar.setAccessible(true);
|
|
|
|
Object toolbar = fieldToolbar.get(mode);
|
|
|
|
|
|
|
|
Class classToolbar = Class.forName("com.android.internal.widget.FloatingToolbar");
|
|
|
|
Field fieldToolbarPopup = classToolbar.getDeclaredField("mPopup");
|
|
|
|
Field fieldToolbarWidth = classToolbar.getDeclaredField("mWidthChanged");
|
|
|
|
fieldToolbarPopup.setAccessible(true);
|
|
|
|
fieldToolbarWidth.setAccessible(true);
|
|
|
|
Object popup = fieldToolbarPopup.get(toolbar);
|
|
|
|
|
|
|
|
Class classToolbarPopup = Class.forName("com.android.internal.widget.FloatingToolbar$FloatingToolbarPopup");
|
|
|
|
Field fieldToolbarPopupParent = classToolbarPopup.getDeclaredField("mParent");
|
|
|
|
fieldToolbarPopupParent.setAccessible(true);
|
|
|
|
|
|
|
|
View currentView = (View) fieldToolbarPopupParent.get(popup);
|
|
|
|
if (currentView != windowView) {
|
|
|
|
fieldToolbarPopupParent.set(popup, windowView);
|
|
|
|
|
|
|
|
Method method = classActionMode.getDeclaredMethod("updateViewLocationInWindow");
|
|
|
|
method.setAccessible(true);
|
|
|
|
method.invoke(mode);
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void onWindowSizeChanged() {
|
|
|
|
int size = sizeNotifierLayout.getHeight();
|
|
|
|
if (!keyboardVisible) {
|
|
|
|
size -= emojiPadding;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onWindowSizeChanged(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onCreate() {
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
2015-06-29 19:12:11 +02:00
|
|
|
sizeNotifierLayout.setDelegate(this);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDestroy() {
|
2015-06-29 19:12:11 +02:00
|
|
|
hidePopup();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (isKeyboardVisible()) {
|
|
|
|
closeKeyboard();
|
|
|
|
}
|
|
|
|
keyboardVisible = false;
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (sizeNotifierLayout != null) {
|
|
|
|
sizeNotifierLayout.setDelegate(null);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(PhotoViewerCaptionEnterViewDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldText(CharSequence text) {
|
|
|
|
if (messageEditText == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
messageEditText.setText(text);
|
|
|
|
messageEditText.setSelection(messageEditText.getText().length());
|
|
|
|
if (delegate != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
delegate.onTextChanged(messageEditText.getText());
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCursorPosition() {
|
|
|
|
if (messageEditText == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return messageEditText.getSelectionStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void replaceWithText(int start, int len, String text) {
|
|
|
|
try {
|
|
|
|
StringBuilder builder = new StringBuilder(messageEditText.getText());
|
|
|
|
builder.replace(start, start + len, text);
|
|
|
|
messageEditText.setText(builder);
|
|
|
|
if (start + text.length() <= messageEditText.length()) {
|
|
|
|
messageEditText.setSelection(start + text.length());
|
|
|
|
} else {
|
|
|
|
messageEditText.setSelection(messageEditText.length());
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldFocused(boolean focus) {
|
|
|
|
if (messageEditText == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (focus) {
|
|
|
|
if (!messageEditText.isFocused()) {
|
|
|
|
messageEditText.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (messageEditText != null) {
|
|
|
|
try {
|
|
|
|
messageEditText.requestFocus();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 600);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (messageEditText.isFocused() && !keyboardVisible) {
|
|
|
|
messageEditText.clearFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public CharSequence getFieldCharSequence() {
|
|
|
|
return messageEditText.getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getEmojiPadding() {
|
|
|
|
return emojiPadding;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPopupView(View view) {
|
|
|
|
return view == emojiView;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showPopup(int show) {
|
|
|
|
if (show == 1) {
|
|
|
|
if (emojiView == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
emojiView = new EmojiView(false, false, getContext());
|
2015-06-29 19:12:11 +02:00
|
|
|
emojiView.setListener(new EmojiView.Listener() {
|
|
|
|
public boolean onBackspace() {
|
|
|
|
if (messageEditText.length() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEmojiSelected(String symbol) {
|
|
|
|
int i = messageEditText.getSelectionEnd();
|
|
|
|
if (i < 0) {
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
try {
|
2015-07-22 20:56:37 +02:00
|
|
|
innerTextChange = true;
|
|
|
|
CharSequence localCharSequence = Emoji.replaceEmoji(symbol/* + "\uFE0F"*/, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2015-06-29 19:12:11 +02:00
|
|
|
messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
|
|
|
|
int j = i + localCharSequence.length();
|
|
|
|
messageEditText.setSelection(j, j);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2015-07-22 20:56:37 +02:00
|
|
|
} finally {
|
|
|
|
innerTextChange = false;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onStickerSelected(TLRPC.Document sticker) {
|
|
|
|
|
|
|
|
}
|
2015-12-09 19:27:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStickersSettingsClick() {
|
|
|
|
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onGifSelected(TLRPC.Document gif) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onGifTab(boolean opened) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStickersTab(boolean opened) {
|
|
|
|
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClearEmojiRecent() {
|
|
|
|
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
});
|
|
|
|
sizeNotifierLayout.addView(emojiView);
|
|
|
|
}
|
|
|
|
|
|
|
|
emojiView.setVisibility(VISIBLE);
|
|
|
|
|
|
|
|
if (keyboardHeight <= 0) {
|
|
|
|
keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height", AndroidUtilities.dp(200));
|
|
|
|
}
|
|
|
|
if (keyboardHeightLand <= 0) {
|
|
|
|
keyboardHeightLand = ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).getInt("kbd_height_land3", AndroidUtilities.dp(200));
|
|
|
|
}
|
|
|
|
int currentHeight = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight;
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emojiView.getLayoutParams();
|
|
|
|
layoutParams.width = AndroidUtilities.displaySize.x;
|
|
|
|
layoutParams.height = currentHeight;
|
|
|
|
emojiView.setLayoutParams(layoutParams);
|
|
|
|
AndroidUtilities.hideKeyboard(messageEditText);
|
|
|
|
if (sizeNotifierLayout != null) {
|
|
|
|
emojiPadding = currentHeight;
|
|
|
|
sizeNotifierLayout.requestLayout();
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_keyboard_w);
|
|
|
|
onWindowSizeChanged();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (emojiButton != null) {
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_smile_w);
|
|
|
|
}
|
|
|
|
if (emojiView != null) {
|
|
|
|
emojiView.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
if (sizeNotifierLayout != null) {
|
|
|
|
if (show == 0) {
|
|
|
|
emojiPadding = 0;
|
|
|
|
}
|
|
|
|
sizeNotifierLayout.requestLayout();
|
|
|
|
onWindowSizeChanged();
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public void hidePopup() {
|
|
|
|
if (isPopupShowing()) {
|
|
|
|
showPopup(0);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void openKeyboardInternal() {
|
|
|
|
showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2);
|
|
|
|
AndroidUtilities.showKeyboard(messageEditText);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void openKeyboard() {
|
|
|
|
messageEditText.requestFocus();
|
|
|
|
AndroidUtilities.showKeyboard(messageEditText);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPopupShowing() {
|
|
|
|
return emojiView != null && emojiView.getVisibility() == VISIBLE;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public void closeKeyboard() {
|
|
|
|
AndroidUtilities.hideKeyboard(messageEditText);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isKeyboardVisible() {
|
2015-06-29 19:12:11 +02:00
|
|
|
return AndroidUtilities.usingHardwareInput && getLayoutParams() != null && ((FrameLayout.LayoutParams) getLayoutParams()).bottomMargin == 0 || keyboardVisible;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSizeChanged(int height, boolean isWidthGreater) {
|
|
|
|
if (height > AndroidUtilities.dp(50) && keyboardVisible) {
|
|
|
|
if (isWidthGreater) {
|
|
|
|
keyboardHeightLand = height;
|
|
|
|
ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height_land3", keyboardHeightLand).commit();
|
|
|
|
} else {
|
|
|
|
keyboardHeight = height;
|
|
|
|
ApplicationLoader.applicationContext.getSharedPreferences("emoji", 0).edit().putInt("kbd_height", keyboardHeight).commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (isPopupShowing()) {
|
|
|
|
int newHeight;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (isWidthGreater) {
|
|
|
|
newHeight = keyboardHeightLand;
|
|
|
|
} else {
|
|
|
|
newHeight = keyboardHeight;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emojiView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
if (layoutParams.width != AndroidUtilities.displaySize.x || layoutParams.height != newHeight) {
|
|
|
|
layoutParams.width = AndroidUtilities.displaySize.x;
|
|
|
|
layoutParams.height = newHeight;
|
2015-06-29 19:12:11 +02:00
|
|
|
emojiView.setLayoutParams(layoutParams);
|
|
|
|
if (sizeNotifierLayout != null) {
|
|
|
|
emojiPadding = layoutParams.height;
|
|
|
|
sizeNotifierLayout.requestLayout();
|
|
|
|
onWindowSizeChanged();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (lastSizeChangeValue1 == height && lastSizeChangeValue2 == isWidthGreater) {
|
|
|
|
onWindowSizeChanged();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastSizeChangeValue1 = height;
|
|
|
|
lastSizeChangeValue2 = isWidthGreater;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
boolean oldValue = keyboardVisible;
|
|
|
|
keyboardVisible = height > 0;
|
2015-06-29 19:12:11 +02:00
|
|
|
if (keyboardVisible && isPopupShowing()) {
|
|
|
|
showPopup(0);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (emojiPadding != 0 && !keyboardVisible && keyboardVisible != oldValue && !isPopupShowing()) {
|
|
|
|
emojiPadding = 0;
|
|
|
|
sizeNotifierLayout.requestLayout();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
onWindowSizeChanged();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == NotificationCenter.emojiDidLoaded) {
|
|
|
|
if (emojiView != null) {
|
|
|
|
emojiView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|