NekoX/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java

1727 lines
75 KiB
Java
Raw Normal View History

/*
2015-10-29 18:10:07 +01:00
* This is the source code of Telegram for Android v. 3.x.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2015-10-29 18:10:07 +01:00
* Copyright Nikolai Kudashov, 2013-2015.
*/
package org.telegram.ui.Components;
2015-10-29 18:10:07 +01:00
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
2015-10-29 18:10:07 +01:00
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
2015-01-02 23:15:07 +01:00
import android.media.AudioManager;
2015-10-29 18:10:07 +01:00
import android.os.Build;
import android.os.PowerManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
2014-11-14 16:40:15 +01:00
import android.view.ViewGroup;
2015-10-29 18:10:07 +01:00
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
2014-12-04 21:27:06 +01:00
import android.widget.PopupWindow;
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ChatObject;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MediaController;
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.SendMessagesHelper;
import org.telegram.messenger.FileLog;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.UserConfig;
2015-07-22 20:56:37 +02:00
import org.telegram.ui.ActionBar.ActionBar;
2015-02-27 20:57:58 +01:00
import org.telegram.ui.ActionBar.BaseFragment;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.messenger.AnimationCompat.AnimatorSetProxy;
import org.telegram.messenger.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.messenger.AnimationCompat.ViewProxy;
import org.telegram.messenger.ApplicationLoader;
2015-06-29 19:12:11 +02:00
import java.util.Locale;
public class ChatActivityEnterView extends FrameLayoutFixed implements NotificationCenter.NotificationCenterDelegate, SizeNotifierFrameLayout.SizeNotifierFrameLayoutDelegate {
public interface ChatActivityEnterViewDelegate {
2015-03-26 18:34:47 +01:00
void onMessageSend(String message);
void needSendTyping();
2015-04-09 20:00:14 +02:00
void onTextChanged(CharSequence text, boolean bigChange);
void onAttachButtonHidden();
void onAttachButtonShow();
void onWindowSizeChanged(int size);
}
2015-03-26 18:34:47 +01:00
private EditText messageEditText;
private ImageView sendButton;
private ImageView emojiButton;
private EmojiView emojiView;
private TextView recordTimeText;
private ImageView audioSendButton;
private FrameLayout recordPanel;
private LinearLayout slideText;
2015-10-29 18:10:07 +01:00
private RecordDot recordDot;
2015-06-29 19:12:11 +02:00
private SizeNotifierFrameLayout sizeNotifierLayout;
private LinearLayout attachButton;
private ImageView botButton;
private LinearLayout textFieldContainer;
private View topView;
2015-06-29 19:12:11 +02:00
private PopupWindow botKeyboardPopup;
private BotKeyboardView botKeyboardView;
2015-09-24 22:52:02 +02:00
private ImageView asAdminButton;
2015-10-29 18:10:07 +01:00
private RecordCircle recordCircle;
2015-06-29 19:12:11 +02:00
private int currentPopupContentType = -1;
2015-09-24 22:52:02 +02:00
private boolean isAsAdmin;
private boolean adminModeAvailable;
2015-06-29 19:12:11 +02:00
private boolean isPaused;
private boolean showKeyboardOnResume;
2015-06-29 19:12:11 +02:00
private MessageObject botButtonsMessageObject;
private TLRPC.TL_replyKeyboardMarkup botReplyMarkup;
private int botCount;
private boolean hasBotCommands;
private PowerManager.WakeLock mWakeLock;
2014-11-17 03:44:57 +01:00
private AnimatorSetProxy runningAnimation;
private AnimatorSetProxy runningAnimation2;
2015-10-29 18:10:07 +01:00
private AnimatorSetProxy runningAnimationAudio;
2014-11-14 16:40:15 +01:00
private int runningAnimationType;
2014-11-17 23:04:31 +01:00
private int audioInterfaceState;
2014-11-14 16:40:15 +01:00
private int keyboardHeight;
private int keyboardHeightLand;
private boolean keyboardVisible;
2015-06-29 19:12:11 +02:00
private int emojiPadding;
2014-11-14 16:40:15 +01:00
private boolean sendByEnter;
private long lastTypingTimeSend;
private String lastTimeString;
private float startedDraggingX = -1;
private float distCanMove = AndroidUtilities.dp(80);
2014-11-14 16:40:15 +01:00
private boolean recordingAudio;
private boolean forceShowSendButton;
private boolean allowStickers;
2015-06-29 19:12:11 +02:00
private int lastSizeChangeValue1;
private boolean lastSizeChangeValue2;
private Activity parentActivity;
2015-02-27 20:57:58 +01:00
private BaseFragment parentFragment;
private long dialog_id;
2014-11-14 16:40:15 +01:00
private boolean ignoreTextChange;
2015-07-22 20:56:37 +02:00
private int innerTextChange;
private MessageObject replyingMessageObject;
2015-06-29 19:12:11 +02:00
private MessageObject botMessageObject;
2015-04-09 20:00:14 +02:00
private TLRPC.WebPage messageWebPage;
private boolean messageWebPageSearch = true;
private ChatActivityEnterViewDelegate delegate;
private float topViewAnimation;
2015-04-09 20:00:14 +02:00
private boolean topViewShowed;
private boolean needShowTopView;
private boolean allowShowTopView;
2015-04-09 20:00:14 +02:00
private AnimatorSetProxy currentTopViewAnimation;
2015-06-29 19:12:11 +02:00
private boolean waitingForKeyboardOpen;
private Runnable openKeyboardRunnable = new Runnable() {
@Override
public void run() {
if (messageEditText != null && waitingForKeyboardOpen && !keyboardVisible && !AndroidUtilities.usingHardwareInput) {
messageEditText.requestFocus();
AndroidUtilities.showKeyboard(messageEditText);
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
}
}
};
2015-10-29 18:10:07 +01:00
private class RecordDot extends View {
private Drawable dotDrawable;
private float alpha;
private long lastUpdateTime;
private boolean isIncr;
public RecordDot(Context context) {
super(context);
dotDrawable = getResources().getDrawable(R.drawable.rec);
}
public void resetAlpha() {
alpha = 1.0f;
lastUpdateTime = System.currentTimeMillis();
isIncr = false;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
dotDrawable.setBounds(0, 0, AndroidUtilities.dp(11), AndroidUtilities.dp(11));
dotDrawable.setAlpha(185 + (int) (70 * alpha));
long dt = (System.currentTimeMillis() - lastUpdateTime);
if (!isIncr) {
alpha -= dt / 200.0f;
if (alpha <= 0) {
alpha = 0;
isIncr = true;
}
} else {
alpha += dt / 200.0f;
if (alpha >= 1) {
alpha = 1;
isIncr = false;
}
}
lastUpdateTime = System.currentTimeMillis();
dotDrawable.draw(canvas);
invalidate();
}
}
private class RecordCircle extends View {
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint paintRecord = new Paint(Paint.ANTI_ALIAS_FLAG);
private Drawable micDrawable;
private float scale;
private float amplitude;
private float animateToAmplitude;
private float animateAmplitudeDiff;
private long lastUpdateTime;
public RecordCircle(Context context) {
super(context);
paint.setColor(0xff5795cc);
paintRecord.setColor(0x0d000000);
micDrawable = getResources().getDrawable(R.drawable.mic_pressed);
}
public void setAmplitude(double value) {
animateToAmplitude = (float) Math.min(100, value) / 100.0f;
animateAmplitudeDiff = (animateToAmplitude - amplitude) / 150.0f;
lastUpdateTime = System.currentTimeMillis();
invalidate();
}
public float getScale() {
return scale;
}
public void setScale(float value) {
scale = value;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
int cx = getMeasuredWidth() / 2;
int cy = getMeasuredHeight() / 2;
float sc;
float alpha;
if (scale <= 0.5f) {
alpha = sc = scale / 0.5f;
} else if (scale <= 0.75f) {
sc = 1.0f - (scale - 0.5f) / 0.25f * 0.1f;
alpha = 1;
} else {
sc = 0.9f + (scale - 0.75f) / 0.25f * 0.1f;
alpha = 1;
}
long dt = System.currentTimeMillis() - lastUpdateTime;
if (animateToAmplitude != amplitude) {
amplitude += animateAmplitudeDiff * dt;
if (animateAmplitudeDiff > 0) {
if (amplitude > animateToAmplitude) {
amplitude = animateToAmplitude;
}
} else {
if (amplitude < animateToAmplitude) {
amplitude = animateToAmplitude;
}
}
invalidate();
}
lastUpdateTime = System.currentTimeMillis();
if (amplitude != 0) {
canvas.drawCircle(getMeasuredWidth() / 2.0f, getMeasuredHeight() / 2.0f, (AndroidUtilities.dp(42) + AndroidUtilities.dp(20) * amplitude) * scale, paintRecord);
}
canvas.drawCircle(getMeasuredWidth() / 2.0f, getMeasuredHeight() / 2.0f, AndroidUtilities.dp(42) * sc, paint);
micDrawable.setBounds(cx - micDrawable.getIntrinsicWidth() / 2, cy - micDrawable.getIntrinsicHeight() / 2, cx + micDrawable.getIntrinsicWidth() / 2, cy + micDrawable.getIntrinsicHeight() / 2);
micDrawable.setAlpha((int) (255 * alpha));
micDrawable.draw(canvas);
}
}
2015-06-29 19:12:11 +02:00
public ChatActivityEnterView(Activity context, SizeNotifierFrameLayout parent, BaseFragment fragment, boolean isChat) {
super(context);
setBackgroundResource(R.drawable.compose_panel);
setFocusable(true);
setFocusableInTouchMode(true);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStarted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStartError);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordStopped);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recordProgressChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidSent);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
2015-01-02 23:15:07 +01:00
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioRouteChanged);
parentActivity = context;
2015-02-27 20:57:58 +01:00
parentFragment = fragment;
2015-05-21 23:27:27 +02:00
sizeNotifierLayout = parent;
2015-06-29 19:12:11 +02:00
sizeNotifierLayout.setDelegate(this);
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
sendByEnter = preferences.getBoolean("send_by_enter", false);
textFieldContainer = new LinearLayout(context);
textFieldContainer.setBackgroundColor(0xffffffff);
textFieldContainer.setOrientation(LinearLayout.HORIZONTAL);
2015-06-29 19:12:11 +02:00
addView(textFieldContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 2, 0, 0));
FrameLayoutFixed frameLayout = new FrameLayoutFixed(context);
2015-06-29 19:12:11 +02:00
textFieldContainer.addView(frameLayout, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1.0f));
emojiButton = new ImageView(context);
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
emojiButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
emojiButton.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(1), 0, 0);
2015-06-29 19:12:11 +02:00
frameLayout.addView(emojiButton, LayoutHelper.createFrame(48, 48, Gravity.BOTTOM));
emojiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
2015-06-29 19:12:11 +02:00
if (!isPopupShowing() || currentPopupContentType != 0) {
showPopup(1, 0);
} else {
2015-06-29 19:12:11 +02:00
openKeyboardInternal();
}
}
});
2015-07-22 20:56:37 +02:00
messageEditText = new EditText(context) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isPopupShowing() && event.getAction() == MotionEvent.ACTION_DOWN) {
showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2, 0);
openKeyboardInternal();
}
return super.onTouchEvent(event);
}
};
2015-09-24 22:52:02 +02:00
updateFieldHint();
2015-03-26 18:34:47 +01:00
messageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
messageEditText.setInputType(messageEditText.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
messageEditText.setSingleLine(false);
messageEditText.setMaxLines(4);
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(0xff000000);
messageEditText.setHintTextColor(0xffb2b2b2);
2015-06-29 19:12:11 +02:00
frameLayout.addView(messageEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 52, 0, isChat ? 50 : 2, 0));
2015-03-26 18:34:47 +01:00
messageEditText.setOnKeyListener(new View.OnKeyListener() {
2015-09-02 00:14:21 +02:00
boolean ctrlPressed = false;
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
2015-06-29 19:12:11 +02:00
if (i == KeyEvent.KEYCODE_BACK && !keyboardVisible && isPopupShowing()) {
if (keyEvent.getAction() == 1) {
2015-09-02 00:14:21 +02:00
if (currentPopupContentType == 1 && botButtonsMessageObject != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
2015-06-29 19:12:11 +02:00
showPopup(0, 0);
}
return true;
2015-09-02 00:14:21 +02:00
} else if (i == KeyEvent.KEYCODE_ENTER && (ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
sendMessage();
return true;
2015-09-02 00:14:21 +02:00
} else if (i == KeyEvent.KEYCODE_CTRL_LEFT || i == KeyEvent.KEYCODE_CTRL_RIGHT) {
ctrlPressed = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
return true;
}
return false;
}
});
2015-03-26 18:34:47 +01:00
messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
2015-09-02 00:14:21 +02:00
boolean ctrlPressed = false;
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_SEND) {
sendMessage();
return true;
2015-09-02 00:14:21 +02:00
} else if (keyEvent != null && i == EditorInfo.IME_NULL) {
if ((ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
sendMessage();
return true;
2015-09-02 00:14:21 +02:00
} else if (i == KeyEvent.KEYCODE_CTRL_LEFT || i == KeyEvent.KEYCODE_CTRL_RIGHT) {
ctrlPressed = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
return true;
}
}
return false;
}
});
2015-03-26 18:34:47 +01:00
messageEditText.addTextChangedListener(new TextWatcher() {
2015-07-22 20:56:37 +02:00
boolean processChange = false;
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
2015-04-09 20:00:14 +02:00
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
2015-07-22 20:56:37 +02:00
if (innerTextChange == 1) {
return;
}
checkSendButton(true);
2015-07-22 20:56:37 +02:00
String message = getTrimmedString(charSequence.toString());
if (delegate != null) {
if (count > 2 || charSequence == null || charSequence.length() == 0) {
2015-04-09 20:00:14 +02:00
messageWebPageSearch = true;
}
delegate.onTextChanged(charSequence, before > count + 1 || (count - before) > 2);
}
2015-07-22 20:56:37 +02:00
if (innerTextChange != 2 && before != count && (count - before) > 1) {
processChange = true;
}
2015-09-24 22:52:02 +02:00
if (!isAsAdmin && message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
TLRPC.User currentUser = null;
if ((int) dialog_id > 0) {
currentUser = MessagesController.getInstance().getUser((int) dialog_id);
}
2015-09-24 22:52:02 +02:00
if (currentUser != null && (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime && !MessagesController.getInstance().onlinePrivacy.containsKey(currentUser.id))) {
return;
}
lastTypingTimeSend = System.currentTimeMillis();
if (delegate != null) {
delegate.needSendTyping();
}
}
}
@Override
public void afterTextChanged(Editable editable) {
2015-07-22 20:56:37 +02:00
if (innerTextChange != 0) {
return;
}
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
sendMessage();
}
2015-07-22 20:56:37 +02:00
if (processChange) {
ImageSpan[] spans = editable.getSpans(0, editable.length(), ImageSpan.class);
for (int i = 0; i < spans.length; i++) {
editable.removeSpan(spans[i]);
}
2015-07-22 20:56:37 +02:00
Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
processChange = false;
}
}
});
if (isChat) {
2015-06-29 19:12:11 +02:00
attachButton = new LinearLayout(context);
attachButton.setOrientation(LinearLayout.HORIZONTAL);
attachButton.setEnabled(false);
ViewProxy.setPivotX(attachButton, AndroidUtilities.dp(48));
2015-06-29 19:12:11 +02:00
frameLayout.addView(attachButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.BOTTOM | Gravity.RIGHT));
botButton = new ImageView(context);
botButton.setImageResource(R.drawable.bot_keyboard2);
botButton.setScaleType(ImageView.ScaleType.CENTER);
botButton.setVisibility(GONE);
attachButton.addView(botButton, LayoutHelper.createLinear(48, 48));
botButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (botReplyMarkup != null) {
if (!isPopupShowing() || currentPopupContentType != 1) {
showPopup(1, 1);
2015-09-02 00:14:21 +02:00
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().remove("hidekeyboard_" + dialog_id).commit();
2015-06-29 19:12:11 +02:00
} else {
2015-09-02 00:14:21 +02:00
if (currentPopupContentType == 1 && botButtonsMessageObject != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
2015-06-29 19:12:11 +02:00
openKeyboardInternal();
}
} else if (hasBotCommands) {
setFieldText("/");
openKeyboard();
}
}
});
2015-09-24 22:52:02 +02:00
asAdminButton = new ImageView(context);
asAdminButton.setImageResource(isAsAdmin ? R.drawable.publish_active : R.drawable.publish);
asAdminButton.setScaleType(ImageView.ScaleType.CENTER);
asAdminButton.setVisibility(adminModeAvailable ? VISIBLE : GONE);
attachButton.addView(asAdminButton, LayoutHelper.createLinear(48, 48));
asAdminButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
isAsAdmin = !isAsAdmin;
asAdminButton.setImageResource(isAsAdmin ? R.drawable.publish_active : R.drawable.publish);
updateFieldHint();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().putBoolean("asadmin_" + dialog_id, isAsAdmin).commit();
}
});
}
recordPanel = new FrameLayoutFixed(context);
recordPanel.setVisibility(GONE);
recordPanel.setBackgroundColor(0xffffffff);
2015-06-29 19:12:11 +02:00
frameLayout.addView(recordPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));
slideText = new LinearLayout(context);
slideText.setOrientation(LinearLayout.HORIZONTAL);
2015-06-29 19:12:11 +02:00
recordPanel.addView(slideText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 30, 0, 0, 0));
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.slidearrow);
2015-06-29 19:12:11 +02:00
slideText.addView(imageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 0, 1, 0, 0));
TextView textView = new TextView(context);
textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
textView.setTextColor(0xff999999);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
2015-06-29 19:12:11 +02:00
slideText.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0));
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setPadding(AndroidUtilities.dp(13), 0, 0, 0);
linearLayout.setBackgroundColor(0xffffffff);
2015-06-29 19:12:11 +02:00
recordPanel.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
2015-10-29 18:10:07 +01:00
recordDot = new RecordDot(context);
linearLayout.addView(recordDot, LayoutHelper.createLinear(11, 11, Gravity.CENTER_VERTICAL, 0, 1, 0, 0));
recordTimeText = new TextView(context);
recordTimeText.setText("00:00");
recordTimeText.setTextColor(0xff4d4c4b);
recordTimeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
2015-06-29 19:12:11 +02:00
linearLayout.addView(recordTimeText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0));
FrameLayout frameLayout1 = new FrameLayout(context);
2015-06-29 19:12:11 +02:00
textFieldContainer.addView(frameLayout1, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM));
audioSendButton = new ImageView(context);
audioSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
2015-10-29 18:10:07 +01:00
audioSendButton.setImageResource(R.drawable.mic);
audioSendButton.setBackgroundColor(0xffffffff);
2015-03-27 11:32:33 +01:00
audioSendButton.setSoundEffectsEnabled(false);
audioSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0);
2015-06-29 19:12:11 +02:00
frameLayout1.addView(audioSendButton, LayoutHelper.createFrame(48, 48));
audioSendButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
2015-02-27 20:57:58 +01:00
if (parentFragment != null) {
2015-10-29 18:10:07 +01:00
if (Build.VERSION.SDK_INT >= 23) {
if (parentActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
parentActivity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 3);
return false;
}
}
2015-05-21 23:27:27 +02:00
String action;
TLRPC.Chat currentChat;
2015-02-27 20:57:58 +01:00
if ((int) dialog_id < 0) {
currentChat = MessagesController.getInstance().getChat(-(int) dialog_id);
if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
action = "bigchat_upload_audio";
} else {
action = "chat_upload_audio";
}
} else {
action = "pm_upload_audio";
}
if (!MessagesController.isFeatureEnabled(action, parentFragment)) {
return false;
}
}
startedDraggingX = -1;
2015-09-24 22:52:02 +02:00
MediaController.getInstance().startRecording(dialog_id, replyingMessageObject, asAdmin());
updateAudioRecordIntefrace();
2014-07-10 02:15:58 +02:00
audioSendButton.getParent().requestDisallowInterceptTouchEvent(true);
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
startedDraggingX = -1;
MediaController.getInstance().stopRecording(true);
recordingAudio = false;
updateAudioRecordIntefrace();
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) {
float x = motionEvent.getX();
if (x < -distCanMove) {
MediaController.getInstance().stopRecording(false);
recordingAudio = false;
updateAudioRecordIntefrace();
}
2014-11-17 03:44:57 +01:00
x = x + ViewProxy.getX(audioSendButton);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
if (startedDraggingX != -1) {
float dist = (x - startedDraggingX);
2015-10-29 18:10:07 +01:00
ViewProxy.setTranslationX(recordCircle, dist);
2014-11-17 03:44:57 +01:00
params.leftMargin = AndroidUtilities.dp(30) + (int) dist;
slideText.setLayoutParams(params);
float alpha = 1.0f + dist / distCanMove;
if (alpha > 1) {
alpha = 1;
} else if (alpha < 0) {
alpha = 0;
}
2014-11-17 03:44:57 +01:00
ViewProxy.setAlpha(slideText, alpha);
}
if (x <= ViewProxy.getX(slideText) + slideText.getWidth() + AndroidUtilities.dp(30)) {
if (startedDraggingX == -1) {
startedDraggingX = x;
distCanMove = (recordPanel.getMeasuredWidth() - slideText.getMeasuredWidth() - AndroidUtilities.dp(48)) / 2.0f;
if (distCanMove <= 0) {
distCanMove = AndroidUtilities.dp(80);
} else if (distCanMove > AndroidUtilities.dp(80)) {
distCanMove = AndroidUtilities.dp(80);
}
}
2014-11-17 03:44:57 +01:00
}
if (params.leftMargin > AndroidUtilities.dp(30)) {
params.leftMargin = AndroidUtilities.dp(30);
2015-10-29 18:10:07 +01:00
ViewProxy.setTranslationX(recordCircle, 0);
2014-11-17 03:44:57 +01:00
slideText.setLayoutParams(params);
ViewProxy.setAlpha(slideText, 1);
startedDraggingX = -1;
}
}
view.onTouchEvent(motionEvent);
return true;
}
});
2015-10-29 18:10:07 +01:00
recordCircle = new RecordCircle(context);
recordCircle.setVisibility(GONE);
sizeNotifierLayout.addView(recordCircle, LayoutHelper.createFrame(124, 124, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, -36, -38));
sendButton = new ImageView(context);
sendButton.setVisibility(View.INVISIBLE);
sendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
sendButton.setImageResource(R.drawable.ic_send);
2015-03-27 11:32:33 +01:00
sendButton.setSoundEffectsEnabled(false);
ViewProxy.setScaleX(sendButton, 0.1f);
ViewProxy.setScaleY(sendButton, 0.1f);
ViewProxy.setAlpha(sendButton, 0.0f);
sendButton.clearAnimation();
2015-06-29 19:12:11 +02:00
frameLayout1.addView(sendButton, LayoutHelper.createFrame(48, 48));
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendMessage();
}
});
2015-06-29 19:12:11 +02:00
SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("emoji", Context.MODE_PRIVATE);
keyboardHeight = sharedPreferences.getInt("kbd_height", AndroidUtilities.dp(200));
keyboardHeightLand = sharedPreferences.getInt("kbd_height_land3", AndroidUtilities.dp(200));
2015-06-29 19:12:11 +02:00
checkSendButton(false);
}
public void addTopView(View view, int height) {
if (view == null) {
return;
}
topView = view;
topView.setVisibility(GONE);
2015-06-29 19:12:11 +02:00
addView(topView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, height, Gravity.TOP | Gravity.LEFT, 0, 2, 0, 0));
needShowTopView = false;
}
public void setTopViewAnimation(float progress) {
2015-04-09 20:00:14 +02:00
topViewAnimation = progress;
LayoutParams layoutParams2 = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams2.topMargin = AndroidUtilities.dp(2) + (int) (topView.getLayoutParams().height * progress);
textFieldContainer.setLayoutParams(layoutParams2);
}
public float getTopViewAnimation() {
return topViewAnimation;
}
public void setForceShowSendButton(boolean value, boolean animated) {
forceShowSendButton = value;
checkSendButton(animated);
}
public void setAllowStickers(boolean value) {
allowStickers = value;
}
2015-09-24 22:52:02 +02:00
public boolean asAdmin() {
return isAsAdmin;
}
public void showTopView(boolean animated) {
2015-09-24 22:52:02 +02:00
if (topView == null || topViewShowed || getVisibility() != VISIBLE) {
return;
}
needShowTopView = true;
2015-04-09 20:00:14 +02:00
topViewShowed = true;
if (allowShowTopView) {
topView.setVisibility(VISIBLE);
2015-04-09 20:00:14 +02:00
if (currentTopViewAnimation != null) {
currentTopViewAnimation.cancel();
currentTopViewAnimation = null;
}
if (animated) {
2015-06-29 19:12:11 +02:00
if (keyboardVisible || isPopupShowing()) {
2015-04-09 20:00:14 +02:00
currentTopViewAnimation = new AnimatorSetProxy();
currentTopViewAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(ChatActivityEnterView.this, "topViewAnimation", 1.0f)
2015-03-26 18:34:47 +01:00
);
2015-04-09 20:00:14 +02:00
currentTopViewAnimation.addListener(new AnimatorListenerAdapterProxy() {
2015-03-26 18:34:47 +01:00
@Override
public void onAnimationEnd(Object animation) {
2015-10-29 18:10:07 +01:00
if (currentTopViewAnimation != null && currentTopViewAnimation.equals(animation)) {
2015-04-09 20:00:14 +02:00
setTopViewAnimation(1.0f);
if (!forceShowSendButton) {
openKeyboard();
}
currentTopViewAnimation = null;
2015-03-26 18:34:47 +01:00
}
}
2015-03-26 18:34:47 +01:00
});
2015-04-09 20:00:14 +02:00
currentTopViewAnimation.setDuration(200);
currentTopViewAnimation.start();
2015-03-26 18:34:47 +01:00
} else {
2015-04-09 20:00:14 +02:00
setTopViewAnimation(1.0f);
2015-03-26 18:34:47 +01:00
if (!forceShowSendButton) {
openKeyboard();
}
2015-03-26 18:34:47 +01:00
}
} else {
2015-04-09 20:00:14 +02:00
setTopViewAnimation(1.0f);
}
}
}
2015-04-09 20:00:14 +02:00
public void hideTopView(final boolean animated) {
if (topView == null || !topViewShowed) {
return;
}
2015-04-09 20:00:14 +02:00
topViewShowed = false;
needShowTopView = false;
if (allowShowTopView) {
2015-04-09 20:00:14 +02:00
float resumeValue = 1.0f;
if (currentTopViewAnimation != null) {
resumeValue = topViewAnimation;
currentTopViewAnimation.cancel();
currentTopViewAnimation = null;
}
if (animated) {
2015-04-09 20:00:14 +02:00
currentTopViewAnimation = new AnimatorSetProxy();
currentTopViewAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(ChatActivityEnterView.this, "topViewAnimation", resumeValue, 0.0f)
);
2015-04-09 20:00:14 +02:00
currentTopViewAnimation.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
2015-10-29 18:10:07 +01:00
if (currentTopViewAnimation != null && currentTopViewAnimation.equals(animation)) {
2015-04-09 20:00:14 +02:00
topView.setVisibility(GONE);
setTopViewAnimation(0.0f);
currentTopViewAnimation = null;
}
}
});
2015-04-09 20:00:14 +02:00
currentTopViewAnimation.setDuration(200);
currentTopViewAnimation.start();
} else {
topView.setVisibility(GONE);
2015-04-09 20:00:14 +02:00
setTopViewAnimation(0.0f);
}
}
}
public boolean isTopViewVisible() {
return topView != null && topView.getVisibility() == VISIBLE;
}
2015-06-29 19:12:11 +02:00
private void onWindowSizeChanged() {
int size = sizeNotifierLayout.getHeight();
if (!keyboardVisible) {
size -= emojiPadding;
}
if (delegate != null) {
delegate.onWindowSizeChanged(size);
}
if (topView != null) {
2015-07-22 20:56:37 +02:00
if (size < AndroidUtilities.dp(72) + ActionBar.getCurrentActionBarHeight()) {
if (allowShowTopView) {
allowShowTopView = false;
if (needShowTopView) {
topView.setVisibility(View.GONE);
2015-04-09 20:00:14 +02:00
setTopViewAnimation(0.0f);
}
}
} else {
if (!allowShowTopView) {
allowShowTopView = true;
if (needShowTopView) {
topView.setVisibility(View.VISIBLE);
2015-04-09 20:00:14 +02:00
setTopViewAnimation(1.0f);
}
}
}
}
}
public void onDestroy() {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStarted);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStartError);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordStopped);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recordProgressChanged);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioDidSent);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioRouteChanged);
if (mWakeLock != null) {
try {
mWakeLock.release();
mWakeLock = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
2015-05-21 23:27:27 +02:00
if (sizeNotifierLayout != null) {
2015-06-29 19:12:11 +02:00
sizeNotifierLayout.setDelegate(null);
}
}
public void onPause() {
isPaused = true;
}
public void onResume() {
isPaused = false;
if (showKeyboardOnResume) {
showKeyboardOnResume = false;
messageEditText.requestFocus();
AndroidUtilities.showKeyboard(messageEditText);
if (!AndroidUtilities.usingHardwareInput && !keyboardVisible) {
waitingForKeyboardOpen = true;
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
2015-05-21 23:27:27 +02:00
}
}
}
public void setDialogId(long id) {
dialog_id = id;
2015-09-24 22:52:02 +02:00
if ((int) dialog_id < 0) {
TLRPC.Chat currentChat = MessagesController.getInstance().getChat(-(int) dialog_id);
isAsAdmin = ChatObject.isChannel(currentChat) && ((currentChat.flags & TLRPC.CHAT_FLAG_ADMIN) != 0 || (currentChat.flags & TLRPC.CHAT_FLAG_USER_IS_EDITOR) != 0);
adminModeAvailable = isAsAdmin && (currentChat.flags & TLRPC.CHAT_FLAG_IS_BROADCAST) == 0;
if (adminModeAvailable) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
isAsAdmin = preferences.getBoolean("asadmin_" + dialog_id, true);
}
if (asAdminButton != null) {
asAdminButton.setVisibility(adminModeAvailable ? VISIBLE : GONE);
asAdminButton.setImageResource(isAsAdmin ? R.drawable.publish_active : R.drawable.publish);
updateFieldHint();
}
}
}
private void updateFieldHint() {
boolean isChannel = false;
if ((int) dialog_id < 0 && ChatObject.isChannel(MessagesController.getInstance().getChat(-(int) dialog_id))) {
isChannel = true;
}
if (isChannel) {
messageEditText.setHint(isAsAdmin ? LocaleController.getString("ChannelBroadcast", R.string.ChannelBroadcast) : LocaleController.getString("ChannelComment", R.string.ChannelComment));
} else {
messageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
}
}
public void setReplyingMessageObject(MessageObject messageObject) {
2015-06-29 19:12:11 +02:00
if (messageObject != null) {
if (botMessageObject == null && botButtonsMessageObject != replyingMessageObject) {
botMessageObject = botButtonsMessageObject;
}
replyingMessageObject = messageObject;
setButtons(replyingMessageObject, true);
} else if (messageObject == null && replyingMessageObject == botButtonsMessageObject) {
replyingMessageObject = null;
setButtons(botMessageObject, false);
botMessageObject = null;
} else {
replyingMessageObject = messageObject;
}
}
2015-04-09 20:00:14 +02:00
public void setWebPage(TLRPC.WebPage webPage, boolean searchWebPages) {
messageWebPage = webPage;
messageWebPageSearch = searchWebPages;
}
public boolean isMessageWebPageSearchEnabled() {
return messageWebPageSearch;
}
private void sendMessage() {
2015-02-27 20:57:58 +01:00
if (parentFragment != null) {
2015-05-21 23:27:27 +02:00
String action;
TLRPC.Chat currentChat;
2015-02-27 20:57:58 +01:00
if ((int) dialog_id < 0) {
currentChat = MessagesController.getInstance().getChat(-(int) dialog_id);
if (currentChat != null && currentChat.participants_count > MessagesController.getInstance().groupBigSize) {
action = "bigchat_message";
} else {
action = "chat_message";
}
} else {
action = "pm_message";
}
if (!MessagesController.isFeatureEnabled(action, parentFragment)) {
return;
}
}
2015-03-26 18:34:47 +01:00
String message = messageEditText.getText().toString();
if (processSendingText(message)) {
messageEditText.setText("");
lastTypingTimeSend = 0;
if (delegate != null) {
2015-03-26 18:34:47 +01:00
delegate.onMessageSend(message);
}
} else if (forceShowSendButton) {
if (delegate != null) {
2015-03-26 18:34:47 +01:00
delegate.onMessageSend(null);
}
}
}
public boolean processSendingText(String text) {
text = getTrimmedString(text);
if (text.length() != 0) {
2014-11-14 16:40:15 +01:00
int count = (int) Math.ceil(text.length() / 4096.0f);
for (int a = 0; a < count; a++) {
2014-10-30 22:27:41 +01:00
String mess = text.substring(a * 4096, Math.min((a + 1) * 4096, text.length()));
2015-09-24 22:52:02 +02:00
SendMessagesHelper.getInstance().sendMessage(mess, dialog_id, replyingMessageObject, messageWebPage, messageWebPageSearch, asAdmin());
}
return true;
}
return false;
}
private String getTrimmedString(String src) {
String result = src.trim();
if (result.length() == 0) {
return result;
}
while (src.startsWith("\n")) {
src = src.substring(1);
}
while (src.endsWith("\n")) {
src = src.substring(0, src.length() - 1);
}
return src;
}
2014-11-17 03:44:57 +01:00
private void checkSendButton(final boolean animated) {
2015-03-26 18:34:47 +01:00
String message = getTrimmedString(messageEditText.getText().toString());
if (message.length() > 0 || forceShowSendButton) {
2014-10-07 22:14:27 +02:00
if (audioSendButton.getVisibility() == View.VISIBLE) {
2014-11-17 03:44:57 +01:00
if (animated) {
2014-10-07 22:14:27 +02:00
if (runningAnimationType == 1) {
return;
}
if (runningAnimation != null) {
2014-11-17 03:44:57 +01:00
runningAnimation.cancel();
2014-10-07 22:14:27 +02:00
runningAnimation = null;
}
2014-11-17 03:44:57 +01:00
if (runningAnimation2 != null) {
runningAnimation2.cancel();
runningAnimation2 = null;
}
2014-10-07 22:14:27 +02:00
2014-11-14 16:40:15 +01:00
if (attachButton != null) {
2014-11-17 03:44:57 +01:00
runningAnimation2 = new AnimatorSetProxy();
runningAnimation2.playTogether(
ObjectAnimatorProxy.ofFloat(attachButton, "alpha", 0.0f),
ObjectAnimatorProxy.ofFloat(attachButton, "scaleX", 0.0f)
);
runningAnimation2.setDuration(100);
runningAnimation2.addListener(new AnimatorListenerAdapterProxy() {
@Override
public void onAnimationEnd(Object animation) {
if (runningAnimation2.equals(animation)) {
attachButton.setVisibility(View.GONE);
2014-11-19 02:23:46 +01:00
attachButton.clearAnimation();
2014-11-17 03:44:57 +01:00
}
}
});
runningAnimation2.start();
2014-11-14 16:40:15 +01:00
2015-07-22 20:56:37 +02:00
updateFieldRight(0);
2014-11-19 02:23:46 +01:00
delegate.onAttachButtonHidden();
2014-11-14 16:40:15 +01:00
}
2014-10-07 22:14:27 +02:00
2014-11-17 03:44:57 +01:00
sendButton.setVisibility(View.VISIBLE);
runningAnimation = new AnimatorSetProxy();
runningAnimationType = 1;
runningAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(audioSendButton, "scaleX", 0.1f),
ObjectAnimatorProxy.ofFloat(audioSendButton, "scaleY", 0.1f),
ObjectAnimatorProxy.ofFloat(audioSendButton, "alpha", 0.0f),
ObjectAnimatorProxy.ofFloat(sendButton, "scaleX", 1.0f),
ObjectAnimatorProxy.ofFloat(sendButton, "scaleY", 1.0f),
ObjectAnimatorProxy.ofFloat(sendButton, "alpha", 1.0f)
);
runningAnimation.setDuration(150);
runningAnimation.addListener(new AnimatorListenerAdapterProxy() {
2014-10-07 22:14:27 +02:00
@Override
2014-11-17 03:44:57 +01:00
public void onAnimationEnd(Object animation) {
2015-10-29 18:10:07 +01:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
2014-10-07 22:14:27 +02:00
sendButton.setVisibility(View.VISIBLE);
2014-11-19 02:23:46 +01:00
audioSendButton.setVisibility(View.GONE);
audioSendButton.clearAnimation();
2014-10-07 22:14:27 +02:00
runningAnimation = null;
runningAnimationType = 0;
}
}
});
2014-11-17 03:44:57 +01:00
runningAnimation.start();
2014-10-07 22:14:27 +02:00
} else {
2014-11-17 03:44:57 +01:00
ViewProxy.setScaleX(audioSendButton, 0.1f);
ViewProxy.setScaleY(audioSendButton, 0.1f);
ViewProxy.setAlpha(audioSendButton, 0.0f);
ViewProxy.setScaleX(sendButton, 1.0f);
ViewProxy.setScaleY(sendButton, 1.0f);
ViewProxy.setAlpha(sendButton, 1.0f);
2014-10-07 22:14:27 +02:00
sendButton.setVisibility(View.VISIBLE);
2014-11-19 02:23:46 +01:00
audioSendButton.setVisibility(View.GONE);
audioSendButton.clearAnimation();
2014-11-14 16:40:15 +01:00
if (attachButton != null) {
attachButton.setVisibility(View.GONE);
2014-11-19 02:23:46 +01:00
attachButton.clearAnimation();
delegate.onAttachButtonHidden();
2015-07-22 20:56:37 +02:00
updateFieldRight(0);
2014-11-14 16:40:15 +01:00
}
2014-10-07 22:14:27 +02:00
}
}
} else if (sendButton.getVisibility() == View.VISIBLE) {
2014-11-17 03:44:57 +01:00
if (animated) {
2014-10-07 22:14:27 +02:00
if (runningAnimationType == 2) {
return;
}
if (runningAnimation != null) {
2014-11-17 03:44:57 +01:00
runningAnimation.cancel();
2014-10-07 22:14:27 +02:00
runningAnimation = null;
}
2014-11-17 03:44:57 +01:00
if (runningAnimation2 != null) {
runningAnimation2.cancel();
runningAnimation2 = null;
}
2014-10-07 22:14:27 +02:00
2014-11-14 16:40:15 +01:00
if (attachButton != null) {
2014-11-17 03:44:57 +01:00
attachButton.setVisibility(View.VISIBLE);
runningAnimation2 = new AnimatorSetProxy();
runningAnimation2.playTogether(
ObjectAnimatorProxy.ofFloat(attachButton, "alpha", 1.0f),
ObjectAnimatorProxy.ofFloat(attachButton, "scaleX", 1.0f)
);
runningAnimation2.setDuration(100);
runningAnimation2.start();
2014-11-14 16:40:15 +01:00
2015-07-22 20:56:37 +02:00
updateFieldRight(1);
2014-11-19 02:23:46 +01:00
delegate.onAttachButtonShow();
2014-11-14 16:40:15 +01:00
}
2014-10-07 22:14:27 +02:00
2014-11-17 03:44:57 +01:00
audioSendButton.setVisibility(View.VISIBLE);
runningAnimation = new AnimatorSetProxy();
runningAnimationType = 2;
runningAnimation.playTogether(
ObjectAnimatorProxy.ofFloat(sendButton, "scaleX", 0.1f),
ObjectAnimatorProxy.ofFloat(sendButton, "scaleY", 0.1f),
ObjectAnimatorProxy.ofFloat(sendButton, "alpha", 0.0f),
ObjectAnimatorProxy.ofFloat(audioSendButton, "scaleX", 1.0f),
ObjectAnimatorProxy.ofFloat(audioSendButton, "scaleY", 1.0f),
ObjectAnimatorProxy.ofFloat(audioSendButton, "alpha", 1.0f)
);
runningAnimation.setDuration(150);
runningAnimation.addListener(new AnimatorListenerAdapterProxy() {
2014-10-07 22:14:27 +02:00
@Override
2014-11-17 03:44:57 +01:00
public void onAnimationEnd(Object animation) {
2015-10-29 18:10:07 +01:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
2014-11-19 02:23:46 +01:00
sendButton.setVisibility(View.GONE);
sendButton.clearAnimation();
2014-10-07 22:14:27 +02:00
audioSendButton.setVisibility(View.VISIBLE);
runningAnimation = null;
runningAnimationType = 0;
}
}
});
2014-11-17 03:44:57 +01:00
runningAnimation.start();
2014-10-07 22:14:27 +02:00
} else {
2014-11-17 03:44:57 +01:00
ViewProxy.setScaleX(sendButton, 0.1f);
ViewProxy.setScaleY(sendButton, 0.1f);
ViewProxy.setAlpha(sendButton, 0.0f);
ViewProxy.setScaleX(audioSendButton, 1.0f);
ViewProxy.setScaleY(audioSendButton, 1.0f);
ViewProxy.setAlpha(audioSendButton, 1.0f);
2014-11-19 02:23:46 +01:00
sendButton.setVisibility(View.GONE);
sendButton.clearAnimation();
2014-10-07 22:14:27 +02:00
audioSendButton.setVisibility(View.VISIBLE);
2014-11-14 16:40:15 +01:00
if (attachButton != null) {
delegate.onAttachButtonShow();
2014-11-14 16:40:15 +01:00
attachButton.setVisibility(View.VISIBLE);
2015-07-22 20:56:37 +02:00
updateFieldRight(1);
}
}
}
}
private void updateFieldRight(int attachVisible) {
if (messageEditText == null) {
return;
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
if (attachVisible == 1) {
if (botButton != null && botButton.getVisibility() == VISIBLE) {
layoutParams.rightMargin = AndroidUtilities.dp(98);
} else {
layoutParams.rightMargin = AndroidUtilities.dp(50);
}
} else if (attachVisible == 2) {
if (layoutParams.rightMargin != AndroidUtilities.dp(2)) {
if (botButton != null && botButton.getVisibility() == VISIBLE) {
layoutParams.rightMargin = AndroidUtilities.dp(98);
} else {
2014-11-19 02:23:46 +01:00
layoutParams.rightMargin = AndroidUtilities.dp(50);
2014-11-14 16:40:15 +01:00
}
2014-10-07 22:14:27 +02:00
}
2015-07-22 20:56:37 +02:00
} else {
layoutParams.rightMargin = AndroidUtilities.dp(2);
}
2015-07-22 20:56:37 +02:00
messageEditText.setLayoutParams(layoutParams);
}
private void updateAudioRecordIntefrace() {
if (recordingAudio) {
2014-11-17 23:04:31 +01:00
if (audioInterfaceState == 1) {
return;
}
audioInterfaceState = 1;
try {
if (mWakeLock == null) {
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
mWakeLock.acquire();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
AndroidUtilities.lockOrientation(parentActivity);
2015-10-29 18:10:07 +01:00
recordPanel.setVisibility(VISIBLE);
recordCircle.setVisibility(VISIBLE);
recordCircle.setAmplitude(0);
recordTimeText.setText("00:00");
2015-10-29 18:10:07 +01:00
recordDot.resetAlpha();
lastTimeString = null;
2014-11-17 03:44:57 +01:00
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
params.leftMargin = AndroidUtilities.dp(30);
slideText.setLayoutParams(params);
ViewProxy.setAlpha(slideText, 1);
2014-11-17 23:04:31 +01:00
ViewProxy.setX(recordPanel, AndroidUtilities.displaySize.x);
2015-10-29 18:10:07 +01:00
ViewProxy.setTranslationX(recordCircle, 0);
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null) {
runningAnimationAudio.cancel();
}
2015-10-29 18:10:07 +01:00
runningAnimationAudio = new AnimatorSetProxy();
runningAnimationAudio.playTogether(ObjectAnimatorProxy.ofFloat(recordPanel, "translationX", 0),
ObjectAnimatorProxy.ofFloat(recordCircle, "scale", 1),
ObjectAnimatorProxy.ofFloat(audioSendButton, "alpha", 0));
runningAnimationAudio.setDuration(300);
2014-11-17 23:04:31 +01:00
runningAnimationAudio.addListener(new AnimatorListenerAdapterProxy() {
2014-11-17 03:44:57 +01:00
@Override
public void onAnimationEnd(Object animator) {
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null && runningAnimationAudio.equals(animator)) {
ViewProxy.setX(recordPanel, 0);
2015-10-29 18:10:07 +01:00
runningAnimationAudio = null;
2014-11-17 23:04:31 +01:00
}
2014-11-17 03:44:57 +01:00
}
});
2015-10-29 18:10:07 +01:00
runningAnimationAudio.setInterpolator(new DecelerateInterpolator());
2014-11-17 23:04:31 +01:00
runningAnimationAudio.start();
} else {
if (mWakeLock != null) {
try {
mWakeLock.release();
mWakeLock = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
AndroidUtilities.unlockOrientation(parentActivity);
2014-11-17 23:04:31 +01:00
if (audioInterfaceState == 0) {
return;
}
audioInterfaceState = 0;
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null) {
runningAnimationAudio.cancel();
}
2015-10-29 18:10:07 +01:00
runningAnimationAudio = new AnimatorSetProxy();
runningAnimationAudio.playTogether(ObjectAnimatorProxy.ofFloat(recordPanel, "translationX", AndroidUtilities.displaySize.x),
ObjectAnimatorProxy.ofFloat(recordCircle, "scale", 0.0f),
ObjectAnimatorProxy.ofFloat(audioSendButton, "alpha", 1.0f));
runningAnimationAudio.setDuration(300);
2014-11-17 23:04:31 +01:00
runningAnimationAudio.addListener(new AnimatorListenerAdapterProxy() {
2014-11-17 03:44:57 +01:00
@Override
public void onAnimationEnd(Object animator) {
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null && runningAnimationAudio.equals(animator)) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
params.leftMargin = AndroidUtilities.dp(30);
slideText.setLayoutParams(params);
ViewProxy.setAlpha(slideText, 1);
recordPanel.setVisibility(View.GONE);
2015-10-29 18:10:07 +01:00
recordCircle.setVisibility(View.GONE);
runningAnimationAudio = null;
2014-11-17 23:04:31 +01:00
}
2014-11-17 03:44:57 +01:00
}
});
2015-10-29 18:10:07 +01:00
runningAnimationAudio.setInterpolator(new AccelerateInterpolator());
2014-11-17 23:04:31 +01:00
runningAnimationAudio.start();
}
}
2015-06-29 19:12:11 +02:00
public void setDelegate(ChatActivityEnterViewDelegate delegate) {
this.delegate = delegate;
}
2015-10-29 18:10:07 +01:00
public void setCommand(MessageObject messageObject, String command, boolean longPress) {
2015-09-24 22:52:02 +02:00
if (command == null || getVisibility() != VISIBLE) {
return;
}
2015-10-29 18:10:07 +01:00
if (longPress) {
String text = messageEditText.getText().toString();
text = command + " " + text.replaceFirst("^/[a-zA-Z@\\d_]{1,255}(\\s|$)", "");
ignoreTextChange = true;
messageEditText.setText(text);
messageEditText.setSelection(messageEditText.getText().length());
ignoreTextChange = false;
if (!keyboardVisible && currentPopupContentType == -1) {
openKeyboard();
}
2015-06-29 19:12:11 +02:00
} else {
2015-10-29 18:10:07 +01:00
TLRPC.User user = messageObject != null && (int) dialog_id < 0 ? MessagesController.getInstance().getUser(messageObject.messageOwner.from_id) : null;
if (botCount != 1 && user != null && (user.flags & TLRPC.USER_FLAG_BOT) != 0 && !command.contains("@")) {
SendMessagesHelper.getInstance().sendMessage(String.format(Locale.US, "%s@%s", command, user.username), dialog_id, null, null, false, asAdmin());
} else {
SendMessagesHelper.getInstance().sendMessage(command, dialog_id, null, null, false, asAdmin());
}
}
}
public void setFieldText(String text) {
2015-03-26 18:34:47 +01:00
if (messageEditText == null) {
2014-11-19 11:32:27 +01:00
return;
}
ignoreTextChange = true;
2015-03-26 18:34:47 +01:00
messageEditText.setText(text);
messageEditText.setSelection(messageEditText.getText().length());
ignoreTextChange = false;
if (delegate != null) {
2015-04-09 20:00:14 +02:00
delegate.onTextChanged(messageEditText.getText(), true);
}
}
2015-10-29 18:10:07 +01:00
public void setSelection(int start) {
if (messageEditText == null) {
return;
}
messageEditText.setSelection(start, messageEditText.length());
}
public int getCursorPosition() {
2015-03-26 18:34:47 +01:00
if (messageEditText == null) {
return 0;
}
2015-03-26 18:34:47 +01:00
return messageEditText.getSelectionStart();
}
public void replaceWithText(int start, int len, String text) {
try {
2015-03-26 18:34:47 +01:00
StringBuilder builder = new StringBuilder(messageEditText.getText());
builder.replace(start, start + len, text);
2015-03-26 18:34:47 +01:00
messageEditText.setText(builder);
messageEditText.setSelection(start + text.length());
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public void setFieldFocused(boolean focus) {
2015-03-26 18:34:47 +01:00
if (messageEditText == null) {
return;
}
if (focus) {
2015-03-26 18:34:47 +01:00
if (!messageEditText.isFocused()) {
messageEditText.postDelayed(new Runnable() {
@Override
public void run() {
2015-03-26 18:34:47 +01:00
if (messageEditText != null) {
2014-10-01 21:55:24 +02:00
try {
2015-03-26 18:34:47 +01:00
messageEditText.requestFocus();
2014-10-01 21:55:24 +02:00
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
}, 600);
}
} else {
2015-03-26 18:34:47 +01:00
if (messageEditText.isFocused() && !keyboardVisible) {
messageEditText.clearFocus();
}
}
}
public boolean hasText() {
2015-03-26 18:34:47 +01:00
return messageEditText != null && messageEditText.length() > 0;
}
public String getFieldText() {
2015-03-26 18:34:47 +01:00
if (messageEditText != null && messageEditText.length() > 0) {
return messageEditText.getText().toString();
}
return null;
}
2014-11-14 16:40:15 +01:00
public void addToAttachLayout(View view) {
if (attachButton == null) {
return;
}
if (view.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) view.getParent();
viewGroup.removeView(view);
}
2015-06-29 19:12:11 +02:00
attachButton.addView(view, LayoutHelper.createLinear(48, 48));
}
private void updateBotButton() {
if (botButton == null) {
return;
}
if (hasBotCommands || botReplyMarkup != null) {
if (botButton.getVisibility() != VISIBLE) {
botButton.setVisibility(VISIBLE);
}
if (botReplyMarkup != null) {
if (isPopupShowing() && currentPopupContentType == 1) {
botButton.setImageResource(R.drawable.ic_msg_panel_kb);
} else {
botButton.setImageResource(R.drawable.bot_keyboard2);
}
} else {
botButton.setImageResource(R.drawable.bot_keyboard);
}
} else {
botButton.setVisibility(GONE);
}
2015-07-22 20:56:37 +02:00
updateFieldRight(2);
2015-06-29 19:12:11 +02:00
ViewProxy.setPivotX(attachButton, AndroidUtilities.dp(botButton.getVisibility() == GONE ? 48 : 96));
attachButton.clearAnimation();
}
public void setBotsCount(int count, boolean hasCommands) {
botCount = count;
if (hasBotCommands != hasCommands) {
hasBotCommands = hasCommands;
updateBotButton();
}
}
public void setButtons(MessageObject messageObject) {
setButtons(messageObject, true);
}
public void setButtons(MessageObject messageObject, boolean openKeyboard) {
if (replyingMessageObject != null && replyingMessageObject == botButtonsMessageObject && replyingMessageObject != messageObject) {
botMessageObject = messageObject;
return;
}
if (botButton == null || botButtonsMessageObject != null && botButtonsMessageObject == messageObject || botButtonsMessageObject == null && messageObject == null) {
return;
}
if (botKeyboardView == null) {
botKeyboardView = new BotKeyboardView(parentActivity);
botKeyboardView.setVisibility(GONE);
botKeyboardView.setDelegate(new BotKeyboardView.BotKeyboardViewDelegate() {
@Override
public void didPressedButton(CharSequence text) {
MessageObject object = replyingMessageObject != null ? replyingMessageObject : ((int) dialog_id < 0 ? botButtonsMessageObject : null);
2015-09-24 22:52:02 +02:00
SendMessagesHelper.getInstance().sendMessage(text.toString(), dialog_id, object, null, false, asAdmin());
2015-06-29 19:12:11 +02:00
if (replyingMessageObject != null) {
openKeyboardInternal();
setButtons(botMessageObject, false);
} else if ((botButtonsMessageObject.messageOwner.reply_markup.flags & 2) != 0) {
openKeyboardInternal();
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().putInt("answered_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
if (delegate != null) {
delegate.onMessageSend(null);
}
}
});
sizeNotifierLayout.addView(botKeyboardView);
}
botButtonsMessageObject = messageObject;
botReplyMarkup = messageObject != null && messageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyKeyboardMarkup ? (TLRPC.TL_replyKeyboardMarkup) messageObject.messageOwner.reply_markup : null;
botKeyboardView.setPanelHeight(AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight);
botKeyboardView.setButtons(botReplyMarkup != null ? botReplyMarkup : null);
if (botReplyMarkup != null) {
2015-09-02 00:14:21 +02:00
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
boolean keyboardHidden = preferences.getInt("hidekeyboard_" + dialog_id, 0) == messageObject.getId();
2015-06-29 19:12:11 +02:00
if (botButtonsMessageObject != replyingMessageObject && (botReplyMarkup.flags & 2) != 0) {
if (preferences.getInt("answered_" + dialog_id, 0) == messageObject.getId()) {
return;
}
}
2015-09-02 00:14:21 +02:00
if (!keyboardHidden && messageEditText.length() == 0 && !isPopupShowing()) {
2015-06-29 19:12:11 +02:00
showPopup(1, 1);
}
} else {
if (isPopupShowing() && currentPopupContentType == 1) {
if (openKeyboard) {
openKeyboardInternal();
} else {
showPopup(0, 1);
}
}
}
updateBotButton();
}
public boolean isPopupView(View view) {
return view == botKeyboardView || view == emojiView;
}
2015-10-29 18:10:07 +01:00
public boolean isRecordCircle(View view) {
return view == recordCircle;
}
2015-06-29 19:12:11 +02:00
private void showPopup(int show, int contentType) {
if (show == 1) {
if (contentType == 0 && emojiView == null) {
if (parentActivity == null) {
return;
}
emojiView = new EmojiView(allowStickers, parentActivity);
emojiView.setVisibility(GONE);
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 = 2;
2015-10-29 18:10:07 +01:00
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, 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 = 0;
2015-06-29 19:12:11 +02:00
}
}
public void onStickerSelected(TLRPC.Document sticker) {
2015-09-24 22:52:02 +02:00
SendMessagesHelper.getInstance().sendSticker(sticker, dialog_id, replyingMessageObject, asAdmin());
2015-06-29 19:12:11 +02:00
if (delegate != null) {
delegate.onMessageSend(null);
}
}
});
sizeNotifierLayout.addView(emojiView);
}
View currentView = null;
if (contentType == 0) {
emojiView.setVisibility(VISIBLE);
if (botKeyboardView != null && botKeyboardView.getVisibility() != GONE) {
botKeyboardView.setVisibility(GONE);
}
currentView = emojiView;
} else if (contentType == 1) {
if (emojiView != null && emojiView.getVisibility() != GONE) {
emojiView.setVisibility(GONE);
}
botKeyboardView.setVisibility(VISIBLE);
currentView = botKeyboardView;
}
currentPopupContentType = contentType;
if (keyboardHeight <= 0) {
keyboardHeight = ApplicationLoader.applicationContext.getSharedPreferences("emoji", Context.MODE_PRIVATE).getInt("kbd_height", AndroidUtilities.dp(200));
}
if (keyboardHeightLand <= 0) {
keyboardHeightLand = ApplicationLoader.applicationContext.getSharedPreferences("emoji", Context.MODE_PRIVATE).getInt("kbd_height_land3", AndroidUtilities.dp(200));
}
int currentHeight = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight;
if (contentType == 1) {
currentHeight = Math.min(botKeyboardView.getKeyboardHeight(), currentHeight);
}
if (botKeyboardView != null) {
botKeyboardView.setPanelHeight(currentHeight);
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) currentView.getLayoutParams();
layoutParams.width = AndroidUtilities.displaySize.x;
layoutParams.height = currentHeight;
currentView.setLayoutParams(layoutParams);
AndroidUtilities.hideKeyboard(messageEditText);
if (sizeNotifierLayout != null) {
emojiPadding = currentHeight;
sizeNotifierLayout.requestLayout();
if (contentType == 0) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
} else if (contentType == 1) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
}
updateBotButton();
onWindowSizeChanged();
}
} else {
if (emojiButton != null) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
}
2015-10-29 18:10:07 +01:00
currentPopupContentType = -1;
2015-06-29 19:12:11 +02:00
if (emojiView != null) {
emojiView.setVisibility(GONE);
}
if (botKeyboardView != null) {
botKeyboardView.setVisibility(GONE);
}
if (sizeNotifierLayout != null) {
if (show == 0) {
emojiPadding = 0;
}
sizeNotifierLayout.requestLayout();
onWindowSizeChanged();
}
updateBotButton();
}
}
2015-09-02 00:14:21 +02:00
public void hidePopup(boolean byBackButton) {
2015-06-29 19:12:11 +02:00
if (isPopupShowing()) {
2015-09-02 00:14:21 +02:00
if (currentPopupContentType == 1 && byBackButton && botButtonsMessageObject != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
2015-06-29 19:12:11 +02:00
showPopup(0, 0);
}
}
private void openKeyboardInternal() {
showPopup(AndroidUtilities.usingHardwareInput || isPaused ? 0 : 2, 0);
messageEditText.requestFocus();
AndroidUtilities.showKeyboard(messageEditText);
if (isPaused) {
showKeyboardOnResume = true;
} else if (!AndroidUtilities.usingHardwareInput && !keyboardVisible) {
waitingForKeyboardOpen = true;
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
}
}
public void openKeyboard() {
AndroidUtilities.showKeyboard(messageEditText);
}
public boolean isPopupShowing() {
return emojiView != null && emojiView.getVisibility() == VISIBLE || botKeyboardView != null && botKeyboardView.getVisibility() == VISIBLE;
2014-11-14 16:40:15 +01:00
}
@Override
2015-03-26 18:34:47 +01:00
public void onSizeChanged(int height, boolean isWidthGreater) {
2014-10-06 12:38:00 +02:00
if (height > AndroidUtilities.dp(50) && keyboardVisible) {
2015-03-26 18:34:47 +01:00
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()) {
2015-05-21 23:27:27 +02:00
int newHeight = isWidthGreater ? keyboardHeightLand : keyboardHeight;
2015-06-29 19:12:11 +02:00
if (currentPopupContentType == 1 && !botKeyboardView.isFullSize()) {
newHeight = Math.min(botKeyboardView.getKeyboardHeight(), newHeight);
}
View currentView = null;
if (currentPopupContentType == 0) {
currentView = emojiView;
} else if (currentPopupContentType == 1) {
currentView = botKeyboardView;
}
if (botKeyboardView != null) {
botKeyboardView.setPanelHeight(newHeight);
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) currentView.getLayoutParams();
2014-12-04 21:27:06 +01: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
currentView.setLayoutParams(layoutParams);
if (sizeNotifierLayout != null) {
emojiPadding = layoutParams.height;
sizeNotifierLayout.requestLayout();
onWindowSizeChanged();
2014-10-06 12:38:00 +02:00
}
}
}
2015-06-29 19:12:11 +02:00
if (lastSizeChangeValue1 == height && lastSizeChangeValue2 == isWidthGreater) {
onWindowSizeChanged();
return;
}
lastSizeChangeValue1 = height;
lastSizeChangeValue2 = isWidthGreater;
boolean oldValue = keyboardVisible;
keyboardVisible = height > 0;
2015-06-29 19:12:11 +02:00
if (keyboardVisible && isPopupShowing()) {
showPopup(0, currentPopupContentType);
}
if (emojiPadding != 0 && !keyboardVisible && keyboardVisible != oldValue && !isPopupShowing()) {
emojiPadding = 0;
sizeNotifierLayout.requestLayout();
}
2015-06-29 19:12:11 +02:00
if (keyboardVisible && waitingForKeyboardOpen) {
waitingForKeyboardOpen = false;
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
}
2015-06-29 19:12:11 +02:00
onWindowSizeChanged();
}
public int getEmojiPadding() {
return emojiPadding;
}
public int getEmojiHeight() {
if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
return keyboardHeightLand;
} else {
return keyboardHeight;
}
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.emojiDidLoaded) {
if (emojiView != null) {
emojiView.invalidateViews();
}
2015-06-29 19:12:11 +02:00
if (botKeyboardView != null) {
botKeyboardView.invalidateViews();
}
} else if (id == NotificationCenter.recordProgressChanged) {
2014-11-14 16:40:15 +01:00
Long time = (Long) args[0] / 1000;
String str = String.format("%02d:%02d", time / 60, time % 60);
if (lastTimeString == null || !lastTimeString.equals(str)) {
if (time % 5 == 0) {
MessagesController.getInstance().sendTyping(dialog_id, 1, 0);
}
if (recordTimeText != null) {
recordTimeText.setText(str);
}
}
2015-10-29 18:10:07 +01:00
if (recordCircle != null) {
recordCircle.setAmplitude((Double) args[1]);
}
} else if (id == NotificationCenter.closeChats) {
2015-03-26 18:34:47 +01:00
if (messageEditText != null && messageEditText.isFocused()) {
AndroidUtilities.hideKeyboard(messageEditText);
}
} else if (id == NotificationCenter.recordStartError || id == NotificationCenter.recordStopped) {
if (recordingAudio) {
MessagesController.getInstance().sendTyping(dialog_id, 2, 0);
recordingAudio = false;
updateAudioRecordIntefrace();
}
} else if (id == NotificationCenter.recordStarted) {
if (!recordingAudio) {
recordingAudio = true;
updateAudioRecordIntefrace();
}
} else if (id == NotificationCenter.audioDidSent) {
if (delegate != null) {
2015-03-26 18:34:47 +01:00
delegate.onMessageSend(null);
}
2015-01-02 23:15:07 +01:00
} else if (id == NotificationCenter.audioRouteChanged) {
if (parentActivity != null) {
boolean frontSpeaker = (Boolean) args[0];
parentActivity.setVolumeControlStream(frontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.USE_DEFAULT_STREAM_TYPE);
}
}
}
}