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

3979 lines
186 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).
*
2017-03-31 01:58:05 +02:00
* Copyright Nikolai Kudashov, 2013-2017.
*/
package org.telegram.ui.Components;
2015-10-29 18:10:07 +01:00
import android.Manifest;
import android.animation.Animator;
2017-03-31 01:58:05 +02:00
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
2017-03-31 01:58:05 +02:00
import android.content.ClipDescription;
import android.content.Context;
2016-03-16 13:26:32 +01:00
import android.content.DialogInterface;
import android.content.SharedPreferences;
2015-10-29 18:10:07 +01:00
import android.content.pm.PackageManager;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
2015-10-29 18:10:07 +01:00
import android.graphics.Paint;
2018-07-30 04:07:02 +02:00
import android.graphics.PixelFormat;
2017-03-31 01:58:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
2017-07-08 18:32:04 +02:00
import android.graphics.RectF;
2015-10-29 18:10:07 +01:00
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;
2016-04-22 15:49:00 +02:00
import android.os.Bundle;
import android.os.PowerManager;
2018-07-30 04:07:02 +02:00
import android.support.annotation.Keep;
2017-03-31 01:58:05 +02:00
import android.support.v13.view.inputmethod.EditorInfoCompat;
import android.support.v13.view.inputmethod.InputConnectionCompat;
import android.support.v13.view.inputmethod.InputContentInfoCompat;
import android.support.v4.os.BuildCompat;
import android.text.Editable;
2016-03-06 02:49:31 +01:00
import android.text.InputFilter;
import android.text.SpannableStringBuilder;
2016-05-25 23:49:47 +02:00
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.util.Property;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
2015-10-29 18:10:07 +01:00
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.EditorInfo;
2017-03-31 01:58:05 +02:00
import android.view.inputmethod.InputConnection;
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;
2016-03-06 02:49:31 +01:00
import android.widget.Toast;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ChatObject;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.DataQuery;
2015-09-24 22:52:02 +02:00
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;
2016-03-06 02:49:31 +01:00
import org.telegram.messenger.NotificationsController;
2015-09-24 22:52:02 +02:00
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;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.SharedConfig;
2017-07-08 18:32:04 +02:00
import org.telegram.messenger.VideoEditedInfo;
import org.telegram.messenger.camera.CameraController;
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;
import org.telegram.messenger.ApplicationLoader;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.AlertDialog;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.ChatActivity;
import org.telegram.ui.DialogsActivity;
2017-12-08 18:35:59 +01:00
import org.telegram.ui.GroupStickersActivity;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.LaunchActivity;
2015-12-09 19:27:52 +01:00
import org.telegram.ui.StickersActivity;
2016-03-06 02:49:31 +01:00
import java.io.File;
2016-04-22 15:49:00 +02:00
import java.util.ArrayList;
2015-06-29 19:12:11 +02:00
import java.util.Locale;
public class ChatActivityEnterView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate, SizeNotifierFrameLayout.SizeNotifierFrameLayoutDelegate, StickersAlert.StickersAlertDelegate {
public interface ChatActivityEnterViewDelegate {
2016-05-25 23:49:47 +02:00
void onMessageSend(CharSequence message);
void needSendTyping();
2015-04-09 20:00:14 +02:00
void onTextChanged(CharSequence text, boolean bigChange);
2018-07-30 04:07:02 +02:00
void onTextSelectionChanged(int start, int end);
void onTextSpansChanged(CharSequence text);
void onAttachButtonHidden();
void onAttachButtonShow();
void onWindowSizeChanged(int size);
void onStickersTab(boolean opened);
2016-05-25 23:49:47 +02:00
void onMessageEditEnd(boolean loading);
2017-03-31 01:58:05 +02:00
void didPressedAttachButton();
void needStartRecordVideo(int state);
2017-07-08 18:32:04 +02:00
void needChangeVideoPreviewState(int state, float seekProgress);
void onSwitchRecordMode(boolean video);
void onPreAudioVideoRecord();
void needStartRecordAudio(int state);
void needShowMediaBanHint();
2018-07-30 04:07:02 +02:00
void onStickersExpandedChange();
2016-03-06 02:49:31 +01:00
}
2018-07-30 04:07:02 +02:00
private int currentAccount = UserConfig.selectedAccount;
private SeekBarWaveform seekBarWaveform;
2016-03-06 02:49:31 +01:00
2018-07-30 04:07:02 +02:00
private class SeekBarWaveformView extends View {
2016-03-06 02:49:31 +01:00
public SeekBarWaveformView(Context context) {
super(context);
seekBarWaveform = new SeekBarWaveform(context);
seekBarWaveform.setDelegate(new SeekBar.SeekBarDelegate() {
@Override
public void onSeekBarDrag(float progress) {
2016-05-25 23:49:47 +02:00
if (audioToSendMessageObject != null) {
audioToSendMessageObject.audioProgress = progress;
MediaController.getInstance().seekToProgress(audioToSendMessageObject, progress);
}
2016-03-06 02:49:31 +01:00
}
});
}
public void setWaveform(byte[] waveform) {
seekBarWaveform.setWaveform(waveform);
invalidate();
}
public void setProgress(float progress) {
seekBarWaveform.setProgress(progress);
invalidate();
}
public boolean isDragging() {
return seekBarWaveform.isDragging();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = seekBarWaveform.onTouch(event.getAction(), event.getX(), event.getY());
if (result) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
requestDisallowInterceptTouchEvent(true);
}
invalidate();
}
return result || super.onTouchEvent(event);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
2016-04-22 15:49:00 +02:00
seekBarWaveform.setSize(right - left, bottom - top);
2016-03-06 02:49:31 +01:00
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
2017-03-31 01:58:05 +02:00
seekBarWaveform.setColors(Theme.getColor(Theme.key_chat_recordedVoiceProgress), Theme.getColor(Theme.key_chat_recordedVoiceProgressInner), Theme.getColor(Theme.key_chat_recordedVoiceProgress));
2016-03-06 02:49:31 +01:00
seekBarWaveform.draw(canvas);
}
}
private EditTextCaption messageEditText;
private ImageView sendButton;
2016-04-22 15:49:00 +02:00
private ImageView cancelBotButton;
private ImageView emojiButton;
private ImageView expandStickersButton;
private EmojiView emojiView;
private TextView recordTimeText;
2017-03-31 01:58:05 +02:00
private FrameLayout audioVideoButtonContainer;
private AnimatorSet audioVideoButtonAnimation;
private ImageView audioSendButton;
2017-03-31 01:58:05 +02:00
private ImageView videoSendButton;
private FrameLayout recordPanel;
2016-03-06 02:49:31 +01:00
private FrameLayout recordedAudioPanel;
2017-07-08 18:32:04 +02:00
private VideoTimelineView videoTimelineView;
2017-03-31 01:58:05 +02:00
private ImageView recordDeleteImageView;
2016-03-06 02:49:31 +01:00
private SeekBarWaveformView recordedAudioSeekBar;
2017-03-31 01:58:05 +02:00
private View recordedAudioBackground;
2016-03-06 02:49:31 +01:00
private ImageView recordedAudioPlayButton;
private TextView recordedAudioTimeTextView;
private LinearLayout slideText;
2017-03-31 01:58:05 +02:00
private ImageView recordCancelImage;
private TextView recordCancelText;
2017-07-08 18:32:04 +02:00
private TextView recordSendText;
2017-03-31 01:58:05 +02:00
private LinearLayout recordTimeContainer;
2015-10-29 18:10:07 +01:00
private RecordDot recordDot;
2015-06-29 19:12:11 +02:00
private SizeNotifierFrameLayout sizeNotifierLayout;
2017-03-31 01:58:05 +02:00
private LinearLayout attachLayout;
private ImageView attachButton;
2015-06-29 19:12:11 +02:00
private ImageView botButton;
private LinearLayout textFieldContainer;
2016-03-06 02:49:31 +01:00
private FrameLayout sendButtonContainer;
2017-03-31 01:58:05 +02:00
private FrameLayout doneButtonContainer;
private ImageView doneButtonImage;
private AnimatorSet doneButtonAnimation;
private ContextProgressView doneButtonProgress;
private View topView;
2015-06-29 19:12:11 +02:00
private PopupWindow botKeyboardPopup;
private BotKeyboardView botKeyboardView;
2016-03-06 02:49:31 +01:00
private ImageView notifyButton;
2015-10-29 18:10:07 +01:00
private RecordCircle recordCircle;
2016-04-22 15:49:00 +02:00
private CloseProgressDrawable2 progressDrawable;
2017-03-31 01:58:05 +02:00
private Paint dotPaint;
private Drawable playDrawable;
private Drawable pauseDrawable;
2018-07-30 04:07:02 +02:00
private boolean searchingStickers;
private boolean destroyed;
2015-06-29 19:12:11 +02:00
2016-03-06 02:49:31 +01:00
private MessageObject editingMessageObject;
2016-05-25 23:49:47 +02:00
private int editingMessageReqId;
2016-03-06 02:49:31 +01:00
private boolean editingCaption;
2017-12-08 18:35:59 +01:00
private TLRPC.ChatFull info;
2017-07-08 18:32:04 +02:00
private boolean hasRecordVideo;
2017-03-31 01:58:05 +02:00
2015-06-29 19:12:11 +02:00
private int currentPopupContentType = -1;
2016-03-06 02:49:31 +01:00
private boolean silent;
private boolean canWriteToChannel;
private boolean isPaused = true;
2015-06-29 19:12:11 +02:00
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;
2017-03-31 01:58:05 +02:00
private PowerManager.WakeLock wakeLock;
private AnimatorSet runningAnimation;
private AnimatorSet runningAnimation2;
private AnimatorSet runningAnimationAudio;
2014-11-14 16:40:15 +01:00
private int runningAnimationType;
2017-03-31 01:58:05 +02:00
private int recordInterfaceState;
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;
2017-07-08 18:32:04 +02:00
private long lastTypingSendTime;
private float startedDraggingX = -1;
private float distCanMove = AndroidUtilities.dp(80);
2017-03-31 01:58:05 +02:00
private boolean recordingAudioVideo;
private boolean forceShowSendButton;
private boolean allowStickers;
private boolean allowGifs;
2015-06-29 19:12:11 +02:00
private int lastSizeChangeValue1;
private boolean lastSizeChangeValue2;
private Activity parentActivity;
2016-04-22 15:49:00 +02:00
private ChatActivity 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;
2016-03-06 02:49:31 +01:00
private TLRPC.TL_document audioToSend;
private String audioToSendPath;
private MessageObject audioToSendMessageObject;
2017-07-08 18:32:04 +02:00
private VideoEditedInfo videoToSendMessageObject;
2016-03-06 02:49:31 +01:00
2015-04-09 20:00:14 +02:00
private boolean topViewShowed;
private boolean needShowTopView;
private boolean allowShowTopView;
private AnimatorSet currentTopViewAnimation;
2016-04-22 15:49:00 +02:00
private MessageObject pendingMessageObject;
private TLRPC.KeyboardButton pendingLocationButton;
2015-06-29 19:12:11 +02:00
private boolean waitingForKeyboardOpen;
private Runnable openKeyboardRunnable = new Runnable() {
@Override
public void run() {
2018-07-30 04:07:02 +02:00
if (!destroyed && messageEditText != null && waitingForKeyboardOpen && !keyboardVisible && !AndroidUtilities.usingHardwareInput && !AndroidUtilities.isInMultiwindow) {
2015-06-29 19:12:11 +02:00
messageEditText.requestFocus();
AndroidUtilities.showKeyboard(messageEditText);
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
}
}
};
private Runnable updateExpandabilityRunnable = new Runnable() {
private int lastKnownPage = -1;
@Override
public void run() {
if (emojiView != null) {
int curPage = emojiView.getCurrentPage();
if (curPage != lastKnownPage) {
lastKnownPage = curPage;
boolean prevOpen = stickersTabOpen;
stickersTabOpen = curPage == 1 || curPage == 2;
2017-12-08 18:35:59 +01:00
if (prevOpen != stickersTabOpen) {
checkSendButton(true);
}
if (!stickersTabOpen && stickersExpanded) {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(true);
emojiView.hideSearchKeyboard();
}
setStickersExpanded(false, true);
2017-12-08 18:35:59 +01:00
}
}
}
}
};
2017-12-08 18:35:59 +01:00
private Property<View, Integer> roundedTranslationYProperty = new Property<View, Integer>(Integer.class, "translationY") {
@Override
2017-12-08 18:35:59 +01:00
public Integer get(View object) {
return Math.round(object.getTranslationY());
}
@Override
2017-12-08 18:35:59 +01:00
public void set(View object, Integer value) {
object.setTranslationY(value);
}
};
2015-06-29 19:12:11 +02:00
2017-03-31 01:58:05 +02:00
private Paint redDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private boolean stickersTabOpen;
private boolean gifsTabOpen;
private boolean stickersExpanded;
2018-07-30 04:07:02 +02:00
private boolean closeAnimationInProgress;
private Animator stickersExpansionAnim;
private float stickersExpansionProgress;
private int stickersExpandedHeight;
private boolean stickersDragging;
private AnimatedArrowDrawable stickersArrow;
2018-07-30 04:07:02 +02:00
private Runnable onFinishInitCameraRunnable = new Runnable() {
@Override
public void run() {
if (delegate != null) {
delegate.needStartRecordVideo(0);
}
}
};
2017-03-31 01:58:05 +02:00
private boolean recordAudioVideoRunnableStarted;
2017-07-08 18:32:04 +02:00
private boolean calledRecordRunnable;
2017-03-31 01:58:05 +02:00
private Runnable recordAudioVideoRunnable = new Runnable() {
@Override
public void run() {
if (delegate == null || parentActivity == null) {
return;
}
2017-07-08 18:32:04 +02:00
delegate.onPreAudioVideoRecord();
calledRecordRunnable = true;
2017-03-31 01:58:05 +02:00
recordAudioVideoRunnableStarted = false;
2017-07-08 18:32:04 +02:00
recordCircle.setLockTranslation(10000);
recordSendText.setAlpha(0.0f);
slideText.setAlpha(1.0f);
slideText.setTranslationY(0);
2017-03-31 01:58:05 +02:00
if (videoSendButton != null && videoSendButton.getTag() != null) {
if (Build.VERSION.SDK_INT >= 23) {
boolean hasAudio = parentActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
boolean hasVideo = parentActivity.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
if (!hasAudio || !hasVideo) {
String[] permissions = new String[!hasAudio && !hasVideo ? 2 : 1];
if (!hasAudio && !hasVideo) {
permissions[0] = Manifest.permission.RECORD_AUDIO;
permissions[1] = Manifest.permission.CAMERA;
} else if (!hasAudio) {
permissions[0] = Manifest.permission.RECORD_AUDIO;
} else {
permissions[0] = Manifest.permission.CAMERA;
}
parentActivity.requestPermissions(permissions, 3);
return;
}
}
2018-07-30 04:07:02 +02:00
if (!CameraController.getInstance().isCameraInitied()) {
CameraController.getInstance().initCamera(onFinishInitCameraRunnable);
} else {
onFinishInitCameraRunnable.run();
}
2017-03-31 01:58:05 +02:00
} else {
if (parentFragment != null) {
if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
parentActivity.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 3);
return;
}
}
2017-07-08 18:32:04 +02:00
delegate.needStartRecordAudio(1);
2017-03-31 01:58:05 +02:00
startedDraggingX = -1;
2018-07-30 04:07:02 +02:00
MediaController.getInstance().startRecording(currentAccount, dialog_id, replyingMessageObject);
2017-03-31 01:58:05 +02:00
updateRecordIntefrace();
audioVideoButtonContainer.getParent().requestDisallowInterceptTouchEvent(true);
}
}
};
2015-10-29 18:10:07 +01:00
private class RecordDot extends View {
private float alpha;
private long lastUpdateTime;
private boolean isIncr;
public RecordDot(Context context) {
super(context);
2017-03-31 01:58:05 +02:00
redDotPaint.setColor(Theme.getColor(Theme.key_chat_recordedVoiceDot));
2015-10-29 18:10:07 +01:00
}
public void resetAlpha() {
alpha = 1.0f;
lastUpdateTime = System.currentTimeMillis();
isIncr = false;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
2017-03-31 01:58:05 +02:00
redDotPaint.setAlpha((int) (255 * alpha));
2015-10-29 18:10:07 +01:00
long dt = (System.currentTimeMillis() - lastUpdateTime);
if (!isIncr) {
2016-03-06 02:49:31 +01:00
alpha -= dt / 400.0f;
2015-10-29 18:10:07 +01:00
if (alpha <= 0) {
alpha = 0;
isIncr = true;
}
} else {
2016-03-06 02:49:31 +01:00
alpha += dt / 400.0f;
2015-10-29 18:10:07 +01:00
if (alpha >= 1) {
alpha = 1;
isIncr = false;
}
}
lastUpdateTime = System.currentTimeMillis();
2017-03-31 01:58:05 +02:00
canvas.drawCircle(AndroidUtilities.dp(5), AndroidUtilities.dp(5), AndroidUtilities.dp(5), redDotPaint);
2015-10-29 18:10:07 +01:00
invalidate();
}
}
2017-03-31 01:58:05 +02:00
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint paintRecord = new Paint(Paint.ANTI_ALIAS_FLAG);
private Drawable micDrawable;
private Drawable cameraDrawable;
2017-07-08 18:32:04 +02:00
private Drawable sendDrawable;
private Drawable lockDrawable;
private Drawable lockTopDrawable;
private Drawable lockArrowDrawable;
private Drawable lockBackgroundDrawable;
private Drawable lockShadowDrawable;
private RectF rect = new RectF();
2015-10-29 18:10:07 +01:00
2017-03-31 01:58:05 +02:00
private class RecordCircle extends View {
2017-07-08 18:32:04 +02:00
2015-10-29 18:10:07 +01:00
private float scale;
private float amplitude;
private float animateToAmplitude;
private float animateAmplitudeDiff;
private long lastUpdateTime;
2017-07-08 18:32:04 +02:00
private float lockAnimatedTranslation;
private float startTranslation;
private boolean sendButtonVisible;
private boolean pressed;
2015-10-29 18:10:07 +01:00
public RecordCircle(Context context) {
super(context);
2017-03-31 01:58:05 +02:00
paint.setColor(Theme.getColor(Theme.key_chat_messagePanelVoiceBackground));
paintRecord.setColor(Theme.getColor(Theme.key_chat_messagePanelVoiceShadow));
2017-07-08 18:32:04 +02:00
lockDrawable = getResources().getDrawable(R.drawable.lock_middle);
lockDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoiceLock), PorterDuff.Mode.MULTIPLY));
lockTopDrawable = getResources().getDrawable(R.drawable.lock_top);
lockTopDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoiceLock), PorterDuff.Mode.MULTIPLY));
lockArrowDrawable = getResources().getDrawable(R.drawable.lock_arrow);
lockArrowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoiceLock), PorterDuff.Mode.MULTIPLY));
lockBackgroundDrawable = getResources().getDrawable(R.drawable.lock_round);
lockBackgroundDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoiceLockBackground), PorterDuff.Mode.MULTIPLY));
lockShadowDrawable = getResources().getDrawable(R.drawable.lock_round_shadow);
lockShadowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoiceLockShadow), PorterDuff.Mode.MULTIPLY));
2017-03-31 01:58:05 +02:00
micDrawable = getResources().getDrawable(R.drawable.mic).mutate();
micDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoicePressed), PorterDuff.Mode.MULTIPLY));
cameraDrawable = getResources().getDrawable(R.drawable.ic_msg_panel_video).mutate();
cameraDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoicePressed), PorterDuff.Mode.MULTIPLY));
2017-07-08 18:32:04 +02:00
sendDrawable = getResources().getDrawable(R.drawable.ic_send).mutate();
sendDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoicePressed), PorterDuff.Mode.MULTIPLY));
2015-10-29 18:10:07 +01:00
}
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;
}
2018-07-30 04:07:02 +02:00
@Keep
2015-10-29 18:10:07 +01:00
public void setScale(float value) {
scale = value;
invalidate();
}
2018-07-30 04:07:02 +02:00
@Keep
2017-07-08 18:32:04 +02:00
public void setLockAnimatedTranslation(float value) {
lockAnimatedTranslation = value;
invalidate();
}
public float getLockAnimatedTranslation() {
return lockAnimatedTranslation;
}
public boolean isSendButtonVisible() {
return sendButtonVisible;
}
public void setSendButtonInvisible() {
sendButtonVisible = false;
invalidate();
}
public int setLockTranslation(float value) {
if (value == 10000) {
sendButtonVisible = false;
lockAnimatedTranslation = -1;
startTranslation = -1;
invalidate();
return 0;
} else {
if (sendButtonVisible) {
return 2;
}
if (lockAnimatedTranslation == -1) {
startTranslation = value;
}
lockAnimatedTranslation = value;
invalidate();
if (startTranslation - lockAnimatedTranslation >= AndroidUtilities.dp(57)) {
sendButtonVisible = true;
return 2;
}
}
return 1;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (sendButtonVisible) {
int x = (int) event.getX();
int y = (int) event.getY();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
2018-07-30 04:07:02 +02:00
return pressed = lockBackgroundDrawable.getBounds().contains(x, y);
2017-07-08 18:32:04 +02:00
} else if (pressed) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (lockBackgroundDrawable.getBounds().contains(x, y)) {
if (videoSendButton != null && videoSendButton.getTag() != null) {
delegate.needStartRecordVideo(3);
} else {
MediaController.getInstance().stopRecording(2);
delegate.needStartRecordAudio(0);
}
}
}
return true;
}
}
return false;
}
2015-10-29 18:10:07 +01:00
@Override
protected void onDraw(Canvas canvas) {
int cx = getMeasuredWidth() / 2;
2017-07-08 18:32:04 +02:00
int cy = AndroidUtilities.dp(170);
float yAdd = 0;
if (lockAnimatedTranslation != 10000) {
yAdd = Math.max(0, (int) (startTranslation - lockAnimatedTranslation));
if (yAdd > AndroidUtilities.dp(57)) {
yAdd = AndroidUtilities.dp(57);
}
}
cy -= yAdd;
2015-10-29 18:10:07 +01:00
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) {
2017-07-08 18:32:04 +02:00
canvas.drawCircle(getMeasuredWidth() / 2.0f, cy, (AndroidUtilities.dp(42) + AndroidUtilities.dp(20) * amplitude) * scale, paintRecord);
}
canvas.drawCircle(getMeasuredWidth() / 2.0f, cy, AndroidUtilities.dp(42) * sc, paint);
Drawable drawable;
if (isSendButtonVisible()) {
drawable = sendDrawable;
} else {
drawable = videoSendButton != null && videoSendButton.getTag() != null ? cameraDrawable : micDrawable;
2015-10-29 18:10:07 +01:00
}
2017-03-31 01:58:05 +02:00
drawable.setBounds(cx - drawable.getIntrinsicWidth() / 2, cy - drawable.getIntrinsicHeight() / 2, cx + drawable.getIntrinsicWidth() / 2, cy + drawable.getIntrinsicHeight() / 2);
drawable.setAlpha((int) (255 * alpha));
drawable.draw(canvas);
2017-07-08 18:32:04 +02:00
float moveProgress = 1.0f - yAdd / AndroidUtilities.dp(57);
float moveProgress2 = Math.max(0.0f, 1.0f - yAdd / AndroidUtilities.dp(57) * 2);
int lockSize;
int lockY;
int lockTopY;
int lockMiddleY;
int lockArrowY;
int intAlpha = (int) (alpha * 255);
if (isSendButtonVisible()) {
lockSize = AndroidUtilities.dp(31);
lockY = AndroidUtilities.dp(57) + (int) (AndroidUtilities.dp(30) * (1.0f - sc) - yAdd + AndroidUtilities.dp(20) * moveProgress);
lockTopY = lockY + AndroidUtilities.dp(5);
lockMiddleY = lockY + AndroidUtilities.dp(11);
lockArrowY = lockY + AndroidUtilities.dp(25);
intAlpha *= yAdd / AndroidUtilities.dp(57);
lockBackgroundDrawable.setAlpha(255);
lockShadowDrawable.setAlpha(255);
lockTopDrawable.setAlpha(intAlpha);
lockDrawable.setAlpha(intAlpha);
lockArrowDrawable.setAlpha((int) (intAlpha * moveProgress2));
} else {
lockSize = AndroidUtilities.dp(31) + (int) (AndroidUtilities.dp(29) * moveProgress);
lockY = AndroidUtilities.dp(57) + (int) (AndroidUtilities.dp(30) * (1.0f - sc)) - (int) yAdd;
lockTopY = lockY + AndroidUtilities.dp(5) + (int) (AndroidUtilities.dp(4) * moveProgress);
lockMiddleY = lockY + AndroidUtilities.dp(11) + (int) (AndroidUtilities.dp(10) * moveProgress);
lockArrowY = lockY + AndroidUtilities.dp(25) + (int) (AndroidUtilities.dp(16) * moveProgress);
lockBackgroundDrawable.setAlpha(intAlpha);
lockShadowDrawable.setAlpha(intAlpha);
lockTopDrawable.setAlpha(intAlpha);
lockDrawable.setAlpha(intAlpha);
lockArrowDrawable.setAlpha((int) (intAlpha * moveProgress2));
}
lockBackgroundDrawable.setBounds(cx - AndroidUtilities.dp(15), lockY, cx + AndroidUtilities.dp(15), lockY + lockSize);
lockBackgroundDrawable.draw(canvas);
lockShadowDrawable.setBounds(cx - AndroidUtilities.dp(16), lockY - AndroidUtilities.dp(1), cx + AndroidUtilities.dp(16), lockY + lockSize + AndroidUtilities.dp(1));
lockShadowDrawable.draw(canvas);
lockTopDrawable.setBounds(cx - AndroidUtilities.dp(6), lockTopY, cx + AndroidUtilities.dp(6), lockTopY + AndroidUtilities.dp(14));
lockTopDrawable.draw(canvas);
lockDrawable.setBounds(cx - AndroidUtilities.dp(7), lockMiddleY, cx + AndroidUtilities.dp(7), lockMiddleY + AndroidUtilities.dp(12));
lockDrawable.draw(canvas);
lockArrowDrawable.setBounds(cx - AndroidUtilities.dp(7.5f), lockArrowY, cx + AndroidUtilities.dp(7.5f), lockArrowY + AndroidUtilities.dp(9));
lockArrowDrawable.draw(canvas);
if (isSendButtonVisible()) {
redDotPaint.setAlpha(255);
rect.set(cx - AndroidUtilities.dp2(6.5f), lockY + AndroidUtilities.dp(9), cx + AndroidUtilities.dp(6.5f), lockY + AndroidUtilities.dp(9 + 13));
canvas.drawRoundRect(rect, AndroidUtilities.dp(1), AndroidUtilities.dp(1), redDotPaint);
}
2015-10-29 18:10:07 +01:00
}
}
2017-03-31 01:58:05 +02:00
public ChatActivityEnterView(Activity context, SizeNotifierFrameLayout parent, ChatActivity fragment, final boolean isChat) {
super(context);
2017-03-31 01:58:05 +02:00
dotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
dotPaint.setColor(Theme.getColor(Theme.key_chat_emojiPanelNewTrending));
setFocusable(true);
setFocusableInTouchMode(true);
setWillNotDraw(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStarted);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStartError);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStopped);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordProgressChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.audioDidSent);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.audioRouteChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.featuredStickersDidLoaded);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
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);
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
sendByEnter = preferences.getBoolean("send_by_enter", false);
textFieldContainer = new LinearLayout(context);
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));
FrameLayout frameLayout = new FrameLayout(context);
2015-06-29 19:12:11 +02:00
textFieldContainer.addView(frameLayout, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1.0f));
2016-10-11 13:57:01 +02:00
emojiButton = new ImageView(context) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
2018-07-30 04:07:02 +02:00
if (attachLayout != null && (emojiView == null || emojiView.getVisibility() != VISIBLE) && !DataQuery.getInstance(currentAccount).getUnreadStickerSets().isEmpty() && dotPaint != null) {
2017-03-31 01:58:05 +02:00
int x = canvas.getWidth() / 2 + AndroidUtilities.dp(4 + 5);
int y = canvas.getHeight() / 2 - AndroidUtilities.dp(13 - 5);
canvas.drawCircle(x, y, AndroidUtilities.dp(5), dotPaint);
2016-10-11 13:57:01 +02:00
}
}
};
2017-03-31 01:58:05 +02:00
emojiButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
emojiButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
2016-03-16 13:26:32 +01:00
emojiButton.setPadding(0, AndroidUtilities.dp(1), 0, 0);
2017-03-31 01:58:05 +02:00
// if (Build.VERSION.SDK_INT >= 21) {
// emojiButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
// }
2016-10-11 13:57:01 +02:00
setEmojiButtonImage();
2016-04-22 15:49:00 +02:00
frameLayout.addView(emojiButton, LayoutHelper.createFrame(48, 48, Gravity.BOTTOM | Gravity.LEFT, 3, 0, 0, 0));
emojiButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
2015-06-29 19:12:11 +02:00
if (!isPopupShowing() || currentPopupContentType != 0) {
showPopup(1, 0);
2017-03-31 01:58:05 +02:00
emojiView.onOpen(messageEditText.length() > 0 && !messageEditText.getText().toString().startsWith("@gif"));
} else {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(false);
messageEditText.requestFocus();
}
2015-06-29 19:12:11 +02:00
openKeyboardInternal();
removeGifFromInputField();
}
}
});
2017-03-31 01:58:05 +02:00
messageEditText = new EditTextCaption(context) {
@Override
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
final InputConnection ic = super.onCreateInputConnection(editorInfo);
EditorInfoCompat.setContentMimeTypes(editorInfo, new String[]{"image/gif", "image/*", "image/jpg", "image/png"});
final InputConnectionCompat.OnCommitContentListener callback = new InputConnectionCompat.OnCommitContentListener() {
@Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
if (BuildCompat.isAtLeastNMR1() && (flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
try {
inputContentInfo.requestPermission();
} catch (Exception e) {
return false;
}
}
ClipDescription description = inputContentInfo.getDescription();
if (description.hasMimeType("image/gif")) {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.prepareSendingDocument(null, null, inputContentInfo.getContentUri(), "image/gif", dialog_id, replyingMessageObject, inputContentInfo, null);
2017-03-31 01:58:05 +02:00
} else {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.prepareSendingPhoto(null, inputContentInfo.getContentUri(), dialog_id, replyingMessageObject, null, null, null, inputContentInfo, 0, null);
2017-03-31 01:58:05 +02:00
}
if (delegate != null) {
delegate.onMessageSend(null);
}
return true;
}
};
return InputConnectionCompat.createWrapper(ic, editorInfo, callback);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isPopupShowing() && event.getAction() == MotionEvent.ACTION_DOWN) {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(false);
}
2017-03-31 01:58:05 +02:00
showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2, 0);
openKeyboardInternal();
}
try {
return super.onTouchEvent(event);
} catch (Exception e) {
FileLog.e(e);
}
return false;
}
2018-07-30 04:07:02 +02:00
@Override
protected void onSelectionChanged(int selStart, int selEnd) {
super.onSelectionChanged(selStart, selEnd);
if (delegate != null) {
delegate.onTextSelectionChanged(selStart, selEnd);
}
}
2017-03-31 01:58:05 +02:00
};
2018-07-30 04:07:02 +02:00
messageEditText.setDelegate(new EditTextCaption.EditTextCaptionDelegate() {
@Override
public void onSpansChanged() {
if (delegate != null) {
delegate.onTextSpansChanged(messageEditText.getText());
}
}
});
2015-09-24 22:52:02 +02:00
updateFieldHint();
2018-07-30 04:07:02 +02:00
int flags = EditorInfo.IME_FLAG_NO_EXTRACT_UI;
if (parentFragment != null && parentFragment.getCurrentEncryptedChat() != null) {
flags |= 0x01000000; //EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING;
}
messageEditText.setImeOptions(flags);
2015-03-26 18:34:47 +01:00
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);
2017-03-31 01:58:05 +02:00
messageEditText.setTextColor(Theme.getColor(Theme.key_chat_messagePanelText));
messageEditText.setHintColor(Theme.getColor(Theme.key_chat_messagePanelHint));
messageEditText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
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));
2016-04-22 15:49:00 +02:00
messageEditText.setOnKeyListener(new 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) {
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
2015-09-02 00:14:21 +02:00
preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(true);
messageEditText.requestFocus();
} else {
showPopup(0, 0);
removeGifFromInputField();
}
}
return true;
2016-10-11 13:57:01 +02:00
} else if (i == KeyEvent.KEYCODE_ENTER && (ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN && editingMessageObject == null) {
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) {
2016-10-11 13:57:01 +02:00
if ((ctrlPressed || sendByEnter) && keyEvent.getAction() == KeyEvent.ACTION_DOWN && editingMessageObject == null) {
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);
CharSequence message = AndroidUtilities.getTrimmedString(charSequence.toString());
if (delegate != null) {
2016-03-06 02:49:31 +01:00
if (!ignoreTextChange) {
2016-10-11 13:57:01 +02:00
if (count > 2 || charSequence == null || charSequence.length() == 0) {
messageWebPageSearch = true;
}
2016-03-06 02:49:31 +01:00
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;
}
if (editingMessageObject == null && !canWriteToChannel && message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
2018-07-30 04:07:02 +02:00
int currentTime = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
TLRPC.User currentUser = null;
if ((int) dialog_id > 0) {
2018-07-30 04:07:02 +02:00
currentUser = MessagesController.getInstance(currentAccount).getUser((int) dialog_id);
}
2018-07-30 04:07:02 +02:00
if (currentUser != null && (currentUser.id == UserConfig.getInstance(currentAccount).getClientUserId() || currentUser.status != null && currentUser.status.expires < currentTime && !MessagesController.getInstance(currentAccount).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;
}
2016-10-11 13:57:01 +02:00
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n' && editingMessageObject == null) {
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) {
2017-03-31 01:58:05 +02:00
attachLayout = new LinearLayout(context);
attachLayout.setOrientation(LinearLayout.HORIZONTAL);
attachLayout.setEnabled(false);
attachLayout.setPivotX(AndroidUtilities.dp(48));
frameLayout.addView(attachLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.BOTTOM | Gravity.RIGHT));
2015-06-29 19:12:11 +02:00
botButton = new ImageView(context);
2017-03-31 01:58:05 +02:00
botButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
2015-06-29 19:12:11 +02:00
botButton.setImageResource(R.drawable.bot_keyboard2);
botButton.setScaleType(ImageView.ScaleType.CENTER);
botButton.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
// if (Build.VERSION.SDK_INT >= 21) {
// botButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
// }
attachLayout.addView(botButton, LayoutHelper.createLinear(48, 48));
2015-06-29 19:12:11 +02:00
botButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(false);
messageEditText.requestFocus();
}
2015-06-29 19:12:11 +02:00
if (botReplyMarkup != null) {
if (!isPopupShowing() || currentPopupContentType != 1) {
showPopup(1, 1);
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
2015-09-02 00:14:21 +02:00
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) {
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
2015-09-02 00:14:21 +02:00
preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
2015-06-29 19:12:11 +02:00
openKeyboardInternal();
}
} else if (hasBotCommands) {
setFieldText("/");
2017-03-31 01:58:05 +02:00
messageEditText.requestFocus();
2015-06-29 19:12:11 +02:00
openKeyboard();
}
2018-07-30 04:07:02 +02:00
if (stickersExpanded) {
setStickersExpanded(false, false);
}
2015-06-29 19:12:11 +02:00
}
});
2015-09-24 22:52:02 +02:00
2016-03-06 02:49:31 +01:00
notifyButton = new ImageView(context);
notifyButton.setImageResource(silent ? R.drawable.notify_members_off : R.drawable.notify_members_on);
2017-03-31 01:58:05 +02:00
notifyButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
2016-03-06 02:49:31 +01:00
notifyButton.setScaleType(ImageView.ScaleType.CENTER);
notifyButton.setVisibility(canWriteToChannel ? VISIBLE : GONE);
2017-03-31 01:58:05 +02:00
// if (Build.VERSION.SDK_INT >= 21) {
// notifyButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
// }
attachLayout.addView(notifyButton, LayoutHelper.createLinear(48, 48));
2016-03-06 02:49:31 +01:00
notifyButton.setOnClickListener(new OnClickListener() {
2016-10-11 13:57:01 +02:00
private Toast visibleToast;
2016-03-06 02:49:31 +01:00
@Override
public void onClick(View v) {
silent = !silent;
notifyButton.setImageResource(silent ? R.drawable.notify_members_off : R.drawable.notify_members_on);
2018-07-30 04:07:02 +02:00
MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + dialog_id, silent).commit();
NotificationsController.getInstance(currentAccount).updateServerNotificationsSettings(dialog_id);
2016-10-11 13:57:01 +02:00
try {
if (visibleToast != null) {
visibleToast.cancel();
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-10-11 13:57:01 +02:00
}
2016-03-06 02:49:31 +01:00
if (silent) {
2016-10-11 13:57:01 +02:00
visibleToast = Toast.makeText(parentActivity, LocaleController.getString("ChannelNotifyMembersInfoOff", R.string.ChannelNotifyMembersInfoOff), Toast.LENGTH_SHORT);
2018-07-30 04:07:02 +02:00
visibleToast.show();
2016-03-06 02:49:31 +01:00
} else {
2016-10-11 13:57:01 +02:00
visibleToast = Toast.makeText(parentActivity, LocaleController.getString("ChannelNotifyMembersInfoOn", R.string.ChannelNotifyMembersInfoOn), Toast.LENGTH_SHORT);
2018-07-30 04:07:02 +02:00
visibleToast.show();
2016-03-06 02:49:31 +01:00
}
2016-03-16 13:26:32 +01:00
updateFieldHint();
2016-03-06 02:49:31 +01:00
}
});
2017-03-31 01:58:05 +02:00
attachButton = new ImageView(context);
attachButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
attachButton.setImageResource(R.drawable.ic_ab_attach);
attachButton.setScaleType(ImageView.ScaleType.CENTER);
// if (Build.VERSION.SDK_INT >= 21) {
// attachButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
// }
attachLayout.addView(attachButton, LayoutHelper.createLinear(48, 48));
attachButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
delegate.didPressedAttachButton();
}
});
}
recordedAudioPanel = new FrameLayout(context);
2016-03-06 02:49:31 +01:00
recordedAudioPanel.setVisibility(audioToSend == null ? GONE : VISIBLE);
2017-03-31 01:58:05 +02:00
recordedAudioPanel.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
2016-03-06 02:49:31 +01:00
recordedAudioPanel.setFocusable(true);
recordedAudioPanel.setFocusableInTouchMode(true);
recordedAudioPanel.setClickable(true);
frameLayout.addView(recordedAudioPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));
2017-03-31 01:58:05 +02:00
recordDeleteImageView = new ImageView(context);
recordDeleteImageView.setScaleType(ImageView.ScaleType.CENTER);
recordDeleteImageView.setImageResource(R.drawable.ic_ab_delete);
recordDeleteImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelVoiceDelete), PorterDuff.Mode.MULTIPLY));
recordedAudioPanel.addView(recordDeleteImageView, LayoutHelper.createFrame(48, 48));
recordDeleteImageView.setOnClickListener(new OnClickListener() {
2016-03-06 02:49:31 +01:00
@Override
public void onClick(View v) {
2017-07-08 18:32:04 +02:00
if (videoToSendMessageObject != null) {
2018-07-30 04:07:02 +02:00
CameraController.getInstance().cancelOnInitRunnable(onFinishInitCameraRunnable);
2017-07-08 18:32:04 +02:00
delegate.needStartRecordVideo(2);
} else {
MessageObject playing = MediaController.getInstance().getPlayingMessageObject();
if (playing != null && playing == audioToSendMessageObject) {
MediaController.getInstance().cleanupPlayer(true, true);
}
2016-03-06 02:49:31 +01:00
}
if (audioToSendPath != null) {
new File(audioToSendPath).delete();
}
hideRecordedAudioPanel();
checkSendButton(true);
}
});
2017-07-08 18:32:04 +02:00
videoTimelineView = new VideoTimelineView(context);
videoTimelineView.setColor(0xff4badf7);
videoTimelineView.setRoundFrames(true);
videoTimelineView.setDelegate(new VideoTimelineView.VideoTimelineViewDelegate() {
@Override
public void onLeftProgressChanged(float progress) {
if (videoToSendMessageObject == null) {
return;
}
videoToSendMessageObject.startTime = (long) (progress * videoToSendMessageObject.estimatedDuration);
delegate.needChangeVideoPreviewState(2, progress);
}
@Override
public void onRightProgressChanged(float progress) {
2017-07-08 18:32:04 +02:00
if (videoToSendMessageObject == null) {
return;
}
videoToSendMessageObject.endTime = (long) (progress * videoToSendMessageObject.estimatedDuration);
delegate.needChangeVideoPreviewState(2, progress);
}
@Override
public void didStartDragging() {
delegate.needChangeVideoPreviewState(1, 0);
}
@Override
public void didStopDragging() {
delegate.needChangeVideoPreviewState(0, 0);
}
});
recordedAudioPanel.addView(videoTimelineView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 32, Gravity.CENTER_VERTICAL | Gravity.LEFT, 40, 0, 0, 0));
2017-03-31 01:58:05 +02:00
recordedAudioBackground = new View(context);
recordedAudioBackground.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(16), Theme.getColor(Theme.key_chat_recordedVoiceBackground)));
2017-07-08 18:32:04 +02:00
recordedAudioPanel.addView(recordedAudioBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_VERTICAL | Gravity.LEFT, 48, 0, 0, 0));
2016-03-06 02:49:31 +01:00
recordedAudioSeekBar = new SeekBarWaveformView(context);
recordedAudioPanel.addView(recordedAudioSeekBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 32, Gravity.CENTER_VERTICAL | Gravity.LEFT, 48 + 44, 0, 52, 0));
2017-03-31 01:58:05 +02:00
playDrawable = Theme.createSimpleSelectorDrawable(context, R.drawable.s_play, Theme.getColor(Theme.key_chat_recordedVoicePlayPause), Theme.getColor(Theme.key_chat_recordedVoicePlayPausePressed));
pauseDrawable = Theme.createSimpleSelectorDrawable(context, R.drawable.s_pause, Theme.getColor(Theme.key_chat_recordedVoicePlayPause), Theme.getColor(Theme.key_chat_recordedVoicePlayPausePressed));
2016-03-06 02:49:31 +01:00
recordedAudioPlayButton = new ImageView(context);
2017-03-31 01:58:05 +02:00
recordedAudioPlayButton.setImageDrawable(playDrawable);
2016-03-06 02:49:31 +01:00
recordedAudioPlayButton.setScaleType(ImageView.ScaleType.CENTER);
recordedAudioPanel.addView(recordedAudioPlayButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.BOTTOM, 48, 0, 0, 0));
recordedAudioPlayButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (audioToSend == null) {
return;
}
2017-07-08 18:32:04 +02:00
if (MediaController.getInstance().isPlayingMessage(audioToSendMessageObject) && !MediaController.getInstance().isMessagePaused()) {
MediaController.getInstance().pauseMessage(audioToSendMessageObject);
2017-03-31 01:58:05 +02:00
recordedAudioPlayButton.setImageDrawable(playDrawable);
2016-03-06 02:49:31 +01:00
} else {
2017-03-31 01:58:05 +02:00
recordedAudioPlayButton.setImageDrawable(pauseDrawable);
2017-07-08 18:32:04 +02:00
MediaController.getInstance().playMessage(audioToSendMessageObject);
2016-03-06 02:49:31 +01:00
}
}
});
recordedAudioTimeTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
recordedAudioTimeTextView.setTextColor(Theme.getColor(Theme.key_chat_messagePanelVoiceDuration));
2016-03-06 02:49:31 +01:00
recordedAudioTimeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
recordedAudioPanel.addView(recordedAudioTimeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL, 0, 0, 13, 0));
recordPanel = new FrameLayout(context);
recordPanel.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
recordPanel.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
2015-06-29 19:12:11 +02:00
frameLayout.addView(recordPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));
2017-07-08 18:32:04 +02:00
recordPanel.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
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));
2017-03-31 01:58:05 +02:00
recordCancelImage = new ImageView(context);
recordCancelImage.setImageResource(R.drawable.slidearrow);
recordCancelImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_recordVoiceCancel), PorterDuff.Mode.MULTIPLY));
slideText.addView(recordCancelImage, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 0, 1, 0, 0));
2017-03-31 01:58:05 +02:00
recordCancelText = new TextView(context);
recordCancelText.setText(LocaleController.getString("SlideToCancel", R.string.SlideToCancel));
recordCancelText.setTextColor(Theme.getColor(Theme.key_chat_recordVoiceCancel));
recordCancelText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
slideText.addView(recordCancelText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0));
2017-07-08 18:32:04 +02:00
recordSendText = new TextView(context);
recordSendText.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
recordSendText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText));
recordSendText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
recordSendText.setGravity(Gravity.CENTER);
recordSendText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
recordSendText.setAlpha(0.0f);
recordSendText.setPadding(AndroidUtilities.dp(36), 0, 0, 0);
recordSendText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (hasRecordVideo && videoSendButton.getTag() != null) {
2018-07-30 04:07:02 +02:00
CameraController.getInstance().cancelOnInitRunnable(onFinishInitCameraRunnable);
2017-07-08 18:32:04 +02:00
delegate.needStartRecordVideo(2);
} else {
delegate.needStartRecordAudio(0);
MediaController.getInstance().stopRecording(0);
}
recordingAudioVideo = false;
updateRecordIntefrace();
}
});
recordPanel.addView(recordSendText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0, 0, 0));
2017-03-31 01:58:05 +02:00
recordTimeContainer = new LinearLayout(context);
recordTimeContainer.setOrientation(LinearLayout.HORIZONTAL);
recordTimeContainer.setPadding(AndroidUtilities.dp(13), 0, 0, 0);
recordTimeContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
recordPanel.addView(recordTimeContainer, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
2015-10-29 18:10:07 +01:00
recordDot = new RecordDot(context);
2017-03-31 01:58:05 +02:00
recordTimeContainer.addView(recordDot, LayoutHelper.createLinear(11, 11, Gravity.CENTER_VERTICAL, 0, 1, 0, 0));
recordTimeText = new TextView(context);
2017-03-31 01:58:05 +02:00
recordTimeText.setTextColor(Theme.getColor(Theme.key_chat_recordTime));
recordTimeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
2017-03-31 01:58:05 +02:00
recordTimeContainer.addView(recordTimeText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 6, 0, 0, 0));
2016-03-06 02:49:31 +01:00
sendButtonContainer = new FrameLayout(context);
textFieldContainer.addView(sendButtonContainer, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM));
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer = new FrameLayout(context);
audioVideoButtonContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_messagePanelBackground));
audioVideoButtonContainer.setSoundEffectsEnabled(false);
sendButtonContainer.addView(audioVideoButtonContainer, LayoutHelper.createFrame(48, 48));
audioVideoButtonContainer.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
2017-07-08 18:32:04 +02:00
if (recordCircle.isSendButtonVisible()) {
if (!hasRecordVideo || calledRecordRunnable) {
startedDraggingX = -1;
if (hasRecordVideo && videoSendButton.getTag() != null) {
delegate.needStartRecordVideo(1);
} else {
delegate.needStartRecordAudio(0);
MediaController.getInstance().stopRecording(1);
}
recordingAudioVideo = false;
updateRecordIntefrace();
}
return false;
}
if (parentFragment != null) {
TLRPC.Chat chat = parentFragment.getCurrentChat();
if (ChatObject.isChannel(chat)) {
if (chat.banned_rights != null && chat.banned_rights.send_media) {
delegate.needShowMediaBanHint();
return false;
}
}
}
2017-03-31 01:58:05 +02:00
if (hasRecordVideo) {
2017-07-08 18:32:04 +02:00
calledRecordRunnable = false;
2017-03-31 01:58:05 +02:00
recordAudioVideoRunnableStarted = true;
AndroidUtilities.runOnUIThread(recordAudioVideoRunnable, 150);
} else {
recordAudioVideoRunnable.run();
}
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
2017-07-08 18:32:04 +02:00
if (recordCircle.isSendButtonVisible() || recordedAudioPanel.getVisibility() == VISIBLE) {
return false;
}
2017-03-31 01:58:05 +02:00
if (recordAudioVideoRunnableStarted) {
AndroidUtilities.cancelRunOnUIThread(recordAudioVideoRunnable);
2017-07-08 18:32:04 +02:00
delegate.onSwitchRecordMode(videoSendButton.getTag() == null);
2017-03-31 01:58:05 +02:00
setRecordVideoButtonVisible(videoSendButton.getTag() == null, true);
2017-07-08 18:32:04 +02:00
} else if (!hasRecordVideo || calledRecordRunnable) {
2017-03-31 01:58:05 +02:00
startedDraggingX = -1;
if (hasRecordVideo && videoSendButton.getTag() != null) {
2018-07-30 04:07:02 +02:00
CameraController.getInstance().cancelOnInitRunnable(onFinishInitCameraRunnable);
2017-03-31 01:58:05 +02:00
delegate.needStartRecordVideo(1);
2015-02-27 20:57:58 +01:00
} else {
2017-07-08 18:32:04 +02:00
delegate.needStartRecordAudio(0);
2017-03-31 01:58:05 +02:00
MediaController.getInstance().stopRecording(1);
2015-02-27 20:57:58 +01:00
}
2017-03-31 01:58:05 +02:00
recordingAudioVideo = false;
updateRecordIntefrace();
2015-02-27 20:57:58 +01:00
}
2017-03-31 01:58:05 +02:00
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudioVideo) {
float x = motionEvent.getX();
2017-07-08 18:32:04 +02:00
float y = motionEvent.getY();
if (recordCircle.isSendButtonVisible()) {
return false;
}
if (recordCircle.setLockTranslation(y) == 2) {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(recordCircle, "lockAnimatedTranslation", recordCircle.startTranslation),
ObjectAnimator.ofFloat(slideText, "alpha", 0.0f),
ObjectAnimator.ofFloat(slideText, "translationY", AndroidUtilities.dp(20)),
ObjectAnimator.ofFloat(recordSendText, "alpha", 1.0f),
ObjectAnimator.ofFloat(recordSendText, "translationY", -AndroidUtilities.dp(20), 0));
animatorSet.setInterpolator(new DecelerateInterpolator());
animatorSet.setDuration(150);
animatorSet.start();
return false;
}
if (x < -distCanMove) {
2017-03-31 01:58:05 +02:00
if (hasRecordVideo && videoSendButton.getTag() != null) {
2018-07-30 04:07:02 +02:00
CameraController.getInstance().cancelOnInitRunnable(onFinishInitCameraRunnable);
2017-03-31 01:58:05 +02:00
delegate.needStartRecordVideo(2);
} else {
2017-07-08 18:32:04 +02:00
delegate.needStartRecordAudio(0);
2017-03-31 01:58:05 +02:00
MediaController.getInstance().stopRecording(0);
}
recordingAudioVideo = false;
updateRecordIntefrace();
}
2014-11-17 03:44:57 +01:00
2017-03-31 01:58:05 +02:00
x = x + audioVideoButtonContainer.getX();
2014-11-17 03:44:57 +01:00
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;
}
slideText.setAlpha(alpha);
2014-11-17 03:44:57 +01:00
}
if (x <= slideText.getX() + slideText.getWidth() + AndroidUtilities.dp(30)) {
2014-11-17 03:44:57 +01:00
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);
slideText.setLayoutParams(params);
slideText.setAlpha(1);
2014-11-17 03:44:57 +01:00
startedDraggingX = -1;
}
}
view.onTouchEvent(motionEvent);
return true;
}
});
2017-03-31 01:58:05 +02:00
audioSendButton = new ImageView(context);
audioSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
audioSendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
audioSendButton.setImageResource(R.drawable.mic);
audioSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0);
audioVideoButtonContainer.addView(audioSendButton, LayoutHelper.createFrame(48, 48));
2017-07-08 18:32:04 +02:00
if (isChat) {
2017-03-31 01:58:05 +02:00
videoSendButton = new ImageView(context);
videoSendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
videoSendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
videoSendButton.setImageResource(R.drawable.ic_msg_panel_video);
videoSendButton.setPadding(0, 0, AndroidUtilities.dp(4), 0);
audioVideoButtonContainer.addView(videoSendButton, LayoutHelper.createFrame(48, 48));
}
2015-10-29 18:10:07 +01:00
recordCircle = new RecordCircle(context);
recordCircle.setVisibility(GONE);
2017-07-08 18:32:04 +02:00
sizeNotifierLayout.addView(recordCircle, LayoutHelper.createFrame(124, 194, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, -36, 0));
2015-10-29 18:10:07 +01:00
2016-04-22 15:49:00 +02:00
cancelBotButton = new ImageView(context);
cancelBotButton.setVisibility(INVISIBLE);
cancelBotButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
cancelBotButton.setImageDrawable(progressDrawable = new CloseProgressDrawable2());
2017-03-31 01:58:05 +02:00
progressDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelCancelInlineBot), PorterDuff.Mode.MULTIPLY));
2016-04-22 15:49:00 +02:00
cancelBotButton.setSoundEffectsEnabled(false);
cancelBotButton.setScaleX(0.1f);
cancelBotButton.setScaleY(0.1f);
cancelBotButton.setAlpha(0.0f);
2016-04-22 15:49:00 +02:00
sendButtonContainer.addView(cancelBotButton, LayoutHelper.createFrame(48, 48));
cancelBotButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String text = messageEditText.getText().toString();
int idx = text.indexOf(' ');
if (idx == -1 || idx == text.length() - 1) {
setFieldText("");
} else {
setFieldText(text.substring(0, idx + 1));
}
}
});
sendButton = new ImageView(context);
2016-04-22 15:49:00 +02:00
sendButton.setVisibility(INVISIBLE);
sendButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
2017-03-31 01:58:05 +02:00
sendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelSend), PorterDuff.Mode.MULTIPLY));
sendButton.setImageResource(R.drawable.ic_send);
2015-03-27 11:32:33 +01:00
sendButton.setSoundEffectsEnabled(false);
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
2016-03-06 02:49:31 +01:00
sendButtonContainer.addView(sendButton, LayoutHelper.createFrame(48, 48));
2016-04-22 15:49:00 +02:00
sendButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
sendMessage();
}
});
expandStickersButton = new ImageView(context);
expandStickersButton.setScaleType(ImageView.ScaleType.CENTER);
expandStickersButton.setImageDrawable(stickersArrow = new AnimatedArrowDrawable(Theme.getColor(Theme.key_chat_messagePanelIcons)));
expandStickersButton.setVisibility(GONE);
expandStickersButton.setScaleX(0.1f);
expandStickersButton.setScaleY(0.1f);
expandStickersButton.setAlpha(0.0f);
sendButtonContainer.addView(expandStickersButton, LayoutHelper.createFrame(48, 48));
expandStickersButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
2017-12-08 18:35:59 +01:00
if (expandStickersButton.getVisibility() != VISIBLE || expandStickersButton.getAlpha() != 1.0f) {
return;
}
2018-07-30 04:07:02 +02:00
if (stickersExpanded) {
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(true);
emojiView.hideSearchKeyboard();
} else if (!stickersDragging) {
if (emojiView != null) {
emojiView.showSearchField(false);
}
}
} else if (!stickersDragging) {
emojiView.showSearchField(true);
}
2017-12-08 18:35:59 +01:00
if (!stickersDragging) {
setStickersExpanded(!stickersExpanded, true);
2017-12-08 18:35:59 +01:00
}
}
});
2017-03-31 01:58:05 +02:00
doneButtonContainer = new FrameLayout(context);
doneButtonContainer.setVisibility(GONE);
textFieldContainer.addView(doneButtonContainer, LayoutHelper.createLinear(48, 48, Gravity.BOTTOM));
// if (Build.VERSION.SDK_INT >= 21) {
// doneButtonContainer.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.INPUT_FIELD_SELECTOR_COLOR));
// }
doneButtonContainer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
doneEditingMessage();
}
});
doneButtonImage = new ImageView(context);
doneButtonImage.setScaleType(ImageView.ScaleType.CENTER);
doneButtonImage.setImageResource(R.drawable.edit_done);
doneButtonImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_editDoneIcon), PorterDuff.Mode.MULTIPLY));
doneButtonContainer.addView(doneButtonImage, LayoutHelper.createFrame(48, 48));
doneButtonProgress = new ContextProgressView(context, 0);
doneButtonProgress.setVisibility(View.INVISIBLE);
doneButtonContainer.addView(doneButtonProgress, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2018-07-30 04:07:02 +02:00
SharedPreferences sharedPreferences = MessagesController.getGlobalEmojiSettings();
2015-06-29 19:12:11 +02:00
keyboardHeight = sharedPreferences.getInt("kbd_height", AndroidUtilities.dp(200));
keyboardHeightLand = sharedPreferences.getInt("kbd_height_land3", AndroidUtilities.dp(200));
2017-03-31 01:58:05 +02:00
setRecordVideoButtonVisible(false, false);
2015-06-29 19:12:11 +02:00
checkSendButton(false);
2017-07-08 18:32:04 +02:00
checkChannelRights();
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
if (child == topView) {
canvas.save();
canvas.clipRect(0, 0, getMeasuredWidth(), child.getLayoutParams().height + AndroidUtilities.dp(2));
}
boolean result = super.drawChild(canvas, child, drawingTime);
if (child == topView) {
canvas.restore();
}
return result;
}
@Override
protected void onDraw(Canvas canvas) {
int top = topView != null && topView.getVisibility() == VISIBLE ? (int) topView.getTranslationY() : 0;
2017-03-31 01:58:05 +02:00
int bottom = top + Theme.chat_composeShadowDrawable.getIntrinsicHeight();
Theme.chat_composeShadowDrawable.setBounds(0, top, getMeasuredWidth(), bottom);
Theme.chat_composeShadowDrawable.draw(canvas);
canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
}
@Override
public boolean hasOverlappingRendering() {
return false;
}
2017-12-08 18:35:59 +01:00
public boolean isSendButtonVisible() {
return sendButton.getVisibility() == VISIBLE;
}
2017-03-31 01:58:05 +02:00
private void setRecordVideoButtonVisible(boolean visible, boolean animated) {
2017-07-08 18:32:04 +02:00
if (videoSendButton == null) {
2017-03-31 01:58:05 +02:00
return;
}
videoSendButton.setTag(visible ? 1 : null);
if (audioVideoButtonAnimation != null) {
audioVideoButtonAnimation.cancel();
audioVideoButtonAnimation = null;
}
if (animated) {
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
2017-07-08 18:32:04 +02:00
boolean isChannel = false;
if ((int) dialog_id < 0) {
2018-07-30 04:07:02 +02:00
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
2017-07-08 18:32:04 +02:00
isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
}
preferences.edit().putBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", visible).commit();
2017-03-31 01:58:05 +02:00
audioVideoButtonAnimation = new AnimatorSet();
audioVideoButtonAnimation.playTogether(
ObjectAnimator.ofFloat(videoSendButton, "scaleX", visible ? 1.0f : 0.1f),
ObjectAnimator.ofFloat(videoSendButton, "scaleY", visible ? 1.0f : 0.1f),
ObjectAnimator.ofFloat(videoSendButton, "alpha", visible ? 1.0f : 0.0f),
ObjectAnimator.ofFloat(audioSendButton, "scaleX", visible ? 0.1f : 1.0f),
ObjectAnimator.ofFloat(audioSendButton, "scaleY", visible ? 0.1f : 1.0f),
ObjectAnimator.ofFloat(audioSendButton, "alpha", visible ? 0.0f : 1.0f));
audioVideoButtonAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animation.equals(audioVideoButtonAnimation)) {
audioVideoButtonAnimation = null;
}
}
});
audioVideoButtonAnimation.setInterpolator(new DecelerateInterpolator());
audioVideoButtonAnimation.setDuration(150);
audioVideoButtonAnimation.start();
} else {
videoSendButton.setScaleX(visible ? 1.0f : 0.1f);
videoSendButton.setScaleY(visible ? 1.0f : 0.1f);
videoSendButton.setAlpha(visible ? 1.0f : 0.0f);
audioSendButton.setScaleX(visible ? 0.1f : 1.0f);
audioSendButton.setScaleY(visible ? 0.1f : 1.0f);
audioSendButton.setAlpha(visible ? 0.0f : 1.0f);
}
}
2017-07-08 18:32:04 +02:00
public boolean isRecordingAudioVideo() {
return recordingAudioVideo;
}
public boolean isRecordLocked() {
return recordingAudioVideo && recordCircle.isSendButtonVisible();
}
public void cancelRecordingAudioVideo() {
if (hasRecordVideo && videoSendButton.getTag() != null) {
2018-07-30 04:07:02 +02:00
CameraController.getInstance().cancelOnInitRunnable(onFinishInitCameraRunnable);
2017-07-08 18:32:04 +02:00
delegate.needStartRecordVideo(2);
} else {
delegate.needStartRecordAudio(0);
MediaController.getInstance().stopRecording(0);
}
recordingAudioVideo = false;
updateRecordIntefrace();
}
public void showContextProgress(boolean show) {
2016-04-22 15:49:00 +02:00
if (progressDrawable == null) {
return;
}
if (show) {
progressDrawable.startAnimation();
} else {
progressDrawable.stopAnimation();
}
}
public void setCaption(String caption) {
if (messageEditText != null) {
messageEditText.setCaption(caption);
2016-04-22 15:49:00 +02:00
checkSendButton(true);
}
}
public void addTopView(View view, int height) {
if (view == null) {
return;
}
topView = view;
topView.setVisibility(GONE);
topView.setTranslationY(height);
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 setForceShowSendButton(boolean value, boolean animated) {
forceShowSendButton = value;
checkSendButton(animated);
}
public void setAllowStickersAndGifs(boolean value, boolean value2) {
2016-03-06 02:49:31 +01:00
if ((allowStickers != value || allowGifs != value2) && emojiView != null) {
if (emojiView.getVisibility() == VISIBLE) {
hidePopup(false);
}
sizeNotifierLayout.removeView(emojiView);
emojiView = null;
}
allowStickers = value;
allowGifs = value2;
2016-10-11 13:57:01 +02:00
setEmojiButtonImage();
}
2017-12-08 18:35:59 +01:00
public void addEmojiToRecent(String code) {
createEmojiView();
emojiView.addEmojiToRecent(code);
}
public void setOpenGifsTabFirst() {
createEmojiView();
2018-07-30 04:07:02 +02:00
DataQuery.getInstance(currentAccount).loadRecents(DataQuery.TYPE_IMAGE, true, true, false);
emojiView.switchToGifRecent();
}
2015-11-26 22:04:02 +01:00
public void showTopView(boolean animated, final boolean openKeyboard) {
2015-09-24 22:52:02 +02:00
if (topView == null || topViewShowed || getVisibility() != VISIBLE) {
2018-07-30 04:07:02 +02:00
if (recordedAudioPanel.getVisibility() != VISIBLE && (!forceShowSendButton || openKeyboard)) {
openKeyboard();
}
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;
}
resizeForTopView(true);
if (animated) {
2015-06-29 19:12:11 +02:00
if (keyboardVisible || isPopupShowing()) {
currentTopViewAnimation = new AnimatorSet();
currentTopViewAnimation.playTogether(ObjectAnimator.ofFloat(topView, "translationY", 0));
2017-03-31 01:58:05 +02:00
currentTopViewAnimation.addListener(new AnimatorListenerAdapter() {
2015-03-26 18:34:47 +01:00
@Override
public void onAnimationEnd(Animator animation) {
2015-10-29 18:10:07 +01:00
if (currentTopViewAnimation != null && currentTopViewAnimation.equals(animation)) {
2016-03-06 02:49:31 +01:00
if (recordedAudioPanel.getVisibility() != VISIBLE && (!forceShowSendButton || openKeyboard)) {
2015-04-09 20:00:14 +02:00
openKeyboard();
}
currentTopViewAnimation = null;
2015-03-26 18:34:47 +01:00
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (currentTopViewAnimation != null && currentTopViewAnimation.equals(animation)) {
currentTopViewAnimation = null;
}
}
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 {
topView.setTranslationY(0);
2016-03-06 02:49:31 +01:00
if (recordedAudioPanel.getVisibility() != VISIBLE && (!forceShowSendButton || openKeyboard)) {
2015-03-26 18:34:47 +01:00
openKeyboard();
}
2015-03-26 18:34:47 +01:00
}
} else {
topView.setTranslationY(0);
2017-03-31 01:58:05 +02:00
if (recordedAudioPanel.getVisibility() != VISIBLE && (!forceShowSendButton || openKeyboard)) {
openKeyboard();
}
}
}
}
2017-03-31 01:58:05 +02:00
public void onEditTimeExpired() {
doneButtonContainer.setVisibility(View.GONE);
}
public void showEditDoneProgress(final boolean show, boolean animated) {
if (doneButtonAnimation != null) {
doneButtonAnimation.cancel();
}
if (!animated) {
if (show) {
doneButtonImage.setScaleX(0.1f);
doneButtonImage.setScaleY(0.1f);
doneButtonImage.setAlpha(0.0f);
doneButtonProgress.setScaleX(1.0f);
doneButtonProgress.setScaleY(1.0f);
doneButtonProgress.setAlpha(1.0f);
doneButtonImage.setVisibility(View.INVISIBLE);
doneButtonProgress.setVisibility(View.VISIBLE);
doneButtonContainer.setEnabled(false);
} else {
doneButtonProgress.setScaleX(0.1f);
doneButtonProgress.setScaleY(0.1f);
doneButtonProgress.setAlpha(0.0f);
doneButtonImage.setScaleX(1.0f);
doneButtonImage.setScaleY(1.0f);
doneButtonImage.setAlpha(1.0f);
doneButtonImage.setVisibility(View.VISIBLE);
doneButtonProgress.setVisibility(View.INVISIBLE);
doneButtonContainer.setEnabled(true);
}
} else {
doneButtonAnimation = new AnimatorSet();
if (show) {
doneButtonProgress.setVisibility(View.VISIBLE);
doneButtonContainer.setEnabled(false);
doneButtonAnimation.playTogether(
ObjectAnimator.ofFloat(doneButtonImage, "scaleX", 0.1f),
ObjectAnimator.ofFloat(doneButtonImage, "scaleY", 0.1f),
ObjectAnimator.ofFloat(doneButtonImage, "alpha", 0.0f),
ObjectAnimator.ofFloat(doneButtonProgress, "scaleX", 1.0f),
ObjectAnimator.ofFloat(doneButtonProgress, "scaleY", 1.0f),
ObjectAnimator.ofFloat(doneButtonProgress, "alpha", 1.0f));
} else {
doneButtonImage.setVisibility(View.VISIBLE);
doneButtonContainer.setEnabled(true);
doneButtonAnimation.playTogether(
ObjectAnimator.ofFloat(doneButtonProgress, "scaleX", 0.1f),
ObjectAnimator.ofFloat(doneButtonProgress, "scaleY", 0.1f),
ObjectAnimator.ofFloat(doneButtonProgress, "alpha", 0.0f),
ObjectAnimator.ofFloat(doneButtonImage, "scaleX", 1.0f),
ObjectAnimator.ofFloat(doneButtonImage, "scaleY", 1.0f),
ObjectAnimator.ofFloat(doneButtonImage, "alpha", 1.0f));
}
doneButtonAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (doneButtonAnimation != null && doneButtonAnimation.equals(animation)) {
if (!show) {
doneButtonProgress.setVisibility(View.INVISIBLE);
} else {
doneButtonImage.setVisibility(View.INVISIBLE);
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (doneButtonAnimation != null && doneButtonAnimation.equals(animation)) {
doneButtonAnimation = null;
}
}
});
doneButtonAnimation.setDuration(150);
doneButtonAnimation.start();
}
}
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
if (currentTopViewAnimation != null) {
currentTopViewAnimation.cancel();
currentTopViewAnimation = null;
}
if (animated) {
currentTopViewAnimation = new AnimatorSet();
currentTopViewAnimation.playTogether(ObjectAnimator.ofFloat(topView, "translationY", topView.getLayoutParams().height));
2017-03-31 01:58:05 +02:00
currentTopViewAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator 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);
resizeForTopView(false);
2015-04-09 20:00:14 +02:00
currentTopViewAnimation = null;
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (currentTopViewAnimation != null && currentTopViewAnimation.equals(animation)) {
currentTopViewAnimation = null;
}
}
});
2015-04-09 20:00:14 +02:00
currentTopViewAnimation.setDuration(200);
currentTopViewAnimation.start();
} else {
topView.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
resizeForTopView(false);
topView.setTranslationY(topView.getLayoutParams().height);
}
}
}
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) {
2016-04-22 15:49:00 +02:00
topView.setVisibility(GONE);
resizeForTopView(false);
topView.setTranslationY(topView.getLayoutParams().height);
}
}
} else {
if (!allowShowTopView) {
allowShowTopView = true;
if (needShowTopView) {
2016-04-22 15:49:00 +02:00
topView.setVisibility(VISIBLE);
resizeForTopView(true);
topView.setTranslationY(0);
}
}
}
}
}
private void resizeForTopView(boolean show) {
LayoutParams layoutParams = (LayoutParams) textFieldContainer.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(2) + (show ? topView.getLayoutParams().height : 0);
textFieldContainer.setLayoutParams(layoutParams);
2018-07-30 04:07:02 +02:00
if (stickersExpanded) {
setStickersExpanded(false, true);
2018-07-30 04:07:02 +02:00
}
}
public void onDestroy() {
2018-07-30 04:07:02 +02:00
destroyed = true;
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStarted);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStartError);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStopped);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordProgressChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.audioDidSent);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.audioRouteChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.messagePlayingDidReset);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.featuredStickersDidLoaded);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
2016-03-06 02:49:31 +01:00
if (emojiView != null) {
emojiView.onDestroy();
}
2017-03-31 01:58:05 +02:00
if (wakeLock != null) {
try {
2017-03-31 01:58:05 +02:00
wakeLock.release();
wakeLock = null;
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
2015-05-21 23:27:27 +02:00
if (sizeNotifierLayout != null) {
2015-06-29 19:12:11 +02:00
sizeNotifierLayout.setDelegate(null);
}
}
2017-07-08 18:32:04 +02:00
public void checkChannelRights() {
if (parentFragment == null) {
return;
}
TLRPC.Chat chat = parentFragment.getCurrentChat();
if (ChatObject.isChannel(chat)) {
audioVideoButtonContainer.setAlpha(chat.banned_rights == null || !chat.banned_rights.send_media ? 1.0f : 0.5f);
if (emojiView != null) {
emojiView.setStickersBanned(chat.banned_rights != null && chat.banned_rights.send_stickers, chat.id);
}
}
}
2015-06-29 19:12:11 +02:00
public void onPause() {
isPaused = true;
2015-11-26 22:04:02 +01:00
closeKeyboard();
2015-06-29 19:12:11 +02:00
}
public void onResume() {
isPaused = false;
if (showKeyboardOnResume) {
showKeyboardOnResume = false;
2018-07-30 04:07:02 +02:00
if (!searchingStickers) {
messageEditText.requestFocus();
}
2015-06-29 19:12:11 +02:00
AndroidUtilities.showKeyboard(messageEditText);
2016-10-11 13:57:01 +02:00
if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow) {
2015-06-29 19:12:11 +02:00
waitingForKeyboardOpen = true;
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
2015-05-21 23:27:27 +02:00
}
}
}
2018-07-30 04:07:02 +02:00
public void setDialogId(long id, int account) {
dialog_id = id;
2018-07-30 04:07:02 +02:00
if (currentAccount != account) {
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStarted);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStartError);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordStopped);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recordProgressChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.audioDidSent);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.audioRouteChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.messagePlayingDidReset);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.featuredStickersDidLoaded);
currentAccount = account;
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStarted);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStartError);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordStopped);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recordProgressChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.audioDidSent);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.audioRouteChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.featuredStickersDidLoaded);
}
2017-07-08 18:32:04 +02:00
int lower_id = (int) dialog_id;
int high_id = (int) (dialog_id >> 32);
2015-09-24 22:52:02 +02:00
if ((int) dialog_id < 0) {
2018-07-30 04:07:02 +02:00
TLRPC.Chat currentChat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
silent = MessagesController.getNotificationsSettings(currentAccount).getBoolean("silent_" + dialog_id, false);
2017-07-08 18:32:04 +02:00
canWriteToChannel = ChatObject.isChannel(currentChat) && (currentChat.creator || currentChat.admin_rights != null && currentChat.admin_rights.post_messages) && !currentChat.megagroup;
2016-03-06 02:49:31 +01:00
if (notifyButton != null) {
notifyButton.setVisibility(canWriteToChannel ? VISIBLE : GONE);
notifyButton.setImageResource(silent ? R.drawable.notify_members_off : R.drawable.notify_members_on);
2017-03-31 01:58:05 +02:00
attachLayout.setPivotX(AndroidUtilities.dp((botButton == null || botButton.getVisibility() == GONE) && (notifyButton == null || notifyButton.getVisibility() == GONE) ? 48 : 96));
2016-03-06 02:49:31 +01:00
}
2017-03-31 01:58:05 +02:00
if (attachLayout != null) {
updateFieldRight(attachLayout.getVisibility() == VISIBLE ? 1 : 0);
2016-05-25 23:49:47 +02:00
}
2015-09-24 22:52:02 +02:00
}
2017-07-08 18:32:04 +02:00
checkRoundVideo();
2016-10-11 13:57:01 +02:00
updateFieldHint();
2015-09-24 22:52:02 +02:00
}
2017-12-08 18:35:59 +01:00
public void setChatInfo(TLRPC.ChatFull chatInfo) {
info = chatInfo;
if (emojiView != null) {
emojiView.setChatInfo(info);
}
}
2017-07-08 18:32:04 +02:00
public void checkRoundVideo() {
if (hasRecordVideo) {
return;
}
if (attachLayout == null || Build.VERSION.SDK_INT < 18) {
hasRecordVideo = false;
setRecordVideoButtonVisible(false, false);
return;
}
int lower_id = (int) dialog_id;
int high_id = (int) (dialog_id >> 32);
if (lower_id == 0 && high_id != 0) {
2018-07-30 04:07:02 +02:00
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(high_id);
2017-07-08 18:32:04 +02:00
if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 66) {
hasRecordVideo = true;
}
} else {
hasRecordVideo = true;
}
boolean isChannel = false;
if ((int) dialog_id < 0) {
2018-07-30 04:07:02 +02:00
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
2017-07-08 18:32:04 +02:00
isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
if (isChannel && !chat.creator && (chat.admin_rights == null || !chat.admin_rights.post_messages)) {
hasRecordVideo = false;
}
}
2018-07-30 04:07:02 +02:00
if (!SharedConfig.inappCamera) {
2017-12-08 18:35:59 +01:00
hasRecordVideo = false;
}
2017-07-08 18:32:04 +02:00
if (hasRecordVideo) {
2018-07-30 04:07:02 +02:00
if (SharedConfig.hasCameraCache) {
CameraController.getInstance().initCamera(null);
}
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
2017-07-08 18:32:04 +02:00
boolean currentModeVideo = preferences.getBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", isChannel);
setRecordVideoButtonVisible(currentModeVideo, false);
} else {
setRecordVideoButtonVisible(false, false);
}
}
public boolean isInVideoMode() {
return videoSendButton.getTag() != null;
}
public boolean hasRecordVideo() {
return hasRecordVideo;
}
2015-09-24 22:52:02 +02:00
private void updateFieldHint() {
boolean isChannel = false;
2015-11-26 22:04:02 +01:00
if ((int) dialog_id < 0) {
2018-07-30 04:07:02 +02:00
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-(int) dialog_id);
2015-11-26 22:04:02 +01:00
isChannel = ChatObject.isChannel(chat) && !chat.megagroup;
2015-09-24 22:52:02 +02:00
}
2018-07-30 04:07:02 +02:00
if (editingMessageObject != null) {
messageEditText.setHintText(editingCaption ? LocaleController.getString("Caption", R.string.Caption) : LocaleController.getString("TypeMessage", R.string.TypeMessage));
} else if (isChannel) {
if (silent) {
messageEditText.setHintText(LocaleController.getString("ChannelSilentBroadcast", R.string.ChannelSilentBroadcast));
2016-03-06 02:49:31 +01:00
} else {
2018-07-30 04:07:02 +02:00
messageEditText.setHintText(LocaleController.getString("ChannelBroadcast", R.string.ChannelBroadcast));
2016-03-06 02:49:31 +01:00
}
2015-09-24 22:52:02 +02:00
} else {
2017-07-08 18:32:04 +02:00
messageEditText.setHintText(LocaleController.getString("TypeMessage", R.string.TypeMessage));
2015-09-24 22:52:02 +02:00
}
}
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;
}
2018-07-30 04:07:02 +02:00
MediaController.getInstance().setReplyingMessage(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;
}
2016-03-06 02:49:31 +01:00
private void hideRecordedAudioPanel() {
audioToSendPath = null;
audioToSend = null;
audioToSendMessageObject = null;
2017-07-08 18:32:04 +02:00
videoToSendMessageObject = null;
videoTimelineView.destroy();
AnimatorSet AnimatorSet = new AnimatorSet();
AnimatorSet.playTogether(
ObjectAnimator.ofFloat(recordedAudioPanel, "alpha", 0.0f)
2016-03-06 02:49:31 +01:00
);
AnimatorSet.setDuration(200);
2017-03-31 01:58:05 +02:00
AnimatorSet.addListener(new AnimatorListenerAdapter() {
2016-03-06 02:49:31 +01:00
@Override
public void onAnimationEnd(Animator animation) {
2016-04-22 15:49:00 +02:00
recordedAudioPanel.setVisibility(GONE);
2016-03-06 02:49:31 +01:00
}
});
AnimatorSet.start();
2016-03-06 02:49:31 +01:00
}
private void sendMessage() {
2017-07-08 18:32:04 +02:00
if (videoToSendMessageObject != null) {
delegate.needStartRecordVideo(4);
hideRecordedAudioPanel();
checkSendButton(true);
return;
} else if (audioToSend != null) {
2016-03-06 02:49:31 +01:00
MessageObject playing = MediaController.getInstance().getPlayingMessageObject();
if (playing != null && playing == audioToSendMessageObject) {
MediaController.getInstance().cleanupPlayer(true, true);
}
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendMessage(audioToSend, null, audioToSendPath, dialog_id, replyingMessageObject, null, null, null, null, 0);
2016-03-06 02:49:31 +01:00
if (delegate != null) {
delegate.onMessageSend(null);
}
hideRecordedAudioPanel();
checkSendButton(true);
return;
}
2016-05-25 23:49:47 +02:00
CharSequence message = messageEditText.getText();
2015-03-26 18:34:47 +01:00
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);
}
}
}
2016-03-06 02:49:31 +01:00
public void doneEditingMessage() {
if (editingMessageObject != null) {
2016-05-25 23:49:47 +02:00
delegate.onMessageEditEnd(true);
2017-03-31 01:58:05 +02:00
showEditDoneProgress(true, true);
CharSequence[] message = new CharSequence[]{messageEditText.getText()};
2018-07-30 04:07:02 +02:00
ArrayList<TLRPC.MessageEntity> entities = DataQuery.getInstance(currentAccount).getEntities(message);
editingMessageReqId = SendMessagesHelper.getInstance(currentAccount).editMessage(editingMessageObject, message[0].toString(), messageWebPageSearch, parentFragment, entities, new Runnable() {
2016-05-25 23:49:47 +02:00
@Override
public void run() {
editingMessageReqId = 0;
setEditingMessageObject(null, false);
}
});
2016-03-06 02:49:31 +01:00
}
}
2016-05-25 23:49:47 +02:00
public boolean processSendingText(CharSequence text) {
text = AndroidUtilities.getTrimmedString(text);
2018-07-30 04:07:02 +02:00
int maxLength = MessagesController.getInstance(currentAccount).maxMessageLength;
if (text.length() != 0) {
2018-07-30 04:07:02 +02:00
int count = (int) Math.ceil(text.length() / (float) maxLength);
for (int a = 0; a < count; a++) {
2018-07-30 04:07:02 +02:00
CharSequence[] message = new CharSequence[]{text.subSequence(a * maxLength, Math.min((a + 1) * maxLength, text.length()))};
ArrayList<TLRPC.MessageEntity> entities = DataQuery.getInstance(currentAccount).getEntities(message);
SendMessagesHelper.getInstance(currentAccount).sendMessage(message[0].toString(), dialog_id, replyingMessageObject, messageWebPage, messageWebPageSearch, entities, null, null);
}
return true;
}
return false;
}
private void checkSendButton(boolean animated) {
2016-03-06 02:49:31 +01:00
if (editingMessageObject != null) {
return;
}
if (isPaused) {
animated = false;
}
CharSequence message = AndroidUtilities.getTrimmedString(messageEditText.getText());
2017-07-08 18:32:04 +02:00
if (message.length() > 0 || forceShowSendButton || audioToSend != null || videoToSendMessageObject != null) {
2017-03-31 01:58:05 +02:00
final String caption = messageEditText.getCaption();
boolean showBotButton = caption != null && (sendButton.getVisibility() == VISIBLE || expandStickersButton.getVisibility() == VISIBLE);
boolean showSendButton = caption == null && (cancelBotButton.getVisibility() == VISIBLE || expandStickersButton.getVisibility() == VISIBLE);
2017-03-31 01:58:05 +02:00
if (audioVideoButtonContainer.getVisibility() == VISIBLE || showBotButton || showSendButton) {
2014-11-17 03:44:57 +01:00
if (animated) {
2017-03-31 01:58:05 +02:00
if (runningAnimationType == 1 && messageEditText.getCaption() == null || runningAnimationType == 3 && caption != null) {
2014-10-07 22:14:27 +02:00
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
2017-03-31 01:58:05 +02:00
if (attachLayout != null) {
runningAnimation2 = new AnimatorSet();
2014-11-17 03:44:57 +01:00
runningAnimation2.playTogether(
2017-03-31 01:58:05 +02:00
ObjectAnimator.ofFloat(attachLayout, "alpha", 0.0f),
ObjectAnimator.ofFloat(attachLayout, "scaleX", 0.0f)
2014-11-17 03:44:57 +01:00
);
runningAnimation2.setDuration(100);
2017-03-31 01:58:05 +02:00
runningAnimation2.addListener(new AnimatorListenerAdapter() {
2014-11-17 03:44:57 +01:00
@Override
public void onAnimationEnd(Animator animation) {
2016-04-22 15:49:00 +02:00
if (runningAnimation2 != null && runningAnimation2.equals(animation)) {
2017-03-31 01:58:05 +02:00
attachLayout.setVisibility(GONE);
2014-11-17 03:44:57 +01:00
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (runningAnimation2 != null && runningAnimation2.equals(animation)) {
runningAnimation2 = null;
}
}
2014-11-17 03:44:57 +01:00
});
runningAnimation2.start();
2015-07-22 20:56:37 +02:00
updateFieldRight(0);
2016-10-11 13:57:01 +02:00
if (delegate != null && getVisibility() == VISIBLE) {
2016-03-06 02:49:31 +01:00
delegate.onAttachButtonHidden();
}
2014-11-14 16:40:15 +01:00
}
2014-10-07 22:14:27 +02:00
runningAnimation = new AnimatorSet();
2014-11-17 03:44:57 +01:00
ArrayList<Animator> animators = new ArrayList<>();
2017-03-31 01:58:05 +02:00
if (audioVideoButtonContainer.getVisibility() == VISIBLE) {
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 0.0f));
2016-04-22 15:49:00 +02:00
}
if (expandStickersButton.getVisibility() == VISIBLE) {
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "alpha", 0.0f));
}
2016-04-22 15:49:00 +02:00
if (showBotButton) {
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 0.0f));
2016-04-22 15:49:00 +02:00
} else if (showSendButton) {
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 0.0f));
2016-04-22 15:49:00 +02:00
}
2017-03-31 01:58:05 +02:00
if (caption != null) {
2016-04-22 15:49:00 +02:00
runningAnimationType = 3;
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 1.0f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 1.0f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 1.0f));
2016-04-22 15:49:00 +02:00
cancelBotButton.setVisibility(VISIBLE);
} else {
runningAnimationType = 1;
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 1.0f));
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 1.0f));
animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 1.0f));
2016-04-22 15:49:00 +02:00
sendButton.setVisibility(VISIBLE);
}
runningAnimation.playTogether(animators);
2014-11-17 03:44:57 +01:00
runningAnimation.setDuration(150);
2017-03-31 01:58:05 +02:00
runningAnimation.addListener(new AnimatorListenerAdapter() {
2014-10-07 22:14:27 +02:00
@Override
public void onAnimationEnd(Animator animation) {
2015-10-29 18:10:07 +01:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
2017-03-31 01:58:05 +02:00
if (caption != null) {
2016-04-22 15:49:00 +02:00
cancelBotButton.setVisibility(VISIBLE);
sendButton.setVisibility(GONE);
} else {
sendButton.setVisibility(VISIBLE);
cancelBotButton.setVisibility(GONE);
}
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(GONE);
expandStickersButton.setVisibility(GONE);
2014-10-07 22:14:27 +02:00
runningAnimation = null;
runningAnimationType = 0;
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
runningAnimation = null;
}
}
2014-10-07 22:14:27 +02:00
});
2014-11-17 03:44:57 +01:00
runningAnimation.start();
2014-10-07 22:14:27 +02:00
} else {
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setScaleX(0.1f);
audioVideoButtonContainer.setScaleY(0.1f);
audioVideoButtonContainer.setAlpha(0.0f);
if (caption != null) {
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
cancelBotButton.setScaleX(1.0f);
cancelBotButton.setScaleY(1.0f);
cancelBotButton.setAlpha(1.0f);
2016-04-22 15:49:00 +02:00
cancelBotButton.setVisibility(VISIBLE);
sendButton.setVisibility(GONE);
} else {
cancelBotButton.setScaleX(0.1f);
cancelBotButton.setScaleY(0.1f);
cancelBotButton.setAlpha(0.0f);
sendButton.setScaleX(1.0f);
sendButton.setScaleY(1.0f);
sendButton.setAlpha(1.0f);
2016-04-22 15:49:00 +02:00
sendButton.setVisibility(VISIBLE);
cancelBotButton.setVisibility(GONE);
}
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(GONE);
if (attachLayout != null) {
attachLayout.setVisibility(GONE);
2016-10-11 13:57:01 +02:00
if (delegate != null && getVisibility() == VISIBLE) {
2016-03-06 02:49:31 +01:00
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 (emojiView != null && emojiView.getVisibility() == VISIBLE && stickersTabOpen && !AndroidUtilities.isInMultiwindow) {
if (animated) {
if (runningAnimationType == 4) {
return;
}
if (runningAnimation != null) {
runningAnimation.cancel();
runningAnimation = null;
}
if (runningAnimation2 != null) {
runningAnimation2.cancel();
runningAnimation2 = null;
}
if (attachLayout != null) {
attachLayout.setVisibility(VISIBLE);
runningAnimation2 = new AnimatorSet();
runningAnimation2.playTogether(
ObjectAnimator.ofFloat(attachLayout, "alpha", 1.0f),
ObjectAnimator.ofFloat(attachLayout, "scaleX", 1.0f)
);
runningAnimation2.setDuration(100);
runningAnimation2.start();
updateFieldRight(1);
if (getVisibility() == VISIBLE) {
delegate.onAttachButtonShow();
}
}
expandStickersButton.setVisibility(VISIBLE);
runningAnimation = new AnimatorSet();
runningAnimationType = 4;
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "scaleX", 1.0f));
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "scaleY", 1.0f));
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "alpha", 1.0f));
if (cancelBotButton.getVisibility() == VISIBLE) {
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 0.0f));
} else if (audioVideoButtonContainer.getVisibility() == VISIBLE) {
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 0.0f));
} else {
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 0.0f));
}
runningAnimation.playTogether(animators);
runningAnimation.setDuration(150);
runningAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (runningAnimation != null && runningAnimation.equals(animation)) {
sendButton.setVisibility(GONE);
cancelBotButton.setVisibility(GONE);
audioVideoButtonContainer.setVisibility(GONE);
expandStickersButton.setVisibility(VISIBLE);
runningAnimation = null;
runningAnimationType = 0;
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (runningAnimation != null && runningAnimation.equals(animation)) {
runningAnimation = null;
}
}
});
runningAnimation.start();
} else {
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
cancelBotButton.setScaleX(0.1f);
cancelBotButton.setScaleY(0.1f);
cancelBotButton.setAlpha(0.0f);
audioVideoButtonContainer.setScaleX(0.1f);
audioVideoButtonContainer.setScaleY(0.1f);
audioVideoButtonContainer.setAlpha(0.0f);
expandStickersButton.setScaleX(1.0f);
expandStickersButton.setScaleY(1.0f);
expandStickersButton.setAlpha(1.0f);
cancelBotButton.setVisibility(GONE);
sendButton.setVisibility(GONE);
audioVideoButtonContainer.setVisibility(GONE);
expandStickersButton.setVisibility(VISIBLE);
if (attachLayout != null) {
if (getVisibility() == VISIBLE) {
delegate.onAttachButtonShow();
}
attachLayout.setVisibility(VISIBLE);
updateFieldRight(1);
}
}
/*expandStickersButton.setAlpha(1f);
expandStickersButton.setScaleX(1);
expandStickersButton.setScaleY(1);
expandStickersButton.setVisibility(VISIBLE);
audioVideoButtonContainer.setVisibility(GONE);*/
} else if (sendButton.getVisibility() == VISIBLE || cancelBotButton.getVisibility() == VISIBLE || expandStickersButton.getVisibility() == 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
2017-03-31 01:58:05 +02:00
if (attachLayout != null) {
attachLayout.setVisibility(VISIBLE);
runningAnimation2 = new AnimatorSet();
2014-11-17 03:44:57 +01:00
runningAnimation2.playTogether(
2017-03-31 01:58:05 +02:00
ObjectAnimator.ofFloat(attachLayout, "alpha", 1.0f),
ObjectAnimator.ofFloat(attachLayout, "scaleX", 1.0f)
2014-11-17 03:44:57 +01:00
);
runningAnimation2.setDuration(100);
runningAnimation2.start();
2015-07-22 20:56:37 +02:00
updateFieldRight(1);
2016-10-11 13:57:01 +02:00
if (getVisibility() == VISIBLE) {
delegate.onAttachButtonShow();
}
2014-11-14 16:40:15 +01:00
}
2014-10-07 22:14:27 +02:00
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(VISIBLE);
runningAnimation = new AnimatorSet();
2014-11-17 03:44:57 +01:00
runningAnimationType = 2;
ArrayList<Animator> animators = new ArrayList<>();
2017-03-31 01:58:05 +02:00
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleX", 1.0f));
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "scaleY", 1.0f));
animators.add(ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 1.0f));
2016-04-22 15:49:00 +02:00
if (cancelBotButton.getVisibility() == VISIBLE) {
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(cancelBotButton, "alpha", 0.0f));
} else if (expandStickersButton.getVisibility() == VISIBLE) {
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(expandStickersButton, "alpha", 0.0f));
2016-04-22 15:49:00 +02:00
} else {
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleX", 0.1f));
animators.add(ObjectAnimator.ofFloat(sendButton, "scaleY", 0.1f));
animators.add(ObjectAnimator.ofFloat(sendButton, "alpha", 0.0f));
2016-04-22 15:49:00 +02:00
}
2014-11-17 03:44:57 +01:00
2016-04-22 15:49:00 +02:00
runningAnimation.playTogether(animators);
2014-11-17 03:44:57 +01:00
runningAnimation.setDuration(150);
2017-03-31 01:58:05 +02:00
runningAnimation.addListener(new AnimatorListenerAdapter() {
2014-10-07 22:14:27 +02:00
@Override
public void onAnimationEnd(Animator animation) {
2015-10-29 18:10:07 +01:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
2016-04-22 15:49:00 +02:00
sendButton.setVisibility(GONE);
cancelBotButton.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(VISIBLE);
2014-10-07 22:14:27 +02:00
runningAnimation = null;
runningAnimationType = 0;
}
}
2016-04-22 15:49:00 +02:00
@Override
public void onAnimationCancel(Animator animation) {
2016-04-22 15:49:00 +02:00
if (runningAnimation != null && runningAnimation.equals(animation)) {
runningAnimation = null;
}
}
2014-10-07 22:14:27 +02:00
});
2014-11-17 03:44:57 +01:00
runningAnimation.start();
2014-10-07 22:14:27 +02:00
} else {
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
cancelBotButton.setScaleX(0.1f);
cancelBotButton.setScaleY(0.1f);
cancelBotButton.setAlpha(0.0f);
expandStickersButton.setScaleX(0.1f);
expandStickersButton.setScaleY(0.1f);
expandStickersButton.setAlpha(0.0f);
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setScaleX(1.0f);
audioVideoButtonContainer.setScaleY(1.0f);
audioVideoButtonContainer.setAlpha(1.0f);
2016-04-22 15:49:00 +02:00
cancelBotButton.setVisibility(GONE);
sendButton.setVisibility(GONE);
expandStickersButton.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(VISIBLE);
if (attachLayout != null) {
2016-10-11 13:57:01 +02:00
if (getVisibility() == VISIBLE) {
delegate.onAttachButtonShow();
}
2017-03-31 01:58:05 +02:00
attachLayout.setVisibility(VISIBLE);
2015-07-22 20:56:37 +02:00
updateFieldRight(1);
}
}
}
}
private void updateFieldRight(int attachVisible) {
2016-03-06 02:49:31 +01:00
if (messageEditText == null || editingMessageObject != null) {
2015-07-22 20:56:37 +02:00
return;
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
if (attachVisible == 1) {
2016-03-06 02:49:31 +01:00
if (botButton != null && botButton.getVisibility() == VISIBLE || notifyButton != null && notifyButton.getVisibility() == VISIBLE) {
2015-07-22 20:56:37 +02:00
layoutParams.rightMargin = AndroidUtilities.dp(98);
} else {
layoutParams.rightMargin = AndroidUtilities.dp(50);
}
} else if (attachVisible == 2) {
if (layoutParams.rightMargin != AndroidUtilities.dp(2)) {
2016-03-06 02:49:31 +01:00
if (botButton != null && botButton.getVisibility() == VISIBLE || notifyButton != null && notifyButton.getVisibility() == VISIBLE) {
2015-07-22 20:56:37 +02:00
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);
}
2017-03-31 01:58:05 +02:00
private void updateRecordIntefrace() {
if (recordingAudioVideo) {
if (recordInterfaceState == 1) {
2014-11-17 23:04:31 +01:00
return;
}
2017-03-31 01:58:05 +02:00
recordInterfaceState = 1;
try {
2017-03-31 01:58:05 +02:00
if (wakeLock == null) {
PowerManager pm = (PowerManager) ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
2017-03-31 01:58:05 +02:00
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
wakeLock.acquire();
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
AndroidUtilities.lockOrientation(parentActivity);
2018-07-30 04:07:02 +02:00
if (delegate != null) {
delegate.needStartRecordAudio(0);
}
2015-10-29 18:10:07 +01:00
recordPanel.setVisibility(VISIBLE);
recordCircle.setVisibility(VISIBLE);
recordCircle.setAmplitude(0);
2017-12-08 18:35:59 +01:00
recordTimeText.setText(String.format("%02d:%02d.%02d", 0, 0, 0));
2015-10-29 18:10:07 +01:00
recordDot.resetAlpha();
lastTimeString = null;
2017-07-08 18:32:04 +02:00
lastTypingSendTime = -1;
2014-11-17 03:44:57 +01:00
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) slideText.getLayoutParams();
params.leftMargin = AndroidUtilities.dp(30);
slideText.setLayoutParams(params);
slideText.setAlpha(1);
recordPanel.setX(AndroidUtilities.displaySize.x);
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null) {
runningAnimationAudio.cancel();
}
runningAnimationAudio = new AnimatorSet();
runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(recordPanel, "translationX", 0),
ObjectAnimator.ofFloat(recordCircle, "scale", 1),
2017-03-31 01:58:05 +02:00
ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 0));
2015-10-29 18:10:07 +01:00
runningAnimationAudio.setDuration(300);
2017-03-31 01:58:05 +02:00
runningAnimationAudio.addListener(new AnimatorListenerAdapter() {
2014-11-17 03:44:57 +01:00
@Override
public void onAnimationEnd(Animator animator) {
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null && runningAnimationAudio.equals(animator)) {
recordPanel.setX(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 {
2017-03-31 01:58:05 +02:00
if (wakeLock != null) {
try {
2017-03-31 01:58:05 +02:00
wakeLock.release();
wakeLock = null;
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
AndroidUtilities.unlockOrientation(parentActivity);
2017-03-31 01:58:05 +02:00
if (recordInterfaceState == 0) {
2014-11-17 23:04:31 +01:00
return;
}
2017-03-31 01:58:05 +02:00
recordInterfaceState = 0;
2014-11-17 23:04:31 +01:00
if (runningAnimationAudio != null) {
runningAnimationAudio.cancel();
}
runningAnimationAudio = new AnimatorSet();
runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(recordPanel, "translationX", AndroidUtilities.displaySize.x),
ObjectAnimator.ofFloat(recordCircle, "scale", 0.0f),
2017-03-31 01:58:05 +02:00
ObjectAnimator.ofFloat(audioVideoButtonContainer, "alpha", 1.0f));
2015-10-29 18:10:07 +01:00
runningAnimationAudio.setDuration(300);
2017-03-31 01:58:05 +02:00
runningAnimationAudio.addListener(new AnimatorListenerAdapter() {
2014-11-17 03:44:57 +01:00
@Override
public void onAnimationEnd(Animator 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);
slideText.setAlpha(1);
2016-04-22 15:49:00 +02:00
recordPanel.setVisibility(GONE);
recordCircle.setVisibility(GONE);
2017-07-08 18:32:04 +02:00
recordCircle.setSendButtonInvisible();
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 AccelerateInterpolator());
2014-11-17 23:04:31 +01:00
runningAnimationAudio.start();
}
}
2017-07-08 18:32:04 +02:00
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (recordingAudioVideo) {
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onInterceptTouchEvent(ev);
}
public void setDelegate(ChatActivityEnterViewDelegate chatActivityEnterViewDelegate) {
delegate = chatActivityEnterViewDelegate;
2015-06-29 19:12:11 +02:00
}
2015-11-26 22:04:02 +01:00
public void setCommand(MessageObject messageObject, String command, boolean longPress, boolean username) {
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();
2018-07-30 04:07:02 +02:00
TLRPC.User user = messageObject != null && (int) dialog_id < 0 ? MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.from_id) : null;
2015-11-26 22:04:02 +01:00
if ((botCount != 1 || username) && user != null && user.bot && !command.contains("@")) {
text = String.format(Locale.US, "%s@%s", command, user.username) + " " + text.replaceFirst("^/[a-zA-Z@\\d_]{1,255}(\\s|$)", "");
} else {
text = command + " " + text.replaceFirst("^/[a-zA-Z@\\d_]{1,255}(\\s|$)", "");
}
2015-10-29 18:10:07 +01:00
ignoreTextChange = true;
messageEditText.setText(text);
messageEditText.setSelection(messageEditText.getText().length());
ignoreTextChange = false;
2016-03-06 02:49:31 +01:00
if (delegate != null) {
delegate.onTextChanged(messageEditText.getText(), true);
}
2015-10-29 18:10:07 +01:00
if (!keyboardVisible && currentPopupContentType == -1) {
openKeyboard();
}
2015-06-29 19:12:11 +02:00
} else {
2018-07-30 04:07:02 +02:00
TLRPC.User user = messageObject != null && (int) dialog_id < 0 ? MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.from_id) : null;
2015-11-26 22:04:02 +01:00
if ((botCount != 1 || username) && user != null && user.bot && !command.contains("@")) {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendMessage(String.format(Locale.US, "%s@%s", command, user.username), dialog_id, replyingMessageObject, null, false, null, null, null);
2015-10-29 18:10:07 +01:00
} else {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendMessage(command, dialog_id, replyingMessageObject, null, false, null, null, null);
2015-10-29 18:10:07 +01:00
}
}
}
2016-05-25 23:49:47 +02:00
public void setEditingMessageObject(MessageObject messageObject, boolean caption) {
2017-07-08 18:32:04 +02:00
if (audioToSend != null || videoToSendMessageObject != null || editingMessageObject == messageObject) {
2016-03-06 02:49:31 +01:00
return;
}
2016-05-25 23:49:47 +02:00
if (editingMessageReqId != 0) {
2018-07-30 04:07:02 +02:00
ConnectionsManager.getInstance(currentAccount).cancelRequest(editingMessageReqId, true);
2016-05-25 23:49:47 +02:00
editingMessageReqId = 0;
}
2016-03-06 02:49:31 +01:00
editingMessageObject = messageObject;
editingCaption = caption;
if (editingMessageObject != null) {
2017-03-31 01:58:05 +02:00
if (doneButtonAnimation != null) {
doneButtonAnimation.cancel();
doneButtonAnimation = null;
}
doneButtonContainer.setVisibility(View.VISIBLE);
showEditDoneProgress(true, false);
2016-03-06 02:49:31 +01:00
InputFilter[] inputFilters = new InputFilter[1];
2018-07-30 04:07:02 +02:00
CharSequence editingText;
2016-03-06 02:49:31 +01:00
if (caption) {
2018-07-30 04:07:02 +02:00
inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(currentAccount).maxCaptionLength);
editingText = editingMessageObject.caption;
2016-03-06 02:49:31 +01:00
} else {
2018-07-30 04:07:02 +02:00
inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(currentAccount).maxMessageLength);
editingText = editingMessageObject.messageText;
}
if (editingText != null) {
ArrayList<TLRPC.MessageEntity> entities = editingMessageObject.messageOwner.entities;//MessagesQuery.getEntities(message);
DataQuery.sortEntities(entities);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(editingText);
Object spansToRemove[] = stringBuilder.getSpans(0, stringBuilder.length(), Object.class);
if (spansToRemove != null && spansToRemove.length > 0) {
for (int a = 0; a < spansToRemove.length; a++) {
stringBuilder.removeSpan(spansToRemove[a]);
2017-03-31 01:58:05 +02:00
}
2018-07-30 04:07:02 +02:00
}
if (entities != null) {
int addToOffset = 0;
try {
for (int a = 0; a < entities.size(); a++) {
TLRPC.MessageEntity entity = entities.get(a);
if (entity.offset + entity.length + addToOffset > stringBuilder.length()) {
continue;
}
if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
if (entity.offset + entity.length + addToOffset < stringBuilder.length() && stringBuilder.charAt(entity.offset + entity.length + addToOffset) == ' ') {
entity.length++;
2017-03-31 01:58:05 +02:00
}
2018-07-30 04:07:02 +02:00
stringBuilder.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) entity).user_id.user_id, 1), entity.offset + addToOffset, entity.offset + entity.length + addToOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityMentionName) {
if (entity.offset + entity.length + addToOffset < stringBuilder.length() && stringBuilder.charAt(entity.offset + entity.length + addToOffset) == ' ') {
entity.length++;
2016-10-11 13:57:01 +02:00
}
2018-07-30 04:07:02 +02:00
stringBuilder.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_messageEntityMentionName) entity).user_id, 1), entity.offset + addToOffset, entity.offset + entity.length + addToOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityCode) {
stringBuilder.insert(entity.offset + entity.length + addToOffset, "`");
stringBuilder.insert(entity.offset + addToOffset, "`");
addToOffset += 2;
} else if (entity instanceof TLRPC.TL_messageEntityPre) {
stringBuilder.insert(entity.offset + entity.length + addToOffset, "```");
stringBuilder.insert(entity.offset + addToOffset, "```");
addToOffset += 6;
} else if (entity instanceof TLRPC.TL_messageEntityBold) {
stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), entity.offset + addToOffset, entity.offset + entity.length + addToOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityItalic) {
stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/ritalic.ttf")), entity.offset + addToOffset, entity.offset + entity.length + addToOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (entity instanceof TLRPC.TL_messageEntityTextUrl) {
stringBuilder.setSpan(new URLSpanReplacement(entity.url), entity.offset + addToOffset, entity.offset + entity.length + addToOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2016-05-25 23:49:47 +02:00
}
}
2018-07-30 04:07:02 +02:00
} catch (Exception e) {
FileLog.e(e);
2016-05-25 23:49:47 +02:00
}
2016-03-06 02:49:31 +01:00
}
2018-07-30 04:07:02 +02:00
setFieldText(Emoji.replaceEmoji(new SpannableStringBuilder(stringBuilder), messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false));
} else {
setFieldText("");
2016-03-06 02:49:31 +01:00
}
messageEditText.setFilters(inputFilters);
openKeyboard();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(4);
messageEditText.setLayoutParams(layoutParams);
sendButton.setVisibility(GONE);
2016-04-22 15:49:00 +02:00
cancelBotButton.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(GONE);
attachLayout.setVisibility(GONE);
2016-03-06 02:49:31 +01:00
sendButtonContainer.setVisibility(GONE);
} else {
2017-03-31 01:58:05 +02:00
doneButtonContainer.setVisibility(View.GONE);
2016-03-06 02:49:31 +01:00
messageEditText.setFilters(new InputFilter[0]);
2016-05-25 23:49:47 +02:00
delegate.onMessageEditEnd(false);
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setVisibility(VISIBLE);
attachLayout.setVisibility(VISIBLE);
2016-03-06 02:49:31 +01:00
sendButtonContainer.setVisibility(VISIBLE);
2017-03-31 01:58:05 +02:00
attachLayout.setScaleX(1.0f);
attachLayout.setAlpha(1.0f);
sendButton.setScaleX(0.1f);
sendButton.setScaleY(0.1f);
sendButton.setAlpha(0.0f);
cancelBotButton.setScaleX(0.1f);
cancelBotButton.setScaleY(0.1f);
cancelBotButton.setAlpha(0.0f);
2017-03-31 01:58:05 +02:00
audioVideoButtonContainer.setScaleX(1.0f);
audioVideoButtonContainer.setScaleY(1.0f);
audioVideoButtonContainer.setAlpha(1.0f);
2016-04-22 15:49:00 +02:00
sendButton.setVisibility(GONE);
cancelBotButton.setVisibility(GONE);
2016-03-06 02:49:31 +01:00
messageEditText.setText("");
2016-10-11 13:57:01 +02:00
if (getVisibility() == VISIBLE) {
delegate.onAttachButtonShow();
}
2016-03-06 02:49:31 +01:00
updateFieldRight(1);
}
updateFieldHint();
}
2017-03-31 01:58:05 +02:00
public ImageView getAttachButton() {
return attachButton;
}
public ImageView getBotButton() {
return botButton;
}
public ImageView getEmojiButton() {
return emojiButton;
}
public ImageView getSendButton() {
return sendButton;
}
public EmojiView getEmojiView() {
return emojiView;
}
2016-03-06 02:49:31 +01:00
public void setFieldText(CharSequence 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();
}
2017-03-31 01:58:05 +02:00
public int getSelectionLength() {
if (messageEditText == null) {
return 0;
}
try {
return messageEditText.getSelectionEnd() - messageEditText.getSelectionStart();
} catch (Exception e) {
FileLog.e(e);
}
return 0;
}
2017-12-08 18:35:59 +01:00
public void replaceWithText(int start, int len, CharSequence text, boolean parseEmoji) {
try {
2016-05-25 23:49:47 +02:00
SpannableStringBuilder builder = new SpannableStringBuilder(messageEditText.getText());
builder.replace(start, start + len, text);
2017-12-08 18:35:59 +01:00
if (parseEmoji) {
Emoji.replaceEmoji(builder, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
}
2015-03-26 18:34:47 +01:00
messageEditText.setText(builder);
messageEditText.setSelection(start + text.length());
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
public void setFieldFocused() {
if (messageEditText != null) {
try {
messageEditText.requestFocus();
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
}
}
public void setFieldFocused(boolean focus) {
2015-03-26 18:34:47 +01:00
if (messageEditText == null) {
return;
}
if (focus) {
2018-07-30 04:07:02 +02:00
if (!searchingStickers && !messageEditText.isFocused()) {
2015-03-26 18:34:47 +01:00
messageEditText.postDelayed(new Runnable() {
@Override
public void run() {
2018-07-30 04:07:02 +02:00
boolean allowFocus;
if (AndroidUtilities.isTablet()) {
if (parentActivity instanceof LaunchActivity) {
LaunchActivity launchActivity = (LaunchActivity) parentActivity;
if (launchActivity != null) {
View layout = launchActivity.getLayersActionBarLayout();
allowFocus = layout == null || layout.getVisibility() != View.VISIBLE;
} else {
allowFocus = true;
}
} else {
allowFocus = true;
}
} else {
allowFocus = true;
}
if (allowFocus && 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) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2014-10-01 21:55:24 +02:00
}
}
}
}, 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;
}
2018-07-30 04:07:02 +02:00
public EditTextCaption getEditField() {
return messageEditText;
}
public CharSequence getFieldText() {
2015-03-26 18:34:47 +01:00
if (messageEditText != null && messageEditText.length() > 0) {
return messageEditText.getText();
}
return null;
}
2015-06-29 19:12:11 +02:00
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);
2017-03-31 01:58:05 +02:00
attachLayout.setPivotX(AndroidUtilities.dp((botButton == null || botButton.getVisibility() == GONE) && (notifyButton == null || notifyButton.getVisibility() == GONE) ? 48 : 96));
2015-06-29 19:12:11 +02:00
}
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
2016-04-22 15:49:00 +02:00
public void didPressedButton(TLRPC.KeyboardButton button) {
2015-06-29 19:12:11 +02:00
MessageObject object = replyingMessageObject != null ? replyingMessageObject : ((int) dialog_id < 0 ? botButtonsMessageObject : null);
2016-04-22 15:49:00 +02:00
didPressedBotButton(button, object, replyingMessageObject != null ? replyingMessageObject : botButtonsMessageObject);
2015-06-29 19:12:11 +02:00
if (replyingMessageObject != null) {
openKeyboardInternal();
setButtons(botMessageObject, false);
2015-11-26 22:04:02 +01:00
} else if (botButtonsMessageObject.messageOwner.reply_markup.single_use) {
2015-06-29 19:12:11 +02:00
openKeyboardInternal();
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
2015-06-29 19:12:11 +02:00
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);
2017-12-08 18:35:59 +01:00
botKeyboardView.setButtons(botReplyMarkup);
2015-06-29 19:12:11 +02:00
if (botReplyMarkup != null) {
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
2015-09-02 00:14:21 +02:00
boolean keyboardHidden = preferences.getInt("hidekeyboard_" + dialog_id, 0) == messageObject.getId();
2015-11-26 22:04:02 +01:00
if (botButtonsMessageObject != replyingMessageObject && botReplyMarkup.single_use) {
2015-06-29 19:12:11 +02:00
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();
}
2016-04-22 15:49:00 +02:00
public void didPressedBotButton(final TLRPC.KeyboardButton button, final MessageObject replyMessageObject, final MessageObject messageObject) {
if (button == null || messageObject == null) {
return;
}
if (button instanceof TLRPC.TL_keyboardButton) {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendMessage(button.text, dialog_id, replyMessageObject, null, false, null, null, null);
2016-04-22 15:49:00 +02:00
} else if (button instanceof TLRPC.TL_keyboardButtonUrl) {
2016-10-11 13:57:01 +02:00
parentFragment.showOpenUrlAlert(button.url, true);
2016-04-22 15:49:00 +02:00
} else if (button instanceof TLRPC.TL_keyboardButtonRequestPhone) {
parentFragment.shareMyContact(messageObject);
} else if (button instanceof TLRPC.TL_keyboardButtonRequestGeoLocation) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("ShareYouLocationTitle", R.string.ShareYouLocationTitle));
builder.setMessage(LocaleController.getString("ShareYouLocationInfo", R.string.ShareYouLocationInfo));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
parentActivity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 2);
pendingMessageObject = messageObject;
pendingLocationButton = button;
return;
}
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendCurrentLocation(messageObject, button);
2016-04-22 15:49:00 +02:00
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
parentFragment.showDialog(builder.create());
2017-03-31 01:58:05 +02:00
} else if (button instanceof TLRPC.TL_keyboardButtonCallback || button instanceof TLRPC.TL_keyboardButtonGame || button instanceof TLRPC.TL_keyboardButtonBuy) {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendCallback(true, messageObject, button, parentFragment);
2016-04-22 15:49:00 +02:00
} else if (button instanceof TLRPC.TL_keyboardButtonSwitchInline) {
if (parentFragment.processSwitchButton((TLRPC.TL_keyboardButtonSwitchInline) button)) {
return;
}
2016-10-11 13:57:01 +02:00
if (button.same_peer) {
int uid = messageObject.messageOwner.from_id;
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
2018-07-30 04:07:02 +02:00
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(uid);
2016-10-11 13:57:01 +02:00
if (user == null) {
return;
}
setFieldText("@" + user.username + " " + button.query);
} else {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 1);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
@Override
2017-12-08 18:35:59 +01:00
public void didSelectDialogs(DialogsActivity fragment, ArrayList<Long> dids, CharSequence message, boolean param) {
2016-10-11 13:57:01 +02:00
int uid = messageObject.messageOwner.from_id;
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
2018-07-30 04:07:02 +02:00
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(uid);
2016-10-11 13:57:01 +02:00
if (user == null) {
fragment.finishFragment();
return;
}
2017-12-08 18:35:59 +01:00
long did = dids.get(0);
2018-07-30 04:07:02 +02:00
DataQuery.getInstance(currentAccount).saveDraft(did, "@" + user.username + " " + button.query, null, null, true);
2016-10-11 13:57:01 +02:00
if (did != dialog_id) {
int lower_part = (int) did;
if (lower_part != 0) {
Bundle args = new Bundle();
if (lower_part > 0) {
args.putInt("user_id", lower_part);
} else if (lower_part < 0) {
args.putInt("chat_id", -lower_part);
}
2018-07-30 04:07:02 +02:00
if (!MessagesController.getInstance(currentAccount).checkCanOpenChat(args, fragment)) {
2016-10-11 13:57:01 +02:00
return;
}
ChatActivity chatActivity = new ChatActivity(args);
if (parentFragment.presentFragment(chatActivity, true)) {
if (!AndroidUtilities.isTablet()) {
parentFragment.removeSelfFromStack();
}
} else {
fragment.finishFragment();
2016-04-22 15:49:00 +02:00
}
} else {
fragment.finishFragment();
}
} else {
fragment.finishFragment();
}
}
2016-10-11 13:57:01 +02:00
});
parentFragment.presentFragment(fragment);
}
2016-04-22 15:49:00 +02:00
}
}
2015-06-29 19:12:11 +02:00
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;
}
private void createEmojiView() {
if (emojiView != null) {
return;
}
2017-12-08 18:35:59 +01:00
emojiView = new EmojiView(allowStickers, allowGifs, parentActivity, info);
emojiView.setVisibility(GONE);
emojiView.setListener(new EmojiView.Listener() {
2018-07-30 04:07:02 +02:00
@Override
public boolean onBackspace() {
if (messageEditText.length() == 0) {
return false;
2015-06-29 19:12:11 +02:00
}
messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
return true;
}
2015-06-29 19:12:11 +02:00
2018-07-30 04:07:02 +02:00
@Override
public void onEmojiSelected(String symbol) {
int i = messageEditText.getSelectionEnd();
if (i < 0) {
i = 0;
}
try {
innerTextChange = 2;
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messageEditText.setSelection(j, j);
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
} finally {
innerTextChange = 0;
}
}
2015-06-29 19:12:11 +02:00
2018-07-30 04:07:02 +02:00
@Override
public void onStickerSelected(TLRPC.Document sticker) {
2017-12-08 18:35:59 +01:00
if (stickersExpanded) {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(true, MessageObject.getStickerSetId(sticker));
emojiView.hideSearchKeyboard();
}
setStickersExpanded(false, true);
2017-12-08 18:35:59 +01:00
}
2016-04-22 15:49:00 +02:00
ChatActivityEnterView.this.onStickerSelected(sticker);
2018-07-30 04:07:02 +02:00
DataQuery.getInstance(currentAccount).addRecentSticker(DataQuery.TYPE_IMAGE, sticker, (int) (System.currentTimeMillis() / 1000), false);
2016-10-11 13:57:01 +02:00
if ((int) dialog_id == 0) {
2018-07-30 04:07:02 +02:00
MessagesController.getInstance(currentAccount).saveGif(sticker);
2016-10-11 13:57:01 +02:00
}
}
2015-12-09 19:27:52 +01:00
@Override
public void onStickersSettingsClick() {
if (parentFragment != null) {
2018-07-30 04:07:02 +02:00
parentFragment.presentFragment(new StickersActivity(DataQuery.TYPE_IMAGE));
}
}
@Override
public void onGifSelected(TLRPC.Document gif) {
2017-12-08 18:35:59 +01:00
if (stickersExpanded) {
setStickersExpanded(false, true);
}
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendSticker(gif, dialog_id, replyingMessageObject);
DataQuery.getInstance(currentAccount).addRecentGif(gif, (int) (System.currentTimeMillis() / 1000));
2016-03-16 13:26:32 +01:00
if ((int) dialog_id == 0) {
2018-07-30 04:07:02 +02:00
MessagesController.getInstance(currentAccount).saveGif(gif);
2016-03-16 13:26:32 +01:00
}
if (delegate != null) {
delegate.onMessageSend(null);
}
}
@Override
public void onGifTab(boolean opened) {
post(updateExpandabilityRunnable);
if (!AndroidUtilities.usingHardwareInput) {
if (opened) {
if (messageEditText.length() == 0) {
messageEditText.setText("@gif ");
messageEditText.setSelection(messageEditText.length());
2015-12-09 19:27:52 +01:00
}
} else if (messageEditText.getText().toString().equals("@gif ")) {
messageEditText.setText("");
2015-12-09 19:27:52 +01:00
}
}
}
@Override
public void onStickersTab(boolean opened) {
delegate.onStickersTab(opened);
post(updateExpandabilityRunnable);
}
2016-03-16 13:26:32 +01:00
@Override
public void onClearEmojiRecent() {
if (parentFragment == null || parentActivity == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearRecentEmoji", R.string.ClearRecentEmoji));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
emojiView.clearRecentEmoji();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
parentFragment.showDialog(builder.create());
}
2016-10-11 13:57:01 +02:00
@Override
2017-03-31 01:58:05 +02:00
public void onShowStickerSet(TLRPC.StickerSet stickerSet, TLRPC.InputStickerSet inputStickerSet) {
2016-10-11 13:57:01 +02:00
if (parentFragment == null || parentActivity == null) {
return;
}
2017-03-31 01:58:05 +02:00
if (stickerSet != null) {
inputStickerSet = new TLRPC.TL_inputStickerSetID();
inputStickerSet.access_hash = stickerSet.access_hash;
inputStickerSet.id = stickerSet.id;
}
parentFragment.showDialog(new StickersAlert(parentActivity, parentFragment, inputStickerSet, null, ChatActivityEnterView.this));
2016-10-11 13:57:01 +02:00
}
@Override
public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet) {
2018-07-30 04:07:02 +02:00
DataQuery.getInstance(currentAccount).removeStickersSet(parentActivity, stickerSet.set, 2, parentFragment, false);
2016-10-11 13:57:01 +02:00
}
@Override
public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
2018-07-30 04:07:02 +02:00
DataQuery.getInstance(currentAccount).removeStickersSet(parentActivity, stickerSet.set, 0, parentFragment, false);
2016-10-11 13:57:01 +02:00
}
2017-12-08 18:35:59 +01:00
@Override
public void onStickersGroupClick(int chatId) {
if (parentFragment != null) {
if (AndroidUtilities.isTablet()) {
hidePopup(false);
}
GroupStickersActivity fragment = new GroupStickersActivity(chatId);
fragment.setInfo(info);
parentFragment.presentFragment(fragment);
}
}
2018-07-30 04:07:02 +02:00
@Override
public void onSearchOpenClose(boolean open) {
searchingStickers = open;
setStickersExpanded(open, false);
}
@Override
public boolean isSearchOpened() {
return searchingStickers;
}
@Override
public boolean isExpanded() {
return stickersExpanded;
}
});
emojiView.setDragListener(new EmojiView.DragListener() {
boolean wasExpanded;
int initialOffset;
@Override
public void onDragStart() {
if (!allowDragging()) {
return;
}
2018-07-30 04:07:02 +02:00
if (stickersExpansionAnim != null) {
stickersExpansionAnim.cancel();
2018-07-30 04:07:02 +02:00
}
stickersDragging = true;
wasExpanded = stickersExpanded;
stickersExpanded = true;
stickersExpandedHeight = sizeNotifierLayout.getHeight() - (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? AndroidUtilities.statusBarHeight : 0) - ActionBar.getCurrentActionBarHeight() - getHeight() + Theme.chat_composeShadowDrawable.getIntrinsicHeight();
emojiView.getLayoutParams().height = stickersExpandedHeight;
emojiView.setLayerType(LAYER_TYPE_HARDWARE, null);
sizeNotifierLayout.requestLayout();
2018-07-30 04:07:02 +02:00
sizeNotifierLayout.setForeground(new ScrimDrawable());
initialOffset = (int) getTranslationY();
2018-07-30 04:07:02 +02:00
if (delegate != null) {
delegate.onStickersExpandedChange();
}
}
@Override
public void onDragEnd(float velocity) {
if (!allowDragging())
return;
stickersDragging = false;
if ((wasExpanded && velocity >= AndroidUtilities.dp(200)) || (!wasExpanded && velocity <= AndroidUtilities.dp(-200)) || (wasExpanded && stickersExpansionProgress <= 0.6f) || (!wasExpanded && stickersExpansionProgress >= 0.4f)) {
setStickersExpanded(!wasExpanded, true);
} else {
setStickersExpanded(wasExpanded, true);
}
}
@Override
public void onDragCancel() {
if (!stickersTabOpen) {
return;
}
stickersDragging = false;
setStickersExpanded(wasExpanded, true);
}
@Override
public void onDrag(int offset) {
if (!allowDragging()) {
return;
}
int origHeight = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight;
offset += initialOffset;
offset = Math.max(Math.min(offset, 0), -(stickersExpandedHeight - origHeight));
emojiView.setTranslationY(offset);
setTranslationY(offset);
stickersExpansionProgress = (float) offset / (-(stickersExpandedHeight - origHeight));
sizeNotifierLayout.invalidate();
}
2018-07-30 04:07:02 +02:00
private boolean allowDragging() {
return stickersTabOpen && !(!stickersExpanded && messageEditText.length() > 0) && emojiView.areThereAnyStickers();
}
});
sizeNotifierLayout.addView(emojiView);
2017-07-08 18:32:04 +02:00
checkChannelRights();
}
2016-04-22 15:49:00 +02:00
@Override
public void onStickerSelected(TLRPC.Document sticker) {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(true);
emojiView.hideSearchKeyboard();
}
setStickersExpanded(false, true);
SendMessagesHelper.getInstance(currentAccount).sendSticker(sticker, dialog_id, replyingMessageObject);
2016-04-22 15:49:00 +02:00
if (delegate != null) {
delegate.onMessageSend(null);
}
}
2016-05-25 23:49:47 +02:00
public void addStickerToRecent(TLRPC.Document sticker) {
createEmojiView();
emojiView.addRecentSticker(sticker);
}
private void showPopup(int show, int contentType) {
if (show == 1) {
if (contentType == 0 && emojiView == null) {
if (parentActivity == null) {
return;
}
createEmojiView();
2015-06-29 19:12:11 +02:00
}
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) {
2018-07-30 04:07:02 +02:00
keyboardHeight = MessagesController.getGlobalEmojiSettings().getInt("kbd_height", AndroidUtilities.dp(200));
2015-06-29 19:12:11 +02:00
}
if (keyboardHeightLand <= 0) {
2018-07-30 04:07:02 +02:00
keyboardHeightLand = MessagesController.getGlobalEmojiSettings().getInt("kbd_height_land3", AndroidUtilities.dp(200));
2015-06-29 19:12:11 +02:00
}
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.height = currentHeight;
currentView.setLayoutParams(layoutParams);
2016-10-11 13:57:01 +02:00
if (!AndroidUtilities.isInMultiwindow) {
AndroidUtilities.hideKeyboard(messageEditText);
}
2015-06-29 19:12:11 +02:00
if (sizeNotifierLayout != null) {
emojiPadding = currentHeight;
sizeNotifierLayout.requestLayout();
if (contentType == 0) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_kb);
} else if (contentType == 1) {
2016-10-11 13:57:01 +02:00
setEmojiButtonImage();
2015-06-29 19:12:11 +02:00
}
updateBotButton();
onWindowSizeChanged();
}
} else {
if (emojiButton != null) {
2016-10-11 13:57:01 +02:00
setEmojiButtonImage();
2015-06-29 19:12:11 +02:00
}
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();
}
if (stickersTabOpen) {
checkSendButton(true);
}
2017-12-08 18:35:59 +01:00
if (stickersExpanded && show != 1) {
setStickersExpanded(false, false);
2017-12-08 18:35:59 +01:00
}
2015-06-29 19:12:11 +02:00
}
2016-10-11 13:57:01 +02:00
private void setEmojiButtonImage() {
int currentPage;
if (emojiView == null) {
2018-07-30 04:07:02 +02:00
currentPage = MessagesController.getGlobalEmojiSettings().getInt("selected_page", 0);
2016-10-11 13:57:01 +02:00
} else {
currentPage = emojiView.getCurrentPage();
}
if (currentPage == 0 || !allowStickers && !allowGifs) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_smiles);
} else if (currentPage == 1) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_stickers);
} else if (currentPage == 2) {
emojiButton.setImageResource(R.drawable.ic_msg_panel_gif);
}
}
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) {
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
2015-09-02 00:14:21 +02:00
preferences.edit().putInt("hidekeyboard_" + dialog_id, botButtonsMessageObject.getId()).commit();
}
2018-07-30 04:07:02 +02:00
if (byBackButton && searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(true);
messageEditText.requestFocus();
setStickersExpanded(false, true);
} else {
if (searchingStickers) {
searchingStickers = false;
emojiView.closeSearch(false);
messageEditText.requestFocus();
}
showPopup(0, 0);
removeGifFromInputField();
}
}
}
private void removeGifFromInputField() {
if (!AndroidUtilities.usingHardwareInput) {
if (messageEditText.getText().toString().equals("@gif ")) {
messageEditText.setText("");
}
2015-06-29 19:12:11 +02:00
}
}
private void openKeyboardInternal() {
showPopup(AndroidUtilities.usingHardwareInput || isPaused ? 0 : 2, 0);
messageEditText.requestFocus();
AndroidUtilities.showKeyboard(messageEditText);
if (isPaused) {
showKeyboardOnResume = true;
2016-10-11 13:57:01 +02:00
} else if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow) {
2015-06-29 19:12:11 +02:00
waitingForKeyboardOpen = true;
AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
}
}
2016-03-06 02:49:31 +01:00
public boolean isEditingMessage() {
return editingMessageObject != null;
}
2016-05-25 23:49:47 +02:00
public MessageObject getEditingMessageObject() {
return editingMessageObject;
}
2016-03-06 02:49:31 +01:00
public boolean isEditingCaption() {
return editingCaption;
}
2016-03-16 13:26:32 +01:00
public boolean hasAudioToSend() {
2017-07-08 18:32:04 +02:00
return audioToSendMessageObject != null || videoToSendMessageObject != null;
2016-03-16 13:26:32 +01:00
}
2015-06-29 19:12:11 +02:00
public void openKeyboard() {
AndroidUtilities.showKeyboard(messageEditText);
}
2015-11-26 22:04:02 +01:00
public void closeKeyboard() {
AndroidUtilities.hideKeyboard(messageEditText);
}
2015-06-29 19:12:11 +02:00
public boolean isPopupShowing() {
return emojiView != null && emojiView.getVisibility() == VISIBLE || botKeyboardView != null && botKeyboardView.getVisibility() == VISIBLE;
2014-11-14 16:40:15 +01:00
}
public boolean isKeyboardVisible() {
return keyboardVisible;
}
2016-10-11 13:57:01 +02:00
public void addRecentGif(TLRPC.Document searchImage) {
2018-07-30 04:07:02 +02:00
DataQuery.getInstance(currentAccount).addRecentGif(searchImage, (int) (System.currentTimeMillis() / 1000));
2017-03-31 01:58:05 +02:00
if (emojiView != null) {
emojiView.addRecentGif(searchImage);
}
}
2017-07-08 18:32:04 +02:00
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
2018-07-30 04:07:02 +02:00
if (w != oldw && stickersExpanded) {
searchingStickers = false;
emojiView.closeSearch(false);
setStickersExpanded(false, false);
2018-07-30 04:07:02 +02:00
}
2017-07-08 18:32:04 +02:00
videoTimelineView.clearFrames();
}
2018-07-30 04:07:02 +02:00
public boolean isStickersExpanded() {
return stickersExpanded;
}
@Override
2015-03-26 18:34:47 +01:00
public void onSizeChanged(int height, boolean isWidthGreater) {
2018-07-30 04:07:02 +02:00
if (searchingStickers) {
lastSizeChangeValue1 = height;
lastSizeChangeValue2 = isWidthGreater;
keyboardVisible = height > 0;
return;
}
2016-10-11 13:57:01 +02:00
if (height > AndroidUtilities.dp(50) && keyboardVisible && !AndroidUtilities.isInMultiwindow) {
2015-03-26 18:34:47 +01:00
if (isWidthGreater) {
keyboardHeightLand = height;
2018-07-30 04:07:02 +02:00
MessagesController.getGlobalEmojiSettings().edit().putInt("kbd_height_land3", keyboardHeightLand).commit();
} else {
keyboardHeight = height;
2018-07-30 04:07:02 +02:00
MessagesController.getGlobalEmojiSettings().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();
2018-07-30 04:07:02 +02:00
if (!closeAnimationInProgress && (layoutParams.width != AndroidUtilities.displaySize.x || layoutParams.height != newHeight) && !stickersExpanded) {
2014-12-04 21:27:06 +01:00
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;
}
@Override
2018-07-30 04:07:02 +02:00
public void didReceivedNotification(int id, int account, 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) {
2016-03-06 02:49:31 +01:00
long t = (Long) args[0];
2017-07-08 18:32:04 +02:00
long time = t / 1000;
2016-03-06 02:49:31 +01:00
int ms = (int) (t % 1000L) / 10;
String str = String.format("%02d:%02d.%02d", time / 60, time % 60, ms);
if (lastTimeString == null || !lastTimeString.equals(str)) {
2017-07-08 18:32:04 +02:00
if (lastTypingSendTime != time && time % 5 == 0) {
lastTypingSendTime = time;
2018-07-30 04:07:02 +02:00
MessagesController.getInstance(currentAccount).sendTyping(dialog_id, videoSendButton != null && videoSendButton.getTag() != null ? 7 : 1, 0);
}
if (recordTimeText != null) {
recordTimeText.setText(str);
}
}
2015-10-29 18:10:07 +01:00
if (recordCircle != null) {
recordCircle.setAmplitude((Double) args[1]);
}
2017-07-08 18:32:04 +02:00
if (videoSendButton != null && videoSendButton.getTag() != null && t >= 59500) {
startedDraggingX = -1;
delegate.needStartRecordVideo(3);
}
} 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) {
2017-03-31 01:58:05 +02:00
if (recordingAudioVideo) {
2018-07-30 04:07:02 +02:00
MessagesController.getInstance(currentAccount).sendTyping(dialog_id, 2, 0);
2017-03-31 01:58:05 +02:00
recordingAudioVideo = false;
updateRecordIntefrace();
}
2017-07-08 18:32:04 +02:00
if (id == NotificationCenter.recordStopped) {
Integer reason = (Integer) args[0];
if (reason == 2) {
videoTimelineView.setVisibility(VISIBLE);
recordedAudioBackground.setVisibility(GONE);
recordedAudioTimeTextView.setVisibility(GONE);
recordedAudioPlayButton.setVisibility(GONE);
recordedAudioSeekBar.setVisibility(GONE);
recordedAudioPanel.setAlpha(1.0f);
recordedAudioPanel.setVisibility(VISIBLE);
} else if (reason == 1) {
/*videoTimelineView.setVisibility(GONE);
recordedAudioBackground.setVisibility(VISIBLE);
recordedAudioTimeTextView.setVisibility(VISIBLE);
recordedAudioPlayButton.setVisibility(VISIBLE);
recordedAudioSeekBar.setVisibility(VISIBLE);
recordedAudioPanel.setAlpha(1.0f);
recordedAudioPanel.setVisibility(VISIBLE);*/
}
}
} else if (id == NotificationCenter.recordStarted) {
2017-03-31 01:58:05 +02:00
if (!recordingAudioVideo) {
recordingAudioVideo = true;
updateRecordIntefrace();
}
} else if (id == NotificationCenter.audioDidSent) {
2017-07-08 18:32:04 +02:00
Object audio = args[0];
if (audio instanceof VideoEditedInfo) {
videoToSendMessageObject = (VideoEditedInfo) audio;
audioToSendPath = (String) args[1];
videoTimelineView.setVideoPath(audioToSendPath);
videoTimelineView.setVisibility(VISIBLE);
videoTimelineView.setMinProgressDiff(1000.0f / videoToSendMessageObject.estimatedDuration);
recordedAudioBackground.setVisibility(GONE);
recordedAudioTimeTextView.setVisibility(GONE);
recordedAudioPlayButton.setVisibility(GONE);
recordedAudioSeekBar.setVisibility(GONE);
recordedAudioPanel.setAlpha(1.0f);
2016-03-06 02:49:31 +01:00
recordedAudioPanel.setVisibility(VISIBLE);
closeKeyboard();
hidePopup(false);
checkSendButton(false);
} else {
2017-07-08 18:32:04 +02:00
audioToSend = (TLRPC.TL_document) args[0];
audioToSendPath = (String) args[1];
if (audioToSend != null) {
if (recordedAudioPanel == null) {
return;
}
videoTimelineView.setVisibility(GONE);
recordedAudioBackground.setVisibility(VISIBLE);
recordedAudioTimeTextView.setVisibility(VISIBLE);
recordedAudioPlayButton.setVisibility(VISIBLE);
recordedAudioSeekBar.setVisibility(VISIBLE);
TLRPC.TL_message message = new TLRPC.TL_message();
message.out = true;
message.id = 0;
message.to_id = new TLRPC.TL_peerUser();
2018-07-30 04:07:02 +02:00
message.to_id.user_id = message.from_id = UserConfig.getInstance(currentAccount).getClientUserId();
2017-07-08 18:32:04 +02:00
message.date = (int) (System.currentTimeMillis() / 1000);
2018-07-30 04:07:02 +02:00
message.message = "";
2017-07-08 18:32:04 +02:00
message.attachPath = audioToSendPath;
message.media = new TLRPC.TL_messageMediaDocument();
message.media.flags |= 3;
2017-07-08 18:32:04 +02:00
message.media.document = audioToSend;
message.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA | TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
2018-07-30 04:07:02 +02:00
audioToSendMessageObject = new MessageObject(UserConfig.selectedAccount, message, false);
2017-07-08 18:32:04 +02:00
recordedAudioPanel.setAlpha(1.0f);
recordedAudioPanel.setVisibility(VISIBLE);
int duration = 0;
for (int a = 0; a < audioToSend.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
duration = attribute.duration;
break;
}
}
for (int a = 0; a < audioToSend.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = audioToSend.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
if (attribute.waveform == null || attribute.waveform.length == 0) {
attribute.waveform = MediaController.getInstance().getWaveform(audioToSendPath);
}
recordedAudioSeekBar.setWaveform(attribute.waveform);
break;
}
}
recordedAudioTimeTextView.setText(String.format("%d:%02d", duration / 60, duration % 60));
closeKeyboard();
hidePopup(false);
checkSendButton(false);
} else {
if (delegate != null) {
delegate.onMessageSend(null);
}
2016-03-06 02:49:31 +01:00
}
}
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);
}
2017-07-08 18:32:04 +02:00
} else if (id == NotificationCenter.messagePlayingDidReset) {
if (audioToSendMessageObject != null && !MediaController.getInstance().isPlayingMessage(audioToSendMessageObject)) {
2017-03-31 01:58:05 +02:00
recordedAudioPlayButton.setImageDrawable(playDrawable);
2016-03-06 02:49:31 +01:00
recordedAudioSeekBar.setProgress(0);
}
2017-07-08 18:32:04 +02:00
} else if (id == NotificationCenter.messagePlayingProgressDidChanged) {
2016-03-06 02:49:31 +01:00
Integer mid = (Integer) args[0];
2017-07-08 18:32:04 +02:00
if (audioToSendMessageObject != null && MediaController.getInstance().isPlayingMessage(audioToSendMessageObject)) {
2016-03-06 02:49:31 +01:00
MessageObject player = MediaController.getInstance().getPlayingMessageObject();
audioToSendMessageObject.audioProgress = player.audioProgress;
audioToSendMessageObject.audioProgressSec = player.audioProgressSec;
if (!recordedAudioSeekBar.isDragging()) {
recordedAudioSeekBar.setProgress(audioToSendMessageObject.audioProgress);
}
}
2016-10-11 13:57:01 +02:00
} else if (id == NotificationCenter.featuredStickersDidLoaded) {
if (emojiButton != null) {
emojiButton.invalidate();
}
}
}
2016-04-22 15:49:00 +02:00
public void onRequestPermissionsResultFragment(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 2) {
if (pendingLocationButton != null) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
2018-07-30 04:07:02 +02:00
SendMessagesHelper.getInstance(currentAccount).sendCurrentLocation(pendingMessageObject, pendingLocationButton);
2016-04-22 15:49:00 +02:00
}
pendingLocationButton = null;
pendingMessageObject = null;
}
}
}
private void setStickersExpanded(boolean expanded, boolean animated) {
2018-07-30 04:07:02 +02:00
if (emojiView == null || expanded && !emojiView.areThereAnyStickers() || stickersExpanded == expanded) {
return;
2017-12-08 18:35:59 +01:00
}
stickersExpanded = expanded;
2018-07-30 04:07:02 +02:00
if (delegate != null) {
delegate.onStickersExpandedChange();
}
final int origHeight = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight;
2017-12-08 18:35:59 +01:00
if (stickersExpansionAnim != null) {
stickersExpansionAnim.cancel();
2017-12-08 18:35:59 +01:00
stickersExpansionAnim = null;
}
if (stickersExpanded) {
stickersExpandedHeight = sizeNotifierLayout.getHeight() - (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? AndroidUtilities.statusBarHeight : 0) - ActionBar.getCurrentActionBarHeight() - getHeight() + Theme.chat_composeShadowDrawable.getIntrinsicHeight();
emojiView.getLayoutParams().height = stickersExpandedHeight;
sizeNotifierLayout.requestLayout();
2018-07-30 04:07:02 +02:00
sizeNotifierLayout.setForeground(new ScrimDrawable());
messageEditText.setText(messageEditText.getText()); // dismiss action mode, if any
if (animated) {
AnimatorSet anims = new AnimatorSet();
anims.playTogether(
ObjectAnimator.ofInt(this, roundedTranslationYProperty, -(stickersExpandedHeight - origHeight)),
ObjectAnimator.ofInt(emojiView, roundedTranslationYProperty, -(stickersExpandedHeight - origHeight)),
ObjectAnimator.ofFloat(stickersArrow, "animationProgress", 1)
);
anims.setDuration(400);
anims.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
((ObjectAnimator) anims.getChildAnimations().get(0)).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
stickersExpansionProgress = getTranslationY() / (-(stickersExpandedHeight - origHeight));
sizeNotifierLayout.invalidate();
}
});
anims.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
stickersExpansionAnim = null;
emojiView.setLayerType(LAYER_TYPE_NONE, null);
}
});
stickersExpansionAnim = anims;
emojiView.setLayerType(LAYER_TYPE_HARDWARE, null);
anims.start();
} else {
stickersExpansionProgress = 1;
setTranslationY(-(stickersExpandedHeight - origHeight));
emojiView.setTranslationY(-(stickersExpandedHeight - origHeight));
stickersArrow.setAnimationProgress(1);
}
} else {
if (animated) {
2018-07-30 04:07:02 +02:00
closeAnimationInProgress = true;
AnimatorSet anims = new AnimatorSet();
anims.playTogether(
ObjectAnimator.ofInt(this, roundedTranslationYProperty, 0),
ObjectAnimator.ofInt(emojiView, roundedTranslationYProperty, 0),
ObjectAnimator.ofFloat(stickersArrow, "animationProgress", 0)
);
anims.setDuration(400);
anims.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
((ObjectAnimator) anims.getChildAnimations().get(0)).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
stickersExpansionProgress = getTranslationY() / (-(stickersExpandedHeight - origHeight));
sizeNotifierLayout.invalidate();
}
});
anims.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
2018-07-30 04:07:02 +02:00
closeAnimationInProgress = false;
stickersExpansionAnim = null;
emojiView.getLayoutParams().height = origHeight;
sizeNotifierLayout.requestLayout();
emojiView.setLayerType(LAYER_TYPE_NONE, null);
2018-07-30 04:07:02 +02:00
sizeNotifierLayout.setForeground(null);
sizeNotifierLayout.setWillNotDraw(false);
}
});
stickersExpansionAnim = anims;
emojiView.setLayerType(LAYER_TYPE_HARDWARE, null);
anims.start();
} else {
stickersExpansionProgress = 0;
setTranslationY(0);
emojiView.setTranslationY(0);
emojiView.getLayoutParams().height = origHeight;
sizeNotifierLayout.requestLayout();
2018-07-30 04:07:02 +02:00
sizeNotifierLayout.setForeground(null);
sizeNotifierLayout.setWillNotDraw(false);
stickersArrow.setAnimationProgress(0);
}
}
}
private class ScrimDrawable extends Drawable {
private Paint paint;
public ScrimDrawable() {
paint = new Paint();
paint.setColor(0);
}
@Override
public void draw(Canvas canvas) {
paint.setAlpha(Math.round(102 * stickersExpansionProgress));
canvas.drawRect(0, 0, getWidth(), emojiView.getY() - getHeight() + Theme.chat_composeShadowDrawable.getIntrinsicHeight(), paint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
@Override
public int getOpacity() {
2018-07-30 04:07:02 +02:00
return PixelFormat.TRANSPARENT;
}
}
}