use of org.telegram.messenger.voip.VoIPService in project Telegram-FOSS by Telegram-FOSS-Team.
the class FragmentContextView method checkCall.
public void checkCall(boolean create) {
VoIPService voIPService = VoIPService.getSharedInstance();
if (visible && currentStyle == 5 && (voIPService == null || voIPService.isHangingUp())) {
return;
}
View fragmentView = fragment.getFragmentView();
if (!create && fragmentView != null) {
if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
create = true;
}
}
boolean callAvailable;
boolean groupActive;
if (GroupCallPip.isShowing()) {
callAvailable = false;
groupActive = false;
} else {
callAvailable = !GroupCallActivity.groupCallUiVisible && supportsCalls && voIPService != null && !voIPService.isHangingUp();
if (voIPService != null && voIPService.groupCall != null && voIPService.groupCall.call instanceof TLRPC.TL_groupCallDiscarded) {
callAvailable = false;
}
groupActive = false;
if (!isPlayingVoice() && !GroupCallActivity.groupCallUiVisible && supportsCalls && !callAvailable && fragment instanceof ChatActivity) {
ChatObject.Call call = ((ChatActivity) fragment).getGroupCall();
if (call != null && call.shouldShowPanel()) {
callAvailable = true;
groupActive = true;
}
}
}
if (!callAvailable) {
if (visible && (create && currentStyle == -1 || currentStyle == 4 || currentStyle == 3 || currentStyle == 1)) {
visible = false;
if (create) {
if (getVisibility() != GONE) {
setVisibility(GONE);
}
setTopPadding(0);
} else {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
final int currentAccount = account;
animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
animatorSet.setDuration(220);
animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
if (animatorSet != null && animatorSet.equals(animation)) {
setVisibility(GONE);
animatorSet = null;
if (checkCallAfterAnimation) {
checkCall(false);
} else if (checkPlayerAfterAnimation) {
checkPlayer(false);
} else if (checkImportAfterAnimation) {
checkImport(false);
}
checkCallAfterAnimation = false;
checkPlayerAfterAnimation = false;
checkImportAfterAnimation = false;
}
}
});
animatorSet.start();
}
} else if (visible && (currentStyle == -1 || currentStyle == 4 || currentStyle == 3 || currentStyle == 1)) {
visible = false;
setVisibility(GONE);
}
if (create && fragment instanceof ChatActivity && ((ChatActivity) fragment).openedWithLivestream() && !GroupCallPip.isShowing()) {
BulletinFactory.of(fragment).createSimpleBulletin(R.raw.linkbroken, LocaleController.getString("InviteExpired", R.string.InviteExpired)).show();
}
} else {
int newStyle;
if (groupActive) {
newStyle = 4;
} else if (voIPService.groupCall != null) {
newStyle = 3;
} else {
newStyle = 1;
}
if (newStyle != currentStyle && animatorSet != null && !create) {
checkCallAfterAnimation = true;
return;
}
if (newStyle != currentStyle && visible && !create) {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
final int currentAccount = account;
animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
animatorSet.setDuration(220);
animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
if (animatorSet != null && animatorSet.equals(animation)) {
visible = false;
animatorSet = null;
checkCall(false);
}
}
});
animatorSet.start();
return;
}
if (groupActive) {
boolean updateAnimated = currentStyle == 4 && visible;
updateStyle(4);
ChatObject.Call call = ((ChatActivity) fragment).getGroupCall();
TLRPC.Chat chat = ((ChatActivity) fragment).getCurrentChat();
if (call.isScheduled()) {
if (gradientPaint == null) {
gradientTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
gradientTextPaint.setColor(0xffffffff);
gradientTextPaint.setTextSize(AndroidUtilities.dp(14));
gradientTextPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
gradientPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
gradientPaint.setColor(0xffffffff);
matrix = new Matrix();
}
joinButton.setVisibility(GONE);
if (!TextUtils.isEmpty(call.call.title)) {
titleTextView.setText(call.call.title, false);
} else {
if (ChatObject.isChannelOrGiga(chat)) {
titleTextView.setText(LocaleController.getString("VoipChannelScheduledVoiceChat", R.string.VoipChannelScheduledVoiceChat), false);
} else {
titleTextView.setText(LocaleController.getString("VoipGroupScheduledVoiceChat", R.string.VoipGroupScheduledVoiceChat), false);
}
}
subtitleTextView.setText(LocaleController.formatStartsTime(call.call.schedule_date, 4), false);
if (!scheduleRunnableScheduled) {
scheduleRunnableScheduled = true;
updateScheduleTimeRunnable.run();
}
} else {
timeLayout = null;
joinButton.setVisibility(VISIBLE);
if (ChatObject.isChannelOrGiga(chat)) {
titleTextView.setText(LocaleController.getString("VoipChannelVoiceChat", R.string.VoipChannelVoiceChat), false);
} else {
titleTextView.setText(LocaleController.getString("VoipGroupVoiceChat", R.string.VoipGroupVoiceChat), false);
}
if (call.call.participants_count == 0) {
subtitleTextView.setText(LocaleController.getString("MembersTalkingNobody", R.string.MembersTalkingNobody), false);
} else {
subtitleTextView.setText(LocaleController.formatPluralString("Participants", call.call.participants_count), false);
}
frameLayout.invalidate();
}
updateAvatars(avatars.avatarsDarawable.wasDraw && updateAnimated);
} else {
if (voIPService != null && voIPService.groupCall != null) {
updateAvatars(currentStyle == 3);
updateStyle(3);
} else {
updateAvatars(currentStyle == 1);
updateStyle(1);
}
}
if (!visible) {
if (!create) {
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
animatorSet = new AnimatorSet();
if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE) {
((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight() + additionalContextView.getStyleHeight());
} else {
((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight());
}
final int currentAccount = account;
animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, new int[] { NotificationCenter.messagesDidLoad });
animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp2(getStyleHeight())));
animatorSet.setDuration(220);
animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
if (animatorSet != null && animatorSet.equals(animation)) {
animatorSet = null;
}
if (checkCallAfterAnimation) {
checkCall(false);
} else if (checkPlayerAfterAnimation) {
checkPlayer(false);
} else if (checkImportAfterAnimation) {
checkImport(false);
}
checkCallAfterAnimation = false;
checkPlayerAfterAnimation = false;
checkImportAfterAnimation = false;
}
});
animatorSet.start();
} else {
updatePaddings();
setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
}
visible = true;
setVisibility(VISIBLE);
}
}
}
use of org.telegram.messenger.voip.VoIPService in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallPip method updateAvatars.
private void updateAvatars(boolean animated) {
if (avatarsImageView.avatarsDarawable.transitionProgressAnimator == null) {
ChatObject.Call call;
VoIPService voIPService = VoIPService.getSharedInstance();
if (voIPService != null) {
call = voIPService.groupCall;
} else {
call = null;
}
if (call != null) {
long selfId = voIPService.getSelfId();
for (int a = 0, N = call.sortedParticipants.size(), k = 0; k < 2; a++) {
if (a < N) {
TLRPC.TL_groupCallParticipant participant = call.sortedParticipants.get(a);
if (MessageObject.getPeerId(participant.peer) == selfId || (SystemClock.uptimeMillis() - participant.lastSpeakTime > 500)) {
continue;
}
avatarsImageView.setObject(k, currentAccount, participant);
k++;
} else {
avatarsImageView.setObject(k, currentAccount, null);
k++;
}
}
avatarsImageView.setObject(2, currentAccount, null);
avatarsImageView.commitTransition(animated);
} else {
for (int a = 0; a < 3; a++) {
avatarsImageView.setObject(a, currentAccount, null);
}
avatarsImageView.commitTransition(animated);
}
} else {
avatarsImageView.updateAfterTransitionEnd();
}
}
use of org.telegram.messenger.voip.VoIPService in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallPipAlertView method updateButtons.
private void updateButtons(boolean animated) {
if (soundButton == null || muteButton == null) {
return;
}
VoIPService service = VoIPService.getSharedInstance();
if (service == null) {
return;
}
boolean bluetooth = service.isBluetoothOn();
boolean checked = !bluetooth && service.isSpeakerphoneOn();
soundButton.setChecked(checked, animated);
if (bluetooth) {
soundButton.setData(R.drawable.calls_bluetooth, Color.WHITE, 0, 0.1f, true, LocaleController.getString("VoipAudioRoutingBluetooth", R.string.VoipAudioRoutingBluetooth), false, animated);
} else if (checked) {
soundButton.setData(R.drawable.calls_speaker, Color.WHITE, 0, 0.3f, true, LocaleController.getString("VoipSpeaker", R.string.VoipSpeaker), false, animated);
} else {
if (service.isHeadsetPlugged()) {
soundButton.setData(R.drawable.calls_headphones, Color.WHITE, 0, 0.1f, true, LocaleController.getString("VoipAudioRoutingHeadset", R.string.VoipAudioRoutingHeadset), false, animated);
} else {
soundButton.setData(R.drawable.calls_speaker, Color.WHITE, 0, 0.1f, true, LocaleController.getString("VoipSpeaker", R.string.VoipSpeaker), false, animated);
}
}
if (service.mutedByAdmin()) {
muteButton.setData(R.drawable.calls_unmute, Color.WHITE, ColorUtils.setAlphaComponent(Color.WHITE, (int) (255 * 0.3f)), 0.1f, true, LocaleController.getString("VoipMutedByAdminShort", R.string.VoipMutedByAdminShort), true, animated);
} else {
muteButton.setData(R.drawable.calls_unmute, Color.WHITE, ColorUtils.setAlphaComponent(Color.WHITE, (int) (255 * (service.isMicMute() ? 0.3f : 0.15f))), 0.1f, true, service.isMicMute() ? LocaleController.getString("VoipUnmute", R.string.VoipUnmute) : LocaleController.getString("VoipMute", R.string.VoipMute), service.isMicMute(), animated);
}
invalidate();
}
use of org.telegram.messenger.voip.VoIPService in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallPipAlertView method onAttachedToWindow.
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
VoIPService service = VoIPService.getSharedInstance();
if (service != null && service.groupCall != null) {
int color2 = AvatarDrawable.getColorForId(service.getChat().id);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setColor(color2);
avatarDrawable.setInfo(service.getChat());
avatarImageView.setImage(ImageLocation.getForLocal(service.getChat().photo.photo_small), "50_50", avatarDrawable, null);
String titleStr;
if (!TextUtils.isEmpty(service.groupCall.call.title)) {
titleStr = service.groupCall.call.title;
} else {
titleStr = service.getChat().title;
}
if (titleStr != null) {
titleStr = titleStr.replace("\n", " ").replaceAll(" +", " ").trim();
}
titleView.setText(titleStr);
updateMembersCount();
service.registerStateListener(this);
if (VoIPService.getSharedInstance() != null) {
mutedByAdmin = VoIPService.getSharedInstance().mutedByAdmin();
}
mutedByAdminProgress = mutedByAdmin ? 1f : 0;
boolean isMute = VoIPService.getSharedInstance() == null || VoIPService.getSharedInstance().isMicMute() || mutedByAdmin;
muteProgress = isMute ? 1f : 0f;
}
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.groupCallUpdated);
updateButtons(false);
}
use of org.telegram.messenger.voip.VoIPService in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallPipAlertView method onDetachedFromWindow.
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
VoIPService service = VoIPService.getSharedInstance();
if (service != null) {
service.unregisterStateListener(this);
}
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.groupCallUpdated);
}
Aggregations