NekoX/TMessagesProj/src/main/java/org/telegram/ui/VoIPActivity.java

1804 lines
83 KiB
Java
Raw Normal View History

2017-03-31 01:58:05 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2017-03-31 01:58:05 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Grishka, 2013-2016.
*/
package org.telegram.ui;
import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
2019-12-31 14:08:08 +01:00
import android.app.KeyguardManager;
import android.content.Context;
2017-03-31 01:58:05 +02:00
import android.content.DialogInterface;
import android.content.Intent;
2018-07-30 04:07:02 +02:00
import android.content.SharedPreferences;
2017-03-31 01:58:05 +02:00
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
2017-12-08 18:35:59 +01:00
import android.graphics.ColorFilter;
2017-03-31 01:58:05 +02:00
import android.graphics.Matrix;
import android.graphics.Paint;
2017-07-08 18:32:04 +02:00
import android.graphics.PixelFormat;
2017-03-31 01:58:05 +02:00
import android.graphics.Rect;
2017-12-08 18:35:59 +01:00
import android.graphics.RectF;
2017-03-31 01:58:05 +02:00
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
2019-05-14 14:08:05 +02:00
import androidx.annotation.IntRange;
2020-03-30 14:00:09 +02:00
import androidx.annotation.Keep;
2019-05-14 14:08:05 +02:00
import androidx.annotation.Nullable;
import androidx.palette.graphics.Palette;
2018-07-30 04:07:02 +02:00
import android.text.Editable;
2017-03-31 01:58:05 +02:00
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
2018-07-30 04:07:02 +02:00
import android.text.TextWatcher;
2017-03-31 01:58:05 +02:00
import android.text.style.CharacterStyle;
2017-07-08 18:32:04 +02:00
import android.text.style.ForegroundColorSpan;
2017-03-31 01:58:05 +02:00
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
2019-05-14 14:08:05 +02:00
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
2017-03-31 01:58:05 +02:00
import android.view.animation.DecelerateInterpolator;
2018-07-30 04:07:02 +02:00
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
2017-03-31 01:58:05 +02:00
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
2017-07-08 18:32:04 +02:00
import android.widget.ScrollView;
2017-03-31 01:58:05 +02:00
import android.widget.TextView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.Emoji;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.FileLog;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.ImageLocation;
2017-03-31 01:58:05 +02:00
import org.telegram.messenger.ImageReceiver;
import org.telegram.messenger.LocaleController;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.MessagesController;
2017-03-31 01:58:05 +02:00
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.SendMessagesHelper;
2019-12-31 14:08:08 +01:00
import org.telegram.messenger.SharedConfig;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.UserConfig;
2017-03-31 01:58:05 +02:00
import org.telegram.messenger.Utilities;
import org.telegram.messenger.voip.EncryptionKeyEmojifier;
2020-03-30 14:00:09 +02:00
import org.telegram.messenger.voip.TgVoip;
2017-12-08 18:35:59 +01:00
import org.telegram.messenger.voip.VoIPBaseService;
2017-03-31 01:58:05 +02:00
import org.telegram.messenger.voip.VoIPService;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.BottomSheet;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.ActionBar.DarkAlertDialog;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
2020-03-30 14:00:09 +02:00
import org.telegram.ui.Components.BackgroundGradientDrawable;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CorrectlyMeasuringTextView;
import org.telegram.ui.Components.CubicBezierInterpolator;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Components.EditTextBoldCursor;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.IdenticonDrawable;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.voip.CallSwipeView;
import org.telegram.ui.Components.voip.CheckableImageView;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Components.voip.DarkTheme;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.voip.FabBackgroundDrawable;
import org.telegram.ui.Components.voip.VoIPHelper;
import java.io.ByteArrayOutputStream;
2019-09-10 12:56:11 +02:00
public class VoIPActivity extends Activity implements VoIPService.StateListener, NotificationCenter.NotificationCenterDelegate {
2017-03-31 01:58:05 +02:00
2018-07-30 04:07:02 +02:00
private int currentAccount = -1;
2017-03-31 01:58:05 +02:00
private static final String TAG = "tg-voip-ui";
private TextView stateText, nameText, stateText2;
private TextView durationText;
2017-12-08 18:35:59 +01:00
private TextView brandingText;
2017-03-31 01:58:05 +02:00
private View endBtn, acceptBtn, declineBtn, endBtnIcon, cancelBtn;
private CheckableImageView spkToggle, micToggle;
2018-07-30 04:07:02 +02:00
private ImageView chatBtn, addMemberBtn;
2017-03-31 01:58:05 +02:00
private FabBackgroundDrawable endBtnBg;
private CallSwipeView acceptSwipe, declineSwipe;
private LinearLayout swipeViewsWrap;
private BackupImageView photoView;
private boolean isIncomingWaiting;
private boolean firstStateChange = true;
private Animator currentDeclineAnim, currentAcceptAnim, textChangingAnim;
private TLRPC.User user;
private boolean didAcceptFromHere = false;
private int callState;
private TextAlphaSpan[] ellSpans;
private AnimatorSet ellAnimator;
private String lastStateText;
2019-09-10 12:56:11 +02:00
private ImageView[] keyEmojiViews = new ImageView[4];
2017-03-31 01:58:05 +02:00
private boolean keyEmojiVisible;
2019-09-10 12:56:11 +02:00
private AnimatorSet emojiAnimator;
2017-03-31 01:58:05 +02:00
private TextView hintTextView;
private Animator tooltipAnim;
private Runnable tooltipHider;
2019-09-10 12:56:11 +02:00
private LinearLayout emojiWrap;
2017-03-31 01:58:05 +02:00
boolean emojiTooltipVisible;
boolean emojiExpanded;
2019-09-10 12:56:11 +02:00
private Bitmap blurredPhoto1, blurredPhoto2;
2017-03-31 01:58:05 +02:00
private ImageView blurOverlayView1, blurOverlayView2;
private TextView emojiExpandedText;
private FrameLayout content;
private boolean retrying;
private AnimatorSet retryAnim;
2017-12-08 18:35:59 +01:00
private int signalBarsCount;
private SignalBarsDrawable signalBarsDrawable;
2018-07-30 04:07:02 +02:00
private LinearLayout bottomButtons;
private TextView accountNameText;
2017-03-31 01:58:05 +02:00
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
super.onCreate(savedInstanceState);
if (VoIPService.getSharedInstance() == null) {
finish();
return;
}
2019-09-10 12:56:11 +02:00
currentAccount = VoIPService.getSharedInstance().getAccount();
if (currentAccount == -1) {
2018-07-30 04:07:02 +02:00
finish();
return;
}
2017-03-31 01:58:05 +02:00
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) < Configuration.SCREENLAYOUT_SIZE_LARGE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
View contentView;
setContentView(contentView = createContentView());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
2018-07-30 04:07:02 +02:00
getWindow().setStatusBarColor(0);
getWindow().setNavigationBarColor(0);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
2019-09-10 12:56:11 +02:00
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
2017-03-31 01:58:05 +02:00
user = VoIPService.getSharedInstance().getUser();
if (user.photo != null) {
2018-07-30 04:07:02 +02:00
photoView.getImageReceiver().setDelegate(new ImageReceiver.ImageReceiverDelegate() {
2017-03-31 01:58:05 +02:00
@Override
2020-03-30 14:00:09 +02:00
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb, boolean memCache) {
2018-07-30 04:07:02 +02:00
ImageReceiver.BitmapHolder bmp = imageReceiver.getBitmapSafe();
if (bmp != null) {
2017-03-31 01:58:05 +02:00
updateBlurredPhotos(bmp);
}
}
});
2019-05-14 14:08:05 +02:00
photoView.setImage(ImageLocation.getForUser(user, true), null, new ColorDrawable(0xFF000000), user);
2018-07-30 04:07:02 +02:00
photoView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
2017-03-31 01:58:05 +02:00
} else {
photoView.setVisibility(View.GONE);
2020-03-30 14:00:09 +02:00
final BackgroundGradientDrawable gradientDrawable = new BackgroundGradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{0xFF1b354e, 0xFF255b7d});
final BackgroundGradientDrawable.Sizes sizes = BackgroundGradientDrawable.Sizes.ofDeviceScreen(BackgroundGradientDrawable.Sizes.Orientation.PORTRAIT);
gradientDrawable.startDithering(sizes, new BackgroundGradientDrawable.ListenerAdapter() {
@Override
public void onAllSizesReady() {
contentView.invalidate();
}
});
contentView.setBackground(gradientDrawable);
2017-03-31 01:58:05 +02:00
}
2018-07-30 04:07:02 +02:00
getWindow().setBackgroundDrawable(new ColorDrawable(0));
2017-03-31 01:58:05 +02:00
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
nameText.setOnClickListener(new View.OnClickListener() {
2019-09-10 12:56:11 +02:00
private int tapCount = 0;
2017-03-31 01:58:05 +02:00
@Override
public void onClick(View v) {
2019-09-10 12:56:11 +02:00
if (BuildVars.DEBUG_VERSION || tapCount == 9) {
2017-03-31 01:58:05 +02:00
showDebugAlert();
2019-09-10 12:56:11 +02:00
tapCount = 0;
} else {
2017-03-31 01:58:05 +02:00
tapCount++;
}
}
});
/*nameText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
showDebugCtlAlert();
return true;
}
});*/
endBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
endBtn.setEnabled(false);
2019-09-10 12:56:11 +02:00
if (retrying) {
2017-03-31 01:58:05 +02:00
Intent intent = new Intent(VoIPActivity.this, VoIPService.class);
intent.putExtra("user_id", user.id);
intent.putExtra("is_outgoing", true);
intent.putExtra("start_incall_activity", false);
2018-07-30 04:07:02 +02:00
intent.putExtra("account", currentAccount);
try {
startService(intent);
} catch (Throwable e) {
FileLog.e(e);
}
2017-03-31 01:58:05 +02:00
hideRetry();
2019-09-10 12:56:11 +02:00
endBtn.postDelayed(new Runnable() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
if (VoIPService.getSharedInstance() == null && !isFinishing()) {
2017-03-31 01:58:05 +02:00
endBtn.postDelayed(this, 100);
return;
}
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().registerStateListener(VoIPActivity.this);
2017-03-31 01:58:05 +02:00
}
}, 100);
return;
}
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().hangUp();
}
});
2019-09-10 12:56:11 +02:00
spkToggle.setOnClickListener(v -> {
VoIPService svc = VoIPService.getSharedInstance();
if (svc == null)
return;
svc.toggleSpeakerphoneOrShowRouteSheet(VoIPActivity.this);
2017-03-31 01:58:05 +02:00
});
2019-09-10 12:56:11 +02:00
micToggle.setOnClickListener(v -> {
if (VoIPService.getSharedInstance() == null) {
finish();
return;
2017-03-31 01:58:05 +02:00
}
2019-09-10 12:56:11 +02:00
boolean checked = !micToggle.isChecked();
micToggle.setChecked(checked);
VoIPService.getSharedInstance().setMicMute(checked);
2017-03-31 01:58:05 +02:00
});
2019-09-10 12:56:11 +02:00
chatBtn.setOnClickListener(v -> {
if (isIncomingWaiting) {
2019-12-31 14:08:08 +01:00
if (SharedConfig.passcodeHash.length() > 0) {
return;
}
try {
KeyguardManager myKM = (KeyguardManager) ApplicationLoader.applicationContext.getSystemService(Context.KEYGUARD_SERVICE);
if (myKM.inKeyguardRestrictedInputMode()) {
return;
}
} catch (Exception ignore) {
return;
}
2019-09-10 12:56:11 +02:00
showMessagesSheet();
return;
2017-03-31 01:58:05 +02:00
}
2019-09-10 12:56:11 +02:00
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE);
intent.putExtra("currentAccount", currentAccount);
intent.setFlags(32768);
intent.putExtra("userId", user.id);
startActivity(intent);
finish();
2017-03-31 01:58:05 +02:00
});
2018-07-30 04:07:02 +02:00
/*addMemberBtn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
showInviteFragment();
}
});*/
2017-03-31 01:58:05 +02:00
spkToggle.setChecked(((AudioManager) getSystemService(AUDIO_SERVICE)).isSpeakerphoneOn());
micToggle.setChecked(VoIPService.getSharedInstance().isMicMute());
onAudioSettingsChanged();
nameText.setText(ContactsController.formatName(user.first_name, user.last_name));
VoIPService.getSharedInstance().registerStateListener(this);
acceptSwipe.setListener(new CallSwipeView.Listener() {
@Override
public void onDragComplete() {
acceptSwipe.setEnabled(false);
declineSwipe.setEnabled(false);
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() == null) {
finish();
2017-03-31 01:58:05 +02:00
return;
}
didAcceptFromHere = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 101);
} else {
VoIPService.getSharedInstance().acceptIncomingCall();
callAccepted();
}
}
@Override
public void onDragStart() {
if (currentDeclineAnim != null) {
currentDeclineAnim.cancel();
}
AnimatorSet set = new AnimatorSet();
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(declineSwipe, View.ALPHA, .2f),
ObjectAnimator.ofFloat(declineBtn, View.ALPHA, .2f)
2017-03-31 01:58:05 +02:00
);
set.setDuration(200);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentDeclineAnim = null;
}
});
currentDeclineAnim = set;
set.start();
declineSwipe.stopAnimatingArrows();
}
@Override
public void onDragCancel() {
if (currentDeclineAnim != null) {
currentDeclineAnim.cancel();
}
AnimatorSet set = new AnimatorSet();
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(declineSwipe, View.ALPHA, 1),
ObjectAnimator.ofFloat(declineBtn, View.ALPHA, 1)
2017-03-31 01:58:05 +02:00
);
set.setDuration(200);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentDeclineAnim = null;
}
});
currentDeclineAnim = set;
set.start();
declineSwipe.startAnimatingArrows();
}
});
declineSwipe.setListener(new CallSwipeView.Listener() {
@Override
public void onDragComplete() {
acceptSwipe.setEnabled(false);
declineSwipe.setEnabled(false);
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().declineIncomingCall(VoIPService.DISCARD_REASON_LINE_BUSY, null);
2017-03-31 01:58:05 +02:00
else
finish();
}
@Override
public void onDragStart() {
if (currentAcceptAnim != null) {
currentAcceptAnim.cancel();
}
AnimatorSet set = new AnimatorSet();
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(acceptSwipe, View.ALPHA, .2f),
ObjectAnimator.ofFloat(acceptBtn, View.ALPHA, .2f)
2017-03-31 01:58:05 +02:00
);
set.setDuration(200);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentAcceptAnim = null;
}
});
currentAcceptAnim = set;
set.start();
acceptSwipe.stopAnimatingArrows();
}
@Override
public void onDragCancel() {
if (currentAcceptAnim != null) {
currentAcceptAnim.cancel();
}
AnimatorSet set = new AnimatorSet();
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(acceptSwipe, View.ALPHA, 1),
ObjectAnimator.ofFloat(acceptBtn, View.ALPHA, 1)
2017-03-31 01:58:05 +02:00
);
set.setDuration(200);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
currentAcceptAnim = null;
}
});
currentAcceptAnim = set;
set.start();
acceptSwipe.startAnimatingArrows();
}
});
2019-09-10 12:56:11 +02:00
cancelBtn.setOnClickListener(new View.OnClickListener() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onClick(View v) {
2017-03-31 01:58:05 +02:00
finish();
}
});
getWindow().getDecorView().setKeepScreenOn(true);
2019-01-23 18:03:33 +01:00
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoad);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.closeInCallActivity);
2017-03-31 01:58:05 +02:00
hintTextView.setText(LocaleController.formatString("CallEmojiKeyTooltip", R.string.CallEmojiKeyTooltip, user.first_name));
emojiExpandedText.setText(LocaleController.formatString("CallEmojiKeyTooltip", R.string.CallEmojiKeyTooltip, user.first_name));
2019-05-14 14:08:05 +02:00
2019-09-10 12:56:11 +02:00
AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
if (am.isTouchExplorationEnabled()) {
nameText.postDelayed(new Runnable() {
2019-05-14 14:08:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
2019-05-14 14:08:05 +02:00
nameText.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
}, 500);
}
2017-03-31 01:58:05 +02:00
}
2019-09-10 12:56:11 +02:00
private View createContentView() {
FrameLayout content = new FrameLayout(this) {
private void setNegativeMargins(Rect insets, LayoutParams lp) {
lp.topMargin = -insets.top;
lp.bottomMargin = -insets.bottom;
lp.leftMargin = -insets.left;
lp.rightMargin = -insets.right;
2018-07-30 04:07:02 +02:00
}
2019-09-10 12:56:11 +02:00
@Override
protected boolean fitSystemWindows(Rect insets) {
setNegativeMargins(insets, (LayoutParams) photoView.getLayoutParams());
2018-07-30 04:07:02 +02:00
setNegativeMargins(insets, (LayoutParams) blurOverlayView1.getLayoutParams());
setNegativeMargins(insets, (LayoutParams) blurOverlayView2.getLayoutParams());
2019-09-10 12:56:11 +02:00
return super.fitSystemWindows(insets);
}
};
2017-03-31 01:58:05 +02:00
content.setBackgroundColor(0);
2018-07-30 04:07:02 +02:00
content.setFitsSystemWindows(true);
content.setClipToPadding(false);
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
BackupImageView photo = new BackupImageView(this) {
private Drawable topGradient = getResources().getDrawable(R.drawable.gradient_top);
private Drawable bottomGradient = getResources().getDrawable(R.drawable.gradient_bottom);
private Paint paint = new Paint();
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
protected void onDraw(Canvas canvas) {
2017-03-31 01:58:05 +02:00
super.onDraw(canvas);
paint.setColor(0x4C000000);
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
topGradient.setBounds(0, 0, getWidth(), AndroidUtilities.dp(170));
topGradient.setAlpha(128);
topGradient.draw(canvas);
2019-09-10 12:56:11 +02:00
bottomGradient.setBounds(0, getHeight() - AndroidUtilities.dp(220), getWidth(), getHeight());
2017-03-31 01:58:05 +02:00
bottomGradient.setAlpha(178);
bottomGradient.draw(canvas);
}
};
2019-09-10 12:56:11 +02:00
content.addView(photoView = photo);
blurOverlayView1 = new ImageView(this);
2017-03-31 01:58:05 +02:00
blurOverlayView1.setScaleType(ImageView.ScaleType.CENTER_CROP);
2019-09-10 12:56:11 +02:00
blurOverlayView1.setAlpha(0f);
2017-03-31 01:58:05 +02:00
content.addView(blurOverlayView1);
2019-09-10 12:56:11 +02:00
blurOverlayView2 = new ImageView(this);
2017-03-31 01:58:05 +02:00
blurOverlayView2.setScaleType(ImageView.ScaleType.CENTER_CROP);
blurOverlayView2.setAlpha(0f);
content.addView(blurOverlayView2);
2019-09-10 12:56:11 +02:00
TextView branding = new TextView(this);
2017-03-31 01:58:05 +02:00
branding.setTextColor(0xCCFFFFFF);
branding.setText(LocaleController.getString("VoipInCallBranding", R.string.VoipInCallBranding));
2019-09-10 12:56:11 +02:00
Drawable logo = getResources().getDrawable(R.drawable.notification).mutate();
2017-03-31 01:58:05 +02:00
logo.setAlpha(0xCC);
logo.setBounds(0, 0, AndroidUtilities.dp(15), AndroidUtilities.dp(15));
2019-09-10 12:56:11 +02:00
signalBarsDrawable = new SignalBarsDrawable();
2017-12-08 18:35:59 +01:00
signalBarsDrawable.setBounds(0, 0, signalBarsDrawable.getIntrinsicWidth(), signalBarsDrawable.getIntrinsicHeight());
branding.setCompoundDrawables(LocaleController.isRTL ? signalBarsDrawable : logo, null, LocaleController.isRTL ? logo : signalBarsDrawable, null);
2017-03-31 01:58:05 +02:00
branding.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
branding.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
branding.setCompoundDrawablePadding(AndroidUtilities.dp(5));
branding.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
2019-09-10 12:56:11 +02:00
content.addView(branding, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 18, 18, 18, 0));
brandingText = branding;
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
TextView name = new TextView(this);
2017-03-31 01:58:05 +02:00
name.setSingleLine();
name.setTextColor(0xFFFFFFFF);
name.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 40);
name.setEllipsize(TextUtils.TruncateAt.END);
name.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
name.setShadowLayer(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(.666666667f), 0x4C000000);
name.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
2019-09-10 12:56:11 +02:00
content.addView(nameText = name, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 43, 18, 0));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
TextView state = new TextView(this);
2017-03-31 01:58:05 +02:00
state.setTextColor(0xCCFFFFFF);
state.setSingleLine();
state.setEllipsize(TextUtils.TruncateAt.END);
state.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
state.setShadowLayer(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(.666666667f), 0x4C000000);
state.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
state.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
//state.setAllCaps(true);
2019-09-10 12:56:11 +02:00
content.addView(stateText = state, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 18, 98, 18, 0));
durationText = state;
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
state = new TextView(this);
2017-03-31 01:58:05 +02:00
state.setTextColor(0xCCFFFFFF);
state.setSingleLine();
state.setEllipsize(TextUtils.TruncateAt.END);
state.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
state.setShadowLayer(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(.666666667f), 0x4C000000);
state.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
state.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
//state.setAllCaps(true);
state.setVisibility(View.GONE);
2019-09-10 12:56:11 +02:00
content.addView(stateText2 = state, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 18, 98, 18, 0));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
ellSpans = new TextAlphaSpan[]{new TextAlphaSpan(), new TextAlphaSpan(), new TextAlphaSpan()};
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
LinearLayout buttons = new LinearLayout(this);
2018-07-30 04:07:02 +02:00
buttons.setOrientation(LinearLayout.HORIZONTAL);
content.addView(buttons, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));
FrameLayout wrap;
2019-09-10 12:56:11 +02:00
TextView accountName = new TextView(this);
2018-07-30 04:07:02 +02:00
accountName.setTextColor(0xCCFFFFFF);
accountName.setSingleLine();
accountName.setEllipsize(TextUtils.TruncateAt.END);
accountName.setShadowLayer(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(.6666667f), 0x4c000000);
accountName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
accountName.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
2019-09-10 12:56:11 +02:00
content.addView(accountNameText = accountName, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 18, 120, 18, 0));
2018-07-30 04:07:02 +02:00
2019-09-10 12:56:11 +02:00
CheckableImageView mic = new CheckableImageView(this);
2017-03-31 01:58:05 +02:00
mic.setBackgroundResource(R.drawable.bg_voip_icon_btn);
2019-09-10 12:56:11 +02:00
Drawable micIcon = getResources().getDrawable(R.drawable.ic_mic_off_white_24dp).mutate();
2018-07-30 04:07:02 +02:00
mic.setAlpha(204);
2017-03-31 01:58:05 +02:00
mic.setImageDrawable(micIcon);
mic.setScaleType(ImageView.ScaleType.CENTER);
2019-05-14 14:08:05 +02:00
mic.setContentDescription(LocaleController.getString("AccDescrMuteMic", R.string.AccDescrMuteMic));
2019-09-10 12:56:11 +02:00
wrap = new FrameLayout(this);
wrap.addView(micToggle = mic, LayoutHelper.createFrame(38, 38, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 0, 10));
2018-07-30 04:07:02 +02:00
buttons.addView(wrap, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f));
2017-03-31 01:58:05 +02:00
2019-12-31 14:08:08 +01:00
chatBtn = new ImageView(this);
2019-09-10 12:56:11 +02:00
Drawable chatIcon = getResources().getDrawable(R.drawable.ic_chat_bubble_white_24dp).mutate();
2017-03-31 01:58:05 +02:00
chatIcon.setAlpha(204);
2019-12-31 14:08:08 +01:00
chatBtn.setImageDrawable(chatIcon);
chatBtn.setScaleType(ImageView.ScaleType.CENTER);
chatBtn.setContentDescription(LocaleController.getString("AccDescrOpenChat", R.string.AccDescrOpenChat));
2019-09-10 12:56:11 +02:00
wrap = new FrameLayout(this);
2019-12-31 14:08:08 +01:00
wrap.addView(chatBtn, LayoutHelper.createFrame(38, 38, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 0, 10));
2018-07-30 04:07:02 +02:00
buttons.addView(wrap, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f));
/*ImageView addMember=new ImageView(this);
Drawable addIcon=getResources().getDrawable(R.drawable.menu_invite).mutate();
addIcon.setColorFilter(null);
addMember.setAlpha(204);
addMember.setImageDrawable(addIcon);
addMember.setScaleType(ImageView.ScaleType.CENTER);
addMember.setEnabled(false);
addMember.setAlpha(.6f);
wrap=new FrameLayout(this);
wrap.addView(addMemberBtn=addMember, LayoutHelper.createFrame(38, 38, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 0, 10));
buttons.addView(wrap, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f));*/
2019-09-10 12:56:11 +02:00
CheckableImageView speaker = new CheckableImageView(this);
2018-07-30 04:07:02 +02:00
speaker.setBackgroundResource(R.drawable.bg_voip_icon_btn);
2019-09-10 12:56:11 +02:00
Drawable speakerIcon = getResources().getDrawable(R.drawable.ic_volume_up_white_24dp).mutate();
2018-07-30 04:07:02 +02:00
speaker.setAlpha(204);
speaker.setImageDrawable(speakerIcon);
speaker.setScaleType(ImageView.ScaleType.CENTER);
2019-05-14 14:08:05 +02:00
speaker.setContentDescription(LocaleController.getString("VoipAudioRoutingSpeaker", R.string.VoipAudioRoutingSpeaker));
2019-09-10 12:56:11 +02:00
wrap = new FrameLayout(this);
wrap.addView(spkToggle = speaker, LayoutHelper.createFrame(38, 38, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 0, 10));
2018-07-30 04:07:02 +02:00
buttons.addView(wrap, LayoutHelper.createLinear(0, LayoutHelper.WRAP_CONTENT, 1f));
2019-09-10 12:56:11 +02:00
bottomButtons = buttons;
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
LinearLayout swipesWrap = new LinearLayout(this);
2017-03-31 01:58:05 +02:00
swipesWrap.setOrientation(LinearLayout.HORIZONTAL);
2019-09-10 12:56:11 +02:00
CallSwipeView acceptSwipe = new CallSwipeView(this);
2017-03-31 01:58:05 +02:00
acceptSwipe.setColor(0xFF45bc4d);
2019-05-14 14:08:05 +02:00
acceptSwipe.setContentDescription(LocaleController.getString("Accept", R.string.Accept));
2019-09-10 12:56:11 +02:00
swipesWrap.addView(this.acceptSwipe = acceptSwipe, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 70, 1f, 4, 4, -35, 4));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
CallSwipeView declineSwipe = new CallSwipeView(this);
2017-03-31 01:58:05 +02:00
declineSwipe.setColor(0xFFe61e44);
2019-05-14 14:08:05 +02:00
declineSwipe.setContentDescription(LocaleController.getString("Decline", R.string.Decline));
2019-09-10 12:56:11 +02:00
swipesWrap.addView(this.declineSwipe = declineSwipe, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 70, 1f, -35, 4, 4, 4));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
content.addView(swipeViewsWrap = swipesWrap, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 20, 0, 20, 68));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
ImageView acceptBtn = new ImageView(this);
FabBackgroundDrawable acceptBtnBg = new FabBackgroundDrawable();
2017-03-31 01:58:05 +02:00
acceptBtnBg.setColor(0xFF45bc4d);
acceptBtn.setBackgroundDrawable(acceptBtnBg);
acceptBtn.setImageResource(R.drawable.ic_call_end_white_36dp);
acceptBtn.setScaleType(ImageView.ScaleType.MATRIX);
2019-09-10 12:56:11 +02:00
Matrix matrix = new Matrix();
2017-03-31 01:58:05 +02:00
matrix.setTranslate(AndroidUtilities.dp(17), AndroidUtilities.dp(17));
matrix.postRotate(-135, AndroidUtilities.dp(35), AndroidUtilities.dp(35));
acceptBtn.setImageMatrix(matrix);
2019-09-10 12:56:11 +02:00
content.addView(this.acceptBtn = acceptBtn, LayoutHelper.createFrame(78, 78, Gravity.BOTTOM | Gravity.LEFT, 20, 0, 0, 68));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
ImageView declineBtn = new ImageView(this);
FabBackgroundDrawable rejectBtnBg = new FabBackgroundDrawable();
2017-03-31 01:58:05 +02:00
rejectBtnBg.setColor(0xFFe61e44);
declineBtn.setBackgroundDrawable(rejectBtnBg);
declineBtn.setImageResource(R.drawable.ic_call_end_white_36dp);
declineBtn.setScaleType(ImageView.ScaleType.CENTER);
2019-09-10 12:56:11 +02:00
content.addView(this.declineBtn = declineBtn, LayoutHelper.createFrame(78, 78, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, 20, 68));
2017-03-31 01:58:05 +02:00
acceptSwipe.setViewToDrag(acceptBtn, false);
declineSwipe.setViewToDrag(declineBtn, true);
2019-09-10 12:56:11 +02:00
FrameLayout end = new FrameLayout(this);
FabBackgroundDrawable endBtnBg = new FabBackgroundDrawable();
2017-03-31 01:58:05 +02:00
endBtnBg.setColor(0xFFe61e44);
2019-09-10 12:56:11 +02:00
end.setBackgroundDrawable(this.endBtnBg = endBtnBg);
ImageView endInner = new ImageView(this);
2017-03-31 01:58:05 +02:00
endInner.setImageResource(R.drawable.ic_call_end_white_36dp);
endInner.setScaleType(ImageView.ScaleType.CENTER);
2019-09-10 12:56:11 +02:00
end.addView(endBtnIcon = endInner, LayoutHelper.createFrame(70, 70));
2017-03-31 01:58:05 +02:00
end.setForeground(getResources().getDrawable(R.drawable.fab_highlight_dark));
2019-05-14 14:08:05 +02:00
end.setContentDescription(LocaleController.getString("VoipEndCall", R.string.VoipEndCall));
2019-09-10 12:56:11 +02:00
content.addView(endBtn = end, LayoutHelper.createFrame(78, 78, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0, 0, 68));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
ImageView cancelBtn = new ImageView(this);
FabBackgroundDrawable cancelBtnBg = new FabBackgroundDrawable();
2017-03-31 01:58:05 +02:00
cancelBtnBg.setColor(0xFFFFFFFF);
cancelBtn.setBackgroundDrawable(cancelBtnBg);
cancelBtn.setImageResource(R.drawable.edit_cancel);
cancelBtn.setColorFilter(0x89000000);
cancelBtn.setScaleType(ImageView.ScaleType.CENTER);
cancelBtn.setVisibility(View.GONE);
2019-05-14 14:08:05 +02:00
cancelBtn.setContentDescription(LocaleController.getString("Cancel", R.string.Cancel));
2019-09-10 12:56:11 +02:00
content.addView(this.cancelBtn = cancelBtn, LayoutHelper.createFrame(78, 78, Gravity.BOTTOM | Gravity.LEFT, 52, 0, 0, 68));
2017-03-31 01:58:05 +02:00
2019-09-10 12:56:11 +02:00
emojiWrap = new LinearLayout(this);
2017-03-31 01:58:05 +02:00
emojiWrap.setOrientation(LinearLayout.HORIZONTAL);
emojiWrap.setClipToPadding(false);
emojiWrap.setPivotX(0);
emojiWrap.setPivotY(0);
2019-09-10 12:56:11 +02:00
emojiWrap.setPadding(AndroidUtilities.dp(14), AndroidUtilities.dp(10), AndroidUtilities.dp(14), AndroidUtilities.dp(10));
for (int i = 0; i < 4; i++) {
ImageView emoji = new ImageView(this);
2017-03-31 01:58:05 +02:00
emoji.setScaleType(ImageView.ScaleType.FIT_XY);
2019-09-10 12:56:11 +02:00
emojiWrap.addView(emoji, LayoutHelper.createLinear(22, 22, i == 0 ? 0 : 4, 0, 0, 0));
keyEmojiViews[i] = emoji;
2017-03-31 01:58:05 +02:00
}
2019-09-10 12:56:11 +02:00
emojiWrap.setOnClickListener(new View.OnClickListener() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onClick(View v) {
if (emojiTooltipVisible) {
2017-03-31 01:58:05 +02:00
setEmojiTooltipVisible(false);
2019-09-10 12:56:11 +02:00
if (tooltipHider != null) {
2017-03-31 01:58:05 +02:00
hintTextView.removeCallbacks(tooltipHider);
2019-09-10 12:56:11 +02:00
tooltipHider = null;
2017-03-31 01:58:05 +02:00
}
}
setEmojiExpanded(!emojiExpanded);
}
});
//keyEmojiText=new TextView(this);
//keyEmojiText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
2019-09-10 12:56:11 +02:00
content.addView(emojiWrap, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT)));
emojiWrap.setOnLongClickListener(new View.OnLongClickListener() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public boolean onLongClick(View v) {
if (emojiExpanded)
2017-03-31 01:58:05 +02:00
return false;
2019-09-10 12:56:11 +02:00
if (tooltipHider != null) {
2017-03-31 01:58:05 +02:00
hintTextView.removeCallbacks(tooltipHider);
2019-09-10 12:56:11 +02:00
tooltipHider = null;
2017-03-31 01:58:05 +02:00
}
setEmojiTooltipVisible(!emojiTooltipVisible);
2019-09-10 12:56:11 +02:00
if (emojiTooltipVisible) {
hintTextView.postDelayed(tooltipHider = new Runnable() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
tooltipHider = null;
2017-03-31 01:58:05 +02:00
setEmojiTooltipVisible(false);
}
}, 5000);
}
return true;
}
});
2019-09-10 12:56:11 +02:00
emojiExpandedText = new TextView(this);
2017-03-31 01:58:05 +02:00
emojiExpandedText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
emojiExpandedText.setTextColor(0xFFFFFFFF);
emojiExpandedText.setGravity(Gravity.CENTER);
2019-09-10 12:56:11 +02:00
emojiExpandedText.setAlpha(0);
2017-03-31 01:58:05 +02:00
content.addView(emojiExpandedText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 10, 32, 10, 0));
hintTextView = new CorrectlyMeasuringTextView(this);
hintTextView.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(3), 0xf2333333));
hintTextView.setTextColor(Theme.getColor(Theme.key_chat_gifSaveHintText));
hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
hintTextView.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10));
hintTextView.setGravity(Gravity.CENTER);
hintTextView.setMaxWidth(AndroidUtilities.dp(300));
hintTextView.setAlpha(0.0f);
content.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT, 0, 42, 10, 0));
2019-09-10 12:56:11 +02:00
int ellMaxAlpha = stateText.getPaint().getAlpha();
ellAnimator = new AnimatorSet();
2017-03-31 01:58:05 +02:00
ellAnimator.playTogether(
createAlphaAnimator(ellSpans[0], 0, ellMaxAlpha, 0, 300),
createAlphaAnimator(ellSpans[1], 0, ellMaxAlpha, 150, 300),
createAlphaAnimator(ellSpans[2], 0, ellMaxAlpha, 300, 300),
createAlphaAnimator(ellSpans[0], ellMaxAlpha, 0, 1000, 400),
createAlphaAnimator(ellSpans[1], ellMaxAlpha, 0, 1000, 400),
createAlphaAnimator(ellSpans[2], ellMaxAlpha, 0, 1000, 400)
);
2019-09-10 12:56:11 +02:00
ellAnimator.addListener(new AnimatorListenerAdapter() {
private Runnable restarter = new Runnable() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
if (!isFinishing())
2017-03-31 01:58:05 +02:00
ellAnimator.start();
}
};
2019-09-10 12:56:11 +02:00
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onAnimationEnd(Animator animation) {
if (!isFinishing()) {
2017-03-31 01:58:05 +02:00
VoIPActivity.this.content.postDelayed(restarter, 300);
}
}
});
2019-09-10 12:56:11 +02:00
content.setClipChildren(false);
this.content = content;
2017-03-31 01:58:05 +02:00
return content;
}
2019-09-10 12:56:11 +02:00
@SuppressLint("ObjectAnimatorBinding")
private ObjectAnimator createAlphaAnimator(Object target, int startVal, int endVal, int startDelay, int duration) {
ObjectAnimator a = ObjectAnimator.ofInt(target, "alpha", startVal, endVal);
2017-03-31 01:58:05 +02:00
a.setDuration(duration);
a.setStartDelay(startDelay);
a.setInterpolator(CubicBezierInterpolator.DEFAULT);
return a;
}
@Override
protected void onDestroy() {
2019-01-23 18:03:33 +01:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiDidLoad);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.closeInCallActivity);
2017-03-31 01:58:05 +02:00
if (VoIPService.getSharedInstance() != null) {
VoIPService.getSharedInstance().unregisterStateListener(this);
}
super.onDestroy();
}
@Override
public void onBackPressed() {
2019-09-10 12:56:11 +02:00
if (emojiExpanded) {
2017-03-31 01:58:05 +02:00
setEmojiExpanded(false);
return;
}
if (!isIncomingWaiting) {
super.onBackPressed();
}
}
@Override
protected void onResume() {
super.onResume();
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().onUIForegroundStateChanged(true);
}
@Override
protected void onPause() {
super.onPause();
2019-09-10 12:56:11 +02:00
if (retrying)
2017-03-31 01:58:05 +02:00
finish();
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().onUIForegroundStateChanged(false);
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 101) {
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() == null) {
2017-07-08 18:32:04 +02:00
finish();
return;
}
2019-09-10 12:56:11 +02:00
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
2017-03-31 01:58:05 +02:00
VoIPService.getSharedInstance().acceptIncomingCall();
callAccepted();
} else {
2019-09-10 12:56:11 +02:00
if (!shouldShowRequestPermissionRationale(Manifest.permission.RECORD_AUDIO)) {
2017-03-31 01:58:05 +02:00
VoIPService.getSharedInstance().declineIncomingCall();
2019-09-10 12:56:11 +02:00
VoIPHelper.permissionDenied(this, new Runnable() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
2017-03-31 01:58:05 +02:00
finish();
}
});
return;
}
acceptSwipe.reset();
}
}
}
private void updateKeyView() {
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() == null)
2017-03-31 01:58:05 +02:00
return;
IdenticonDrawable img = new IdenticonDrawable();
img.setColors(new int[]{0x00FFFFFF, 0xFFFFFFFF, 0x99FFFFFF, 0x33FFFFFF});
2017-12-08 18:35:59 +01:00
TLRPC.EncryptedChat encryptedChat = new TLRPC.TL_encryptedChat();
try {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
2017-03-31 01:58:05 +02:00
buf.write(VoIPService.getSharedInstance().getEncryptionKey());
2019-09-10 12:56:11 +02:00
buf.write(VoIPService.getSharedInstance().getGA());
2017-03-31 01:58:05 +02:00
encryptedChat.auth_key = buf.toByteArray();
2019-09-10 12:56:11 +02:00
} catch (Exception checkedExceptionsAreBad) {
}
2017-03-31 01:58:05 +02:00
byte[] sha256 = Utilities.computeSHA256(encryptedChat.auth_key, 0, encryptedChat.auth_key.length);
2019-09-10 12:56:11 +02:00
String[] emoji = EncryptionKeyEmojifier.emojifyForCall(sha256);
2017-03-31 01:58:05 +02:00
//keyEmojiText.setText(Emoji.replaceEmoji(TextUtils.join(" ", emoji), keyEmojiText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(32), false));
2019-09-10 12:56:11 +02:00
emojiWrap.setContentDescription(LocaleController.getString("EncryptionKey", R.string.EncryptionKey) + ", " + TextUtils.join(", ", emoji));
for (int i = 0; i < 4; i++) {
2017-12-08 18:35:59 +01:00
Drawable drawable = Emoji.getEmojiDrawable(emoji[i]);
if (drawable != null) {
drawable.setBounds(0, 0, AndroidUtilities.dp(22), AndroidUtilities.dp(22));
keyEmojiViews[i].setImageDrawable(drawable);
}
2017-03-31 01:58:05 +02:00
}
}
2019-09-10 12:56:11 +02:00
private CharSequence getFormattedDebugString() {
String in = VoIPService.getSharedInstance().getDebugString();
SpannableString ss = new SpannableString(in);
int offset = 0;
do {
int lineEnd = in.indexOf('\n', offset + 1);
if (lineEnd == -1)
lineEnd = in.length();
String line = in.substring(offset, lineEnd);
if (line.contains("IN_USE")) {
2017-07-08 18:32:04 +02:00
ss.setSpan(new ForegroundColorSpan(0xFF00FF00), offset, lineEnd, 0);
2019-09-10 12:56:11 +02:00
} else {
if (line.contains(": ")) {
ss.setSpan(new ForegroundColorSpan(0xAAFFFFFF), offset, offset + line.indexOf(':') + 1, 0);
2017-07-08 18:32:04 +02:00
}
}
2019-09-10 12:56:11 +02:00
} while ((offset = in.indexOf('\n', offset + 1)) != -1);
2017-07-08 18:32:04 +02:00
return ss;
}
2017-03-31 01:58:05 +02:00
private void showDebugAlert() {
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() == null)
2017-03-31 01:58:05 +02:00
return;
2019-09-10 12:56:11 +02:00
VoIPService.getSharedInstance().forceRating();
final LinearLayout debugOverlay = new LinearLayout(this);
2017-07-08 18:32:04 +02:00
debugOverlay.setOrientation(LinearLayout.VERTICAL);
debugOverlay.setBackgroundColor(0xCC000000);
2019-09-10 12:56:11 +02:00
int pad = AndroidUtilities.dp(16);
debugOverlay.setPadding(pad, pad * 2, pad, pad * 2);
2017-07-08 18:32:04 +02:00
2019-09-10 12:56:11 +02:00
TextView title = new TextView(this);
2017-07-08 18:32:04 +02:00
title.setTextColor(0xFFFFFFFF);
title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
title.setTypeface(Typeface.DEFAULT_BOLD);
title.setGravity(Gravity.CENTER);
2020-03-30 14:00:09 +02:00
title.setText(getDebugTitle());
2017-07-08 18:32:04 +02:00
debugOverlay.addView(title, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 0, 0, 16));
2019-09-10 12:56:11 +02:00
ScrollView scroll = new ScrollView(this);
final TextView debugText = new TextView(this);
2017-07-08 18:32:04 +02:00
debugText.setTypeface(Typeface.MONOSPACE);
debugText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
debugText.setMaxWidth(AndroidUtilities.dp(350));
debugText.setTextColor(0xFFFFFFFF);
debugText.setText(getFormattedDebugString());
scroll.addView(debugText);
debugOverlay.addView(scroll, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 1f));
2019-09-10 12:56:11 +02:00
TextView closeBtn = new TextView(this);
2017-07-08 18:32:04 +02:00
closeBtn.setBackgroundColor(0xFFFFFFFF);
closeBtn.setTextColor(0xFF000000);
closeBtn.setPadding(pad, pad, pad, pad);
closeBtn.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
closeBtn.setText(LocaleController.getString("Close", R.string.Close));
debugOverlay.addView(closeBtn, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 0));
2019-09-10 12:56:11 +02:00
final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
2017-07-08 18:32:04 +02:00
wm.addView(debugOverlay, new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION_PANEL, 0, PixelFormat.TRANSLUCENT));
2019-09-10 12:56:11 +02:00
closeBtn.setOnClickListener(new View.OnClickListener() {
2017-07-08 18:32:04 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onClick(View v) {
2017-07-08 18:32:04 +02:00
wm.removeView(debugOverlay);
}
});
2017-03-31 01:58:05 +02:00
final Runnable r = new Runnable() {
@Override
public void run() {
2017-07-08 18:32:04 +02:00
if (isFinishing() || VoIPService.getSharedInstance() == null) {
2017-03-31 01:58:05 +02:00
return;
}
2020-03-30 14:00:09 +02:00
title.setText(getDebugTitle());
2017-07-08 18:32:04 +02:00
debugText.setText(getFormattedDebugString());
debugOverlay.postDelayed(this, 500);
2017-03-31 01:58:05 +02:00
}
};
2017-07-08 18:32:04 +02:00
debugOverlay.postDelayed(r, 500);
2017-03-31 01:58:05 +02:00
}
2020-03-30 14:00:09 +02:00
private String getDebugTitle() {
String title = "libtgvoip";
final String version = TgVoip.getVersion();
if (version != null) {
title += " v" + version;
}
return title;
}
2019-09-10 12:56:11 +02:00
private void showInviteFragment() {
2018-07-30 04:07:02 +02:00
/*KeyguardManager km=(KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if(km.inKeyguardRestrictedInputMode()){
VoIPHelper.dismissKeyguard(this, new VoIPHelper.OnKeyguardDismissListener(){
@Override
public void onDismissed(){
showInviteFragment();
}
@Override
public void onCanceled(){
}
});
return;
}
FragmentStackDialog d=new FragmentStackDialog(VoIPActivity.this);
d.show();
CallUpgradeToGroupActivity fragment=new CallUpgradeToGroupActivity(currentAccount);
fragment.setDelegate(new CallUpgradeToGroupActivity.ResultReceiver(){
@Override
public void didSelectUsers(ArrayList<Integer> ids){
if(VoIPService.getSharedInstance()==null)
return;
VoIPService.getSharedInstance().upgradeToGroupCall(ids);
}
});
d.presentFragment(fragment);*/
}
2017-03-31 01:58:05 +02:00
private void startUpdatingCallDuration() {
Runnable r = new Runnable() {
@Override
public void run() {
if (isFinishing() || VoIPService.getSharedInstance() == null) {
return;
}
2019-09-10 12:56:11 +02:00
if (callState == VoIPService.STATE_ESTABLISHED || callState == VoIPService.STATE_RECONNECTING) {
2019-12-31 14:08:08 +01:00
durationText.setText(AndroidUtilities.formatShortDuration((int) (VoIPService.getSharedInstance().getCallDuration() / 1000)));
2017-03-31 01:58:05 +02:00
durationText.postDelayed(this, 500);
}
}
};
r.run();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (isIncomingWaiting && (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().stopRinging();
2017-03-31 01:58:05 +02:00
else
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
private void callAccepted() {
endBtn.setVisibility(View.VISIBLE);
2019-09-10 12:56:11 +02:00
if (VoIPService.getSharedInstance().hasEarpiece())
2017-03-31 01:58:05 +02:00
spkToggle.setVisibility(View.VISIBLE);
2018-07-30 04:07:02 +02:00
else
spkToggle.setVisibility(View.GONE);
bottomButtons.setVisibility(View.VISIBLE);
2017-03-31 01:58:05 +02:00
if (didAcceptFromHere) {
acceptBtn.setVisibility(View.GONE);
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
colorAnim.setEvaluator(new ArgbEvaluator());
}
AnimatorSet set = new AnimatorSet();
AnimatorSet decSet = new AnimatorSet();
decSet.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(endBtnIcon, View.ROTATION, -135, 0),
2017-03-31 01:58:05 +02:00
colorAnim
);
decSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
decSet.setDuration(500);
AnimatorSet accSet = new AnimatorSet();
accSet.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(swipeViewsWrap, View.ALPHA, 1, 0),
ObjectAnimator.ofFloat(declineBtn, View.ALPHA, 0),
ObjectAnimator.ofFloat(accountNameText, View.ALPHA, 0)
2017-03-31 01:58:05 +02:00
);
accSet.setInterpolator(CubicBezierInterpolator.EASE_IN);
accSet.setDuration(125);
set.playTogether(
decSet,
accSet
);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
swipeViewsWrap.setVisibility(View.GONE);
declineBtn.setVisibility(View.GONE);
2018-07-30 04:07:02 +02:00
accountNameText.setVisibility(View.GONE);
2017-03-31 01:58:05 +02:00
}
});
set.start();
} else {
AnimatorSet set = new AnimatorSet();
AnimatorSet decSet = new AnimatorSet();
decSet.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(bottomButtons, View.ALPHA, 0, 1)
2017-03-31 01:58:05 +02:00
);
decSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
decSet.setDuration(500);
AnimatorSet accSet = new AnimatorSet();
accSet.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(swipeViewsWrap, View.ALPHA, 1, 0),
ObjectAnimator.ofFloat(declineBtn, View.ALPHA, 0),
ObjectAnimator.ofFloat(acceptBtn, View.ALPHA, 0),
ObjectAnimator.ofFloat(accountNameText, View.ALPHA, 0)
2017-03-31 01:58:05 +02:00
);
accSet.setInterpolator(CubicBezierInterpolator.EASE_IN);
accSet.setDuration(125);
set.playTogether(
decSet,
accSet
);
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
swipeViewsWrap.setVisibility(View.GONE);
declineBtn.setVisibility(View.GONE);
acceptBtn.setVisibility(View.GONE);
2018-07-30 04:07:02 +02:00
accountNameText.setVisibility(View.GONE);
2017-03-31 01:58:05 +02:00
}
});
set.start();
}
}
2019-09-10 12:56:11 +02:00
private void showRetry() {
if (retryAnim != null)
2017-03-31 01:58:05 +02:00
retryAnim.cancel();
endBtn.setEnabled(false);
2019-09-10 12:56:11 +02:00
retrying = true;
2017-03-31 01:58:05 +02:00
cancelBtn.setVisibility(View.VISIBLE);
cancelBtn.setAlpha(0);
2019-09-10 12:56:11 +02:00
AnimatorSet set = new AnimatorSet();
2017-03-31 01:58:05 +02:00
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFFe61e44, 0xFF45bc4d);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFFe61e44, 0xFF45bc4d);
colorAnim.setEvaluator(new ArgbEvaluator());
}
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(cancelBtn, View.ALPHA, 0, 1),
ObjectAnimator.ofFloat(endBtn, View.TRANSLATION_X, 0, content.getWidth() / 2 - AndroidUtilities.dp(52) - endBtn.getWidth() / 2),
2017-03-31 01:58:05 +02:00
colorAnim,
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(endBtnIcon, View.ROTATION, 0, -135)//,
//ObjectAnimator.ofFloat(spkToggle, View.ALPHA, 0),
//ObjectAnimator.ofFloat(micToggle, View.ALPHA, 0),
//ObjectAnimator.ofFloat(chatBtn, View.ALPHA, 0)
2017-03-31 01:58:05 +02:00
);
set.setStartDelay(200);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
2019-09-10 12:56:11 +02:00
set.addListener(new AnimatorListenerAdapter() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onAnimationEnd(Animator animation) {
2018-07-30 04:07:02 +02:00
//bottomButtons.setVisibility(View.GONE);
2019-09-10 12:56:11 +02:00
retryAnim = null;
2017-03-31 01:58:05 +02:00
endBtn.setEnabled(true);
}
});
2019-09-10 12:56:11 +02:00
retryAnim = set;
2017-03-31 01:58:05 +02:00
set.start();
}
2019-09-10 12:56:11 +02:00
private void hideRetry() {
if (retryAnim != null)
2017-03-31 01:58:05 +02:00
retryAnim.cancel();
2019-09-10 12:56:11 +02:00
retrying = false;
2018-07-30 04:07:02 +02:00
//bottomButtons.setVisibility(View.VISIBLE);
2017-03-31 01:58:05 +02:00
ObjectAnimator colorAnim;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
colorAnim = ObjectAnimator.ofArgb(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
} else {
colorAnim = ObjectAnimator.ofInt(endBtnBg, "color", 0xFF45bc4d, 0xFFe61e44);
colorAnim.setEvaluator(new ArgbEvaluator());
}
2019-09-10 12:56:11 +02:00
AnimatorSet set = new AnimatorSet();
2017-03-31 01:58:05 +02:00
set.playTogether(
colorAnim,
ObjectAnimator.ofFloat(endBtnIcon, "rotation", -135, 0),
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(endBtn, View.TRANSLATION_X, 0),
ObjectAnimator.ofFloat(cancelBtn, View.ALPHA, 0)//,
//ObjectAnimator.ofFloat(bottomButtons, View.ALPHA, 1)
2017-03-31 01:58:05 +02:00
);
set.setStartDelay(200);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
2019-09-10 12:56:11 +02:00
set.addListener(new AnimatorListenerAdapter() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onAnimationEnd(Animator animation) {
2017-03-31 01:58:05 +02:00
cancelBtn.setVisibility(View.GONE);
endBtn.setEnabled(true);
2019-09-10 12:56:11 +02:00
retryAnim = null;
2017-03-31 01:58:05 +02:00
}
});
2019-09-10 12:56:11 +02:00
retryAnim = set;
2017-03-31 01:58:05 +02:00
set.start();
}
@Override
public void onStateChanged(final int state) {
2019-09-10 12:56:11 +02:00
final int prevState = callState;
callState = state;
2017-03-31 01:58:05 +02:00
runOnUiThread(new Runnable() {
@Override
public void run() {
2019-09-10 12:56:11 +02:00
boolean wasFirstStateChange = firstStateChange;
2017-03-31 01:58:05 +02:00
if (firstStateChange) {
2019-09-10 12:56:11 +02:00
spkToggle.setChecked(((AudioManager) getSystemService(AUDIO_SERVICE)).isSpeakerphoneOn());
2017-03-31 01:58:05 +02:00
if (isIncomingWaiting = state == VoIPService.STATE_WAITING_INCOMING) {
swipeViewsWrap.setVisibility(View.VISIBLE);
endBtn.setVisibility(View.GONE);
2018-07-30 04:07:02 +02:00
//bottomButtons.setVisibility(View.GONE);
2019-09-10 12:56:11 +02:00
acceptSwipe.startAnimatingArrows();
declineSwipe.startAnimatingArrows();
if (UserConfig.getActivatedAccountsCount() > 1) {
TLRPC.User self = UserConfig.getInstance(currentAccount).getCurrentUser();
accountNameText.setText(LocaleController.formatString("VoipAnsweringAsAccount", R.string.VoipAnsweringAsAccount, ContactsController.formatName(self.first_name, self.last_name)));
} else {
accountNameText.setVisibility(View.GONE);
}
2017-03-31 01:58:05 +02:00
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
2019-09-10 12:56:11 +02:00
VoIPService svc = VoIPService.getSharedInstance();
if (svc != null)
svc.startRingtoneAndVibration();
setTitle(LocaleController.getString("VoipIncoming", R.string.VoipIncoming));
2017-03-31 01:58:05 +02:00
} else {
swipeViewsWrap.setVisibility(View.GONE);
acceptBtn.setVisibility(View.GONE);
declineBtn.setVisibility(View.GONE);
2018-07-30 04:07:02 +02:00
accountNameText.setVisibility(View.GONE);
2017-03-31 01:58:05 +02:00
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
if (state != VoIPService.STATE_ESTABLISHED)
emojiWrap.setVisibility(View.GONE);
firstStateChange = false;
}
2019-09-10 12:56:11 +02:00
if (isIncomingWaiting && state != VoIPService.STATE_WAITING_INCOMING && state != VoIPBaseService.STATE_ENDED && state != VoIPService.STATE_HANGING_UP) {
2017-03-31 01:58:05 +02:00
isIncomingWaiting = false;
if (!didAcceptFromHere)
callAccepted();
}
if (state == VoIPService.STATE_WAITING_INCOMING) {
setStateTextAnimated(LocaleController.getString("VoipIncoming", R.string.VoipIncoming), false);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
} else if (state == VoIPService.STATE_WAIT_INIT || state == VoIPService.STATE_WAIT_INIT_ACK) {
setStateTextAnimated(LocaleController.getString("VoipConnecting", R.string.VoipConnecting), true);
} else if (state == VoIPService.STATE_EXCHANGING_KEYS) {
setStateTextAnimated(LocaleController.getString("VoipExchangingKeys", R.string.VoipExchangingKeys), true);
} else if (state == VoIPService.STATE_WAITING) {
setStateTextAnimated(LocaleController.getString("VoipWaiting", R.string.VoipWaiting), true);
} else if (state == VoIPService.STATE_RINGING) {
setStateTextAnimated(LocaleController.getString("VoipRinging", R.string.VoipRinging), true);
} else if (state == VoIPService.STATE_REQUESTING) {
setStateTextAnimated(LocaleController.getString("VoipRequesting", R.string.VoipRequesting), true);
} else if (state == VoIPService.STATE_HANGING_UP) {
setStateTextAnimated(LocaleController.getString("VoipHangingUp", R.string.VoipHangingUp), true);
2017-07-08 18:32:04 +02:00
endBtnIcon.setAlpha(.5f);
endBtn.setEnabled(false);
2017-12-08 18:35:59 +01:00
} else if (state == VoIPBaseService.STATE_ENDED) {
2017-03-31 01:58:05 +02:00
setStateTextAnimated(LocaleController.getString("VoipCallEnded", R.string.VoipCallEnded), false);
stateText.postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
}, 200);
} else if (state == VoIPService.STATE_BUSY) {
endBtn.setContentDescription(LocaleController.getString("CallAgain", R.string.CallAgain));
2017-03-31 01:58:05 +02:00
//endBtn.setEnabled(false);
setStateTextAnimated(LocaleController.getString("VoipBusy", R.string.VoipBusy), false);
/*stateText.postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
}, 2000);*/
showRetry();
2019-09-10 12:56:11 +02:00
} else if (state == VoIPService.STATE_ESTABLISHED || state == VoIPService.STATE_RECONNECTING) {
2018-07-30 04:07:02 +02:00
/*if(VoIPService.getSharedInstance().canUpgrate()){
addMemberBtn.setEnabled(true);
addMemberBtn.setAlpha(1f);
}*/
2019-05-14 14:08:05 +02:00
setTitle(null);
2019-09-10 12:56:11 +02:00
if (!wasFirstStateChange && state == VoIPService.STATE_ESTABLISHED) {
int count = MessagesController.getGlobalMainSettings().getInt("call_emoji_tooltip_count", 0);
if (count < 3) {
2017-03-31 01:58:05 +02:00
setEmojiTooltipVisible(true);
2019-09-10 12:56:11 +02:00
hintTextView.postDelayed(tooltipHider = new Runnable() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
tooltipHider = null;
2017-03-31 01:58:05 +02:00
setEmojiTooltipVisible(false);
}
}, 5000);
2019-09-10 12:56:11 +02:00
MessagesController.getGlobalMainSettings().edit().putInt("call_emoji_tooltip_count", count + 1).commit();
2017-03-31 01:58:05 +02:00
}
}
2019-09-10 12:56:11 +02:00
if (prevState != VoIPService.STATE_ESTABLISHED && prevState != VoIPService.STATE_RECONNECTING) {
2017-07-08 18:32:04 +02:00
setStateTextAnimated("0:00", false);
startUpdatingCallDuration();
updateKeyView();
2019-09-10 12:56:11 +02:00
if (emojiWrap.getVisibility() != View.VISIBLE) {
2017-07-08 18:32:04 +02:00
emojiWrap.setVisibility(View.VISIBLE);
emojiWrap.setAlpha(0f);
emojiWrap.animate().alpha(1).setDuration(200).setInterpolator(new DecelerateInterpolator()).start();
}
2017-03-31 01:58:05 +02:00
}
} else if (state == VoIPService.STATE_FAILED) {
setStateTextAnimated(LocaleController.getString("VoipFailed", R.string.VoipFailed), false);
2020-03-30 14:00:09 +02:00
final VoIPService voipService = VoIPService.getSharedInstance();
final String lastError = voipService != null ? voipService.getLastError() : TgVoip.ERROR_UNKNOWN;
if (!TextUtils.equals(lastError, TgVoip.ERROR_UNKNOWN)) {
if (TextUtils.equals(lastError, TgVoip.ERROR_INCOMPATIBLE)) {
final String name = ContactsController.formatName(user.first_name, user.last_name);
final String message = LocaleController.formatString("VoipPeerIncompatible", R.string.VoipPeerIncompatible, name);
showErrorDialog(AndroidUtilities.replaceTags(message));
} else if (TextUtils.equals(lastError, TgVoip.ERROR_PEER_OUTDATED)) {
final String name = ContactsController.formatName(user.first_name, user.last_name);
final String message = LocaleController.formatString("VoipPeerOutdated", R.string.VoipPeerOutdated, name);
showErrorDialog(AndroidUtilities.replaceTags(message));
} else if (TextUtils.equals(lastError, TgVoip.ERROR_PRIVACY)) {
final String name = ContactsController.formatName(user.first_name, user.last_name);
final String message = LocaleController.formatString("CallNotAvailable", R.string.CallNotAvailable, name);
showErrorDialog(AndroidUtilities.replaceTags(message));
} else if (TextUtils.equals(lastError, TgVoip.ERROR_AUDIO_IO)) {
showErrorDialog("Error initializing audio hardware");
} else if (TextUtils.equals(lastError, TgVoip.ERROR_LOCALIZED)) {
finish();
} else if (TextUtils.equals(lastError, TgVoip.ERROR_CONNECTION_SERVICE)) {
showErrorDialog(LocaleController.getString("VoipErrorUnknown", R.string.VoipErrorUnknown));
} else {
stateText.postDelayed(() -> finish(), 1000);
}
2017-03-31 01:58:05 +02:00
} else {
2020-03-30 14:00:09 +02:00
stateText.postDelayed(() -> finish(), 1000);
2017-03-31 01:58:05 +02:00
}
}
2017-12-08 18:35:59 +01:00
brandingText.invalidate();
}
});
}
@Override
2019-09-10 12:56:11 +02:00
public void onSignalBarsCountChanged(final int count) {
runOnUiThread(new Runnable() {
2017-12-08 18:35:59 +01:00
@Override
2019-09-10 12:56:11 +02:00
public void run() {
signalBarsCount = count;
2017-12-08 18:35:59 +01:00
brandingText.invalidate();
2017-03-31 01:58:05 +02:00
}
});
}
2019-09-10 12:56:11 +02:00
private void showErrorDialog(CharSequence message) {
2018-07-30 04:07:02 +02:00
AlertDialog dlg = new DarkAlertDialog.Builder(VoIPActivity.this)
2017-03-31 01:58:05 +02:00
.setTitle(LocaleController.getString("VoipFailed", R.string.VoipFailed))
.setMessage(message)
.setPositiveButton(LocaleController.getString("OK", R.string.OK), null)
.show();
dlg.setCanceledOnTouchOutside(true);
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
});
2019-09-10 12:56:11 +02:00
}
2017-03-31 01:58:05 +02:00
@Override
public void onAudioSettingsChanged() {
2019-09-10 12:56:11 +02:00
VoIPBaseService svc = VoIPBaseService.getSharedInstance();
if (svc == null)
2017-03-31 01:58:05 +02:00
return;
2018-07-30 04:07:02 +02:00
micToggle.setChecked(svc.isMicMute());
2019-09-10 12:56:11 +02:00
if (!svc.hasEarpiece() && !svc.isBluetoothHeadsetConnected()) {
2017-03-31 01:58:05 +02:00
spkToggle.setVisibility(View.INVISIBLE);
2019-09-10 12:56:11 +02:00
} else {
2017-03-31 01:58:05 +02:00
spkToggle.setVisibility(View.VISIBLE);
2019-09-10 12:56:11 +02:00
if (!svc.hasEarpiece()) {
2017-03-31 01:58:05 +02:00
spkToggle.setImageResource(R.drawable.ic_bluetooth_white_24dp);
2018-07-30 04:07:02 +02:00
spkToggle.setChecked(svc.isSpeakerphoneOn());
2019-09-10 12:56:11 +02:00
} else if (svc.isBluetoothHeadsetConnected()) {
switch (svc.getCurrentAudioRoute()) {
case VoIPBaseService.AUDIO_ROUTE_BLUETOOTH:
spkToggle.setImageResource(R.drawable.ic_bluetooth_white_24dp);
break;
case VoIPBaseService.AUDIO_ROUTE_SPEAKER:
spkToggle.setImageResource(R.drawable.ic_volume_up_white_24dp);
break;
case VoIPBaseService.AUDIO_ROUTE_EARPIECE:
spkToggle.setImageResource(R.drawable.ic_phone_in_talk_white_24dp);
break;
2017-03-31 01:58:05 +02:00
}
spkToggle.setChecked(false);
2019-09-10 12:56:11 +02:00
} else {
2017-03-31 01:58:05 +02:00
spkToggle.setImageResource(R.drawable.ic_volume_up_white_24dp);
2018-07-30 04:07:02 +02:00
spkToggle.setChecked(svc.isSpeakerphoneOn());
2017-03-31 01:58:05 +02:00
}
}
}
2019-09-10 12:56:11 +02:00
private void setStateTextAnimated(String _newText, boolean ellipsis) {
if (_newText.equals(lastStateText))
2017-03-31 01:58:05 +02:00
return;
2019-09-10 12:56:11 +02:00
lastStateText = _newText;
if (textChangingAnim != null)
2017-03-31 01:58:05 +02:00
textChangingAnim.cancel();
CharSequence newText;
2019-09-10 12:56:11 +02:00
if (ellipsis) {
if (!ellAnimator.isRunning())
2017-03-31 01:58:05 +02:00
ellAnimator.start();
2019-09-10 12:56:11 +02:00
SpannableStringBuilder ssb = new SpannableStringBuilder(_newText.toUpperCase());
for (TextAlphaSpan s : ellSpans)
2017-03-31 01:58:05 +02:00
s.setAlpha(0);
2019-09-10 12:56:11 +02:00
SpannableString ell = new SpannableString("...");
2017-03-31 01:58:05 +02:00
ell.setSpan(ellSpans[0], 0, 1, 0);
ell.setSpan(ellSpans[1], 1, 2, 0);
ell.setSpan(ellSpans[2], 2, 3, 0);
ssb.append(ell);
2019-09-10 12:56:11 +02:00
newText = ssb;
} else {
if (ellAnimator.isRunning())
2017-03-31 01:58:05 +02:00
ellAnimator.cancel();
2019-09-10 12:56:11 +02:00
newText = _newText.toUpperCase();
2017-03-31 01:58:05 +02:00
}
stateText2.setText(newText);
stateText2.setVisibility(View.VISIBLE);
stateText.setPivotX(LocaleController.isRTL ? stateText.getWidth() : 0);
2019-09-10 12:56:11 +02:00
stateText.setPivotY(stateText.getHeight() / 2);
2017-03-31 01:58:05 +02:00
stateText2.setPivotX(LocaleController.isRTL ? stateText.getWidth() : 0);
2019-09-10 12:56:11 +02:00
stateText2.setPivotY(stateText.getHeight() / 2);
durationText = stateText2;
AnimatorSet set = new AnimatorSet();
2017-03-31 01:58:05 +02:00
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(stateText2, View.ALPHA, 0, 1),
ObjectAnimator.ofFloat(stateText2, View.TRANSLATION_Y, stateText.getHeight() / 2, 0),
ObjectAnimator.ofFloat(stateText2, View.SCALE_X, 0.7f, 1),
ObjectAnimator.ofFloat(stateText2, View.SCALE_Y, 0.7f, 1),
ObjectAnimator.ofFloat(stateText, View.ALPHA, 1, 0),
ObjectAnimator.ofFloat(stateText, View.TRANSLATION_Y, 0, -stateText.getHeight() / 2),
ObjectAnimator.ofFloat(stateText, View.SCALE_X, 1, 0.7f),
ObjectAnimator.ofFloat(stateText, View.SCALE_Y, 1, 0.7f)
2017-03-31 01:58:05 +02:00
);
set.setDuration(200);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
2019-09-10 12:56:11 +02:00
set.addListener(new AnimatorListenerAdapter() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onAnimationEnd(Animator animation) {
textChangingAnim = null;
2017-03-31 01:58:05 +02:00
stateText2.setVisibility(View.GONE);
2019-09-10 12:56:11 +02:00
durationText = stateText;
2017-03-31 01:58:05 +02:00
stateText.setTranslationY(0);
stateText.setScaleX(1);
stateText.setScaleY(1);
stateText.setAlpha(1);
stateText.setText(stateText2.getText());
}
});
2019-09-10 12:56:11 +02:00
textChangingAnim = set;
2017-03-31 01:58:05 +02:00
set.start();
}
@Override
2019-09-10 12:56:11 +02:00
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.emojiDidLoad) {
for (ImageView iv : keyEmojiViews) {
2017-03-31 01:58:05 +02:00
iv.invalidate();
}
}
2019-09-10 12:56:11 +02:00
if (id == NotificationCenter.closeInCallActivity) {
2017-03-31 01:58:05 +02:00
finish();
}
}
2019-09-10 12:56:11 +02:00
private void setEmojiTooltipVisible(boolean visible) {
emojiTooltipVisible = visible;
if (tooltipAnim != null)
tooltipAnim.cancel();
hintTextView.setVisibility(View.VISIBLE);
2020-03-30 14:00:09 +02:00
ObjectAnimator oa = ObjectAnimator.ofFloat(hintTextView, View.ALPHA, visible ? 1 : 0);
2019-09-10 12:56:11 +02:00
oa.setDuration(300);
oa.setInterpolator(CubicBezierInterpolator.DEFAULT);
oa.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
tooltipAnim = null;
}
});
tooltipAnim = oa;
oa.start();
2017-03-31 01:58:05 +02:00
}
2019-09-10 12:56:11 +02:00
private void setEmojiExpanded(boolean expanded) {
if (emojiExpanded == expanded)
2017-03-31 01:58:05 +02:00
return;
2019-09-10 12:56:11 +02:00
emojiExpanded = expanded;
if (emojiAnimator != null)
2017-03-31 01:58:05 +02:00
emojiAnimator.cancel();
2019-09-10 12:56:11 +02:00
if (expanded) {
int[] loc = {0, 0}, loc2 = {0, 0};
2017-03-31 01:58:05 +02:00
emojiWrap.getLocationInWindow(loc);
emojiExpandedText.getLocationInWindow(loc2);
2019-09-10 12:56:11 +02:00
Rect rect = new Rect();
2017-03-31 01:58:05 +02:00
getWindow().getDecorView().getGlobalVisibleRect(rect);
2019-09-10 12:56:11 +02:00
int offsetY = loc2[1] - (loc[1] + emojiWrap.getHeight()) - AndroidUtilities.dp(32) - emojiWrap.getHeight();
int firstOffsetX = (rect.width() / 2 - Math.round(emojiWrap.getWidth() * 2.5f) / 2) - loc[0];
AnimatorSet set = new AnimatorSet();
2017-03-31 01:58:05 +02:00
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(emojiWrap, View.TRANSLATION_Y, offsetY),
ObjectAnimator.ofFloat(emojiWrap, View.TRANSLATION_X, firstOffsetX),
ObjectAnimator.ofFloat(emojiWrap, View.SCALE_X, 2.5f),
ObjectAnimator.ofFloat(emojiWrap, View.SCALE_Y, 2.5f),
ObjectAnimator.ofFloat(blurOverlayView1, View.ALPHA, blurOverlayView1.getAlpha(), 1, 1),
ObjectAnimator.ofFloat(blurOverlayView2, View.ALPHA, blurOverlayView2.getAlpha(), blurOverlayView2.getAlpha(), 1),
ObjectAnimator.ofFloat(emojiExpandedText, View.ALPHA, 1)
2017-03-31 01:58:05 +02:00
);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
2019-09-10 12:56:11 +02:00
emojiAnimator = set;
set.addListener(new AnimatorListenerAdapter() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onAnimationEnd(Animator animation) {
emojiAnimator = null;
2017-03-31 01:58:05 +02:00
}
});
set.start();
2019-09-10 12:56:11 +02:00
} else {
AnimatorSet set = new AnimatorSet();
2017-03-31 01:58:05 +02:00
set.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(emojiWrap, View.TRANSLATION_X, 0),
ObjectAnimator.ofFloat(emojiWrap, View.TRANSLATION_Y, 0),
ObjectAnimator.ofFloat(emojiWrap, View.SCALE_X, 1),
ObjectAnimator.ofFloat(emojiWrap, View.SCALE_Y, 1),
ObjectAnimator.ofFloat(blurOverlayView1, View.ALPHA, blurOverlayView1.getAlpha(), blurOverlayView1.getAlpha(), 0),
ObjectAnimator.ofFloat(blurOverlayView2, View.ALPHA, blurOverlayView2.getAlpha(), 0, 0),
ObjectAnimator.ofFloat(emojiExpandedText, View.ALPHA, 0)
2017-03-31 01:58:05 +02:00
);
set.setDuration(300);
set.setInterpolator(CubicBezierInterpolator.DEFAULT);
2019-09-10 12:56:11 +02:00
emojiAnimator = set;
set.addListener(new AnimatorListenerAdapter() {
2017-03-31 01:58:05 +02:00
@Override
2019-09-10 12:56:11 +02:00
public void onAnimationEnd(Animator animation) {
emojiAnimator = null;
2017-03-31 01:58:05 +02:00
}
});
set.start();
}
}
2018-07-30 04:07:02 +02:00
private void updateBlurredPhotos(final ImageReceiver.BitmapHolder src) {
new Thread(new Runnable() {
2017-03-31 01:58:05 +02:00
@Override
2018-07-30 04:07:02 +02:00
public void run() {
try {
Bitmap blur1 = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(blur1);
canvas.drawBitmap(src.bitmap, null, new Rect(0, 0, 150, 150), new Paint(Paint.FILTER_BITMAP_FLAG));
Utilities.blurBitmap(blur1, 3, 0, blur1.getWidth(), blur1.getHeight(), blur1.getRowBytes());
final Palette palette = Palette.from(src.bitmap).generate();
Paint paint = new Paint();
paint.setColor((palette.getDarkMutedColor(0xFF547499) & 0x00FFFFFF) | 0x44000000);
canvas.drawColor(0x26000000);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
Bitmap blur2 = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
canvas = new Canvas(blur2);
canvas.drawBitmap(src.bitmap, null, new Rect(0, 0, 50, 50), new Paint(Paint.FILTER_BITMAP_FLAG));
Utilities.blurBitmap(blur2, 3, 0, blur2.getWidth(), blur2.getHeight(), blur2.getRowBytes());
paint.setAlpha(0x66);
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
blurredPhoto1 = blur1;
blurredPhoto2 = blur2;
2019-09-10 12:56:11 +02:00
runOnUiThread(() -> {
blurOverlayView1.setImageBitmap(blurredPhoto1);
blurOverlayView2.setImageBitmap(blurredPhoto2);
src.release();
2018-07-30 04:07:02 +02:00
});
} catch (Throwable ignore) {
}
2017-03-31 01:58:05 +02:00
}
}).start();
}
2019-09-10 12:56:11 +02:00
private void sendTextMessage(final String text) {
AndroidUtilities.runOnUIThread(() -> SendMessagesHelper.getInstance(currentAccount).sendMessage(text, user.id, null, null, false, null, null, null, true, 0));
2018-07-30 04:07:02 +02:00
}
2019-09-10 12:56:11 +02:00
private void showMessagesSheet() {
if (VoIPService.getSharedInstance() != null)
2018-07-30 04:07:02 +02:00
VoIPService.getSharedInstance().stopRinging();
2019-09-10 12:56:11 +02:00
SharedPreferences prefs = getSharedPreferences("mainconfig", MODE_PRIVATE);
final String[] msgs = {prefs.getString("quick_reply_msg1", LocaleController.getString("QuickReplyDefault1", R.string.QuickReplyDefault1)),
2018-07-30 04:07:02 +02:00
prefs.getString("quick_reply_msg2", LocaleController.getString("QuickReplyDefault2", R.string.QuickReplyDefault2)),
prefs.getString("quick_reply_msg3", LocaleController.getString("QuickReplyDefault3", R.string.QuickReplyDefault3)),
prefs.getString("quick_reply_msg4", LocaleController.getString("QuickReplyDefault4", R.string.QuickReplyDefault4))};
2019-09-10 12:56:11 +02:00
LinearLayout sheetView = new LinearLayout(this);
2018-07-30 04:07:02 +02:00
sheetView.setOrientation(LinearLayout.VERTICAL);
2019-12-31 14:08:08 +01:00
final BottomSheet sheet = new BottomSheet(this, true);
2019-09-10 12:56:11 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(0xff2b2b2b);
sheet.setOnDismissListener(dialog -> getWindow().setNavigationBarColor(0));
2018-07-30 04:07:02 +02:00
}
2019-09-10 12:56:11 +02:00
View.OnClickListener listener = v -> {
sheet.dismiss();
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().declineIncomingCall(VoIPService.DISCARD_REASON_LINE_BUSY, () -> sendTextMessage((String) v.getTag()));
2018-07-30 04:07:02 +02:00
};
2019-09-10 12:56:11 +02:00
for (String msg : msgs) {
BottomSheet.BottomSheetCell cell = new BottomSheet.BottomSheetCell(this, 0);
2018-07-30 04:07:02 +02:00
cell.setTextAndIcon(msg, 0);
cell.setTextColor(0xFFFFFFFF);
cell.setTag(msg);
2019-09-10 12:56:11 +02:00
cell.setOnClickListener(listener);
2018-07-30 04:07:02 +02:00
sheetView.addView(cell);
}
2019-09-10 12:56:11 +02:00
FrameLayout customWrap = new FrameLayout(this);
final BottomSheet.BottomSheetCell cell = new BottomSheet.BottomSheetCell(this, 0);
cell.setTextAndIcon(LocaleController.getString("QuickReplyCustom", R.string.QuickReplyCustom), 0);
cell.setTextColor(0xFFFFFFFF);
customWrap.addView(cell);
final FrameLayout editor = new FrameLayout(this);
2019-12-31 14:08:08 +01:00
final EditTextBoldCursor field = new EditTextBoldCursor(this);
2019-09-10 12:56:11 +02:00
field.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
field.setTextColor(0xFFFFFFFF);
field.setHintTextColor(DarkTheme.getColor(Theme.key_chat_messagePanelHint));
field.setBackgroundDrawable(null);
field.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(11), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
field.setHint(LocaleController.getString("QuickReplyCustom", R.string.QuickReplyCustom));
field.setMinHeight(AndroidUtilities.dp(48));
field.setGravity(Gravity.BOTTOM);
field.setMaxLines(4);
field.setSingleLine(false);
field.setInputType(field.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
editor.addView(field, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 48 : 0, 0, LocaleController.isRTL ? 0 : 48, 0));
final ImageView sendBtn = new ImageView(this);
sendBtn.setScaleType(ImageView.ScaleType.CENTER);
sendBtn.setImageDrawable(DarkTheme.getThemedDrawable(this, R.drawable.ic_send, Theme.key_chat_messagePanelSend));
if (LocaleController.isRTL)
sendBtn.setScaleX(-0.1f);
else
sendBtn.setScaleX(0.1f);
sendBtn.setScaleY(0.1f);
sendBtn.setAlpha(0f);
editor.addView(sendBtn, LayoutHelper.createFrame(48, 48, Gravity.BOTTOM | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT)));
sendBtn.setOnClickListener(v -> {
if (field.length() == 0)
return;
sheet.dismiss();
if (VoIPService.getSharedInstance() != null)
VoIPService.getSharedInstance().declineIncomingCall(VoIPService.DISCARD_REASON_LINE_BUSY, new Runnable() {
@Override
public void run() {
sendTextMessage(field.getText().toString());
}
});
});
sendBtn.setVisibility(View.INVISIBLE);
final ImageView cancelBtn = new ImageView(this);
cancelBtn.setScaleType(ImageView.ScaleType.CENTER);
cancelBtn.setImageDrawable(DarkTheme.getThemedDrawable(this, R.drawable.edit_cancel, Theme.key_chat_messagePanelIcons));
editor.addView(cancelBtn, LayoutHelper.createFrame(48, 48, Gravity.BOTTOM | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT)));
cancelBtn.setOnClickListener(v -> {
editor.setVisibility(View.GONE);
cell.setVisibility(View.VISIBLE);
field.setText("");
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(field.getWindowToken(), 0);
});
field.addTextChangedListener(new TextWatcher() {
boolean prevState = false;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
boolean hasText = s.length() > 0;
if (prevState != hasText) {
prevState = hasText;
if (hasText) {
sendBtn.setVisibility(View.VISIBLE);
sendBtn.animate().alpha(1).scaleX(LocaleController.isRTL ? -1 : 1).scaleY(1).setDuration(200).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
cancelBtn.animate().alpha(0).scaleX(0.1f).scaleY(0.1f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(200).withEndAction(new Runnable() {
@Override
public void run() {
cancelBtn.setVisibility(View.INVISIBLE);
}
}).start();
} else {
cancelBtn.setVisibility(View.VISIBLE);
cancelBtn.animate().alpha(1).scaleX(1).scaleY(1).setDuration(200).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
sendBtn.animate().alpha(0).scaleX(LocaleController.isRTL ? -0.1f : 0.1f).scaleY(0.1f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(200).withEndAction(new Runnable() {
@Override
public void run() {
sendBtn.setVisibility(View.INVISIBLE);
}
}).start();
}
}
}
});
editor.setVisibility(View.GONE);
customWrap.addView(editor);
cell.setOnClickListener(v -> {
editor.setVisibility(View.VISIBLE);
cell.setVisibility(View.INVISIBLE);
field.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(field, 0);
});
sheetView.addView(customWrap);
2018-07-30 04:07:02 +02:00
sheet.setCustomView(sheetView);
sheet.setBackgroundColor(0xff2b2b2b);
sheet.show();
}
2019-09-10 12:56:11 +02:00
private class TextAlphaSpan extends CharacterStyle {
2017-03-31 01:58:05 +02:00
private int alpha;
2019-09-10 12:56:11 +02:00
public TextAlphaSpan() {
this.alpha = 0;
2017-03-31 01:58:05 +02:00
}
2020-03-30 14:00:09 +02:00
@Keep
2019-09-10 12:56:11 +02:00
public int getAlpha() {
2017-03-31 01:58:05 +02:00
return alpha;
}
2020-03-30 14:00:09 +02:00
@Keep
2019-09-10 12:56:11 +02:00
public void setAlpha(int alpha) {
this.alpha = alpha;
2017-03-31 01:58:05 +02:00
stateText.invalidate();
stateText2.invalidate();
}
@Override
2019-09-10 12:56:11 +02:00
public void updateDrawState(TextPaint tp) {
2017-03-31 01:58:05 +02:00
tp.setAlpha(alpha);
}
}
2017-12-08 18:35:59 +01:00
2019-09-10 12:56:11 +02:00
private class SignalBarsDrawable extends Drawable {
2017-12-08 18:35:59 +01:00
2019-09-10 12:56:11 +02:00
private int[] barHeights = {AndroidUtilities.dp(3), AndroidUtilities.dp(6), AndroidUtilities.dp(9), AndroidUtilities.dp(12)};
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private RectF rect = new RectF();
private int offsetStart = 6;
2017-12-08 18:35:59 +01:00
@Override
2019-09-10 12:56:11 +02:00
public void draw(Canvas canvas) {
if (callState != VoIPService.STATE_ESTABLISHED && callState != VoIPService.STATE_RECONNECTING)
2017-12-08 18:35:59 +01:00
return;
paint.setColor(0xFFFFFFFF);
2019-09-10 12:56:11 +02:00
int x = getBounds().left + AndroidUtilities.dp(LocaleController.isRTL ? 0 : offsetStart);
int y = getBounds().top;
for (int i = 0; i < 4; i++) {
paint.setAlpha(i + 1 <= signalBarsCount ? 242 : 102);
rect.set(x + AndroidUtilities.dp(4 * i), y + getIntrinsicHeight() - barHeights[i], x + AndroidUtilities.dp(4) * i + AndroidUtilities.dp(3), y + getIntrinsicHeight());
2017-12-08 18:35:59 +01:00
canvas.drawRoundRect(rect, AndroidUtilities.dp(.3f), AndroidUtilities.dp(.3f), paint);
}
}
@Override
2019-09-10 12:56:11 +02:00
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
2017-12-08 18:35:59 +01:00
}
@Override
2019-09-10 12:56:11 +02:00
public void setColorFilter(@Nullable ColorFilter colorFilter) {
2017-12-08 18:35:59 +01:00
}
@Override
2019-09-10 12:56:11 +02:00
public int getIntrinsicWidth() {
return AndroidUtilities.dp(15 + offsetStart);
2017-12-08 18:35:59 +01:00
}
@Override
2019-09-10 12:56:11 +02:00
public int getIntrinsicHeight() {
2017-12-08 18:35:59 +01:00
return AndroidUtilities.dp(12);
}
@Override
2019-09-10 12:56:11 +02:00
public int getOpacity() {
2017-12-08 18:35:59 +01:00
return PixelFormat.TRANSLUCENT;
}
}
2017-03-31 01:58:05 +02:00
}