Search in sources :

Example 1 with PopupAudioView

use of org.telegram.ui.Components.PopupAudioView in project Telegram-FOSS by Telegram-FOSS-Team.

the class PopupNotificationActivity method getViewForMessage.

private ViewGroup getViewForMessage(int num, boolean applyOffset) {
    if (popupMessages.size() == 1 && (num < 0 || num >= popupMessages.size())) {
        return null;
    }
    if (num == -1) {
        num = popupMessages.size() - 1;
    } else if (num == popupMessages.size()) {
        num = 0;
    }
    ViewGroup view;
    MessageObject messageObject = popupMessages.get(num);
    if ((messageObject.type == 1 || messageObject.type == 4) && !messageObject.isSecretMedia()) {
        if (imageViews.size() > 0) {
            view = imageViews.get(0);
            imageViews.remove(0);
        } else {
            view = new FrameLayout(this);
            FrameLayout frameLayout = new FrameLayout(this);
            frameLayout.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10));
            frameLayout.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            view.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            BackupImageView backupImageView = new BackupImageView(this);
            backupImageView.setTag(311);
            frameLayout.addView(backupImageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            TextView textView = new TextView(this);
            textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            textView.setGravity(Gravity.CENTER);
            textView.setTag(312);
            frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
            view.setTag(2);
            view.setOnClickListener(v -> openCurrentMessage());
        }
        TextView messageText = view.findViewWithTag(312);
        BackupImageView imageView = view.findViewWithTag(311);
        imageView.setAspectFit(true);
        if (messageObject.type == 1) {
            TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
            TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
            boolean photoSet = false;
            if (currentPhotoObject != null) {
                boolean photoExist = true;
                if (messageObject.type == 1) {
                    File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
                    if (!cacheFile.exists()) {
                        photoExist = false;
                    }
                }
                if (!messageObject.needDrawBluredPreview()) {
                    if (photoExist || DownloadController.getInstance(messageObject.currentAccount).canDownloadMedia(messageObject)) {
                        imageView.setImage(ImageLocation.getForObject(currentPhotoObject, messageObject.photoThumbsObject), "100_100", ImageLocation.getForObject(thumb, messageObject.photoThumbsObject), "100_100_b", currentPhotoObject.size, messageObject);
                        photoSet = true;
                    } else {
                        if (thumb != null) {
                            imageView.setImage(ImageLocation.getForObject(thumb, messageObject.photoThumbsObject), "100_100_b", null, null, messageObject);
                            photoSet = true;
                        }
                    }
                }
            }
            if (!photoSet) {
                imageView.setVisibility(View.GONE);
                messageText.setVisibility(View.VISIBLE);
                messageText.setTextSize(TypedValue.COMPLEX_UNIT_SP, SharedConfig.fontSize);
                messageText.setText(messageObject.messageText);
            } else {
                imageView.setVisibility(View.VISIBLE);
                messageText.setVisibility(View.GONE);
            }
        } else if (messageObject.type == 4) {
            messageText.setVisibility(View.GONE);
            messageText.setText(messageObject.messageText);
            imageView.setVisibility(View.VISIBLE);
            TLRPC.GeoPoint geoPoint = messageObject.messageOwner.media.geo;
            double lat = geoPoint.lat;
            double lon = geoPoint._long;
            if (MessagesController.getInstance(messageObject.currentAccount).mapProvider == 2) {
                imageView.setImage(ImageLocation.getForWebFile(WebFile.createWithGeoPoint(geoPoint, 100, 100, 15, Math.min(2, (int) Math.ceil(AndroidUtilities.density)))), null, null, null, messageObject);
            } else {
                String currentUrl = AndroidUtilities.formapMapUrl(messageObject.currentAccount, lat, lon, 100, 100, true, 15, -1);
                imageView.setImage(currentUrl, null, null);
            }
        }
    } else if (messageObject.type == 2) {
        PopupAudioView cell;
        if (audioViews.size() > 0) {
            view = audioViews.get(0);
            audioViews.remove(0);
            cell = view.findViewWithTag(300);
        } else {
            view = new FrameLayout(this);
            FrameLayout frameLayout = new FrameLayout(this);
            frameLayout.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10));
            frameLayout.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            view.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            FrameLayout frameLayout1 = new FrameLayout(this);
            frameLayout.addView(frameLayout1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 20, 0, 20, 0));
            cell = new PopupAudioView(this);
            cell.setTag(300);
            frameLayout1.addView(cell);
            view.setTag(3);
            view.setOnClickListener(v -> openCurrentMessage());
        }
        cell.setMessageObject(messageObject);
        if (DownloadController.getInstance(messageObject.currentAccount).canDownloadMedia(messageObject)) {
            cell.downloadAudioIfNeed();
        }
    } else {
        if (textViews.size() > 0) {
            view = textViews.get(0);
            textViews.remove(0);
        } else {
            view = new FrameLayout(this);
            ScrollView scrollView = new ScrollView(this);
            scrollView.setFillViewport(true);
            view.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            LinearLayout linearLayout = new LinearLayout(this);
            linearLayout.setOrientation(LinearLayout.HORIZONTAL);
            linearLayout.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            scrollView.addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
            linearLayout.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10), AndroidUtilities.dp(10));
            linearLayout.setOnClickListener(v -> openCurrentMessage());
            TextView textView = new TextView(this);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            textView.setTag(301);
            textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            textView.setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            textView.setGravity(Gravity.CENTER);
            linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
            view.setTag(1);
        }
        TextView messageText = view.findViewWithTag(301);
        messageText.setTextSize(TypedValue.COMPLEX_UNIT_SP, SharedConfig.fontSize);
        messageText.setText(messageObject.messageText);
    }
    if (view.getParent() == null) {
        messageContainer.addView(view);
    }
    view.setVisibility(View.VISIBLE);
    if (applyOffset) {
        int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.width = widht;
        if (num == currentMessageNum) {
            view.setTranslationX(0);
        } else if (num == currentMessageNum - 1) {
            view.setTranslationX(-widht);
        } else if (num == currentMessageNum + 1) {
            view.setTranslationX(widht);
        }
        view.setLayoutParams(layoutParams);
        view.invalidate();
    }
    return view;
}
Also used : KeyguardManager(android.app.KeyguardManager) TypingDotsDrawable(org.telegram.ui.Components.TypingDotsDrawable) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) WebFile(org.telegram.messenger.WebFile) PowerManager(android.os.PowerManager) ApplicationLoader(org.telegram.messenger.ApplicationLoader) AttributeSet(android.util.AttributeSet) MediaController(org.telegram.messenger.MediaController) View(android.view.View) StatusDrawable(org.telegram.ui.Components.StatusDrawable) NotificationsController(org.telegram.messenger.NotificationsController) PlayingGameDrawable(org.telegram.ui.Components.PlayingGameDrawable) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) RoundStatusDrawable(org.telegram.ui.Components.RoundStatusDrawable) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) RelativeLayout(android.widget.RelativeLayout) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) FileLoader(org.telegram.messenger.FileLoader) SendingFileDrawable(org.telegram.ui.Components.SendingFileDrawable) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) ArrayList(java.util.ArrayList) VelocityTracker(android.view.VelocityTracker) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) SharedConfig(org.telegram.messenger.SharedConfig) MessageObject(org.telegram.messenger.MessageObject) DownloadController(org.telegram.messenger.DownloadController) DialogObject(org.telegram.messenger.DialogObject) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) PopupAudioView(org.telegram.ui.Components.PopupAudioView) R(org.telegram.messenger.R) BackupImageView(org.telegram.ui.Components.BackupImageView) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) TypedValue(android.util.TypedValue) RecordStatusDrawable(org.telegram.ui.Components.RecordStatusDrawable) ScrollView(android.widget.ScrollView) ContactsController(org.telegram.messenger.ContactsController) Configuration(android.content.res.Configuration) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ViewGroup(android.view.ViewGroup) PopupAudioView(org.telegram.ui.Components.PopupAudioView) TLRPC(org.telegram.tgnet.TLRPC) ScrollView(android.widget.ScrollView) BackupImageView(org.telegram.ui.Components.BackupImageView) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) TextView(android.widget.TextView) MessageObject(org.telegram.messenger.MessageObject) WebFile(org.telegram.messenger.WebFile) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 2 with PopupAudioView

use of org.telegram.ui.Components.PopupAudioView in project Telegram-FOSS by Telegram-FOSS-Team.

the class PopupNotificationActivity method didReceivedNotification.

@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.appDidLogout) {
        if (account == lastResumedAccount) {
            onFinish();
            finish();
        }
    } else if (id == NotificationCenter.pushMessagesUpdated) {
        if (!isReply) {
            popupMessages.clear();
            for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
                if (UserConfig.getInstance(a).isClientActivated()) {
                    popupMessages.addAll(NotificationsController.getInstance(a).popupMessages);
                }
            }
            getNewMessage();
            if (!popupMessages.isEmpty()) {
                for (int a = 0; a < 3; a++) {
                    int num = currentMessageNum - 1 + a;
                    MessageObject messageObject;
                    if (popupMessages.size() == 1 && (num < 0 || num >= popupMessages.size())) {
                        messageObject = null;
                    } else {
                        if (num == -1) {
                            num = popupMessages.size() - 1;
                        } else if (num == popupMessages.size()) {
                            num = 0;
                        }
                        messageObject = popupMessages.get(num);
                    }
                    if (setMessageObjects[a] != messageObject) {
                        updateInterfaceForCurrentMessage(0);
                    }
                }
            }
        }
    } else if (id == NotificationCenter.updateInterfaces) {
        if (currentMessageObject == null || account != lastResumedAccount) {
            return;
        }
        int updateMask = (Integer) args[0];
        if ((updateMask & MessagesController.UPDATE_MASK_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_STATUS) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_MEMBERS) != 0) {
            updateSubtitle();
        }
        if ((updateMask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (updateMask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
            checkAndUpdateAvatar();
        }
        if ((updateMask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
            CharSequence printString = MessagesController.getInstance(currentMessageObject.currentAccount).getPrintingString(currentMessageObject.getDialogId(), 0, false);
            if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && !lastPrintString.equals(printString)) {
                updateSubtitle();
            }
        }
    } else if (id == NotificationCenter.messagePlayingDidReset) {
        Integer mid = (Integer) args[0];
        if (messageContainer != null) {
            int count = messageContainer.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = messageContainer.getChildAt(a);
                if ((Integer) view.getTag() == 3) {
                    PopupAudioView cell = view.findViewWithTag(300);
                    MessageObject messageObject = cell.getMessageObject();
                    if (messageObject != null && messageObject.currentAccount == account && messageObject.getId() == mid) {
                        cell.updateButtonState();
                        break;
                    }
                }
            }
        }
    } else if (id == NotificationCenter.messagePlayingProgressDidChanged) {
        Integer mid = (Integer) args[0];
        if (messageContainer != null) {
            int count = messageContainer.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = messageContainer.getChildAt(a);
                if ((Integer) view.getTag() == 3) {
                    PopupAudioView cell = view.findViewWithTag(300);
                    MessageObject messageObject = cell.getMessageObject();
                    if (messageObject != null && messageObject.currentAccount == account && messageObject.getId() == mid) {
                        cell.updateProgress();
                        break;
                    }
                }
            }
        }
    } else if (id == NotificationCenter.emojiLoaded) {
        if (messageContainer != null) {
            int count = messageContainer.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = messageContainer.getChildAt(a);
                if ((Integer) view.getTag() == 1) {
                    TextView textView = view.findViewWithTag(301);
                    if (textView != null) {
                        textView.invalidate();
                    }
                }
            }
        }
    } else if (id == NotificationCenter.contactsDidLoad) {
        if (account == lastResumedAccount) {
            updateSubtitle();
        }
    }
}
Also used : PopupAudioView(org.telegram.ui.Components.PopupAudioView) TextView(android.widget.TextView) MessageObject(org.telegram.messenger.MessageObject) View(android.view.View) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) PopupAudioView(org.telegram.ui.Components.PopupAudioView) BackupImageView(org.telegram.ui.Components.BackupImageView) ScrollView(android.widget.ScrollView)

Aggregations

View (android.view.View)2 ScrollView (android.widget.ScrollView)2 TextView (android.widget.TextView)2 MessageObject (org.telegram.messenger.MessageObject)2 BackupImageView (org.telegram.ui.Components.BackupImageView)2 ChatActivityEnterView (org.telegram.ui.Components.ChatActivityEnterView)2 PopupAudioView (org.telegram.ui.Components.PopupAudioView)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 Activity (android.app.Activity)1 KeyguardManager (android.app.KeyguardManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 PowerManager (android.os.PowerManager)1