2014-07-03 00:39:05 +02:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.4.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).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013-2014.
|
|
|
|
*/
|
|
|
|
|
2014-12-01 18:56:31 +01:00
|
|
|
package org.telegram.ui.Components;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.Rect;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.media.AudioManager;
|
2014-12-01 18:56:31 +01:00
|
|
|
import android.os.Build;
|
2014-07-03 00:39:05 +02:00
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.style.ImageSpan;
|
2014-11-06 22:34:47 +01:00
|
|
|
import android.view.Gravity;
|
2014-07-03 00:39:05 +02:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
2014-11-14 16:40:15 +01:00
|
|
|
import android.view.ViewGroup;
|
2014-07-03 00:39:05 +02:00
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
import android.widget.ImageView;
|
2014-12-04 21:27:06 +01:00
|
|
|
import android.widget.PopupWindow;
|
2014-07-03 00:39:05 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.telegram.android.AndroidUtilities;
|
|
|
|
import org.telegram.android.Emoji;
|
|
|
|
import org.telegram.android.LocaleController;
|
|
|
|
import org.telegram.android.MediaController;
|
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.SendMessagesHelper;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
|
|
|
import org.telegram.messenger.FileLog;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
|
|
|
|
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
|
|
|
|
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
|
|
|
|
import org.telegram.ui.AnimationCompat.ViewProxy;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-12-04 21:27:06 +01:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
public class ChatActivityEnterView implements NotificationCenter.NotificationCenterDelegate, SizeNotifierRelativeLayout.SizeNotifierRelativeLayoutDelegate {
|
|
|
|
|
|
|
|
public static interface ChatActivityEnterViewDelegate {
|
|
|
|
public abstract void onMessageSend();
|
|
|
|
public abstract void needSendTyping();
|
2015-01-02 23:15:07 +01:00
|
|
|
public abstract void onTextChanged(CharSequence text);
|
2014-11-19 02:23:46 +01:00
|
|
|
public abstract void onAttachButtonHidden();
|
|
|
|
public abstract void onAttachButtonShow();
|
2015-01-02 23:15:07 +01:00
|
|
|
public abstract void onWindowSizeChanged(int size);
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private EditText messsageEditText;
|
|
|
|
private ImageButton sendButton;
|
2014-12-04 21:27:06 +01:00
|
|
|
private PopupWindow emojiPopup;
|
2014-07-03 00:39:05 +02:00
|
|
|
private ImageView emojiButton;
|
|
|
|
private EmojiView emojiView;
|
|
|
|
private TextView recordTimeText;
|
|
|
|
private ImageButton audioSendButton;
|
|
|
|
private View recordPanel;
|
|
|
|
private View slideText;
|
2014-11-14 16:40:15 +01:00
|
|
|
private PowerManager.WakeLock mWakeLock;
|
2014-07-03 00:39:05 +02:00
|
|
|
private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
|
2014-11-14 16:40:15 +01:00
|
|
|
private FrameLayout attachButton;
|
2014-11-17 03:44:57 +01:00
|
|
|
private AnimatorSetProxy runningAnimation;
|
|
|
|
private AnimatorSetProxy runningAnimation2;
|
2014-11-17 23:04:31 +01:00
|
|
|
private ObjectAnimatorProxy runningAnimationAudio;
|
2014-11-14 16:40:15 +01:00
|
|
|
private int runningAnimationType;
|
2014-11-17 23:04:31 +01:00
|
|
|
private int audioInterfaceState;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-11-14 16:40:15 +01:00
|
|
|
private int keyboardHeight;
|
|
|
|
private int keyboardHeightLand;
|
2014-07-03 00:39:05 +02:00
|
|
|
private boolean keyboardVisible;
|
2014-11-14 16:40:15 +01:00
|
|
|
private boolean sendByEnter;
|
|
|
|
private long lastTypingTimeSend;
|
|
|
|
private String lastTimeString;
|
2014-07-03 00:39:05 +02:00
|
|
|
private float startedDraggingX = -1;
|
|
|
|
private float distCanMove = AndroidUtilities.dp(80);
|
2014-11-14 16:40:15 +01:00
|
|
|
private boolean recordingAudio;
|
2014-07-03 00:39:05 +02:00
|
|
|
|
|
|
|
private Activity parentActivity;
|
|
|
|
private long dialog_id;
|
2014-11-14 16:40:15 +01:00
|
|
|
private boolean ignoreTextChange;
|
2014-07-03 00:39:05 +02:00
|
|
|
private ChatActivityEnterViewDelegate delegate;
|
|
|
|
|
|
|
|
public ChatActivityEnterView() {
|
2014-08-22 16:24:33 +02:00
|
|
|
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);
|
2014-09-28 15:37:26 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.hideEmojiKeyboard);
|
2015-01-02 23:15:07 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioRouteChanged);
|
2014-07-03 00:39:05 +02:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
sendByEnter = preferences.getBoolean("send_by_enter", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onDestroy() {
|
2014-08-22 16:24:33 +02:00
|
|
|
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);
|
2014-09-28 15:37:26 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.hideEmojiKeyboard);
|
2015-01-02 23:15:07 +01:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioRouteChanged);
|
2014-07-03 00:39:05 +02:00
|
|
|
if (mWakeLock != null) {
|
|
|
|
try {
|
|
|
|
mWakeLock.release();
|
|
|
|
mWakeLock = null;
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
|
|
|
sizeNotifierRelativeLayout.delegate = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setContainerView(Activity activity, View containerView) {
|
|
|
|
parentActivity = activity;
|
|
|
|
|
2014-11-14 16:40:15 +01:00
|
|
|
sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) containerView.findViewById(R.id.chat_layout);
|
2014-07-03 00:39:05 +02:00
|
|
|
sizeNotifierRelativeLayout.delegate = this;
|
|
|
|
|
2014-11-14 16:40:15 +01:00
|
|
|
messsageEditText = (EditText) containerView.findViewById(R.id.chat_text_edit);
|
2014-07-03 00:39:05 +02:00
|
|
|
messsageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
|
|
|
|
|
2014-11-14 16:40:15 +01:00
|
|
|
attachButton = (FrameLayout) containerView.findViewById(R.id.chat_attach_button);
|
2014-11-17 03:44:57 +01:00
|
|
|
if (attachButton != null) {
|
|
|
|
ViewProxy.setPivotX(attachButton, AndroidUtilities.dp(48));
|
2014-11-19 02:23:46 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(50);
|
|
|
|
messsageEditText.setLayoutParams(layoutParams);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2014-11-14 16:40:15 +01:00
|
|
|
|
|
|
|
sendButton = (ImageButton) containerView.findViewById(R.id.chat_send_button);
|
2014-07-03 00:39:05 +02:00
|
|
|
sendButton.setVisibility(View.INVISIBLE);
|
2014-11-21 01:14:44 +01:00
|
|
|
ViewProxy.setScaleX(sendButton, 0.1f);
|
|
|
|
ViewProxy.setScaleY(sendButton, 0.1f);
|
|
|
|
ViewProxy.setAlpha(sendButton, 0.0f);
|
2014-11-24 15:14:40 +01:00
|
|
|
sendButton.clearAnimation();
|
2014-11-14 16:40:15 +01:00
|
|
|
emojiButton = (ImageView) containerView.findViewById(R.id.chat_smile_button);
|
|
|
|
audioSendButton = (ImageButton) containerView.findViewById(R.id.chat_audio_send_button);
|
2014-07-03 00:39:05 +02:00
|
|
|
recordPanel = containerView.findViewById(R.id.record_panel);
|
2014-11-14 16:40:15 +01:00
|
|
|
recordTimeText = (TextView) containerView.findViewById(R.id.recording_time_text);
|
2014-07-03 00:39:05 +02:00
|
|
|
slideText = containerView.findViewById(R.id.slideText);
|
2014-11-14 16:40:15 +01:00
|
|
|
TextView textView = (TextView) containerView.findViewById(R.id.slideToCancelTextView);
|
2014-07-03 00:39:05 +02:00
|
|
|
textView.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
|
|
|
|
|
|
|
|
emojiButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-12-04 21:27:06 +01:00
|
|
|
showEmojiPopup(emojiPopup == null || !emojiPopup.isShowing());
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messsageEditText.setOnKeyListener(new View.OnKeyListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onKey(View view, int i, KeyEvent keyEvent) {
|
2014-12-04 21:27:06 +01:00
|
|
|
if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (keyEvent.getAction() == 1) {
|
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messsageEditText.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2014-12-04 21:27:06 +01:00
|
|
|
if (emojiPopup != null && emojiPopup.isShowing()) {
|
2014-07-03 00:39:05 +02:00
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == EditorInfo.IME_ACTION_SEND) {
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
} else if (sendByEnter) {
|
|
|
|
if (keyEvent != null && i == EditorInfo.IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
sendMessage();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
sendButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
audioSendButton.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
|
|
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
startedDraggingX = -1;
|
|
|
|
MediaController.getInstance().startRecording(dialog_id);
|
|
|
|
updateAudioRecordIntefrace();
|
2014-07-10 02:15:58 +02:00
|
|
|
audioSendButton.getParent().requestDisallowInterceptTouchEvent(true);
|
2014-07-03 00:39:05 +02:00
|
|
|
} 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);
|
|
|
|
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-07-03 00:39:05 +02:00
|
|
|
}
|
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-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
if (params.leftMargin > AndroidUtilities.dp(30)) {
|
|
|
|
params.leftMargin = AndroidUtilities.dp(30);
|
|
|
|
slideText.setLayoutParams(params);
|
|
|
|
ViewProxy.setAlpha(slideText, 1);
|
|
|
|
startedDraggingX = -1;
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
view.onTouchEvent(motionEvent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
messsageEditText.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
|
|
|
String message = getTrimmedString(charSequence.toString());
|
2014-10-07 22:14:27 +02:00
|
|
|
checkSendButton(true);
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onTextChanged(charSequence);
|
|
|
|
}
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
|
|
|
|
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
|
|
|
|
TLRPC.User currentUser = null;
|
2014-11-14 16:40:15 +01:00
|
|
|
if ((int) dialog_id > 0) {
|
|
|
|
currentUser = MessagesController.getInstance().getUser((int) dialog_id);
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
if (currentUser != null && (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime)) {
|
2014-07-03 00:39:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastTypingTimeSend = System.currentTimeMillis();
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.needSendTyping();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable editable) {
|
|
|
|
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
|
|
|
|
sendMessage();
|
|
|
|
}
|
|
|
|
int i = 0;
|
|
|
|
ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
|
|
|
|
int j = arrayOfImageSpan.length;
|
|
|
|
while (true) {
|
|
|
|
if (i >= j) {
|
|
|
|
Emoji.replaceEmoji(editable, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
editable.removeSpan(arrayOfImageSpan[i]);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-10-07 22:14:27 +02:00
|
|
|
checkSendButton(false);
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void sendMessage() {
|
|
|
|
if (processSendingText(messsageEditText.getText().toString())) {
|
|
|
|
messsageEditText.setText("");
|
|
|
|
lastTypingTimeSend = 0;
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onMessageSend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-07-03 00:39:05 +02:00
|
|
|
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()));
|
2014-08-22 16:24:33 +02:00
|
|
|
SendMessagesHelper.getInstance().sendMessage(mess, dialog_id);
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
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) {
|
2014-07-03 00:39:05 +02:00
|
|
|
String message = getTrimmedString(messsageEditText.getText().toString());
|
|
|
|
if (message.length() > 0) {
|
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
|
|
|
|
2014-11-20 15:45:33 +01:00
|
|
|
if (messsageEditText != null) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(0);
|
|
|
|
messsageEditText.setLayoutParams(layoutParams);
|
|
|
|
}
|
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) {
|
|
|
|
if (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();
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(0);
|
|
|
|
messsageEditText.setLayoutParams(layoutParams);
|
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
|
|
|
|
2014-11-20 15:45:33 +01:00
|
|
|
if (messsageEditText != null) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(50);
|
|
|
|
messsageEditText.setLayoutParams(layoutParams);
|
|
|
|
}
|
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) {
|
|
|
|
if (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) {
|
|
|
|
attachButton.setVisibility(View.VISIBLE);
|
2014-11-19 02:23:46 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messsageEditText.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = AndroidUtilities.dp(50);
|
|
|
|
messsageEditText.setLayoutParams(layoutParams);
|
2014-11-14 16:40:15 +01:00
|
|
|
}
|
2014-10-07 22:14:27 +02:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAudioRecordIntefrace() {
|
|
|
|
if (recordingAudio) {
|
2014-11-17 23:04:31 +01:00
|
|
|
if (audioInterfaceState == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
audioInterfaceState = 1;
|
2014-07-03 00:39:05 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
recordPanel.setVisibility(View.VISIBLE);
|
|
|
|
recordTimeText.setText("00:00");
|
|
|
|
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);
|
|
|
|
if (runningAnimationAudio != null) {
|
|
|
|
runningAnimationAudio.cancel();
|
|
|
|
}
|
|
|
|
runningAnimationAudio = ObjectAnimatorProxy.ofFloatProxy(recordPanel, "translationX", 0).setDuration(300);
|
|
|
|
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);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
});
|
2014-11-17 23:04:31 +01:00
|
|
|
runningAnimationAudio.setInterpolator(new AccelerateDecelerateInterpolator());
|
|
|
|
runningAnimationAudio.start();
|
2014-07-03 00:39:05 +02:00
|
|
|
} 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-07-03 00:39:05 +02:00
|
|
|
|
2014-11-17 23:04:31 +01:00
|
|
|
if (runningAnimationAudio != null) {
|
|
|
|
runningAnimationAudio.cancel();
|
|
|
|
}
|
|
|
|
runningAnimationAudio = ObjectAnimatorProxy.ofFloatProxy(recordPanel, "translationX", AndroidUtilities.displaySize.x).setDuration(300);
|
|
|
|
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);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
});
|
2014-11-17 23:04:31 +01:00
|
|
|
runningAnimationAudio.setInterpolator(new AccelerateDecelerateInterpolator());
|
|
|
|
runningAnimationAudio.start();
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showEmojiPopup(boolean show) {
|
|
|
|
if (show) {
|
2014-12-04 21:27:06 +01:00
|
|
|
if (emojiPopup == null) {
|
2014-12-01 18:56:31 +01:00
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emojiView = new EmojiView(parentActivity);
|
|
|
|
emojiView.setListener(new EmojiView.Listener() {
|
|
|
|
public void onBackspace() {
|
|
|
|
messsageEditText.dispatchKeyEvent(new KeyEvent(0, 67));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEmojiSelected(String symbol) {
|
|
|
|
int i = messsageEditText.getSelectionEnd();
|
|
|
|
if (i < 0) {
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messsageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
|
|
|
|
messsageEditText.setText(messsageEditText.getText().insert(i, localCharSequence));
|
|
|
|
int j = i + localCharSequence.length();
|
|
|
|
messsageEditText.setSelection(j, j);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-12-04 21:27:06 +01:00
|
|
|
emojiPopup = new PopupWindow(emojiView);
|
2014-12-01 18:56:31 +01:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
2014-12-04 21:27:06 +01:00
|
|
|
try {
|
|
|
|
Field field = PopupWindow.class.getDeclaredField("mWindowLayoutType");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(emojiPopup, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
|
|
|
|
} catch (Exception e) {
|
|
|
|
/* ignored */
|
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
int currentHeight;
|
2014-12-01 18:56:31 +01:00
|
|
|
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = wm.getDefaultDisplay().getRotation();
|
2014-07-03 00:39:05 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
currentHeight = keyboardHeightLand;
|
|
|
|
} else {
|
|
|
|
currentHeight = keyboardHeight;
|
|
|
|
}
|
2014-12-04 21:27:06 +01:00
|
|
|
emojiPopup.setHeight(View.MeasureSpec.makeMeasureSpec(currentHeight, View.MeasureSpec.EXACTLY));
|
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
|
|
|
emojiPopup.setWidth(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.x, View.MeasureSpec.EXACTLY));
|
2014-09-14 01:40:36 +02:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-11-21 11:59:05 +01:00
|
|
|
try {
|
2014-12-04 21:27:06 +01:00
|
|
|
emojiPopup.showAtLocation(parentActivity.getWindow().getDecorView(), Gravity.BOTTOM | Gravity.LEFT, 0, 0);
|
2014-11-21 11:59:05 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2014-12-01 18:56:31 +01:00
|
|
|
return;
|
2014-11-21 11:59:05 +01:00
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
if (!keyboardVisible) {
|
2014-09-14 01:40:36 +02:00
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
|
|
|
sizeNotifierRelativeLayout.setPadding(0, 0, 0, currentHeight);
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_msg_panel_hide);
|
2015-01-02 23:15:07 +01:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onWindowSizeChanged(sizeNotifierRelativeLayout.getHeight() - sizeNotifierRelativeLayout.getPaddingBottom());
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (emojiButton != null) {
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
|
|
|
|
}
|
2014-12-04 21:27:06 +01:00
|
|
|
if (emojiPopup != null) {
|
|
|
|
emojiPopup.dismiss();
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
|
|
|
sizeNotifierRelativeLayout.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
|
|
|
sizeNotifierRelativeLayout.setPadding(0, 0, 0, 0);
|
2015-01-02 23:15:07 +01:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onWindowSizeChanged(sizeNotifierRelativeLayout.getHeight() - sizeNotifierRelativeLayout.getPaddingBottom());
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 18:56:31 +01:00
|
|
|
public void hideEmojiPopup() {
|
2014-12-04 21:27:06 +01:00
|
|
|
if (emojiPopup != null && emojiPopup.isShowing()) {
|
2014-12-01 18:56:31 +01:00
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(ChatActivityEnterViewDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDialogId(long id) {
|
|
|
|
dialog_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldText(String text) {
|
2014-11-19 11:32:27 +01:00
|
|
|
if (messsageEditText == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
ignoreTextChange = true;
|
|
|
|
messsageEditText.setText(text);
|
|
|
|
messsageEditText.setSelection(messsageEditText.getText().length());
|
|
|
|
ignoreTextChange = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFieldFocused(boolean focus) {
|
|
|
|
if (messsageEditText == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (focus) {
|
|
|
|
if (!messsageEditText.isFocused()) {
|
|
|
|
messsageEditText.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (messsageEditText != null) {
|
2014-10-01 21:55:24 +02:00
|
|
|
try {
|
|
|
|
messsageEditText.requestFocus();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 600);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (messsageEditText.isFocused() && !keyboardVisible) {
|
|
|
|
messsageEditText.clearFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasText() {
|
|
|
|
return messsageEditText != null && messsageEditText.length() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getFieldText() {
|
|
|
|
if (messsageEditText != null && messsageEditText.length() > 0) {
|
|
|
|
return messsageEditText.getText().toString();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEmojiPopupShowing() {
|
2014-12-04 21:27:06 +01:00
|
|
|
return emojiPopup != null && emojiPopup.isShowing();
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
attachButton.addView(view);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
|
|
|
|
layoutParams.gravity = Gravity.CENTER;
|
2015-01-02 23:15:07 +01:00
|
|
|
layoutParams.width = AndroidUtilities.dp(48);
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
2014-11-14 16:40:15 +01:00
|
|
|
view.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
@Override
|
|
|
|
public void onSizeChanged(int height) {
|
|
|
|
Rect localRect = new Rect();
|
|
|
|
parentActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
|
|
|
|
|
2014-12-01 18:56:31 +01:00
|
|
|
WindowManager wm = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
if (wm == null || wm.getDefaultDisplay() == null) {
|
2014-07-03 00:39:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
int rotation = wm.getDefaultDisplay().getRotation();
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2014-10-06 12:38:00 +02:00
|
|
|
if (height > AndroidUtilities.dp(50) && keyboardVisible) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 21:27:06 +01:00
|
|
|
if (emojiPopup != null && emojiPopup.isShowing()) {
|
2014-10-06 12:38:00 +02:00
|
|
|
int newHeight = 0;
|
2014-07-03 00:39:05 +02:00
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
2014-10-06 12:38:00 +02:00
|
|
|
newHeight = keyboardHeightLand;
|
2014-07-03 00:39:05 +02:00
|
|
|
} else {
|
2014-10-06 12:38:00 +02:00
|
|
|
newHeight = keyboardHeight;
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2014-12-04 21:27:06 +01:00
|
|
|
final WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) emojiPopup.getContentView().getLayoutParams();
|
|
|
|
if (layoutParams.width != AndroidUtilities.displaySize.x || layoutParams.height != newHeight) {
|
|
|
|
layoutParams.width = AndroidUtilities.displaySize.x;
|
|
|
|
layoutParams.height = newHeight;
|
|
|
|
wm.updateViewLayout(emojiPopup.getContentView(), layoutParams);
|
2014-10-06 12:38:00 +02:00
|
|
|
if (!keyboardVisible) {
|
|
|
|
sizeNotifierRelativeLayout.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (sizeNotifierRelativeLayout != null) {
|
2014-12-04 21:27:06 +01:00
|
|
|
sizeNotifierRelativeLayout.setPadding(0, 0, 0, layoutParams.height);
|
2014-10-06 12:38:00 +02:00
|
|
|
sizeNotifierRelativeLayout.requestLayout();
|
2015-01-02 23:15:07 +01:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onWindowSizeChanged(sizeNotifierRelativeLayout.getHeight() - sizeNotifierRelativeLayout.getPaddingBottom());
|
|
|
|
}
|
2014-10-06 12:38:00 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2014-10-06 12:38:00 +02:00
|
|
|
});
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean oldValue = keyboardVisible;
|
|
|
|
keyboardVisible = height > 0;
|
|
|
|
if (keyboardVisible && sizeNotifierRelativeLayout.getPaddingBottom() > 0) {
|
|
|
|
showEmojiPopup(false);
|
2014-12-04 21:27:06 +01:00
|
|
|
} else if (!keyboardVisible && keyboardVisible != oldValue && emojiPopup != null && emojiPopup.isShowing()) {
|
2014-07-03 00:39:05 +02:00
|
|
|
showEmojiPopup(false);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onWindowSizeChanged(sizeNotifierRelativeLayout.getHeight() - sizeNotifierRelativeLayout.getPaddingBottom());
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.emojiDidLoaded) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (emojiView != null) {
|
|
|
|
emojiView.invalidateViews();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.recordProgressChanged) {
|
2014-11-14 16:40:15 +01:00
|
|
|
Long time = (Long) args[0] / 1000;
|
2014-07-03 00:39:05 +02:00
|
|
|
String str = String.format("%02d:%02d", time / 60, time % 60);
|
|
|
|
if (lastTimeString == null || !lastTimeString.equals(str)) {
|
|
|
|
if (recordTimeText != null) {
|
|
|
|
recordTimeText.setText(str);
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.closeChats) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (messsageEditText != null && messsageEditText.isFocused()) {
|
|
|
|
AndroidUtilities.hideKeyboard(messsageEditText);
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.recordStartError || id == NotificationCenter.recordStopped) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (recordingAudio) {
|
|
|
|
recordingAudio = false;
|
|
|
|
updateAudioRecordIntefrace();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.recordStarted) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (!recordingAudio) {
|
|
|
|
recordingAudio = true;
|
|
|
|
updateAudioRecordIntefrace();
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.audioDidSent) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onMessageSend();
|
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
} else if (id == NotificationCenter.hideEmojiKeyboard) {
|
|
|
|
hideEmojiPopup();
|
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);
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|