Search in sources :

Example 1 with VoIPService

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);
        }
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) ChatObject(org.telegram.messenger.ChatObject) AnimatorSet(android.animation.AnimatorSet) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TLRPC(org.telegram.tgnet.TLRPC) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) Matrix(android.graphics.Matrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) VoIPService(org.telegram.messenger.voip.VoIPService)

Example 2 with VoIPService

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();
    }
}
Also used : ChatObject(org.telegram.messenger.ChatObject) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC) VoIPService(org.telegram.messenger.voip.VoIPService)

Example 3 with VoIPService

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();
}
Also used : VoIPService(org.telegram.messenger.voip.VoIPService)

Example 4 with VoIPService

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);
}
Also used : SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) VoIPService(org.telegram.messenger.voip.VoIPService)

Example 5 with VoIPService

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);
}
Also used : VoIPService(org.telegram.messenger.voip.VoIPService)

Aggregations

VoIPService (org.telegram.messenger.voip.VoIPService)44 Paint (android.graphics.Paint)16 SuppressLint (android.annotation.SuppressLint)13 TLRPC (org.telegram.tgnet.TLRPC)13 ObjectAnimator (android.animation.ObjectAnimator)10 Animator (android.animation.Animator)9 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)9 View (android.view.View)9 ImageView (android.widget.ImageView)9 TextView (android.widget.TextView)9 ValueAnimator (android.animation.ValueAnimator)8 ChatObject (org.telegram.messenger.ChatObject)7 BackupImageView (org.telegram.ui.Components.BackupImageView)7 HintView (org.telegram.ui.Components.HintView)7 Intent (android.content.Intent)6 AnimatorSet (android.animation.AnimatorSet)5 LinearLayout (android.widget.LinearLayout)5 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)5 Canvas (android.graphics.Canvas)4 SharedPreferences (android.content.SharedPreferences)3