Search in sources :

Example 31 with ChatActivity

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

the class BackButtonMenu method goToPulledDialog.

public static void goToPulledDialog(BaseFragment fragment, PulledDialog dialog) {
    if (dialog == null) {
        return;
    }
    if (dialog.activity == ChatActivity.class) {
        Bundle bundle = new Bundle();
        if (dialog.chat != null) {
            bundle.putLong("chat_id", dialog.chat.id);
        } else if (dialog.user != null) {
            bundle.putLong("user_id", dialog.user.id);
        }
        bundle.putInt("dialog_folder_id", dialog.folderId);
        bundle.putInt("dialog_filter_id", dialog.filterId);
        fragment.presentFragment(new ChatActivity(bundle), true);
    } else if (dialog.activity == ProfileActivity.class) {
        Bundle bundle = new Bundle();
        bundle.putLong("dialog_id", dialog.dialogId);
        fragment.presentFragment(new ProfileActivity(bundle), true);
    }
}
Also used : ProfileActivity(org.telegram.ui.ProfileActivity) ChatActivity(org.telegram.ui.ChatActivity) Bundle(android.os.Bundle)

Example 32 with ChatActivity

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

the class AudioPlayerAlert method onSubItemClick.

private void onSubItemClick(int id) {
    final MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
    if (messageObject == null || parentActivity == null) {
        return;
    }
    if (id == 1) {
        if (UserConfig.selectedAccount != currentAccount) {
            parentActivity.switchToAccount(currentAccount, true);
        }
        Bundle args = new Bundle();
        args.putBoolean("onlySelect", true);
        args.putInt("dialogsType", 3);
        DialogsActivity fragment = new DialogsActivity(args);
        final ArrayList<MessageObject> fmessages = new ArrayList<>();
        fmessages.add(messageObject);
        fragment.setDelegate((fragment1, dids, message, param) -> {
            if (dids.size() > 1 || dids.get(0) == UserConfig.getInstance(currentAccount).getClientUserId() || message != null) {
                for (int a = 0; a < dids.size(); a++) {
                    long did = dids.get(a);
                    if (message != null) {
                        SendMessagesHelper.getInstance(currentAccount).sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
                    }
                    SendMessagesHelper.getInstance(currentAccount).sendMessage(fmessages, did, false, false, true, 0);
                }
                fragment1.finishFragment();
            } else {
                long did = dids.get(0);
                Bundle args1 = new Bundle();
                args1.putBoolean("scrollToTopOnResume", true);
                if (DialogObject.isEncryptedDialog(did)) {
                    args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
                } else if (DialogObject.isUserDialog(did)) {
                    args1.putLong("user_id", did);
                } else {
                    args1.putLong("chat_id", -did);
                }
                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
                ChatActivity chatActivity = new ChatActivity(args1);
                if (parentActivity.presentFragment(chatActivity, true, false)) {
                    chatActivity.showFieldPanelForForward(true, fmessages);
                } else {
                    fragment1.finishFragment();
                }
            }
        });
        parentActivity.presentFragment(fragment);
        dismiss();
    } else if (id == 2) {
        try {
            File f = null;
            boolean isVideo = false;
            if (!TextUtils.isEmpty(messageObject.messageOwner.attachPath)) {
                f = new File(messageObject.messageOwner.attachPath);
                if (!f.exists()) {
                    f = null;
                }
            }
            if (f == null) {
                f = FileLoader.getPathToMessage(messageObject.messageOwner);
            }
            if (f.exists()) {
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType(messageObject.getMimeType());
                if (Build.VERSION.SDK_INT >= 24) {
                    try {
                        intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(ApplicationLoader.applicationContext, BuildConfig.APPLICATION_ID + ".provider", f));
                        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    } catch (Exception ignore) {
                        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
                    }
                } else {
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
                }
                parentActivity.startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
                builder.show();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else if (id == 4) {
        if (UserConfig.selectedAccount != currentAccount) {
            parentActivity.switchToAccount(currentAccount, true);
        }
        Bundle args = new Bundle();
        long did = messageObject.getDialogId();
        if (DialogObject.isEncryptedDialog(did)) {
            args.putInt("enc_id", DialogObject.getEncryptedChatId(did));
        } else if (DialogObject.isUserDialog(did)) {
            args.putLong("user_id", did);
        } else {
            TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-did);
            if (chat != null && chat.migrated_to != null) {
                args.putLong("migrated_to", did);
                did = -chat.migrated_to.channel_id;
            }
            args.putLong("chat_id", -did);
        }
        args.putInt("message_id", messageObject.getId());
        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
        parentActivity.presentFragment(new ChatActivity(args), false, false);
        dismiss();
    } else if (id == 5) {
        if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            parentActivity.requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
            return;
        }
        String fileName = FileLoader.getDocumentFileName(messageObject.getDocument());
        if (TextUtils.isEmpty(fileName)) {
            fileName = messageObject.getFileName();
        }
        String path = messageObject.messageOwner.attachPath;
        if (path != null && path.length() > 0) {
            File temp = new File(path);
            if (!temp.exists()) {
                path = null;
            }
        }
        if (path == null || path.length() == 0) {
            path = FileLoader.getPathToMessage(messageObject.messageOwner).toString();
        }
        MediaController.saveFile(path, parentActivity, 3, fileName, messageObject.getDocument() != null ? messageObject.getDocument().mime_type : "", () -> BulletinFactory.of((FrameLayout) containerView, resourcesProvider).createDownloadBulletin(BulletinFactory.FileType.AUDIO).show());
    }
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ChatActivity(org.telegram.ui.ChatActivity) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) DialogsActivity(org.telegram.ui.DialogsActivity) Paint(android.graphics.Paint) MessageObject(org.telegram.messenger.MessageObject) File(java.io.File)

Example 33 with ChatActivity

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

the class SharedMediaLayout method onActionBarItemClick.

public void onActionBarItemClick(View v, int id) {
    if (id == delete) {
        TLRPC.Chat currentChat = null;
        TLRPC.User currentUser = null;
        TLRPC.EncryptedChat currentEncryptedChat = null;
        if (DialogObject.isEncryptedDialog(dialog_id)) {
            currentEncryptedChat = profileActivity.getMessagesController().getEncryptedChat(DialogObject.getEncryptedChatId(dialog_id));
        } else if (DialogObject.isUserDialog(dialog_id)) {
            currentUser = profileActivity.getMessagesController().getUser(dialog_id);
        } else {
            currentChat = profileActivity.getMessagesController().getChat(-dialog_id);
        }
        AlertsCreator.createDeleteMessagesAlert(profileActivity, currentUser, currentChat, currentEncryptedChat, null, mergeDialogId, null, selectedFiles, null, false, 1, () -> {
            showActionMode(false);
            actionBar.closeSearchField();
            cantDeleteMessagesCount = 0;
        }, null, null);
    } else if (id == forward) {
        if (info != null) {
            TLRPC.Chat chat = profileActivity.getMessagesController().getChat(info.id);
            if (profileActivity.getMessagesController().isChatNoForwards(chat)) {
                if (fwdRestrictedHint != null) {
                    fwdRestrictedHint.setText(ChatObject.isChannel(chat) && !chat.megagroup ? LocaleController.getString("ForwardsRestrictedInfoChannel", R.string.ForwardsRestrictedInfoChannel) : LocaleController.getString("ForwardsRestrictedInfoGroup", R.string.ForwardsRestrictedInfoGroup));
                    fwdRestrictedHint.showForView(v, true);
                }
                return;
            }
        }
        if (hasNoforwardsMessage()) {
            if (fwdRestrictedHint != null) {
                fwdRestrictedHint.setText(LocaleController.getString("ForwardsRestrictedInfoBot", R.string.ForwardsRestrictedInfoBot));
                fwdRestrictedHint.showForView(v, true);
            }
            return;
        }
        Bundle args = new Bundle();
        args.putBoolean("onlySelect", true);
        args.putInt("dialogsType", 3);
        DialogsActivity fragment = new DialogsActivity(args);
        fragment.setDelegate((fragment1, dids, message, param) -> {
            ArrayList<MessageObject> fmessages = new ArrayList<>();
            for (int a = 1; a >= 0; a--) {
                ArrayList<Integer> ids = new ArrayList<>();
                for (int b = 0; b < selectedFiles[a].size(); b++) {
                    ids.add(selectedFiles[a].keyAt(b));
                }
                Collections.sort(ids);
                for (Integer id1 : ids) {
                    if (id1 > 0) {
                        fmessages.add(selectedFiles[a].get(id1));
                    }
                }
                selectedFiles[a].clear();
            }
            cantDeleteMessagesCount = 0;
            showActionMode(false);
            if (dids.size() > 1 || dids.get(0) == profileActivity.getUserConfig().getClientUserId() || message != null) {
                updateRowsSelection();
                for (int a = 0; a < dids.size(); a++) {
                    long did = dids.get(a);
                    if (message != null) {
                        profileActivity.getSendMessagesHelper().sendMessage(message.toString(), did, null, null, null, true, null, null, null, true, 0, null);
                    }
                    profileActivity.getSendMessagesHelper().sendMessage(fmessages, did, false, false, true, 0);
                }
                fragment1.finishFragment();
            } else {
                long did = dids.get(0);
                Bundle args1 = new Bundle();
                args1.putBoolean("scrollToTopOnResume", true);
                if (DialogObject.isEncryptedDialog(did)) {
                    args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
                } else {
                    if (DialogObject.isUserDialog(did)) {
                        args1.putLong("user_id", did);
                    } else {
                        args1.putLong("chat_id", -did);
                    }
                    if (!profileActivity.getMessagesController().checkCanOpenChat(args1, fragment1)) {
                        return;
                    }
                }
                profileActivity.getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
                ChatActivity chatActivity = new ChatActivity(args1);
                fragment1.presentFragment(chatActivity, true);
                chatActivity.showFieldPanelForForward(true, fmessages);
            }
        });
        profileActivity.presentFragment(fragment);
    } else if (id == gotochat) {
        if (selectedFiles[0].size() + selectedFiles[1].size() != 1) {
            return;
        }
        MessageObject messageObject = selectedFiles[selectedFiles[0].size() == 1 ? 0 : 1].valueAt(0);
        Bundle args = new Bundle();
        long dialogId = messageObject.getDialogId();
        if (DialogObject.isEncryptedDialog(dialogId)) {
            args.putInt("enc_id", DialogObject.getEncryptedChatId(dialogId));
        } else if (DialogObject.isUserDialog(dialogId)) {
            args.putLong("user_id", dialogId);
        } else {
            TLRPC.Chat chat = profileActivity.getMessagesController().getChat(-dialogId);
            if (chat != null && chat.migrated_to != null) {
                args.putLong("migrated_to", dialogId);
                dialogId = -chat.migrated_to.channel_id;
            }
            args.putLong("chat_id", -dialogId);
        }
        args.putInt("message_id", messageObject.getId());
        args.putBoolean("need_remove_previous_same_chat_activity", false);
        profileActivity.presentFragment(new ChatActivity(args), false);
    }
}
Also used : Bundle(android.os.Bundle) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) ProfileActivity(org.telegram.ui.ProfileActivity) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) DialogsActivity(org.telegram.ui.DialogsActivity) Canvas(android.graphics.Canvas) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ContextCompat(androidx.core.content.ContextCompat) Surface(android.view.Surface) Interpolator(android.view.animation.Interpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerCell(org.telegram.ui.Cells.DividerCell) FileLoader(org.telegram.messenger.FileLoader) ChatActivity(org.telegram.ui.ChatActivity) Visibility(android.transition.Visibility) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) Log(com.google.android.exoplayer2.util.Log) TLRPC(org.telegram.tgnet.TLRPC) TransitionValues(android.transition.TransitionValues) CalendarActivity(org.telegram.ui.CalendarActivity) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) ManageChatUserCell(org.telegram.ui.Cells.ManageChatUserCell) Gravity(android.view.Gravity) SparseBooleanArray(android.util.SparseBooleanArray) UserObject(org.telegram.messenger.UserObject) TypedValue(android.util.TypedValue) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ArticleViewer(org.telegram.ui.ArticleViewer) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) ChatObject(org.telegram.messenger.ChatObject) EditText(android.widget.EditText) ValueAnimator(android.animation.ValueAnimator) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) WindowManager(android.view.WindowManager) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) TransitionManager(android.transition.TransitionManager) ViewConfiguration(android.view.ViewConfiguration) ApplicationLoader(org.telegram.messenger.ApplicationLoader) SharedPhotoVideoCell(org.telegram.ui.Cells.SharedPhotoVideoCell) MediaController(org.telegram.messenger.MediaController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TransitionSet(android.transition.TransitionSet) Utilities(org.telegram.messenger.Utilities) SharedMediaSectionCell(org.telegram.ui.Cells.SharedMediaSectionCell) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ViewGroup(android.view.ViewGroup) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) SearchAdapterHelper(org.telegram.ui.Adapters.SearchAdapterHelper) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) Spanned(android.text.Spanned) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Theme(org.telegram.ui.ActionBar.Theme) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ChangeBounds(android.transition.ChangeBounds) SharedPhotoVideoCell2(org.telegram.ui.Cells.SharedPhotoVideoCell2) HashSet(java.util.HashSet) VelocityTracker(android.view.VelocityTracker) PhotoViewer(org.telegram.ui.PhotoViewer) MotionEvent(android.view.MotionEvent) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) SharedLinkCell(org.telegram.ui.Cells.SharedLinkCell) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) Browser(org.telegram.messenger.browser.Browser) DialogObject(org.telegram.messenger.DialogObject) FileLog(org.telegram.messenger.FileLog) MessagesController(org.telegram.messenger.MessagesController) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) MEDIA_PHOTOVIDEO(org.telegram.messenger.MediaDataController.MEDIA_PHOTOVIDEO) Bitmap(android.graphics.Bitmap) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) ImageReceiver(org.telegram.messenger.ImageReceiver) Collections(java.util.Collections) LoadingCell(org.telegram.ui.Cells.LoadingCell) ChatActivity(org.telegram.ui.ChatActivity) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) DialogsActivity(org.telegram.ui.DialogsActivity) TLRPC(org.telegram.tgnet.TLRPC) MessageObject(org.telegram.messenger.MessageObject)

Example 34 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method onActivityResultFragment.

public void onActivityResultFragment(int requestCode, Intent data, String currentPicturePath) {
    if (parentAlert.baseFragment == null || parentAlert.baseFragment.getParentActivity() == null) {
        return;
    }
    mediaFromExternalCamera = true;
    if (requestCode == 0) {
        PhotoViewer.getInstance().setParentActivity(parentAlert.baseFragment.getParentActivity(), resourcesProvider);
        PhotoViewer.getInstance().setMaxSelectedPhotos(parentAlert.maxSelectedPhotos, parentAlert.allowOrder);
        final ArrayList<Object> arrayList = new ArrayList<>();
        int orientation = 0;
        try {
            ExifInterface ei = new ExifInterface(currentPicturePath);
            int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            switch(exif) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    orientation = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    orientation = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    orientation = 270;
                    break;
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, lastImageId--, 0, currentPicturePath, orientation, false, 0, 0, 0);
        photoEntry.canDeleteAfter = true;
        openPhotoViewer(photoEntry, false, true);
    } else if (requestCode == 2) {
        String videoPath = null;
        if (BuildVars.LOGS_ENABLED) {
            FileLog.d("pic path " + currentPicturePath);
        }
        if (data != null && currentPicturePath != null) {
            if (new File(currentPicturePath).exists()) {
                data = null;
            }
        }
        if (data != null) {
            Uri uri = data.getData();
            if (uri != null) {
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("video record uri " + uri.toString());
                }
                videoPath = AndroidUtilities.getPath(uri);
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("resolved path = " + videoPath);
                }
                if (videoPath == null || !(new File(videoPath).exists())) {
                    videoPath = currentPicturePath;
                }
            } else {
                videoPath = currentPicturePath;
            }
            if (!(parentAlert.baseFragment instanceof ChatActivity) || !((ChatActivity) parentAlert.baseFragment).isSecretChat()) {
                AndroidUtilities.addMediaToGallery(currentPicturePath);
            }
            currentPicturePath = null;
        }
        if (videoPath == null && currentPicturePath != null) {
            File f = new File(currentPicturePath);
            if (f.exists()) {
                videoPath = currentPicturePath;
            }
        }
        MediaMetadataRetriever mediaMetadataRetriever = null;
        long duration = 0;
        try {
            mediaMetadataRetriever = new MediaMetadataRetriever();
            mediaMetadataRetriever.setDataSource(videoPath);
            String d = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            if (d != null) {
                duration = (int) Math.ceil(Long.parseLong(d) / 1000.0f);
            }
        } catch (Exception e) {
            FileLog.e(e);
        } finally {
            try {
                if (mediaMetadataRetriever != null) {
                    mediaMetadataRetriever.release();
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        final Bitmap bitmap = SendMessagesHelper.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
        String fileName = Integer.MIN_VALUE + "_" + SharedConfig.getLastLocalId() + ".jpg";
        final File cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
        try {
            FileOutputStream stream = new FileOutputStream(cacheFile);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 55, stream);
        } catch (Throwable e) {
            FileLog.e(e);
        }
        SharedConfig.saveConfig();
        MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, lastImageId--, 0, videoPath, 0, true, 0, 0, 0);
        entry.duration = (int) duration;
        entry.thumbPath = cacheFile.getAbsolutePath();
        openPhotoViewer(entry, false, true);
    }
}
Also used : MediaController(org.telegram.messenger.MediaController) ChatActivity(org.telegram.ui.ChatActivity) ExifInterface(androidx.exifinterface.media.ExifInterface) ArrayList(java.util.ArrayList) Uri(android.net.Uri) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) MediaMetadataRetriever(android.media.MediaMetadataRetriever) FileOutputStream(java.io.FileOutputStream) MessageObject(org.telegram.messenger.MessageObject) ChatObject(org.telegram.messenger.ChatObject) File(java.io.File)

Example 35 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method showCamera.

public void showCamera() {
    if (parentAlert.paused || !mediaEnabled) {
        return;
    }
    if (cameraView == null) {
        cameraView = new CameraView(parentAlert.baseFragment.getParentActivity(), parentAlert.openWithFrontFaceCamera) {

            @Override
            protected void dispatchDraw(Canvas canvas) {
                if (Build.VERSION.SDK_INT >= 21) {
                    super.dispatchDraw(canvas);
                } else {
                    if (cameraAnimationInProgress) {
                        AndroidUtilities.rectTmp.set(animationClipLeft + cameraViewOffsetX * (1f - cameraOpenProgress), animationClipTop + cameraViewOffsetY * (1f - cameraOpenProgress), animationClipRight, animationClipBottom);
                    } else if (!cameraAnimationInProgress && !cameraOpened) {
                        AndroidUtilities.rectTmp.set(cameraViewOffsetX, cameraViewOffsetY, getMeasuredWidth(), getMeasuredHeight());
                    } else {
                        AndroidUtilities.rectTmp.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
                    }
                    canvas.save();
                    canvas.clipRect(AndroidUtilities.rectTmp);
                    super.dispatchDraw(canvas);
                    canvas.restore();
                }
            }
        };
        cameraView.setRecordFile(AndroidUtilities.generateVideoPath(parentAlert.baseFragment instanceof ChatActivity && ((ChatActivity) parentAlert.baseFragment).isSecretChat()));
        cameraView.setFocusable(true);
        cameraView.setFpsLimit(30);
        if (Build.VERSION.SDK_INT >= 21) {
            Path path = new Path();
            float[] radii = new float[8];
            cameraView.setOutlineProvider(new ViewOutlineProvider() {

                @Override
                public void getOutline(View view, Outline outline) {
                    if (cameraAnimationInProgress) {
                        AndroidUtilities.rectTmp.set(animationClipLeft + cameraViewOffsetX * (1f - cameraOpenProgress), animationClipTop + cameraViewOffsetY * (1f - cameraOpenProgress), animationClipRight, animationClipBottom);
                        outline.setRect((int) AndroidUtilities.rectTmp.left, (int) AndroidUtilities.rectTmp.top, (int) AndroidUtilities.rectTmp.right, (int) AndroidUtilities.rectTmp.bottom);
                    } else if (!cameraAnimationInProgress && !cameraOpened) {
                        int rad = AndroidUtilities.dp(8 * parentAlert.cornerRadius);
                        outline.setRoundRect((int) cameraViewOffsetX, (int) cameraViewOffsetY, view.getMeasuredWidth() + rad, view.getMeasuredHeight() + rad, rad);
                    } else {
                        outline.setRect(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
                    }
                }
            });
            cameraView.setClipToOutline(true);
        }
        cameraView.setContentDescription(LocaleController.getString("AccDescrInstantCamera", R.string.AccDescrInstantCamera));
        parentAlert.getContainer().addView(cameraView, 1, new FrameLayout.LayoutParams(itemSize, itemSize));
        cameraView.setDelegate(new CameraView.CameraViewDelegate() {

            @Override
            public void onCameraCreated(Camera camera) {
            }

            @Override
            public void onCameraInit() {
                String current = cameraView.getCameraSession().getCurrentFlashMode();
                String next = cameraView.getCameraSession().getNextFlashMode();
                if (current.equals(next)) {
                    for (int a = 0; a < 2; a++) {
                        flashModeButton[a].setVisibility(View.INVISIBLE);
                        flashModeButton[a].setAlpha(0.0f);
                        flashModeButton[a].setTranslationY(0.0f);
                    }
                } else {
                    setCameraFlashModeIcon(flashModeButton[0], cameraView.getCameraSession().getCurrentFlashMode());
                    for (int a = 0; a < 2; a++) {
                        flashModeButton[a].setVisibility(a == 0 ? View.VISIBLE : View.INVISIBLE);
                        flashModeButton[a].setAlpha(a == 0 && cameraOpened ? 1.0f : 0.0f);
                        flashModeButton[a].setTranslationY(0.0f);
                    }
                }
                switchCameraButton.setImageResource(cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2);
                switchCameraButton.setVisibility(cameraView.hasFrontFaceCamera() ? View.VISIBLE : View.INVISIBLE);
                if (!cameraOpened) {
                    cameraInitAnimation = new AnimatorSet();
                    cameraInitAnimation.playTogether(ObjectAnimator.ofFloat(cameraView, View.ALPHA, 0.0f, 1.0f), ObjectAnimator.ofFloat(cameraIcon, View.ALPHA, 0.0f, 1.0f));
                    cameraInitAnimation.setDuration(180);
                    cameraInitAnimation.addListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (animation.equals(cameraInitAnimation)) {
                                canSaveCameraPreview = true;
                                cameraInitAnimation = null;
                                if (!isHidden) {
                                    int count = gridView.getChildCount();
                                    for (int a = 0; a < count; a++) {
                                        View child = gridView.getChildAt(a);
                                        if (child instanceof PhotoAttachCameraCell) {
                                            child.setVisibility(View.INVISIBLE);
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            cameraInitAnimation = null;
                        }
                    });
                    cameraInitAnimation.start();
                }
            }
        });
        if (cameraIcon == null) {
            cameraIcon = new FrameLayout(parentAlert.baseFragment.getParentActivity()) {

                @Override
                protected void onDraw(Canvas canvas) {
                    int w = cameraDrawable.getIntrinsicWidth();
                    int h = cameraDrawable.getIntrinsicHeight();
                    int x = (itemSize - w) / 2;
                    int y = (itemSize - h) / 2;
                    if (cameraViewOffsetY != 0) {
                        y -= cameraViewOffsetY;
                    }
                    cameraDrawable.setBounds(x, y, x + w, y + h);
                    cameraDrawable.draw(canvas);
                }
            };
            cameraIcon.setWillNotDraw(false);
            cameraIcon.setClipChildren(true);
        }
        parentAlert.getContainer().addView(cameraIcon, 2, new FrameLayout.LayoutParams(itemSize, itemSize));
        cameraView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
        cameraView.setEnabled(mediaEnabled);
        cameraIcon.setAlpha(mediaEnabled ? 1.0f : 0.2f);
        cameraIcon.setEnabled(mediaEnabled);
        if (isHidden) {
            cameraView.setVisibility(GONE);
            cameraIcon.setVisibility(GONE);
        }
        checkCameraViewPosition();
        invalidate();
    }
    if (zoomControlView != null) {
        zoomControlView.setZoom(0.0f, false);
        cameraZoom = 0.0f;
    }
    cameraView.setTranslationX(cameraViewLocation[0]);
    cameraView.setTranslationY(cameraViewLocation[1] + currentPanTranslationY);
    cameraIcon.setTranslationX(cameraViewLocation[0]);
    cameraIcon.setTranslationY(cameraViewLocation[1] + cameraViewOffsetY + currentPanTranslationY);
}
Also used : Path(android.graphics.Path) PhotoAttachCameraCell(org.telegram.ui.Cells.PhotoAttachCameraCell) ChatActivity(org.telegram.ui.ChatActivity) Canvas(android.graphics.Canvas) Outline(android.graphics.Outline) AnimatorSet(android.animation.AnimatorSet) ViewOutlineProvider(android.view.ViewOutlineProvider) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) CameraView(org.telegram.messenger.camera.CameraView) CameraView(org.telegram.messenger.camera.CameraView) Paint(android.graphics.Paint) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FrameLayout(android.widget.FrameLayout) Camera(android.hardware.Camera)

Aggregations

ChatActivity (org.telegram.ui.ChatActivity)41 Paint (android.graphics.Paint)22 TLRPC (org.telegram.tgnet.TLRPC)21 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 Animator (android.animation.Animator)12 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)12 View (android.view.View)12 TextPaint (android.text.TextPaint)11 AnimatorSet (android.animation.AnimatorSet)10 ObjectAnimator (android.animation.ObjectAnimator)10 ImageView (android.widget.ImageView)10 MessageObject (org.telegram.messenger.MessageObject)10 Bundle (android.os.Bundle)9 ChatObject (org.telegram.messenger.ChatObject)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)8 ValueAnimator (android.animation.ValueAnimator)7 SuppressLint (android.annotation.SuppressLint)7 FrameLayout (android.widget.FrameLayout)6