use of org.telegram.ui.Components.VideoEditTextureView in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method setParentActivity.
public void setParentActivity(final Activity activity, Theme.ResourcesProvider resourcesProvider) {
Theme.createChatResources(activity, false);
this.resourcesProvider = resourcesProvider;
currentAccount = UserConfig.selectedAccount;
centerImage.setCurrentAccount(currentAccount);
leftImage.setCurrentAccount(currentAccount);
rightImage.setCurrentAccount(currentAccount);
if (parentActivity == activity || activity == null) {
return;
}
inBubbleMode = activity instanceof BubbleActivity;
parentActivity = activity;
activityContext = new ContextThemeWrapper(parentActivity, R.style.Theme_TMessages);
touchSlop = ViewConfiguration.get(parentActivity).getScaledTouchSlop();
if (progressDrawables == null) {
final Drawable circleDrawable = ContextCompat.getDrawable(parentActivity, R.drawable.circle_big);
progressDrawables = new Drawable[] { // PROGRESS_EMPTY
circleDrawable, // PROGRESS_CANCEL
ContextCompat.getDrawable(parentActivity, R.drawable.cancel_big), // PROGRESS_LOAD
ContextCompat.getDrawable(parentActivity, R.drawable.load_big) };
}
scroller = new Scroller(activity);
windowView = new FrameLayout(activity) {
private Runnable attachRunnable;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return isVisible && super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return isVisible && PhotoViewer.this.onTouchEvent(event);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
if (!muteVideo && sendPhotoType != SELECT_TYPE_AVATAR && isCurrentVideo && videoPlayer != null && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN && (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP || event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN)) {
videoPlayer.setVolume(1.0f);
}
return super.dispatchKeyEvent(event);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (videoPlayerControlVisible && isPlaying) {
switch(ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
AndroidUtilities.cancelRunOnUIThread(hideActionBarRunnable);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_POINTER_UP:
scheduleActionBarHide();
break;
}
}
return super.dispatchTouchEvent(ev);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result;
try {
result = super.drawChild(canvas, child, drawingTime);
} catch (Throwable ignore) {
result = false;
}
return result;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
WindowInsets insets = (WindowInsets) lastInsets;
if (!inBubbleMode) {
if (AndroidUtilities.incorrectDisplaySizeFix) {
if (heightSize > AndroidUtilities.displaySize.y) {
heightSize = AndroidUtilities.displaySize.y;
}
heightSize += AndroidUtilities.statusBarHeight;
} else {
int insetBottom = insets.getStableInsetBottom();
if (insetBottom >= 0 && AndroidUtilities.statusBarHeight >= 0) {
int newSize = heightSize - AndroidUtilities.statusBarHeight - insets.getStableInsetBottom();
if (newSize > 0 && newSize < 4096) {
AndroidUtilities.displaySize.y = newSize;
}
}
}
}
int bottomInsets = insets.getSystemWindowInsetBottom();
if (captionEditText.isPopupShowing()) {
bottomInsets -= containerView.getKeyboardHeight();
}
heightSize -= bottomInsets;
} else {
if (heightSize > AndroidUtilities.displaySize.y) {
heightSize = AndroidUtilities.displaySize.y;
}
}
setMeasuredDimension(widthSize, heightSize);
ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
animatingImageView.measure(MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.AT_MOST));
containerView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
}
@SuppressWarnings("DrawAllocation")
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
animatingImageView.layout(0, 0, animatingImageView.getMeasuredWidth(), animatingImageView.getMeasuredHeight());
containerView.layout(0, 0, containerView.getMeasuredWidth(), containerView.getMeasuredHeight());
wasLayout = true;
if (changed) {
if (!dontResetZoomOnFirstLayout) {
scale = 1;
translationX = 0;
translationY = 0;
updateMinMax(scale);
}
if (checkImageView != null) {
checkImageView.post(() -> {
LayoutParams layoutParams = (LayoutParams) checkImageView.getLayoutParams();
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
int newMargin = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(34)) / 2 + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0);
if (newMargin != layoutParams.topMargin) {
layoutParams.topMargin = newMargin;
checkImageView.setLayoutParams(layoutParams);
}
layoutParams = (LayoutParams) photosCounterView.getLayoutParams();
newMargin = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(40)) / 2 + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0);
if (layoutParams.topMargin != newMargin) {
layoutParams.topMargin = newMargin;
photosCounterView.setLayoutParams(layoutParams);
}
});
}
}
if (dontResetZoomOnFirstLayout) {
setScaleToFill();
dontResetZoomOnFirstLayout = false;
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
attachedToWindow = true;
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
attachedToWindow = false;
wasLayout = false;
}
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
closeCaptionEnter(true);
return false;
}
PhotoViewer.getInstance().closePhoto(true, false);
return true;
}
return super.dispatchKeyEventPreIme(event);
}
@Override
protected void onDraw(Canvas canvas) {
if (Build.VERSION.SDK_INT >= 21 && isVisible && lastInsets != null) {
WindowInsets insets = (WindowInsets) lastInsets;
if (animationInProgress == 1) {
blackPaint.setAlpha((int) (255 * animatingImageView.getAnimationProgress()));
} else if (animationInProgress == 3) {
blackPaint.setAlpha((int) (255 * (1.0f - animatingImageView.getAnimationProgress())));
} else {
blackPaint.setAlpha(backgroundDrawable.getAlpha());
}
canvas.drawRect(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight() + insets.getSystemWindowInsetBottom(), blackPaint);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (parentChatActivity != null) {
View undoView = parentChatActivity.getUndoView();
if (undoView.getVisibility() == View.VISIBLE) {
canvas.save();
View parent = (View) undoView.getParent();
canvas.clipRect(parent.getX(), parent.getY(), parent.getX() + parent.getWidth(), parent.getY() + parent.getHeight());
canvas.translate(undoView.getX(), undoView.getY());
undoView.draw(canvas);
canvas.restore();
invalidate();
}
}
}
};
windowView.setBackgroundDrawable(backgroundDrawable);
windowView.setClipChildren(true);
windowView.setFocusable(false);
animatingImageView = new ClippingImageView(activity);
animatingImageView.setAnimationValues(animationValues);
windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40));
containerView = new FrameLayoutDrawer(activity);
containerView.setFocusable(false);
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
if (Build.VERSION.SDK_INT >= 21) {
containerView.setFitsSystemWindows(true);
containerView.setOnApplyWindowInsetsListener((v, insets) -> {
int newTopInset = insets.getSystemWindowInsetTop();
if (parentActivity instanceof LaunchActivity && (newTopInset != 0 || AndroidUtilities.isInMultiwindow) && !inBubbleMode && AndroidUtilities.statusBarHeight != newTopInset) {
AndroidUtilities.statusBarHeight = newTopInset;
((LaunchActivity) parentActivity).drawerLayoutContainer.requestLayout();
}
WindowInsets oldInsets = (WindowInsets) lastInsets;
lastInsets = insets;
if (oldInsets == null || !oldInsets.toString().equals(insets.toString())) {
if (animationInProgress == 1 || animationInProgress == 3) {
animatingImageView.setTranslationX(animatingImageView.getTranslationX() - getLeftInset());
animationValues[0][2] = animatingImageView.getTranslationX();
}
if (windowView != null) {
windowView.requestLayout();
}
}
containerView.setPadding(insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(), 0);
if (actionBar != null) {
AndroidUtilities.cancelRunOnUIThread(updateContainerFlagsRunnable);
if (isVisible && animationInProgress == 0) {
AndroidUtilities.runOnUIThread(updateContainerFlagsRunnable, 200);
}
}
if (Build.VERSION.SDK_INT >= 30) {
return WindowInsets.CONSUMED;
} else {
return insets.consumeSystemWindowInsets();
}
});
containerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
if (Build.VERSION.SDK_INT >= 28) {
windowLayoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
}
paintingOverlay = new PaintingOverlay(parentActivity);
containerView.addView(paintingOverlay, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
actionBar = new ActionBar(activity) {
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
containerView.invalidate();
}
};
actionBar.setOverlayTitleAnimation(true);
actionBar.setTitleColor(0xffffffff);
actionBar.setSubtitleColor(0xffffffff);
actionBar.setBackgroundColor(Theme.ACTION_BAR_PHOTO_VIEWER_COLOR);
actionBar.setOccupyStatusBar(isStatusBarVisible());
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, false);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
containerView.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (needCaptionLayout && (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible())) {
closeCaptionEnter(false);
return;
}
closePhoto(true, false);
} else if (id == gallery_menu_save) {
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;
}
File f = null;
final boolean isVideo;
if (currentMessageObject != null) {
if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && currentMessageObject.messageOwner.media.webpage != null && currentMessageObject.messageOwner.media.webpage.document == null) {
TLObject fileLocation = getFileLocation(currentIndex, null);
f = FileLoader.getPathToAttach(fileLocation, true);
} else {
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
}
isVideo = currentMessageObject.isVideo();
} else if (currentFileLocationVideo != null) {
f = FileLoader.getPathToAttach(getFileLocation(currentFileLocationVideo), getFileLocationExt(currentFileLocationVideo), avatarsDialogId != 0 || isEvent);
isVideo = false;
} else if (pageBlocksAdapter != null) {
f = pageBlocksAdapter.getFile(currentIndex);
isVideo = pageBlocksAdapter.isVideo(currentIndex);
} else {
isVideo = false;
}
if (f != null && f.exists()) {
MediaController.saveFile(f.toString(), parentActivity, isVideo ? 1 : 0, null, null, () -> BulletinFactory.createSaveToGalleryBulletin(containerView, isVideo, 0xf9222222, 0xffffffff).show());
} else {
showDownloadAlert();
}
} else if (id == gallery_menu_showall) {
if (currentDialogId != 0) {
disableShowCheck = true;
Bundle args2 = new Bundle();
args2.putLong("dialog_id", currentDialogId);
MediaActivity mediaActivity = new MediaActivity(args2, null);
if (parentChatActivity != null) {
mediaActivity.setChatInfo(parentChatActivity.getCurrentChatInfo());
}
closePhoto(false, false);
if (parentActivity instanceof LaunchActivity) {
((LaunchActivity) parentActivity).presentFragment(mediaActivity, false, true);
}
}
} else if (id == gallery_menu_showinchat) {
if (currentMessageObject == null) {
return;
}
Bundle args = new Bundle();
long dialogId = currentDialogId;
if (currentMessageObject != null) {
dialogId = currentMessageObject.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 = MessagesController.getInstance(currentAccount).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", currentMessageObject.getId());
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
if (parentActivity instanceof LaunchActivity) {
LaunchActivity launchActivity = (LaunchActivity) parentActivity;
boolean remove = launchActivity.getMainFragmentsCount() > 1 || AndroidUtilities.isTablet();
launchActivity.presentFragment(new ChatActivity(args), remove, true);
}
closePhoto(false, false);
currentMessageObject = null;
} else if (id == gallery_menu_send) {
if (currentMessageObject == null || !(parentActivity instanceof LaunchActivity)) {
return;
}
((LaunchActivity) parentActivity).switchToAccount(currentMessageObject.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(currentMessageObject);
final ChatActivity parentChatActivityFinal = parentChatActivity;
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();
if (parentChatActivityFinal != null) {
if (dids.size() == 1) {
parentChatActivityFinal.getUndoView().showWithAction(dids.get(0), UndoView.ACTION_FWD_MESSAGES, fmessages.size());
} else {
parentChatActivityFinal.getUndoView().showWithAction(0, UndoView.ACTION_FWD_MESSAGES, fmessages.size(), dids.size(), null, null);
}
}
} 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 (((LaunchActivity) parentActivity).presentFragment(chatActivity, true, false)) {
chatActivity.showFieldPanelForForward(true, fmessages);
} else {
fragment1.finishFragment();
}
}
});
((LaunchActivity) parentActivity).presentFragment(fragment, false, true);
closePhoto(false, false);
} else if (id == gallery_menu_delete) {
if (parentActivity == null || placeProvider == null) {
return;
}
boolean isChannel = false;
if (currentMessageObject != null && !currentMessageObject.scheduled) {
long dialogId = currentMessageObject.getDialogId();
if (DialogObject.isChatDialog(dialogId)) {
isChannel = ChatObject.isChannel(MessagesController.getInstance(currentAccount).getChat(-dialogId));
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
String text = placeProvider.getDeleteMessageString();
if (text != null) {
builder.setTitle(LocaleController.getString("AreYouSureDeletePhotoTitle", R.string.AreYouSureDeletePhotoTitle));
builder.setMessage(text);
} else if (isEmbedVideo || currentFileLocationVideo != null && currentFileLocationVideo != currentFileLocation || currentMessageObject != null && currentMessageObject.isVideo()) {
builder.setTitle(LocaleController.getString("AreYouSureDeleteVideoTitle", R.string.AreYouSureDeleteVideoTitle));
if (isChannel) {
builder.setMessage(LocaleController.formatString("AreYouSureDeleteVideoEveryone", R.string.AreYouSureDeleteVideoEveryone));
} else {
builder.setMessage(LocaleController.formatString("AreYouSureDeleteVideo", R.string.AreYouSureDeleteVideo));
}
} else if (currentMessageObject != null && currentMessageObject.isGif()) {
builder.setTitle(LocaleController.getString("AreYouSureDeleteGIFTitle", R.string.AreYouSureDeleteGIFTitle));
if (isChannel) {
builder.setMessage(LocaleController.formatString("AreYouSureDeleteGIFEveryone", R.string.AreYouSureDeleteGIFEveryone));
} else {
builder.setMessage(LocaleController.formatString("AreYouSureDeleteGIF", R.string.AreYouSureDeleteGIF));
}
} else {
builder.setTitle(LocaleController.getString("AreYouSureDeletePhotoTitle", R.string.AreYouSureDeletePhotoTitle));
if (isChannel) {
builder.setMessage(LocaleController.formatString("AreYouSureDeletePhotoEveryone", R.string.AreYouSureDeletePhotoEveryone));
} else {
builder.setMessage(LocaleController.formatString("AreYouSureDeletePhoto", R.string.AreYouSureDeletePhoto));
}
}
final boolean[] deleteForAll = new boolean[1];
if (currentMessageObject != null && !currentMessageObject.scheduled) {
long dialogId = currentMessageObject.getDialogId();
if (!DialogObject.isEncryptedDialog(dialogId)) {
TLRPC.Chat currentChat;
TLRPC.User currentUser;
if (DialogObject.isUserDialog(dialogId)) {
currentUser = MessagesController.getInstance(currentAccount).getUser(dialogId);
currentChat = null;
} else {
currentUser = null;
currentChat = MessagesController.getInstance(currentAccount).getChat(-dialogId);
}
if (currentUser != null || !ChatObject.isChannel(currentChat)) {
boolean hasOutgoing = false;
int currentDate = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
int revokeTimeLimit;
if (currentUser != null) {
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimePmLimit;
} else {
revokeTimeLimit = MessagesController.getInstance(currentAccount).revokeTimeLimit;
}
if (currentUser != null && currentUser.id != UserConfig.getInstance(currentAccount).getClientUserId() || currentChat != null) {
boolean canRevokeInbox = currentUser != null && MessagesController.getInstance(currentAccount).canRevokePmInbox;
if ((currentMessageObject.messageOwner.action == null || currentMessageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && (currentMessageObject.isOut() || canRevokeInbox || ChatObject.hasAdminRights(currentChat)) && (currentDate - currentMessageObject.messageOwner.date) <= revokeTimeLimit) {
FrameLayout frameLayout = new FrameLayout(parentActivity);
CheckBoxCell cell = new CheckBoxCell(parentActivity, 1, resourcesProvider);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (currentChat != null) {
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
} else {
cell.setText(LocaleController.formatString("DeleteForUser", R.string.DeleteForUser, UserObject.getFirstName(currentUser)), "", false, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
cell.setOnClickListener(v -> {
CheckBoxCell cell1 = (CheckBoxCell) v;
deleteForAll[0] = !deleteForAll[0];
cell1.setChecked(deleteForAll[0], true);
});
builder.setView(frameLayout);
builder.setCustomViewOffset(9);
}
}
}
}
}
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
if (!imagesArr.isEmpty()) {
if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
return;
}
MessageObject obj = imagesArr.get(currentIndex);
if (obj.isSent()) {
closePhoto(false, false);
ArrayList<Integer> arr = new ArrayList<>();
if (slideshowMessageId != 0) {
arr.add(slideshowMessageId);
} else {
arr.add(obj.getId());
}
ArrayList<Long> random_ids = null;
TLRPC.EncryptedChat encryptedChat = null;
if (DialogObject.isEncryptedDialog(obj.getDialogId()) && obj.messageOwner.random_id != 0) {
random_ids = new ArrayList<>();
random_ids.add(obj.messageOwner.random_id);
encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(DialogObject.getEncryptedChatId(obj.getDialogId()));
}
MessagesController.getInstance(currentAccount).deleteMessages(arr, random_ids, encryptedChat, obj.getDialogId(), deleteForAll[0], obj.scheduled);
}
} else if (!avatarsArr.isEmpty()) {
if (currentIndex < 0 || currentIndex >= avatarsArr.size()) {
return;
}
TLRPC.Message message = imagesArrMessages.get(currentIndex);
if (message != null) {
ArrayList<Integer> arr = new ArrayList<>();
arr.add(message.id);
MessagesController.getInstance(currentAccount).deleteMessages(arr, null, null, MessageObject.getDialogId(message), true, false);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.reloadDialogPhotos);
}
if (isCurrentAvatarSet()) {
if (avatarsDialogId > 0) {
MessagesController.getInstance(currentAccount).deleteUserPhoto(null);
} else {
MessagesController.getInstance(currentAccount).changeChatAvatar(-avatarsDialogId, null, null, null, 0, null, null, null, null);
}
closePhoto(false, false);
} else {
TLRPC.Photo photo = avatarsArr.get(currentIndex);
if (photo == null) {
return;
}
TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
inputPhoto.id = photo.id;
inputPhoto.access_hash = photo.access_hash;
inputPhoto.file_reference = photo.file_reference;
if (inputPhoto.file_reference == null) {
inputPhoto.file_reference = new byte[0];
}
if (avatarsDialogId > 0) {
MessagesController.getInstance(currentAccount).deleteUserPhoto(inputPhoto);
}
MessagesStorage.getInstance(currentAccount).clearUserPhoto(avatarsDialogId, photo.id);
imagesArrLocations.remove(currentIndex);
imagesArrLocationsSizes.remove(currentIndex);
imagesArrLocationsVideo.remove(currentIndex);
imagesArrMessages.remove(currentIndex);
avatarsArr.remove(currentIndex);
if (imagesArrLocations.isEmpty()) {
closePhoto(false, false);
} else {
int index = currentIndex;
if (index >= avatarsArr.size()) {
index = avatarsArr.size() - 1;
}
currentIndex = -1;
setImageIndex(index);
}
if (message == null) {
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.reloadDialogPhotos);
}
}
} else if (!secureDocuments.isEmpty()) {
if (placeProvider == null) {
return;
}
secureDocuments.remove(currentIndex);
placeProvider.deleteImageAtIndex(currentIndex);
if (secureDocuments.isEmpty()) {
closePhoto(false, false);
} else {
int index = currentIndex;
if (index >= secureDocuments.size()) {
index = secureDocuments.size() - 1;
}
currentIndex = -1;
setImageIndex(index);
}
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showAlertDialog(builder);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(getThemedColor(Theme.key_dialogTextRed2));
}
} else if (id == gallery_menu_share || id == gallery_menu_share2) {
onSharePressed();
} else if (id == gallery_menu_speed) {
menuItemSpeed.setVisibility(View.VISIBLE);
menuItemSpeed.toggleSubMenu();
for (int a = 0; a < speedItems.length; a++) {
if (a == 0 && Math.abs(currentVideoSpeed - 0.25f) < 0.001f || a == 1 && Math.abs(currentVideoSpeed - 0.5f) < 0.001f || a == 2 && Math.abs(currentVideoSpeed - 1.0f) < 0.001f || a == 3 && Math.abs(currentVideoSpeed - 1.5f) < 0.001f || a == 4 && Math.abs(currentVideoSpeed - 2.0f) < 0.001f) {
speedItems[a].setColors(0xff6BB6F9, 0xff6BB6F9);
} else {
speedItems[a].setColors(0xfffafafa, 0xfffafafa);
}
}
} else if (id == gallery_menu_openin) {
try {
if (isEmbedVideo) {
Browser.openUrl(parentActivity, currentMessageObject.messageOwner.media.webpage.url);
closePhoto(false, false);
} else if (currentMessageObject != null) {
if (AndroidUtilities.openForView(currentMessageObject, parentActivity, resourcesProvider)) {
closePhoto(false, false);
} else {
showDownloadAlert();
}
} else if (pageBlocksAdapter != null) {
if (AndroidUtilities.openForView(pageBlocksAdapter.getMedia(currentIndex), parentActivity)) {
closePhoto(false, false);
} else {
showDownloadAlert();
}
}
} catch (Exception e) {
FileLog.e(e);
}
} else if (id == gallery_menu_masks || id == gallery_menu_masks2) {
if (parentActivity == null || currentMessageObject == null) {
return;
}
TLObject object;
if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
object = currentMessageObject.messageOwner.media.photo;
} else if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
object = currentMessageObject.messageOwner.media.document;
} else {
return;
}
masksAlert = new StickersAlert(parentActivity, currentMessageObject, object, resourcesProvider) {
@Override
public void dismiss() {
super.dismiss();
if (masksAlert == this) {
masksAlert = null;
}
}
};
masksAlert.show();
} else if (id == gallery_menu_pip) {
if (pipItem.getAlpha() != 1.0f) {
return;
}
if (isEmbedVideo) {
pipVideoView = photoViewerWebView.openInPip();
if (pipVideoView != null) {
if (PipInstance != null) {
PipInstance.destroyPhotoViewer();
}
isInline = true;
PipInstance = Instance;
Instance = null;
isVisible = false;
if (currentPlaceObject != null && !currentPlaceObject.imageReceiver.getVisible()) {
currentPlaceObject.imageReceiver.setVisible(true, true);
}
dismissInternal();
}
} else {
switchToPip(false);
}
} else if (id == gallery_menu_cancel_loading) {
if (currentMessageObject == null) {
return;
}
FileLoader.getInstance(currentAccount).cancelLoadFile(currentMessageObject.getDocument());
releasePlayer(false);
bottomLayout.setTag(1);
bottomLayout.setVisibility(View.VISIBLE);
} else if (id == gallery_menu_savegif) {
if (currentMessageObject != null) {
TLRPC.Document document = currentMessageObject.getDocument();
if (parentChatActivity != null && parentChatActivity.chatActivityEnterView != null) {
parentChatActivity.chatActivityEnterView.addRecentGif(document);
} else {
MediaDataController.getInstance(currentAccount).addRecentGif(document, (int) (System.currentTimeMillis() / 1000));
}
MessagesController.getInstance(currentAccount).saveGif(currentMessageObject, document);
} else if (pageBlocksAdapter != null) {
TLObject object = pageBlocksAdapter.getMedia(currentIndex);
if (object instanceof TLRPC.Document) {
TLRPC.Document document = (TLRPC.Document) object;
MediaDataController.getInstance(currentAccount).addRecentGif(document, (int) (System.currentTimeMillis() / 1000));
MessagesController.getInstance(currentAccount).saveGif(pageBlocksAdapter.getParentObject(), document);
}
} else {
return;
}
if (containerView != null) {
BulletinFactory.of(containerView, resourcesProvider).createDownloadBulletin(BulletinFactory.FileType.GIF, resourcesProvider).show();
}
} else if (id == gallery_menu_set_as_main) {
TLRPC.Photo photo = avatarsArr.get(currentIndex);
if (photo == null || photo.sizes.isEmpty()) {
return;
}
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 800);
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 90);
UserConfig userConfig = UserConfig.getInstance(currentAccount);
if (avatarsDialogId == userConfig.clientUserId) {
TLRPC.TL_photos_updateProfilePhoto req = new TLRPC.TL_photos_updateProfilePhoto();
req.id = new TLRPC.TL_inputPhoto();
req.id.id = photo.id;
req.id.access_hash = photo.access_hash;
req.id.file_reference = photo.file_reference;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_photos_photo) {
TLRPC.TL_photos_photo photos_photo = (TLRPC.TL_photos_photo) response;
MessagesController.getInstance(currentAccount).putUsers(photos_photo.users, false);
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(userConfig.clientUserId);
if (photos_photo.photo instanceof TLRPC.TL_photo) {
int idx = avatarsArr.indexOf(photo);
if (idx >= 0) {
avatarsArr.set(idx, photos_photo.photo);
}
if (user != null) {
user.photo.photo_id = photos_photo.photo.id;
userConfig.setCurrentUser(user);
userConfig.saveConfig(true);
}
}
}
}));
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(userConfig.clientUserId);
if (user != null) {
user.photo.photo_id = photo.id;
user.photo.dc_id = photo.dc_id;
user.photo.photo_small = smallSize.location;
user.photo.photo_big = bigSize.location;
userConfig.setCurrentUser(user);
userConfig.saveConfig(true);
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.mainUserInfoChanged);
}
} else {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-avatarsDialogId);
if (chat == null) {
return;
}
TLRPC.TL_inputChatPhoto inputChatPhoto = new TLRPC.TL_inputChatPhoto();
inputChatPhoto.id = new TLRPC.TL_inputPhoto();
inputChatPhoto.id.id = photo.id;
inputChatPhoto.id.access_hash = photo.access_hash;
inputChatPhoto.id.file_reference = photo.file_reference;
MessagesController.getInstance(currentAccount).changeChatAvatar(-avatarsDialogId, inputChatPhoto, null, null, 0, null, null, null, null);
chat.photo.dc_id = photo.dc_id;
chat.photo.photo_small = smallSize.location;
chat.photo.photo_big = bigSize.location;
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_AVATAR);
}
currentAvatarLocation = ImageLocation.getForPhoto(bigSize, photo);
avatarsArr.remove(currentIndex);
avatarsArr.add(0, photo);
ImageLocation location = imagesArrLocations.get(currentIndex);
imagesArrLocations.remove(currentIndex);
imagesArrLocations.add(0, location);
location = imagesArrLocationsVideo.get(currentIndex);
imagesArrLocationsVideo.remove(currentIndex);
imagesArrLocationsVideo.add(0, location);
Integer size = imagesArrLocationsSizes.get(currentIndex);
imagesArrLocationsSizes.remove(currentIndex);
imagesArrLocationsSizes.add(0, size);
TLRPC.Message message = imagesArrMessages.get(currentIndex);
imagesArrMessages.remove(currentIndex);
imagesArrMessages.add(0, message);
currentIndex = -1;
setImageIndex(0);
groupedPhotosListView.clear();
groupedPhotosListView.fillList();
hintView.showWithAction(avatarsDialogId, UndoView.ACTION_PROFILE_PHOTO_CHANGED, currentFileLocationVideo == currentFileLocation ? null : 1);
AndroidUtilities.runOnUIThread(() -> {
if (menuItem == null) {
return;
}
menuItem.hideSubItem(gallery_menu_set_as_main);
}, 300);
} else if (id == gallery_menu_edit_avatar) {
File f = FileLoader.getPathToAttach(getFileLocation(currentFileLocationVideo), getFileLocationExt(currentFileLocationVideo), true);
boolean isVideo = currentFileLocationVideo.imageType == FileLoader.IMAGE_TYPE_ANIMATION;
String thumb;
if (isVideo) {
thumb = FileLoader.getPathToAttach(getFileLocation(currentFileLocation), getFileLocationExt(currentFileLocation), true).getAbsolutePath();
} else {
thumb = null;
}
placeProvider.openPhotoForEdit(f.getAbsolutePath(), thumb, isVideo);
}
}
@Override
public boolean canOpenMenu() {
menuItemSpeed.setVisibility(View.INVISIBLE);
if (currentMessageObject != null || currentSecureDocument != null) {
return true;
} else if (currentFileLocationVideo != null) {
File f = FileLoader.getPathToAttach(getFileLocation(currentFileLocationVideo), getFileLocationExt(currentFileLocationVideo), avatarsDialogId != 0 || isEvent);
return f.exists();
} else if (pageBlocksAdapter != null) {
return true;
}
return false;
}
});
ActionBarMenu menu = actionBar.createMenu();
masksItem = menu.addItem(gallery_menu_masks, R.drawable.msg_mask);
masksItem.setContentDescription(LocaleController.getString("Masks", R.string.Masks));
pipItem = menu.addItem(gallery_menu_pip, R.drawable.ic_goinline);
pipItem.setContentDescription(LocaleController.getString("AccDescrPipMode", R.string.AccDescrPipMode));
sendItem = menu.addItem(gallery_menu_send, R.drawable.msg_forward);
sendItem.setContentDescription(LocaleController.getString("Forward", R.string.Forward));
shareItem = menu.addItem(gallery_menu_share2, R.drawable.share);
shareItem.setContentDescription(LocaleController.getString("ShareFile", R.string.ShareFile));
menuItem = menu.addItem(0, R.drawable.ic_ab_other);
menuItemSpeed = new ActionBarMenuItem(parentActivity, null, 0, 0, resourcesProvider);
menuItemSpeed.setDelegate(id -> {
if (id >= gallery_menu_speed_veryslow && id <= gallery_menu_speed_veryfast) {
switch(id) {
case gallery_menu_speed_veryslow:
currentVideoSpeed = 0.25f;
break;
case gallery_menu_speed_slow:
currentVideoSpeed = 0.5f;
break;
case gallery_menu_speed_normal:
currentVideoSpeed = 1.0f;
break;
case gallery_menu_speed_fast:
currentVideoSpeed = 1.5f;
break;
case gallery_menu_speed_veryfast:
currentVideoSpeed = 2.0f;
break;
}
if (currentMessageObject != null) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("playback_speed", Activity.MODE_PRIVATE);
if (Math.abs(currentVideoSpeed - 1.0f) < 0.001f) {
preferences.edit().remove("speed" + currentMessageObject.getDialogId() + "_" + currentMessageObject.getId()).commit();
} else {
preferences.edit().putFloat("speed" + currentMessageObject.getDialogId() + "_" + currentMessageObject.getId(), currentVideoSpeed).commit();
}
}
if (videoPlayer != null) {
videoPlayer.setPlaybackSpeed(currentVideoSpeed);
}
if (photoViewerWebView != null) {
photoViewerWebView.setPlaybackSpeed(currentVideoSpeed);
}
setMenuItemIcon();
menuItemSpeed.setVisibility(View.INVISIBLE);
}
});
menuItem.addView(menuItemSpeed);
menuItemSpeed.setVisibility(View.INVISIBLE);
speedItem = menuItem.addSubItem(gallery_menu_speed, R.drawable.msg_speed, null, LocaleController.getString("Speed", R.string.Speed), true, false);
speedItem.setSubtext(LocaleController.getString("SpeedNormal", R.string.SpeedNormal));
speedItem.setItemHeight(56);
speedItem.setTag(R.id.width_tag, 240);
speedItem.setColors(0xfffafafa, 0xfffafafa);
speedItem.setRightIcon(R.drawable.msg_arrowright);
speedGap = menuItem.addGap(gallery_menu_gap);
menuItem.getPopupLayout().setFitItems(true);
speedItems[0] = menuItemSpeed.addSubItem(gallery_menu_speed_veryslow, R.drawable.msg_speed_0_2, LocaleController.getString("SpeedVerySlow", R.string.SpeedVerySlow)).setColors(0xfffafafa, 0xfffafafa);
speedItems[1] = menuItemSpeed.addSubItem(gallery_menu_speed_slow, R.drawable.msg_speed_0_5, LocaleController.getString("SpeedSlow", R.string.SpeedSlow)).setColors(0xfffafafa, 0xfffafafa);
speedItems[2] = menuItemSpeed.addSubItem(gallery_menu_speed_normal, R.drawable.msg_speed_1, LocaleController.getString("SpeedNormal", R.string.SpeedNormal)).setColors(0xfffafafa, 0xfffafafa);
speedItems[3] = menuItemSpeed.addSubItem(gallery_menu_speed_fast, R.drawable.msg_speed_1_5, LocaleController.getString("SpeedFast", R.string.SpeedFast)).setColors(0xfffafafa, 0xfffafafa);
speedItems[4] = menuItemSpeed.addSubItem(gallery_menu_speed_veryfast, R.drawable.msg_speed_2, LocaleController.getString("SpeedVeryFast", R.string.SpeedVeryFast)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_openin, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp)).setColors(0xfffafafa, 0xfffafafa);
menuItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
allMediaItem = menuItem.addSubItem(gallery_menu_showall, R.drawable.msg_media, LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia));
allMediaItem.setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_savegif, R.drawable.msg_gif, LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_showinchat, R.drawable.msg_message, LocaleController.getString("ShowInChat", R.string.ShowInChat)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_masks2, R.drawable.msg_sticker, LocaleController.getString("ShowStickers", R.string.ShowStickers)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_share, R.drawable.msg_shareout, LocaleController.getString("ShareFile", R.string.ShareFile)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_save, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)).setColors(0xfffafafa, 0xfffafafa);
// menuItem.addSubItem(gallery_menu_edit_avatar, R.drawable.photo_paint, LocaleController.getString("EditPhoto", R.string.EditPhoto)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_set_as_main, R.drawable.menu_private, LocaleController.getString("SetAsMain", R.string.SetAsMain)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_delete, R.drawable.msg_delete, LocaleController.getString("Delete", R.string.Delete)).setColors(0xfffafafa, 0xfffafafa);
menuItem.addSubItem(gallery_menu_cancel_loading, R.drawable.msg_cancel, LocaleController.getString("StopDownload", R.string.StopDownload)).setColors(0xfffafafa, 0xfffafafa);
menuItem.redrawPopup(0xf9222222);
menuItemSpeed.redrawPopup(0xf9222222);
setMenuItemIcon();
menuItem.setSubMenuDelegate(new ActionBarMenuItem.ActionBarSubMenuItemDelegate() {
@Override
public void onShowSubMenu() {
if (videoPlayerControlVisible && isPlaying) {
AndroidUtilities.cancelRunOnUIThread(hideActionBarRunnable);
}
}
@Override
public void onHideSubMenu() {
if (videoPlayerControlVisible && isPlaying) {
scheduleActionBarHide();
}
}
});
bottomLayout = new FrameLayout(activityContext) {
@Override
protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
if (child == nameTextView || child == dateTextView) {
widthUsed = bottomButtonsLayout.getMeasuredWidth();
}
super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
}
};
bottomLayout.setBackgroundColor(0x7f000000);
containerView.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
pressedDrawable[0] = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[] { 0x32000000, 0 });
pressedDrawable[0].setShape(GradientDrawable.RECTANGLE);
pressedDrawable[1] = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, new int[] { 0x32000000, 0 });
pressedDrawable[1].setShape(GradientDrawable.RECTANGLE);
groupedPhotosListView = new GroupedPhotosListView(activityContext, AndroidUtilities.dp(10));
containerView.addView(groupedPhotosListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 68, Gravity.BOTTOM | Gravity.LEFT));
groupedPhotosListView.setDelegate(new GroupedPhotosListView.GroupedPhotosListViewDelegate() {
@Override
public int getCurrentIndex() {
return currentIndex;
}
@Override
public int getCurrentAccount() {
return currentAccount;
}
@Override
public long getAvatarsDialogId() {
return avatarsDialogId;
}
@Override
public int getSlideshowMessageId() {
return slideshowMessageId;
}
@Override
public ArrayList<ImageLocation> getImagesArrLocations() {
return imagesArrLocations;
}
@Override
public ArrayList<MessageObject> getImagesArr() {
return imagesArr;
}
@Override
public List<TLRPC.PageBlock> getPageBlockArr() {
return pageBlocksAdapter != null ? pageBlocksAdapter.getAll() : null;
}
@Override
public Object getParentObject() {
return pageBlocksAdapter != null ? pageBlocksAdapter.getParentObject() : null;
}
@Override
public void setCurrentIndex(int index) {
currentIndex = -1;
if (currentThumb != null) {
currentThumb.release();
currentThumb = null;
}
dontAutoPlay = true;
setImageIndex(index);
dontAutoPlay = false;
}
@Override
public void onShowAnimationStart() {
containerView.requestLayout();
}
@Override
public void onStopScrolling() {
if (shouldMessageObjectAutoPlayed(currentMessageObject)) {
playerAutoStarted = true;
onActionClick(true);
checkProgress(0, false, true);
}
}
@Override
public boolean validGroupId(long groupId) {
if (placeProvider != null) {
return placeProvider.validateGroupId(groupId);
}
return true;
}
});
for (int a = 0; a < 3; a++) {
fullscreenButton[a] = new ImageView(parentActivity);
fullscreenButton[a].setImageResource(R.drawable.msg_maxvideo);
fullscreenButton[a].setContentDescription(LocaleController.getString("AccSwitchToFullscreen", R.string.AccSwitchToFullscreen));
fullscreenButton[a].setScaleType(ImageView.ScaleType.CENTER);
fullscreenButton[a].setBackground(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
fullscreenButton[a].setVisibility(View.INVISIBLE);
fullscreenButton[a].setAlpha(1.0f);
containerView.addView(fullscreenButton[a], LayoutHelper.createFrame(48, 48));
fullscreenButton[a].setOnClickListener(v -> {
if (parentActivity == null) {
return;
}
wasRotated = false;
fullscreenedByButton = 1;
if (prevOrientation == -10) {
prevOrientation = parentActivity.getRequestedOrientation();
}
WindowManager manager = (WindowManager) parentActivity.getSystemService(Activity.WINDOW_SERVICE);
int displayRotation = manager.getDefaultDisplay().getRotation();
if (displayRotation == Surface.ROTATION_270) {
parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
toggleActionBar(false, false);
});
}
final LinkMovementMethod captionLinkMovementMethod = new CaptionLinkMovementMethod();
captionTextViewSwitcher = new CaptionTextViewSwitcher(containerView.getContext());
captionTextViewSwitcher.setFactory(() -> createCaptionTextView(captionLinkMovementMethod));
captionTextViewSwitcher.setVisibility(View.INVISIBLE);
setCaptionHwLayerEnabled(true);
for (int a = 0; a < 3; a++) {
photoProgressViews[a] = new PhotoProgressView(containerView) {
@Override
protected void onBackgroundStateUpdated(int state) {
if (this == photoProgressViews[0]) {
updateAccessibilityOverlayVisibility();
}
}
@Override
protected void onVisibilityChanged(boolean visible) {
if (this == photoProgressViews[0]) {
updateAccessibilityOverlayVisibility();
}
}
};
photoProgressViews[a].setBackgroundState(PROGRESS_EMPTY, false, true);
}
miniProgressView = new RadialProgressView(activityContext, resourcesProvider) {
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
if (containerView != null) {
containerView.invalidate();
}
}
@Override
public void invalidate() {
super.invalidate();
if (containerView != null) {
containerView.invalidate();
}
}
};
miniProgressView.setUseSelfAlpha(true);
miniProgressView.setProgressColor(0xffffffff);
miniProgressView.setSize(AndroidUtilities.dp(54));
miniProgressView.setBackgroundResource(R.drawable.circle_big);
miniProgressView.setVisibility(View.INVISIBLE);
miniProgressView.setAlpha(0.0f);
containerView.addView(miniProgressView, LayoutHelper.createFrame(64, 64, Gravity.CENTER));
bottomButtonsLayout = new LinearLayout(containerView.getContext());
bottomButtonsLayout.setOrientation(LinearLayout.HORIZONTAL);
bottomLayout.addView(bottomButtonsLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
paintButton = new ImageView(containerView.getContext());
paintButton.setImageResource(R.drawable.photo_paint);
paintButton.setScaleType(ImageView.ScaleType.CENTER);
paintButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
bottomButtonsLayout.addView(paintButton, LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT));
paintButton.setOnClickListener(v -> openCurrentPhotoInPaintModeForSelect());
paintButton.setContentDescription(LocaleController.getString("AccDescrPhotoEditor", R.string.AccDescrPhotoEditor));
shareButton = new ImageView(containerView.getContext());
shareButton.setImageResource(R.drawable.share);
shareButton.setScaleType(ImageView.ScaleType.CENTER);
shareButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
bottomButtonsLayout.addView(shareButton, LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT));
shareButton.setOnClickListener(v -> onSharePressed());
shareButton.setContentDescription(LocaleController.getString("ShareFile", R.string.ShareFile));
nameTextView = new FadingTextViewLayout(containerView.getContext()) {
@Override
protected void onTextViewCreated(TextView textView) {
super.onTextViewCreated(textView);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setTextColor(0xffffffff);
textView.setGravity(Gravity.LEFT);
}
};
bottomLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 5, 8, 0));
dateTextView = new FadingTextViewLayout(containerView.getContext(), true) {
private LocaleController.LocaleInfo lastLocaleInfo = null;
private int staticCharsCount = 0;
@Override
protected void onTextViewCreated(TextView textView) {
super.onTextViewCreated(textView);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setTextColor(0xffffffff);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setGravity(Gravity.LEFT);
}
@Override
protected int getStaticCharsCount() {
final LocaleController.LocaleInfo localeInfo = LocaleController.getInstance().getCurrentLocaleInfo();
if (lastLocaleInfo != localeInfo) {
lastLocaleInfo = localeInfo;
staticCharsCount = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date()), LocaleController.getInstance().formatterDay.format(new Date())).length();
}
return staticCharsCount;
}
@Override
public void setText(CharSequence text, boolean animated) {
if (animated) {
boolean dontAnimateUnchangedStaticChars = true;
if (LocaleController.isRTL) {
final int staticCharsCount = getStaticCharsCount();
if (staticCharsCount > 0) {
if (text.length() != staticCharsCount || getText() == null || getText().length() != staticCharsCount) {
dontAnimateUnchangedStaticChars = false;
}
}
}
setText(text, true, dontAnimateUnchangedStaticChars);
} else {
setText(text, false, false);
}
}
};
bottomLayout.addView(dateTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 25, 8, 0));
createVideoControlsInterface();
progressView = new RadialProgressView(parentActivity, resourcesProvider);
progressView.setProgressColor(0xffffffff);
progressView.setBackgroundResource(R.drawable.circle_big);
progressView.setVisibility(View.INVISIBLE);
containerView.addView(progressView, LayoutHelper.createFrame(54, 54, Gravity.CENTER));
qualityPicker = new PickerBottomLayoutViewer(parentActivity);
qualityPicker.setBackgroundColor(0x7f000000);
qualityPicker.updateSelectedCount(0, false);
qualityPicker.setTranslationY(AndroidUtilities.dp(120));
qualityPicker.doneButton.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
qualityPicker.doneButton.setTextColor(getThemedColor(Theme.key_dialogFloatingButton));
containerView.addView(qualityPicker, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
qualityPicker.cancelButton.setOnClickListener(view -> {
selectedCompression = previousCompression;
didChangedCompressionLevel(false);
showQualityView(false);
requestVideoPreview(2);
});
qualityPicker.doneButton.setOnClickListener(view -> {
showQualityView(false);
requestVideoPreview(2);
});
videoForwardDrawable = new VideoForwardDrawable(false);
videoForwardDrawable.setDelegate(new VideoForwardDrawable.VideoForwardDrawableDelegate() {
@Override
public void onAnimationEnd() {
}
@Override
public void invalidate() {
containerView.invalidate();
}
});
qualityChooseView = new QualityChooseView(parentActivity);
qualityChooseView.setTranslationY(AndroidUtilities.dp(120));
qualityChooseView.setVisibility(View.INVISIBLE);
qualityChooseView.setBackgroundColor(0x7f000000);
containerView.addView(qualityChooseView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 70, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48));
pickerView = new FrameLayout(activityContext) {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return bottomTouchEnabled && super.dispatchTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return bottomTouchEnabled && super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return bottomTouchEnabled && super.onTouchEvent(event);
}
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
if (videoTimelineView != null && videoTimelineView.getVisibility() != GONE) {
videoTimelineView.setTranslationY(translationY);
videoAvatarTooltip.setTranslationY(translationY);
}
if (videoAvatarTooltip != null && videoAvatarTooltip.getVisibility() != GONE) {
videoAvatarTooltip.setTranslationY(translationY);
}
}
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
if (videoTimelineView != null && videoTimelineView.getVisibility() != GONE) {
videoTimelineView.setAlpha(alpha);
}
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if (videoTimelineView != null && videoTimelineView.getVisibility() != GONE) {
videoTimelineView.setVisibility(visibility == VISIBLE ? VISIBLE : INVISIBLE);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (itemsLayout.getVisibility() != GONE) {
int x = (right - left - AndroidUtilities.dp(70) - itemsLayout.getMeasuredWidth()) / 2;
itemsLayout.layout(x, itemsLayout.getTop(), x + itemsLayout.getMeasuredWidth(), itemsLayout.getTop() + itemsLayout.getMeasuredHeight());
}
}
};
pickerView.setBackgroundColor(0x7f000000);
containerView.addView(pickerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT));
docNameTextView = new TextView(containerView.getContext());
docNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
docNameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
docNameTextView.setSingleLine(true);
docNameTextView.setMaxLines(1);
docNameTextView.setEllipsize(TextUtils.TruncateAt.END);
docNameTextView.setTextColor(0xffffffff);
docNameTextView.setGravity(Gravity.LEFT);
pickerView.addView(docNameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 20, 23, 84, 0));
docInfoTextView = new TextView(containerView.getContext());
docInfoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
docInfoTextView.setSingleLine(true);
docInfoTextView.setMaxLines(1);
docInfoTextView.setEllipsize(TextUtils.TruncateAt.END);
docInfoTextView.setTextColor(0xffffffff);
docInfoTextView.setGravity(Gravity.LEFT);
pickerView.addView(docInfoTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 20, 46, 84, 0));
videoTimelineView = new VideoTimelinePlayView(parentActivity) {
@Override
public void setTranslationY(float translationY) {
if (getTranslationY() != translationY) {
super.setTranslationY(translationY);
containerView.invalidate();
}
}
};
videoTimelineView.setDelegate(new VideoTimelinePlayView.VideoTimelineViewDelegate() {
private Runnable seekToRunnable;
private int seekTo;
private boolean wasPlaying;
@Override
public void onLeftProgressChanged(float progress) {
if (videoPlayer == null) {
return;
}
if (videoPlayer.isPlaying()) {
manuallyPaused = false;
videoPlayer.pause();
containerView.invalidate();
}
updateAvatarStartTime(1);
seekTo(progress);
videoPlayerSeekbar.setProgress(0);
videoTimelineView.setProgress(progress);
updateVideoInfo();
}
@Override
public void onRightProgressChanged(float progress) {
if (videoPlayer == null) {
return;
}
if (videoPlayer.isPlaying()) {
manuallyPaused = false;
videoPlayer.pause();
containerView.invalidate();
}
updateAvatarStartTime(2);
seekTo(progress);
videoPlayerSeekbar.setProgress(1f);
videoTimelineView.setProgress(progress);
updateVideoInfo();
}
@Override
public void onPlayProgressChanged(float progress) {
if (videoPlayer == null) {
return;
}
if (sendPhotoType == SELECT_TYPE_AVATAR) {
updateAvatarStartTime(0);
}
seekTo(progress);
}
private void seekTo(float progress) {
seekTo = (int) (videoDuration * progress);
if (seekToRunnable == null) {
AndroidUtilities.runOnUIThread(seekToRunnable = () -> {
if (videoPlayer != null) {
videoPlayer.seekTo(seekTo);
}
if (sendPhotoType == SELECT_TYPE_AVATAR) {
needCaptureFrameReadyAtTime = seekTo;
if (captureFrameReadyAtTime != needCaptureFrameReadyAtTime) {
captureFrameReadyAtTime = -1;
}
}
seekToRunnable = null;
}, 100);
}
}
private void updateAvatarStartTime(int fix) {
if (sendPhotoType != SELECT_TYPE_AVATAR) {
return;
}
if (fix != 0) {
if (photoCropView != null && (videoTimelineView.getLeftProgress() > avatarStartProgress || videoTimelineView.getRightProgress() < avatarStartProgress)) {
photoCropView.setVideoThumbVisible(false);
if (fix == 1) {
avatarStartTime = (long) (videoDuration * 1000 * videoTimelineView.getLeftProgress());
} else {
avatarStartTime = (long) (videoDuration * 1000 * videoTimelineView.getRightProgress());
}
captureFrameAtTime = -1;
}
} else {
avatarStartProgress = videoTimelineView.getProgress();
avatarStartTime = (long) (videoDuration * 1000 * avatarStartProgress);
}
}
@Override
public void didStartDragging(int type) {
if (type == VideoTimelinePlayView.TYPE_PROGRESS) {
cancelVideoPlayRunnable();
if (sendPhotoType == SELECT_TYPE_AVATAR) {
cancelFlashAnimations();
captureFrameAtTime = -1;
}
if (wasPlaying = videoPlayer != null && videoPlayer.isPlaying()) {
manuallyPaused = false;
videoPlayer.pause();
containerView.invalidate();
}
}
}
@Override
public void didStopDragging(int type) {
if (seekToRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(seekToRunnable);
seekToRunnable.run();
}
cancelVideoPlayRunnable();
if (sendPhotoType == SELECT_TYPE_AVATAR && flashView != null && type == VideoTimelinePlayView.TYPE_PROGRESS) {
cancelFlashAnimations();
captureFrameAtTime = avatarStartTime;
if (captureFrameReadyAtTime == seekTo) {
captureCurrentFrame();
}
} else {
if (sendPhotoType == SELECT_TYPE_AVATAR || wasPlaying) {
manuallyPaused = false;
if (videoPlayer != null) {
videoPlayer.play();
}
}
}
}
});
showVideoTimeline(false, false);
videoTimelineView.setBackgroundColor(0x7f000000);
containerView.addView(videoTimelineView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 58, Gravity.LEFT | Gravity.BOTTOM, 0, 8, 0, 0));
videoAvatarTooltip = new TextView(parentActivity);
videoAvatarTooltip.setSingleLine(true);
videoAvatarTooltip.setVisibility(View.GONE);
videoAvatarTooltip.setText(LocaleController.getString("ChooseCover", R.string.ChooseCover));
videoAvatarTooltip.setGravity(Gravity.CENTER_HORIZONTAL);
videoAvatarTooltip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
videoAvatarTooltip.setTextColor(0xff8c8c8c);
containerView.addView(videoAvatarTooltip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 0, 8, 0, 0));
pickerViewSendButton = new ImageView(parentActivity) {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return bottomTouchEnabled && super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return bottomTouchEnabled && super.onTouchEvent(event);
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
if (captionEditText.getCaptionLimitOffset() < 0) {
captionLimitView.setVisibility(visibility);
} else {
captionLimitView.setVisibility(View.GONE);
}
}
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
captionLimitView.setTranslationY(translationY);
}
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
captionLimitView.setAlpha(alpha);
}
};
pickerViewSendButton.setScaleType(ImageView.ScaleType.CENTER);
pickerViewSendDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), getThemedColor(Theme.key_dialogFloatingButton), getThemedColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
pickerViewSendButton.setBackgroundDrawable(pickerViewSendDrawable);
pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(0xffffffff, PorterDuff.Mode.MULTIPLY));
pickerViewSendButton.setImageResource(R.drawable.attach_send);
pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
containerView.addView(pickerViewSendButton, LayoutHelper.createFrame(56, 56, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 14, 14));
pickerViewSendButton.setContentDescription(LocaleController.getString("Send", R.string.Send));
pickerViewSendButton.setOnClickListener(v -> {
if (captionEditText.getCaptionLimitOffset() < 0) {
AndroidUtilities.shakeView(captionLimitView, 2, 0);
Vibrator vibrator = (Vibrator) captionLimitView.getContext().getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null) {
vibrator.vibrate(200);
}
return;
}
if (parentChatActivity != null && parentChatActivity.isInScheduleMode() && !parentChatActivity.isEditingMessageMedia()) {
showScheduleDatePickerDialog();
} else {
sendPressed(true, 0);
}
});
pickerViewSendButton.setOnLongClickListener(view -> {
if (placeProvider != null && !placeProvider.allowSendingSubmenu()) {
return false;
}
if (parentChatActivity == null || parentChatActivity.isInScheduleMode()) {
return false;
}
if (captionEditText.getCaptionLimitOffset() < 0) {
return false;
}
TLRPC.Chat chat = parentChatActivity.getCurrentChat();
TLRPC.User user = parentChatActivity.getCurrentUser();
sendPopupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(parentActivity);
sendPopupLayout.setAnimationEnabled(false);
sendPopupLayout.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
v.getHitRect(hitRect);
if (!hitRect.contains((int) event.getX(), (int) event.getY())) {
sendPopupWindow.dismiss();
}
}
}
return false;
});
sendPopupLayout.setDispatchKeyEventListener(keyEvent -> {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
});
sendPopupLayout.setShownFromBotton(false);
sendPopupLayout.setBackgroundColor(0xf9222222);
final boolean canReplace = placeProvider != null && placeProvider.canReplace(currentIndex);
final int[] order = { 4, 3, 2, 0, 1 };
for (int i = 0; i < 5; i++) {
final int a = order[i];
if (a != 2 && a != 3 && canReplace) {
continue;
}
if (a == 0 && !parentChatActivity.canScheduleMessage()) {
continue;
}
if (a == 0 && placeProvider != null && placeProvider.getSelectedPhotos() != null) {
HashMap<Object, Object> hashMap = placeProvider.getSelectedPhotos();
boolean hasTtl = false;
for (HashMap.Entry<Object, Object> entry : hashMap.entrySet()) {
Object object = entry.getValue();
if (object instanceof MediaController.PhotoEntry) {
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
if (photoEntry.ttl != 0) {
hasTtl = true;
break;
}
} else if (object instanceof MediaController.SearchImage) {
MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
if (searchImage.ttl != 0) {
hasTtl = true;
break;
}
}
}
if (hasTtl) {
continue;
}
} else if (a == 1 && UserObject.isUserSelf(user)) {
continue;
} else if ((a == 2 || a == 3) && !canReplace) {
continue;
} else if (a == 4 && (isCurrentVideo || timeItem.getColorFilter() != null)) {
continue;
}
ActionBarMenuSubItem cell = new ActionBarMenuSubItem(parentActivity, a == 0, a == 3, resourcesProvider);
if (a == 0) {
if (UserObject.isUserSelf(user)) {
cell.setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.msg_schedule);
} else {
cell.setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.msg_schedule);
}
} else if (a == 1) {
cell.setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
} else if (a == 2) {
cell.setTextAndIcon(LocaleController.getString("ReplacePhoto", R.string.ReplacePhoto), R.drawable.msg_replace);
} else if (a == 3) {
cell.setTextAndIcon(LocaleController.getString("SendAsNewPhoto", R.string.SendAsNewPhoto), R.drawable.msg_sendphoto);
} else if (a == 4) {
cell.setTextAndIcon(LocaleController.getString("SendWithoutCompression", R.string.SendWithoutCompression), R.drawable.msg_sendfile);
}
cell.setMinimumWidth(AndroidUtilities.dp(196));
cell.setColors(0xffffffff, 0xffffffff);
sendPopupLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
cell.setOnClickListener(v -> {
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
if (a == 0) {
showScheduleDatePickerDialog();
} else if (a == 1) {
sendPressed(false, 0);
} else if (a == 2) {
replacePressed();
} else if (a == 3) {
sendPressed(true, 0);
} else if (a == 4) {
sendPressed(true, 0, false, true);
}
});
}
if (sendPopupLayout.getChildCount() == 0) {
return false;
}
sendPopupLayout.setupRadialSelectors(0x24ffffff);
sendPopupWindow = new ActionBarPopupWindow(sendPopupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
sendPopupWindow.setAnimationEnabled(false);
sendPopupWindow.setAnimationStyle(R.style.PopupContextAnimation2);
sendPopupWindow.setOutsideTouchable(true);
sendPopupWindow.setClippingEnabled(true);
sendPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
sendPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
sendPopupWindow.getContentView().setFocusableInTouchMode(true);
sendPopupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
sendPopupWindow.setFocusable(true);
int[] location = new int[2];
view.getLocationInWindow(location);
sendPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, location[0] + view.getMeasuredWidth() - sendPopupLayout.getMeasuredWidth() + AndroidUtilities.dp(14), location[1] - sendPopupLayout.getMeasuredHeight() - AndroidUtilities.dp(18));
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
});
captionLimitView = new TextView(parentActivity);
captionLimitView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
captionLimitView.setTextColor(0xffEC7777);
captionLimitView.setGravity(Gravity.CENTER);
captionLimitView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
containerView.addView(captionLimitView, LayoutHelper.createFrame(56, 20, Gravity.BOTTOM | Gravity.RIGHT, 3, 0, 14, 78));
itemsLayout = new LinearLayout(parentActivity) {
boolean ignoreLayout;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int visibleItemsCount = 0;
int count = getChildCount();
for (int a = 0; a < count; a++) {
View v = getChildAt(a);
if (v.getVisibility() != VISIBLE) {
continue;
}
visibleItemsCount++;
}
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
if (visibleItemsCount != 0) {
int itemWidth = Math.min(AndroidUtilities.dp(70), width / visibleItemsCount);
if (compressItem.getVisibility() == VISIBLE) {
ignoreLayout = true;
int compressIconWidth;
if (selectedCompression < 2) {
compressIconWidth = 48;
} else {
compressIconWidth = 64;
}
int padding = Math.max(0, (itemWidth - AndroidUtilities.dp(compressIconWidth)) / 2);
compressItem.setPadding(padding, 0, padding, 0);
ignoreLayout = false;
}
for (int a = 0; a < count; a++) {
View v = getChildAt(a);
if (v.getVisibility() == GONE) {
continue;
}
v.measure(MeasureSpec.makeMeasureSpec(itemWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
setMeasuredDimension(itemWidth * visibleItemsCount, height);
} else {
setMeasuredDimension(width, height);
}
}
};
itemsLayout.setOrientation(LinearLayout.HORIZONTAL);
pickerView.addView(itemsLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 70, 0));
cropItem = new ImageView(parentActivity);
cropItem.setScaleType(ImageView.ScaleType.CENTER);
cropItem.setImageResource(R.drawable.photo_crop);
cropItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
itemsLayout.addView(cropItem, LayoutHelper.createLinear(48, 48));
cropItem.setOnClickListener(v -> {
if (captionEditText.getTag() != null) {
return;
}
if (isCurrentVideo) {
if (!videoConvertSupported) {
return;
}
if (videoTextureView instanceof VideoEditTextureView) {
VideoEditTextureView textureView = (VideoEditTextureView) videoTextureView;
if (textureView.getVideoWidth() <= 0 || textureView.getVideoHeight() <= 0) {
return;
}
} else {
return;
}
}
switchToEditMode(1);
});
cropItem.setContentDescription(LocaleController.getString("CropImage", R.string.CropImage));
rotateItem = new ImageView(parentActivity);
rotateItem.setScaleType(ImageView.ScaleType.CENTER);
rotateItem.setImageResource(R.drawable.tool_rotate);
rotateItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
itemsLayout.addView(rotateItem, LayoutHelper.createLinear(48, 48));
rotateItem.setOnClickListener(v -> {
if (photoCropView == null) {
return;
}
if (photoCropView.rotate()) {
rotateItem.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingButton), PorterDuff.Mode.MULTIPLY));
} else {
rotateItem.setColorFilter(null);
}
});
rotateItem.setContentDescription(LocaleController.getString("AccDescrRotate", R.string.AccDescrRotate));
mirrorItem = new ImageView(parentActivity);
mirrorItem.setScaleType(ImageView.ScaleType.CENTER);
mirrorItem.setImageResource(R.drawable.photo_flip);
mirrorItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
itemsLayout.addView(mirrorItem, LayoutHelper.createLinear(48, 48));
mirrorItem.setOnClickListener(v -> {
if (photoCropView == null) {
return;
}
if (photoCropView.mirror()) {
mirrorItem.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingButton), PorterDuff.Mode.MULTIPLY));
} else {
mirrorItem.setColorFilter(null);
}
});
mirrorItem.setContentDescription(LocaleController.getString("AccDescrMirror", R.string.AccDescrMirror));
paintItem = new ImageView(parentActivity);
paintItem.setScaleType(ImageView.ScaleType.CENTER);
paintItem.setImageResource(R.drawable.photo_paint);
paintItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
itemsLayout.addView(paintItem, LayoutHelper.createLinear(48, 48));
paintItem.setOnClickListener(v -> {
if (captionEditText.getTag() != null) {
return;
}
if (isCurrentVideo) {
if (!videoConvertSupported) {
return;
}
if (videoTextureView instanceof VideoEditTextureView) {
VideoEditTextureView textureView = (VideoEditTextureView) videoTextureView;
if (textureView.getVideoWidth() <= 0 || textureView.getVideoHeight() <= 0) {
return;
}
} else {
return;
}
}
switchToEditMode(3);
});
paintItem.setContentDescription(LocaleController.getString("AccDescrPhotoEditor", R.string.AccDescrPhotoEditor));
muteItem = new ImageView(parentActivity);
muteItem.setScaleType(ImageView.ScaleType.CENTER);
muteItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
containerView.addView(muteItem, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 0, 0));
muteItem.setOnClickListener(v -> {
if (captionEditText.getTag() != null) {
return;
}
muteVideo = !muteVideo;
updateMuteButton();
updateVideoInfo();
if (muteVideo && !checkImageView.isChecked()) {
checkImageView.callOnClick();
} else {
Object object = imagesArrLocals.get(currentIndex);
if (object instanceof MediaController.MediaEditState) {
((MediaController.MediaEditState) object).editedInfo = getCurrentVideoEditedInfo();
}
}
});
cameraItem = new ImageView(parentActivity);
cameraItem.setScaleType(ImageView.ScaleType.CENTER);
cameraItem.setImageResource(R.drawable.photo_add);
cameraItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
cameraItem.setContentDescription(LocaleController.getString("AccDescrTakeMorePics", R.string.AccDescrTakeMorePics));
containerView.addView(cameraItem, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 16, 0));
cameraItem.setOnClickListener(v -> {
if (placeProvider == null || captionEditText.getTag() != null) {
return;
}
placeProvider.needAddMorePhotos();
closePhoto(true, false);
});
tuneItem = new ImageView(parentActivity);
tuneItem.setScaleType(ImageView.ScaleType.CENTER);
tuneItem.setImageResource(R.drawable.photo_tools);
tuneItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
itemsLayout.addView(tuneItem, LayoutHelper.createLinear(48, 48));
tuneItem.setOnClickListener(v -> {
if (captionEditText.getTag() != null) {
return;
}
if (isCurrentVideo) {
if (!videoConvertSupported) {
return;
}
if (videoTextureView instanceof VideoEditTextureView) {
VideoEditTextureView textureView = (VideoEditTextureView) videoTextureView;
if (textureView.getVideoWidth() <= 0 || textureView.getVideoHeight() <= 0) {
return;
}
} else {
return;
}
}
switchToEditMode(2);
});
tuneItem.setContentDescription(LocaleController.getString("AccDescrPhotoAdjust", R.string.AccDescrPhotoAdjust));
compressItem = new ImageView(parentActivity);
compressItem.setTag(1);
compressItem.setScaleType(ImageView.ScaleType.CENTER);
compressItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
selectedCompression = selectCompression();
int compressIconWidth;
if (selectedCompression <= 1) {
compressItem.setImageResource(R.drawable.video_quality1);
} else if (selectedCompression == 2) {
compressItem.setImageResource(R.drawable.video_quality2);
} else {
selectedCompression = compressionsCount - 1;
compressItem.setImageResource(R.drawable.video_quality3);
}
compressItem.setContentDescription(LocaleController.getString("AccDescrVideoQuality", R.string.AccDescrVideoQuality));
itemsLayout.addView(compressItem, LayoutHelper.createLinear(48, 48));
compressItem.setOnClickListener(v -> {
if (captionEditText.getTag() != null || muteVideo) {
return;
}
if (compressItem.getTag() == null) {
if (videoConvertSupported) {
if (tooltip == null) {
tooltip = new Tooltip(activity, containerView, 0xcc111111, Color.WHITE);
}
tooltip.setText(LocaleController.getString("VideoQualityIsTooLow", R.string.VideoQualityIsTooLow));
tooltip.show(compressItem);
}
return;
}
showQualityView(true);
requestVideoPreview(1);
});
timeItem = new ImageView(parentActivity);
timeItem.setScaleType(ImageView.ScaleType.CENTER);
timeItem.setImageResource(R.drawable.photo_timer);
timeItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
timeItem.setContentDescription(LocaleController.getString("SetTimer", R.string.SetTimer));
itemsLayout.addView(timeItem, LayoutHelper.createLinear(48, 48));
timeItem.setOnClickListener(v -> {
if (parentActivity == null || captionEditText.getTag() != null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(parentActivity, false, resourcesProvider);
builder.setUseHardwareLayer(false);
LinearLayout linearLayout = new LinearLayout(parentActivity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setCustomView(linearLayout);
TextView titleView = new TextView(parentActivity);
titleView.setLines(1);
titleView.setSingleLine(true);
titleView.setText(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
titleView.setTextColor(0xffffffff);
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
titleView.setPadding(AndroidUtilities.dp(21), AndroidUtilities.dp(8), AndroidUtilities.dp(21), AndroidUtilities.dp(4));
titleView.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
titleView.setOnTouchListener((v13, event) -> true);
titleView = new TextView(parentActivity);
titleView.setText(isCurrentVideo ? LocaleController.getString("MessageLifetimeVideo", R.string.MessageLifetimeVideo) : LocaleController.getString("MessageLifetimePhoto", R.string.MessageLifetimePhoto));
titleView.setTextColor(0xff808080);
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
titleView.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), AndroidUtilities.dp(8));
titleView.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
titleView.setOnTouchListener((v12, event) -> true);
final BottomSheet bottomSheet = builder.create();
final NumberPicker numberPicker = new NumberPicker(parentActivity, resourcesProvider);
numberPicker.setMinValue(0);
numberPicker.setMaxValue(28);
Object object = imagesArrLocals.get(currentIndex);
int currentTTL;
if (object instanceof MediaController.PhotoEntry) {
currentTTL = ((MediaController.PhotoEntry) object).ttl;
} else if (object instanceof MediaController.SearchImage) {
currentTTL = ((MediaController.SearchImage) object).ttl;
} else {
currentTTL = 0;
}
if (currentTTL == 0) {
SharedPreferences preferences1 = MessagesController.getGlobalMainSettings();
numberPicker.setValue(preferences1.getInt("self_destruct", 7));
} else {
if (currentTTL >= 0 && currentTTL < 21) {
numberPicker.setValue(currentTTL);
} else {
numberPicker.setValue(21 + currentTTL / 5 - 5);
}
}
numberPicker.setTextColor(0xffffffff);
numberPicker.setSelectorColor(0xff4d4d4d);
numberPicker.setFormatter(value -> {
if (value == 0) {
return LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever);
} else if (value >= 1 && value < 21) {
return LocaleController.formatTTLString(value);
} else {
return LocaleController.formatTTLString((value - 16) * 5);
}
});
linearLayout.addView(numberPicker, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
FrameLayout buttonsLayout = new FrameLayout(parentActivity) {
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int count = getChildCount();
int width = right - left;
for (int a = 0; a < count; a++) {
View child = getChildAt(a);
if ((Integer) child.getTag() == Dialog.BUTTON_POSITIVE) {
child.layout(width - getPaddingRight() - child.getMeasuredWidth(), getPaddingTop(), width - getPaddingRight(), getPaddingTop() + child.getMeasuredHeight());
} else if ((Integer) child.getTag() == Dialog.BUTTON_NEGATIVE) {
int x = getPaddingLeft();
child.layout(x, getPaddingTop(), x + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
} else {
child.layout(getPaddingLeft(), getPaddingTop(), getPaddingLeft() + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
}
}
}
};
buttonsLayout.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
linearLayout.addView(buttonsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 52));
TextView textView = new TextView(parentActivity);
textView.setMinWidth(AndroidUtilities.dp(64));
textView.setTag(Dialog.BUTTON_POSITIVE);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTextColor(getThemedColor(Theme.key_dialogFloatingButton));
textView.setGravity(Gravity.CENTER);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(0xff49bcf2));
textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
textView.setOnClickListener(v1 -> {
int value = numberPicker.getValue();
SharedPreferences preferences1 = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences1.edit();
editor.putInt("self_destruct", value);
editor.commit();
bottomSheet.dismiss();
int seconds;
if (value >= 0 && value < 21) {
seconds = value;
} else {
seconds = (value - 16) * 5;
}
Object object1 = imagesArrLocals.get(currentIndex);
if (object1 instanceof MediaController.PhotoEntry) {
((MediaController.PhotoEntry) object1).ttl = seconds;
} else if (object1 instanceof MediaController.SearchImage) {
((MediaController.SearchImage) object1).ttl = seconds;
}
timeItem.setColorFilter(seconds != 0 ? new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingButton), PorterDuff.Mode.MULTIPLY) : null);
if (!checkImageView.isChecked()) {
checkImageView.callOnClick();
}
});
textView = new TextView(parentActivity);
textView.setMinWidth(AndroidUtilities.dp(64));
textView.setTag(Dialog.BUTTON_NEGATIVE);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTextColor(0xffffffff);
textView.setGravity(Gravity.CENTER);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(0xffffffff));
textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
textView.setOnClickListener(v14 -> bottomSheet.dismiss());
bottomSheet.show();
bottomSheet.setBackgroundColor(0xff000000);
});
editorDoneLayout = new PickerBottomLayoutViewer(activityContext);
editorDoneLayout.setBackgroundColor(0xcc000000);
editorDoneLayout.updateSelectedCount(0, false);
editorDoneLayout.setVisibility(View.GONE);
containerView.addView(editorDoneLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
editorDoneLayout.cancelButton.setOnClickListener(view -> {
cropTransform.setViewTransform(previousHasTransform, previousCropPx, previousCropPy, previousCropRotation, previousCropOrientation, previousCropScale, 1.0f, 1.0f, previousCropPw, previousCropPh, 0, 0, previousCropMirrored);
switchToEditMode(0);
});
editorDoneLayout.doneButton.setOnClickListener(view -> {
if (currentEditMode == 1 && !photoCropView.isReady()) {
return;
}
applyCurrentEditMode();
switchToEditMode(0);
});
resetButton = new TextView(activityContext);
resetButton.setVisibility(View.GONE);
resetButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
resetButton.setTextColor(0xffffffff);
resetButton.setGravity(Gravity.CENTER);
resetButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, 0));
resetButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
resetButton.setText(LocaleController.getString("Reset", R.string.CropReset).toUpperCase());
resetButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
editorDoneLayout.addView(resetButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.CENTER));
resetButton.setOnClickListener(v -> photoCropView.reset());
gestureDetector = new GestureDetector2(containerView.getContext(), this);
gestureDetector.setIsLongpressEnabled(false);
setDoubleTapEnabled(true);
ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = (imageReceiver, set, thumb, memCache) -> {
if (imageReceiver == centerImage && set && !thumb) {
if (!isCurrentVideo && (currentEditMode == 1 || sendPhotoType == SELECT_TYPE_AVATAR) && photoCropView != null) {
Bitmap bitmap = imageReceiver.getBitmap();
if (bitmap != null) {
photoCropView.setBitmap(bitmap, imageReceiver.getOrientation(), sendPhotoType != SELECT_TYPE_AVATAR, true, paintingOverlay, cropTransform, null, null);
}
}
if (paintingOverlay.getVisibility() == View.VISIBLE) {
containerView.requestLayout();
}
detectFaces();
}
if (imageReceiver == centerImage && set && placeProvider != null && placeProvider.scaleToFill() && !ignoreDidSetImage && sendPhotoType != SELECT_TYPE_AVATAR) {
if (!wasLayout) {
dontResetZoomOnFirstLayout = true;
} else {
setScaleToFill();
}
}
};
centerImage.setParentView(containerView);
centerImage.setCrossfadeAlpha((byte) 2);
centerImage.setInvalidateAll(true);
centerImage.setDelegate(imageReceiverDelegate);
leftImage.setParentView(containerView);
leftImage.setCrossfadeAlpha((byte) 2);
leftImage.setInvalidateAll(true);
leftImage.setDelegate(imageReceiverDelegate);
rightImage.setParentView(containerView);
rightImage.setCrossfadeAlpha((byte) 2);
rightImage.setInvalidateAll(true);
rightImage.setDelegate(imageReceiverDelegate);
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();
checkImageView = new CheckBox(containerView.getContext(), R.drawable.selectphoto_large) {
@Override
public boolean onTouchEvent(MotionEvent event) {
return bottomTouchEnabled && super.onTouchEvent(event);
}
};
checkImageView.setDrawBackground(true);
checkImageView.setHasBorder(true);
checkImageView.setSize(34);
checkImageView.setCheckOffset(AndroidUtilities.dp(1));
checkImageView.setColor(getThemedColor(Theme.key_dialogFloatingButton), 0xffffffff);
checkImageView.setVisibility(View.GONE);
containerView.addView(checkImageView, LayoutHelper.createFrame(34, 34, Gravity.RIGHT | Gravity.TOP, 0, rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 61 : 71, 11, 0));
if (isStatusBarVisible()) {
((FrameLayout.LayoutParams) checkImageView.getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
}
checkImageView.setOnClickListener(v -> {
if (captionEditText.getTag() != null) {
return;
}
setPhotoChecked();
});
photosCounterView = new CounterView(parentActivity);
containerView.addView(photosCounterView, LayoutHelper.createFrame(40, 40, Gravity.RIGHT | Gravity.TOP, 0, rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68, 64, 0));
if (isStatusBarVisible()) {
((FrameLayout.LayoutParams) photosCounterView.getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
}
photosCounterView.setOnClickListener(v -> {
if (captionEditText.getTag() != null || placeProvider == null || placeProvider.getSelectedPhotosOrder() == null || placeProvider.getSelectedPhotosOrder().isEmpty()) {
return;
}
togglePhotosListView(!isPhotosListViewVisible, true);
});
selectedPhotosListView = new SelectedPhotosListView(parentActivity);
selectedPhotosListView.setVisibility(View.GONE);
selectedPhotosListView.setAlpha(0.0f);
selectedPhotosListView.setLayoutManager(new LinearLayoutManager(parentActivity, LinearLayoutManager.HORIZONTAL, true) {
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScrollerEnd linearSmoothScroller = new LinearSmoothScrollerEnd(recyclerView.getContext()) {
@Override
protected int calculateTimeForDeceleration(int dx) {
return Math.max(180, super.calculateTimeForDeceleration(dx));
}
};
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
});
selectedPhotosListView.setAdapter(selectedPhotosAdapter = new ListAdapter(parentActivity));
containerView.addView(selectedPhotosListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 103, Gravity.LEFT | Gravity.TOP));
selectedPhotosListView.setOnItemClickListener((view, position) -> {
if (!imagesArrLocals.isEmpty() && currentIndex >= 0 && currentIndex < imagesArrLocals.size()) {
Object entry = imagesArrLocals.get(currentIndex);
if (entry instanceof MediaController.MediaEditState) {
((MediaController.MediaEditState) entry).editedInfo = getCurrentVideoEditedInfo();
}
}
ignoreDidSetImage = true;
int idx = imagesArrLocals.indexOf(view.getTag());
if (idx >= 0) {
currentIndex = -1;
setImageIndex(idx);
}
ignoreDidSetImage = false;
});
captionEditText = new PhotoViewerCaptionEnterView(activityContext, containerView, windowView, resourcesProvider) {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
try {
return !bottomTouchEnabled && super.dispatchTouchEvent(ev);
} catch (Exception e) {
FileLog.e(e);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return !bottomTouchEnabled && super.onInterceptTouchEvent(ev);
} catch (Exception e) {
FileLog.e(e);
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (bottomTouchEnabled && event.getAction() == MotionEvent.ACTION_DOWN) {
keyboardAnimationEnabled = true;
}
return !bottomTouchEnabled && super.onTouchEvent(event);
}
@Override
protected void extendActionMode(ActionMode actionMode, Menu menu) {
if (parentChatActivity != null) {
parentChatActivity.extendActionMode(menu);
}
}
};
captionEditText.setDelegate(new PhotoViewerCaptionEnterView.PhotoViewerCaptionEnterViewDelegate() {
@Override
public void onCaptionEnter() {
closeCaptionEnter(true);
}
@Override
public void onTextChanged(CharSequence text) {
if (mentionsAdapter != null && captionEditText != null && parentChatActivity != null && text != null) {
mentionsAdapter.searchUsernameOrHashtag(text.toString(), captionEditText.getCursorPosition(), parentChatActivity.messages, false, false);
}
int color = getThemedColor(Theme.key_dialogFloatingIcon);
if (captionEditText.getCaptionLimitOffset() < 0) {
captionLimitView.setText(Integer.toString(captionEditText.getCaptionLimitOffset()));
captionLimitView.setVisibility(pickerViewSendButton.getVisibility());
pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(ColorUtils.setAlphaComponent(color, (int) (Color.alpha(color) * 0.58f)), PorterDuff.Mode.MULTIPLY));
} else {
pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
captionLimitView.setVisibility(View.GONE);
}
if (placeProvider != null) {
placeProvider.onCaptionChanged(text);
}
}
@Override
public void onWindowSizeChanged(int size) {
int height = AndroidUtilities.dp(36 * Math.min(3, mentionsAdapter.getItemCount()) + (mentionsAdapter.getItemCount() > 3 ? 18 : 0));
if (size - ActionBar.getCurrentActionBarHeight() * 2 < height) {
allowMentions = false;
if (mentionListView != null && mentionListView.getVisibility() == View.VISIBLE) {
mentionListView.setVisibility(View.INVISIBLE);
}
} else {
allowMentions = true;
if (mentionListView != null && mentionListView.getVisibility() == View.INVISIBLE) {
mentionListView.setVisibility(View.VISIBLE);
}
}
}
@Override
public void onEmojiViewCloseStart() {
setOffset(captionEditText.getEmojiPadding());
if (captionEditText.getTag() != null) {
if (isCurrentVideo) {
actionBar.setTitleAnimated(muteVideo ? LocaleController.getString("GifCaption", R.string.GifCaption) : LocaleController.getString("VideoCaption", R.string.VideoCaption), true, 220);
} else {
actionBar.setTitleAnimated(LocaleController.getString("PhotoCaption", R.string.PhotoCaption), true, 220);
}
checkImageView.animate().alpha(0f).setDuration(220).start();
photosCounterView.animate().alpha(0f).setDuration(220).start();
selectedPhotosListView.animate().alpha(0.0f).translationY(-AndroidUtilities.dp(10)).setDuration(220).start();
} else {
checkImageView.animate().alpha(1f).setDuration(220).start();
photosCounterView.animate().alpha(1f).setDuration(220).start();
if (lastTitle != null) {
actionBar.setTitleAnimated(lastTitle, false, 220);
lastTitle = null;
}
}
}
@Override
public void onEmojiViewCloseEnd() {
setOffset(0);
captionEditText.setVisibility(View.GONE);
}
private void setOffset(int offset) {
for (int i = 0; i < containerView.getChildCount(); i++) {
View child = containerView.getChildAt(i);
if (child == cameraItem || child == muteItem || child == pickerView || child == videoTimelineView || child == pickerViewSendButton || child == captionTextViewSwitcher || muteItem.getVisibility() == View.VISIBLE && child == bottomLayout) {
child.setTranslationY(offset);
}
}
}
});
if (Build.VERSION.SDK_INT >= 19) {
captionEditText.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
captionEditText.setVisibility(View.GONE);
containerView.addView(captionEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT));
mentionListView = new RecyclerListView(activityContext, resourcesProvider) {
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
return !bottomTouchEnabled && super.dispatchTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return !bottomTouchEnabled && super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return !bottomTouchEnabled && super.onTouchEvent(event);
}
};
mentionListView.setTag(5);
mentionLayoutManager = new LinearLayoutManager(activityContext) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
};
mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mentionListView.setLayoutManager(mentionLayoutManager);
mentionListView.setBackgroundColor(0x7f000000);
mentionListView.setVisibility(View.GONE);
mentionListView.setClipToPadding(true);
mentionListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
containerView.addView(mentionListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));
mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(activityContext, true, 0, 0, new MentionsAdapter.MentionsAdapterDelegate() {
@Override
public void needChangePanelVisibility(boolean show) {
if (show) {
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) mentionListView.getLayoutParams();
int height = 36 * Math.min(3, mentionsAdapter.getItemCount()) + (mentionsAdapter.getItemCount() > 3 ? 18 : 0);
layoutParams3.height = AndroidUtilities.dp(height);
layoutParams3.topMargin = -AndroidUtilities.dp(height);
mentionListView.setLayoutParams(layoutParams3);
if (mentionListAnimation != null) {
mentionListAnimation.cancel();
mentionListAnimation = null;
}
if (mentionListView.getVisibility() == View.VISIBLE) {
mentionListView.setAlpha(1.0f);
return;
} else {
mentionLayoutManager.scrollToPositionWithOffset(0, 10000);
}
if (allowMentions) {
mentionListView.setVisibility(View.VISIBLE);
mentionListAnimation = new AnimatorSet();
mentionListAnimation.playTogether(ObjectAnimator.ofFloat(mentionListView, View.ALPHA, 0.0f, 1.0f));
mentionListAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
mentionListAnimation = null;
}
}
});
mentionListAnimation.setDuration(200);
mentionListAnimation.start();
} else {
mentionListView.setAlpha(1.0f);
mentionListView.setVisibility(View.INVISIBLE);
}
} else {
if (mentionListAnimation != null) {
mentionListAnimation.cancel();
mentionListAnimation = null;
}
if (mentionListView.getVisibility() == View.GONE) {
return;
}
if (allowMentions) {
mentionListAnimation = new AnimatorSet();
mentionListAnimation.playTogether(ObjectAnimator.ofFloat(mentionListView, View.ALPHA, 0.0f));
mentionListAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
mentionListView.setVisibility(View.GONE);
mentionListAnimation = null;
}
}
});
mentionListAnimation.setDuration(200);
mentionListAnimation.start();
} else {
mentionListView.setVisibility(View.GONE);
}
}
}
@Override
public void onContextSearch(boolean searching) {
}
@Override
public void onContextClick(TLRPC.BotInlineResult result) {
}
}, resourcesProvider));
mentionListView.setOnItemClickListener((view, position) -> {
Object object = mentionsAdapter.getItem(position);
int start = mentionsAdapter.getResultStartPosition();
int len = mentionsAdapter.getResultLength();
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
if (user.username != null) {
captionEditText.replaceWithText(start, len, "@" + user.username + " ", false);
} else {
String name = UserObject.getFirstName(user);
Spannable spannable = new SpannableString(name + " ");
spannable.setSpan(new URLSpanUserMentionPhotoViewer("" + user.id, true), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
captionEditText.replaceWithText(start, len, spannable, false);
}
} else if (object instanceof String) {
captionEditText.replaceWithText(start, len, object + " ", false);
} else if (object instanceof MediaDataController.KeywordResult) {
String code = ((MediaDataController.KeywordResult) object).emoji;
captionEditText.addEmojiToRecent(code);
captionEditText.replaceWithText(start, len, code, true);
}
});
mentionListView.setOnItemLongClickListener((view, position) -> {
Object object = mentionsAdapter.getItem(position);
if (object instanceof String) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> mentionsAdapter.clearRecentHashtags());
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
return true;
}
return false;
});
hintView = new UndoView(activityContext, null, false, resourcesProvider);
hintView.setAdditionalTranslationY(AndroidUtilities.dp(112));
hintView.setColors(0xf9222222, 0xffffffff);
containerView.addView(hintView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
AccessibilityManager am = (AccessibilityManager) activityContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
if (am.isEnabled()) {
playButtonAccessibilityOverlay = new View(activityContext);
playButtonAccessibilityOverlay.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
playButtonAccessibilityOverlay.setFocusable(true);
containerView.addView(playButtonAccessibilityOverlay, LayoutHelper.createFrame(64, 64, Gravity.CENTER));
}
}
use of org.telegram.ui.Components.VideoEditTextureView in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method checkFullscreenButton.
private void checkFullscreenButton() {
if (imagesArr.isEmpty()) {
for (int b = 0; b < 3; b++) {
fullscreenButton[b].setVisibility(View.INVISIBLE);
}
return;
}
for (int b = 0; b < 3; b++) {
int index = currentIndex;
if (b == 1) {
index += 1;
} else if (b == 2) {
index -= 1;
}
if (index < 0 || index >= imagesArr.size()) {
fullscreenButton[b].setVisibility(View.INVISIBLE);
continue;
}
MessageObject messageObject = imagesArr.get(index);
if (!messageObject.isVideo()) {
fullscreenButton[b].setVisibility(View.INVISIBLE);
continue;
}
int w = b == 0 && videoTextureView != null ? videoTextureView.getMeasuredWidth() : 0;
int h = b == 0 && videoTextureView != null ? videoTextureView.getMeasuredHeight() : 0;
TLRPC.Document document = messageObject.getDocument();
for (int a = 0, N = document.attributes.size(); a < N; a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
w = attribute.w;
h = attribute.h;
break;
}
}
if (AndroidUtilities.displaySize.y > AndroidUtilities.displaySize.x && !(videoTextureView instanceof VideoEditTextureView) && w > h) {
if (fullscreenButton[b].getVisibility() != View.VISIBLE) {
fullscreenButton[b].setVisibility(View.VISIBLE);
}
float scale = w / (float) containerView.getMeasuredWidth();
int height = (int) (h / scale);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fullscreenButton[b].getLayoutParams();
layoutParams.topMargin = (containerView.getMeasuredHeight() + height) / 2 - AndroidUtilities.dp(48);
} else {
if (fullscreenButton[b].getVisibility() != View.INVISIBLE) {
fullscreenButton[b].setVisibility(View.INVISIBLE);
}
}
float currentTranslationX;
if (imageMoveAnimation != null) {
currentTranslationX = translationX + (animateToX - translationX) * animationValue;
} else {
currentTranslationX = translationX;
}
float offsetX;
if (b == 1) {
offsetX = 0;
} else if (b == 2) {
offsetX = -AndroidUtilities.displaySize.x - AndroidUtilities.dp(15) + (currentTranslationX - maxX);
} else {
offsetX = currentTranslationX < minX ? (currentTranslationX - minX) : 0;
}
fullscreenButton[b].setTranslationX(offsetX + AndroidUtilities.displaySize.x - AndroidUtilities.dp(48));
}
}
use of org.telegram.ui.Components.VideoEditTextureView in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method createVideoTextureView.
private void createVideoTextureView(MediaController.SavedFilterState savedFilterState) {
if (videoTextureView != null) {
return;
}
aspectRatioFrameLayout = new AspectRatioFrameLayout(parentActivity) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (textureImageView != null) {
ViewGroup.LayoutParams layoutParams = textureImageView.getLayoutParams();
layoutParams.width = getMeasuredWidth();
layoutParams.height = getMeasuredHeight();
}
if (videoTextureView instanceof VideoEditTextureView) {
videoTextureView.setPivotX(videoTextureView.getMeasuredWidth() / 2);
firstFrameView.setPivotX(videoTextureView.getMeasuredWidth() / 2);
} else {
videoTextureView.setPivotX(0);
firstFrameView.setPivotX(0);
}
checkFullscreenButton();
}
};
aspectRatioFrameLayout.setWillNotDraw(false);
aspectRatioFrameLayout.setVisibility(View.INVISIBLE);
containerView.addView(aspectRatioFrameLayout, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
if (imagesArrLocals.isEmpty()) {
videoTextureView = new TextureView(parentActivity);
} else {
VideoEditTextureView videoEditTextureView = new VideoEditTextureView(parentActivity, videoPlayer);
if (savedFilterState != null) {
videoEditTextureView.setDelegate(thread -> thread.setFilterGLThreadDelegate(FilterShaders.getFilterShadersDelegate(savedFilterState)));
}
videoTextureView = videoEditTextureView;
}
if (injectingVideoPlayerSurface != null) {
videoTextureView.setSurfaceTexture(injectingVideoPlayerSurface);
textureUploaded = true;
videoSizeSet = true;
injectingVideoPlayerSurface = null;
}
videoTextureView.setPivotX(0);
videoTextureView.setPivotY(0);
videoTextureView.setOpaque(false);
aspectRatioFrameLayout.addView(videoTextureView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
firstFrameView = new ImageView(parentActivity);
firstFrameView.setPivotX(0);
firstFrameView.setPivotY(0);
firstFrameView.setScaleType(ImageView.ScaleType.FIT_XY);
aspectRatioFrameLayout.addView(firstFrameView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
if (sendPhotoType == SELECT_TYPE_AVATAR) {
flashView = new View(parentActivity);
flashView.setBackgroundColor(0xffffffff);
flashView.setAlpha(0.0f);
aspectRatioFrameLayout.addView(flashView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
}
}
use of org.telegram.ui.Components.VideoEditTextureView in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method preparePlayer.
private void preparePlayer(Uri uri, boolean playWhenReady, boolean preview, MediaController.SavedFilterState savedFilterState) {
if (!preview) {
currentPlayingVideoFile = uri;
}
if (parentActivity == null) {
return;
}
streamingAlertShown = false;
startedPlayTime = SystemClock.elapsedRealtime();
currentVideoFinishedLoading = false;
lastBufferedPositionCheck = 0;
firstAnimationDelay = true;
inPreview = preview;
releasePlayer(false);
if (imagesArrLocals.isEmpty()) {
createVideoTextureView(null);
}
if (Build.VERSION.SDK_INT >= 21 && textureImageView == null) {
textureImageView = new ImageView(parentActivity);
textureImageView.setBackgroundColor(0xffff0000);
textureImageView.setPivotX(0);
textureImageView.setPivotY(0);
textureImageView.setVisibility(View.INVISIBLE);
containerView.addView(textureImageView);
}
checkFullscreenButton();
if (orientationEventListener == null) {
orientationEventListener = new OrientationEventListener(ApplicationLoader.applicationContext) {
@Override
public void onOrientationChanged(int orientation) {
if (orientationEventListener == null || aspectRatioFrameLayout == null || aspectRatioFrameLayout.getVisibility() != View.VISIBLE) {
return;
}
if (parentActivity != null && fullscreenedByButton != 0) {
if (fullscreenedByButton == 1) {
if (orientation >= 270 - 30 && orientation <= 270 + 30) {
wasRotated = true;
} else if (wasRotated && orientation > 0 && (orientation >= 330 || orientation <= 30)) {
parentActivity.setRequestedOrientation(prevOrientation);
fullscreenedByButton = 0;
wasRotated = false;
}
} else {
if (orientation > 0 && (orientation >= 330 || orientation <= 30)) {
wasRotated = true;
} else if (wasRotated && orientation >= 270 - 30 && orientation <= 270 + 30) {
parentActivity.setRequestedOrientation(prevOrientation);
fullscreenedByButton = 0;
wasRotated = false;
}
}
}
}
};
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
} else {
orientationEventListener.disable();
orientationEventListener = null;
}
}
textureUploaded = false;
videoSizeSet = false;
videoCrossfadeStarted = false;
boolean newPlayerCreated = false;
playerWasReady = false;
playerWasPlaying = false;
captureFrameReadyAtTime = -1;
captureFrameAtTime = -1;
needCaptureFrameReadyAtTime = -1;
if (videoPlayer == null) {
if (injectingVideoPlayer != null) {
videoPlayer = injectingVideoPlayer;
injectingVideoPlayer = null;
playerInjected = true;
updatePlayerState(videoPlayer.getPlayWhenReady(), videoPlayer.getPlaybackState());
} else {
videoPlayer = new VideoPlayer() {
@Override
public void play() {
super.play();
playOrStopAnimatedStickers(true);
}
@Override
public void pause() {
super.pause();
if (currentEditMode == 0) {
playOrStopAnimatedStickers(false);
}
}
@Override
public void seekTo(long positionMs) {
super.seekTo(positionMs);
if (isCurrentVideo) {
seekAnimatedStickersTo(positionMs);
}
}
};
newPlayerCreated = true;
}
if (videoTextureView != null) {
videoPlayer.setTextureView(videoTextureView);
}
firstFrameSet = false;
videoPlayer.setDelegate(new VideoPlayer.VideoPlayerDelegate() {
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
updatePlayerState(playWhenReady, playbackState);
}
@Override
public void onError(VideoPlayer player, Exception e) {
if (videoPlayer != player) {
return;
}
FileLog.e(e);
if (!menuItem.isSubItemVisible(gallery_menu_openin)) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("CantPlayVideo", R.string.CantPlayVideo));
builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), (dialog, which) -> {
try {
AndroidUtilities.openForView(currentMessageObject, parentActivity, resourcesProvider);
closePhoto(false, false);
} catch (Exception e1) {
FileLog.e(e1);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showAlertDialog(builder);
}
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
if (aspectRatioFrameLayout != null) {
if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
int temp = width;
width = height;
height = temp;
}
aspectRatioFrameLayout.setAspectRatio(height == 0 ? 1 : (width * pixelWidthHeightRatio) / height, unappliedRotationDegrees);
if (videoTextureView instanceof VideoEditTextureView) {
((VideoEditTextureView) videoTextureView).setVideoSize((int) (width * pixelWidthHeightRatio), height);
if (sendPhotoType == SELECT_TYPE_AVATAR) {
setCropBitmap();
}
}
videoSizeSet = true;
}
}
@Override
public void onRenderedFirstFrame() {
if (!textureUploaded) {
textureUploaded = true;
containerView.invalidate();
}
if (videoTextureView != null && !firstFrameSet && videoPlayer.getCurrentPosition() <= 60) {
firstFrameView.setImageBitmap(videoTextureView.getBitmap());
firstFrameSet = true;
}
}
@Override
public void onRenderedFirstFrame(AnalyticsListener.EventTime eventTime) {
if (eventTime.eventPlaybackPositionMs == needCaptureFrameReadyAtTime) {
captureFrameReadyAtTime = eventTime.eventPlaybackPositionMs;
needCaptureFrameReadyAtTime = -1;
captureCurrentFrame();
}
}
@Override
public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
if (changingTextureView) {
changingTextureView = false;
if (isInline) {
waitingForFirstTextureUpload = 1;
changedTextureView.setSurfaceTexture(surfaceTexture);
changedTextureView.setSurfaceTextureListener(surfaceTextureListener);
changedTextureView.setVisibility(View.VISIBLE);
return true;
}
}
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
if (waitingForFirstTextureUpload == 2) {
if (textureImageView != null) {
textureImageView.setVisibility(View.INVISIBLE);
textureImageView.setImageDrawable(null);
if (currentBitmap != null) {
currentBitmap.recycle();
currentBitmap = null;
}
}
switchingInlineMode = false;
if (Build.VERSION.SDK_INT >= 21) {
aspectRatioFrameLayout.getLocationInWindow(pipPosition);
// pipPosition[0] -= getLeftInset();
pipPosition[1] -= containerView.getTranslationY();
textureImageView.setTranslationX(textureImageView.getTranslationX() + getLeftInset());
videoTextureView.setTranslationX(videoTextureView.getTranslationX() + getLeftInset() - aspectRatioFrameLayout.getX());
if (firstFrameView != null) {
firstFrameView.setTranslationX(videoTextureView.getTranslationX());
}
AnimatorSet animatorSet = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(textureImageView, View.SCALE_X, 1.0f));
animators.add(ObjectAnimator.ofFloat(textureImageView, View.SCALE_Y, 1.0f));
animators.add(ObjectAnimator.ofFloat(textureImageView, View.TRANSLATION_X, pipPosition[0]));
animators.add(ObjectAnimator.ofFloat(textureImageView, View.TRANSLATION_Y, pipPosition[1]));
animators.add(ObjectAnimator.ofFloat(videoTextureView, View.SCALE_X, 1.0f));
animators.add(ObjectAnimator.ofFloat(videoTextureView, View.SCALE_Y, 1.0f));
animators.add(ObjectAnimator.ofFloat(videoTextureView, View.TRANSLATION_X, pipPosition[0] - aspectRatioFrameLayout.getX()));
animators.add(ObjectAnimator.ofFloat(videoTextureView, View.TRANSLATION_Y, pipPosition[1] - aspectRatioFrameLayout.getY()));
animators.add(ObjectAnimator.ofInt(backgroundDrawable, AnimationProperties.COLOR_DRAWABLE_ALPHA, 255));
if (firstFrameView != null) {
animators.add(ObjectAnimator.ofFloat(firstFrameView, View.SCALE_X, 1.0f));
animators.add(ObjectAnimator.ofFloat(firstFrameView, View.SCALE_Y, 1.0f));
animators.add(ObjectAnimator.ofFloat(firstFrameView, View.TRANSLATION_X, pipPosition[0] - aspectRatioFrameLayout.getX()));
animators.add(ObjectAnimator.ofFloat(firstFrameView, View.TRANSLATION_Y, pipPosition[1] - aspectRatioFrameLayout.getY()));
}
animatorSet.playTogether(animators);
final DecelerateInterpolator interpolator = new DecelerateInterpolator();
animatorSet.setInterpolator(interpolator);
animatorSet.setDuration(250);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
pipAnimationInProgress = false;
}
});
animatorSet.start();
toggleActionBar(true, true, new ActionBarToggleParams().enableStatusBarAnimation(false).enableTranslationAnimation(false).animationDuration(250).animationInterpolator(interpolator));
} else {
toggleActionBar(true, false);
// containerView.setTranslationY(0);
}
waitingForFirstTextureUpload = 0;
}
}
});
}
if (!imagesArrLocals.isEmpty()) {
createVideoTextureView(savedFilterState);
}
videoTextureView.setAlpha(videoCrossfadeAlpha = 0.0f);
if (paintingOverlay != null) {
paintingOverlay.setAlpha(videoCrossfadeAlpha);
}
shouldSavePositionForCurrentVideo = null;
shouldSavePositionForCurrentVideoShortTerm = null;
lastSaveTime = 0;
if (newPlayerCreated) {
seekToProgressPending = seekToProgressPending2;
videoPlayerSeekbar.setProgress(0);
videoTimelineView.setProgress(0);
videoPlayerSeekbar.setBufferedProgress(0);
if (currentMessageObject != null) {
final int duration = currentMessageObject.getDuration();
final String name = currentMessageObject.getFileName();
if (!TextUtils.isEmpty(name)) {
if (duration >= 10 * 60) {
if (currentMessageObject.forceSeekTo < 0) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("media_saved_pos", Activity.MODE_PRIVATE);
float pos = preferences.getFloat(name, -1);
if (pos > 0 && pos < 0.999f) {
currentMessageObject.forceSeekTo = pos;
videoPlayerSeekbar.setProgress(pos);
}
}
shouldSavePositionForCurrentVideo = name;
} else if (duration >= 10) {
SavedVideoPosition videoPosition = null;
for (int i = savedVideoPositions.size() - 1; i >= 0; i--) {
final SavedVideoPosition item = savedVideoPositions.valueAt(i);
if (item.timestamp < SystemClock.elapsedRealtime() - 5 * 1000) {
savedVideoPositions.removeAt(i);
} else if (videoPosition == null && savedVideoPositions.keyAt(i).equals(name)) {
videoPosition = item;
}
}
if (currentMessageObject.forceSeekTo < 0 && videoPosition != null) {
float pos = videoPosition.position;
if (pos > 0 && pos < 0.999f) {
currentMessageObject.forceSeekTo = pos;
videoPlayerSeekbar.setProgress(pos);
}
}
shouldSavePositionForCurrentVideoShortTerm = name;
}
}
}
videoPlayer.preparePlayer(uri, "other");
videoPlayer.setPlayWhenReady(playWhenReady);
}
playerLooping = currentMessageObject != null && currentMessageObject.getDuration() <= 30;
videoPlayerControlFrameLayout.setSeekBarTransitionEnabled(playerLooping);
videoPlayer.setLooping(playerLooping);
if (currentMessageObject != null && currentMessageObject.forceSeekTo >= 0) {
seekToProgressPending = currentMessageObject.forceSeekTo;
currentMessageObject.forceSeekTo = -1;
}
if (currentBotInlineResult != null && (currentBotInlineResult.type.equals("video") || MessageObject.isVideoDocument(currentBotInlineResult.document))) {
bottomLayout.setVisibility(View.VISIBLE);
bottomLayout.setPadding(0, 0, AndroidUtilities.dp(84), 0);
pickerView.setVisibility(View.GONE);
} else {
bottomLayout.setPadding(0, 0, 0, 0);
}
if (pageBlocksAdapter != null) {
bottomLayout.setVisibility(View.VISIBLE);
}
setVideoPlayerControlVisible(!isCurrentVideo, true);
if (!isCurrentVideo) {
scheduleActionBarHide(playerAutoStarted ? 3000 : 1000);
}
if (currentMessageObject != null) {
videoPlayer.setPlaybackSpeed(currentVideoSpeed);
}
inPreview = preview;
}
use of org.telegram.ui.Components.VideoEditTextureView in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoViewer method onDraw.
@SuppressLint({ "NewApi", "DrawAllocation" })
private void onDraw(Canvas canvas) {
if (animationInProgress == 1 || animationInProgress == 3 || !isVisible && animationInProgress != 2 && !pipAnimationInProgress) {
return;
}
if (padImageForHorizontalInsets) {
canvas.save();
canvas.translate(getLeftInset() / 2 - getRightInset() / 2, 0);
}
float currentTranslationY;
float currentTranslationX;
float currentScale;
float aty = -1;
long newUpdateTime = System.currentTimeMillis();
long dt = newUpdateTime - videoCrossfadeAlphaLastTime;
if (dt > 20) {
dt = 17;
}
videoCrossfadeAlphaLastTime = newUpdateTime;
if (imageMoveAnimation != null) {
if (!scroller.isFinished()) {
scroller.abortAnimation();
}
float ts = scale + (animateToScale - scale) * animationValue;
float tx = translationX + (animateToX - translationX) * animationValue;
float ty = translationY + (animateToY - translationY) * animationValue;
if (animateToScale == 1 && scale == 1 && translationX == 0) {
aty = ty;
}
currentScale = ts;
currentTranslationY = ty;
currentTranslationX = tx;
updateMinMax(currentScale);
containerView.invalidate();
} else {
if (animationStartTime != 0) {
translationX = animateToX;
translationY = animateToY;
scale = animateToScale;
animationStartTime = 0;
updateMinMax(scale);
zoomAnimation = false;
}
if (!scroller.isFinished()) {
if (scroller.computeScrollOffset()) {
if (scroller.getStartX() < maxX && scroller.getStartX() > minX) {
translationX = scroller.getCurrX();
}
if (scroller.getStartY() < maxY && scroller.getStartY() > minY) {
translationY = scroller.getCurrY();
}
containerView.invalidate();
}
}
if (switchImageAfterAnimation != 0) {
openedFullScreenVideo = false;
if (!imagesArrLocals.isEmpty() && currentIndex >= 0 && currentIndex < imagesArrLocals.size()) {
Object object = imagesArrLocals.get(currentIndex);
if (object instanceof MediaController.MediaEditState) {
((MediaController.MediaEditState) object).editedInfo = getCurrentVideoEditedInfo();
}
}
if (switchImageAfterAnimation == 1) {
AndroidUtilities.runOnUIThread(() -> switchToNextIndex(1, false));
} else if (switchImageAfterAnimation == 2) {
AndroidUtilities.runOnUIThread(() -> switchToNextIndex(-1, false));
}
switchImageAfterAnimation = 0;
}
currentScale = scale;
currentTranslationY = translationY;
currentTranslationX = translationX;
if (!moving) {
aty = translationY;
}
}
if (photoViewerWebView != null) {
photoViewerWebView.setTranslationY(currentTranslationY);
}
if (isActionBarVisible) {
if (currentScale <= 1.0001f) {
if (!allowShowFullscreenButton && fullscreenButton[0].getTag() == null) {
fullscreenButton[0].animate().alpha(1.0f).setDuration(120).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
fullscreenButton[0].setTag(null);
}
}).start();
fullscreenButton[0].setTag(1);
allowShowFullscreenButton = true;
}
} else {
if (allowShowFullscreenButton) {
fullscreenButton[0].animate().alpha(0.0f).setDuration(120).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
fullscreenButton[0].setTag(null);
}
}).start();
fullscreenButton[0].setTag(1);
allowShowFullscreenButton = false;
}
}
}
int containerWidth = getContainerViewWidth();
int containerHeight = getContainerViewHeight();
if (animationInProgress != 2 && animationInProgress != 4 && !pipAnimationInProgress && !isInline) {
if (currentEditMode == 0 && sendPhotoType != SELECT_TYPE_AVATAR && scale == 1 && aty != -1 && !zoomAnimation) {
float maxValue = containerWidth / 4.0f;
backgroundDrawable.setAlpha((int) Math.max(127, 255 * (1.0f - (Math.min(Math.abs(aty), maxValue) / maxValue))));
} else {
backgroundDrawable.setAlpha(255);
}
} else if (animationInProgress == 4) {
canvas.drawColor(0xff000000);
}
sideImage = null;
if (currentEditMode == 0 && sendPhotoType != SELECT_TYPE_AVATAR) {
if (scale >= 1.0f && !zoomAnimation && !zooming) {
if (currentTranslationX > maxX + AndroidUtilities.dp(5)) {
sideImage = leftImage;
} else if (currentTranslationX < minX - AndroidUtilities.dp(5)) {
sideImage = rightImage;
} else {
groupedPhotosListView.setMoveProgress(0.0f);
}
}
changingPage = sideImage != null;
}
for (int a = 0; a < 3; a++) {
float offsetX;
if (a == 1) {
offsetX = 0;
} else if (a == 2) {
offsetX = -containerView.getMeasuredWidth() - AndroidUtilities.dp(15) + (currentTranslationX - maxX);
} else {
offsetX = currentTranslationX < minX ? (currentTranslationX - minX) : 0;
}
fullscreenButton[a].setTranslationX(offsetX + containerView.getMeasuredWidth() - AndroidUtilities.dp(48));
}
if (sideImage == rightImage) {
float translateX = currentTranslationX;
float scaleDiff = 0;
float alpha = 1;
if (!zoomAnimation && translateX < minX) {
alpha = Math.min(1.0f, (minX - translateX) / containerWidth);
scaleDiff = (1.0f - alpha) * 0.3f;
translateX = -containerWidth - AndroidUtilities.dp(30) / 2;
}
if (sideImage.hasBitmapImage()) {
canvas.save();
canvas.translate(containerWidth / 2, containerHeight / 2);
canvas.translate(containerWidth + AndroidUtilities.dp(30) / 2 + translateX, 0);
canvas.scale(1.0f - scaleDiff, 1.0f - scaleDiff);
int bitmapWidth = sideImage.getBitmapWidth();
int bitmapHeight = sideImage.getBitmapHeight();
float scaleX = containerWidth / (float) bitmapWidth;
float scaleY = containerHeight / (float) bitmapHeight;
float scale = Math.min(scaleX, scaleY);
int width = (int) (bitmapWidth * scale);
int height = (int) (bitmapHeight * scale);
sideImage.setAlpha(alpha);
sideImage.setImageCoords(-width / 2, -height / 2, width, height);
sideImage.draw(canvas);
canvas.restore();
}
groupedPhotosListView.setMoveProgress(-alpha);
canvas.save();
canvas.translate(translateX, currentTranslationY / currentScale);
canvas.translate((containerWidth * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale);
photoProgressViews[1].setScale(1.0f - scaleDiff);
photoProgressViews[1].setAlpha(alpha);
photoProgressViews[1].onDraw(canvas);
if (isActionBarVisible) {
fullscreenButton[1].setAlpha(alpha);
}
canvas.restore();
} else {
if (isActionBarVisible) {
fullscreenButton[1].setAlpha(0.0f);
}
}
float translateX = currentTranslationX;
float scaleDiff = 0;
float alpha = 1;
if (!zoomAnimation && translateX > maxX && currentEditMode == 0 && sendPhotoType != SELECT_TYPE_AVATAR) {
alpha = Math.min(1.0f, (translateX - maxX) / containerWidth);
scaleDiff = alpha * 0.3f;
alpha = 1.0f - alpha;
translateX = maxX;
}
boolean drawTextureView = videoSizeSet && aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == View.VISIBLE;
if (centerImage.hasBitmapImage() || drawTextureView && textureUploaded) {
canvas.save();
canvas.translate(containerWidth / 2 + getAdditionX(), containerHeight / 2 + getAdditionY());
canvas.translate(translateX, currentTranslationY + (currentEditMode != 3 ? currentPanTranslationY : currentPanTranslationY / 2));
canvas.scale(currentScale - scaleDiff, currentScale - scaleDiff);
if (currentEditMode == 3 && keyboardSize > AndroidUtilities.dp(20)) {
int trueH = getContainerViewHeight(true, 0);
int h = getContainerViewHeight(false, 0);
if (trueH != h) {
canvas.translate(0, (trueH - h) / 2);
}
}
boolean drawCenterImage = false;
if (!pipAnimationInProgress && (!drawTextureView || !textureUploaded && !videoSizeSet || !videoCrossfadeStarted || videoCrossfadeAlpha != 1.0f)) {
if (videoFrameBitmap != null && isCurrentVideo) {
int w = videoFrameBitmap.getWidth(), h = videoFrameBitmap.getHeight(), l = -w / 2, t = -h / 2;
if (alpha < 1f) {
canvas.saveLayerAlpha(l, t, l + w, t + h, (int) (255 * alpha), Canvas.ALL_SAVE_FLAG);
}
canvas.drawBitmap(videoFrameBitmap, l, t, videoFrameBitmapPaint);
if (alpha < 1f) {
canvas.restore();
}
} else {
centerImage.setAlpha(alpha);
int width = centerImage.getBitmapWidth();
int height = centerImage.getBitmapHeight();
float scale;
if (isCurrentVideo && currentEditMode == 0 && sendPhotoType == SELECT_TYPE_AVATAR) {
scale = getCropFillScale(false);
} else {
scale = Math.min(containerWidth / (float) width, containerHeight / (float) height);
}
width *= scale;
height *= scale;
centerImage.setImageCoords(-width / 2, -height / 2, width, height);
if (isCurrentVideo) {
centerImage.draw(canvas);
} else {
drawCenterImage = true;
}
}
}
int bitmapWidth, originalWidth;
int bitmapHeight, originalHeight;
if (drawTextureView && textureUploaded && videoSizeSet) {
originalWidth = bitmapWidth = videoTextureView.getMeasuredWidth();
originalHeight = bitmapHeight = videoTextureView.getMeasuredHeight();
} else {
originalWidth = bitmapWidth = centerImage.getBitmapWidth();
originalHeight = bitmapHeight = centerImage.getBitmapHeight();
}
float scale = Math.min(containerWidth / (float) originalWidth, containerHeight / (float) originalHeight);
int width = (int) (originalWidth * scale);
int height = (int) (originalHeight * scale);
boolean applyCrop;
float scaleToFitX = 1.0f;
if (!imagesArrLocals.isEmpty()) {
if (currentEditMode == 3 || switchingToMode == 3) {
applyCrop = true;
} else if (sendPhotoType == SELECT_TYPE_AVATAR) {
applyCrop = (switchingToMode == 0 || currentEditMode != 3 && currentEditMode != 2);
} else {
applyCrop = imageMoveAnimation != null && switchingToMode != -1 || currentEditMode == 0 || currentEditMode == 1 || switchingToMode != -1;
}
} else {
applyCrop = false;
}
if (applyCrop) {
int rotatedWidth = originalWidth;
int rotatedHeight = originalHeight;
int orientation = cropTransform.getOrientation();
if (orientation == 90 || orientation == 270) {
int temp = bitmapWidth;
bitmapWidth = bitmapHeight;
bitmapHeight = temp;
temp = rotatedWidth;
rotatedWidth = rotatedHeight;
rotatedHeight = temp;
}
float cropAnimationValue;
if (sendPhotoType != SELECT_TYPE_AVATAR && (currentEditMode == 3 || switchingToMode == 3)) {
cropAnimationValue = 1.0f;
} else if (imageMoveAnimation != null && switchingToMode != -1) {
if (currentEditMode == 1 || switchingToMode == 1 || (currentEditMode == 2 || currentEditMode == 3) && switchingToMode == -1) {
cropAnimationValue = 1.0f;
} else if (switchingToMode == 0) {
cropAnimationValue = animationValue;
} else {
cropAnimationValue = 1.0f - animationValue;
}
} else {
cropAnimationValue = currentEditMode == 2 || currentEditMode == 3 ? 0.0f : 1.0f;
}
float cropPw = cropTransform.getCropPw();
float cropPh = cropTransform.getCropPh();
bitmapWidth *= cropPw + (1.0f - cropPw) * (1.0f - cropAnimationValue);
bitmapHeight *= cropPh + (1.0f - cropPh) * (1.0f - cropAnimationValue);
scaleToFitX = containerWidth / (float) bitmapWidth;
if (scaleToFitX * bitmapHeight > containerHeight) {
scaleToFitX = containerHeight / (float) bitmapHeight;
}
if (sendPhotoType != SELECT_TYPE_AVATAR && (currentEditMode != 1 || switchingToMode == 0) && editState.cropState != null) {
float startW = bitmapWidth * scaleToFitX;
float startH = bitmapHeight * scaleToFitX;
float originalScaleToFitX = containerWidth / (float) originalWidth;
if (originalScaleToFitX * originalHeight > containerHeight) {
originalScaleToFitX = containerHeight / (float) originalHeight;
}
float finalW = originalWidth * originalScaleToFitX / (currentScale - scaleDiff);
float finalH = originalHeight * originalScaleToFitX / (currentScale - scaleDiff);
float w = startW + (finalW - startW) * (1.0f - cropAnimationValue);
float h = startH + (finalH - startH) * (1.0f - cropAnimationValue);
canvas.clipRect(-w / 2, -h / 2, w / 2, h / 2);
}
if (sendPhotoType == SELECT_TYPE_AVATAR || cropTransform.hasViewTransform()) {
float cropScale;
if (currentEditMode == 1 || sendPhotoType == SELECT_TYPE_AVATAR) {
if (videoTextureView != null) {
videoTextureView.setScaleX(cropTransform.isMirrored() ? -1.0f : 1.0f);
if (firstFrameView != null) {
firstFrameView.setScaleX(videoTextureView.getScaleX());
}
}
float trueScale = 1.0f + (cropTransform.getTrueCropScale() - 1.0f) * (1.0f - cropAnimationValue);
cropScale = cropTransform.getScale() / trueScale;
float scaleToFit = containerWidth / (float) rotatedWidth;
if (scaleToFit * rotatedHeight > containerHeight) {
scaleToFit = containerHeight / (float) rotatedHeight;
}
cropScale *= scaleToFit / scale;
if (sendPhotoType == SELECT_TYPE_AVATAR) {
if (currentEditMode == 3 || switchingToMode == 3) {
cropScale /= 1.0f + (cropTransform.getMinScale() - 1.0f) * (1.0f - cropAnimationValue);
} else if (switchingToMode == 0) {
cropScale /= cropTransform.getMinScale();
}
}
} else {
if (videoTextureView != null) {
videoTextureView.setScaleX(editState.cropState != null && editState.cropState.mirrored ? -1.0f : 1.0f);
if (firstFrameView != null) {
firstFrameView.setScaleX(videoTextureView.getScaleX());
}
}
cropScale = editState.cropState != null ? editState.cropState.cropScale : 1.0f;
float trueScale = 1.0f + (cropScale - 1.0f) * (1.0f - cropAnimationValue);
cropScale *= scaleToFitX / scale / trueScale;
}
canvas.translate(cropTransform.getCropAreaX() * cropAnimationValue, cropTransform.getCropAreaY() * cropAnimationValue);
canvas.scale(cropScale, cropScale);
canvas.translate(cropTransform.getCropPx() * rotatedWidth * scale * cropAnimationValue, cropTransform.getCropPy() * rotatedHeight * scale * cropAnimationValue);
float rotation = (cropTransform.getRotation() + orientation);
if (rotation > 180) {
rotation -= 360;
}
if (sendPhotoType == SELECT_TYPE_AVATAR && (currentEditMode == 3 || switchingToMode == 3)) {
canvas.rotate(rotation);
} else {
canvas.rotate(rotation * cropAnimationValue);
}
} else {
if (videoTextureView != null) {
videoTextureView.setScaleX(1.0f);
videoTextureView.setScaleY(1.0f);
if (firstFrameView != null) {
firstFrameView.setScaleX(1);
firstFrameView.setScaleY(1);
}
}
}
}
if (currentEditMode == 3) {
float add = containerView.adjustPanLayoutHelper.animationInProgress() ? keyboardSize / 2f + currentPanTranslationY / 2 : 0;
photoPaintView.setTransform(currentScale, currentTranslationX, currentTranslationY + add, bitmapWidth * scaleToFitX, bitmapHeight * scaleToFitX);
}
if (drawCenterImage) {
boolean mirror = false;
if (!imagesArrLocals.isEmpty()) {
if (currentEditMode == 1 || sendPhotoType == SELECT_TYPE_AVATAR) {
mirror = cropTransform.isMirrored();
} else {
mirror = editState.cropState != null && editState.cropState.mirrored;
}
}
if (mirror) {
canvas.save();
canvas.scale(-1, 1);
}
if (photoViewerWebView == null || !photoViewerWebView.isLoaded()) {
centerImage.draw(canvas);
}
if (mirror) {
canvas.restore();
}
}
canvas.translate(-width / 2, -height / 2);
if (drawTextureView || paintingOverlay.getVisibility() == View.VISIBLE) {
canvas.scale(scale, scale);
}
if (drawTextureView) {
if (!videoCrossfadeStarted && textureUploaded && videoSizeSet) {
videoCrossfadeStarted = true;
videoCrossfadeAlpha = 0.0f;
videoCrossfadeAlphaLastTime = System.currentTimeMillis();
containerView.getMeasuredHeight();
}
videoTextureView.setAlpha(alpha * videoCrossfadeAlpha);
if (videoTextureView instanceof VideoEditTextureView) {
VideoEditTextureView videoEditTextureView = (VideoEditTextureView) videoTextureView;
videoEditTextureView.setViewRect((containerWidth - width) / 2 + getAdditionX() + translateX, (containerHeight - height) / 2 + getAdditionY() + currentTranslationY + currentPanTranslationY, width, height);
}
aspectRatioFrameLayout.draw(canvas);
if (videoCrossfadeStarted && videoCrossfadeAlpha < 1.0f) {
videoCrossfadeAlpha += dt / (playerInjected ? 100.0f : 200.0f);
containerView.invalidate();
if (videoCrossfadeAlpha > 1.0f) {
videoCrossfadeAlpha = 1.0f;
}
}
paintingOverlay.setAlpha(alpha);
}
if (paintingOverlay.getVisibility() == View.VISIBLE && (isCurrentVideo || currentEditMode != 2 || switchingToMode != -1)) {
canvas.clipRect(0, 0, paintingOverlay.getMeasuredWidth(), paintingOverlay.getMeasuredHeight());
paintingOverlay.draw(canvas);
}
canvas.restore();
for (int a = 0; a < pressedDrawable.length; a++) {
if (drawPressedDrawable[a] || pressedDrawableAlpha[a] != 0) {
pressedDrawable[a].setAlpha((int) (pressedDrawableAlpha[a] * 255));
if (a == 0) {
pressedDrawable[a].setBounds(0, 0, containerView.getMeasuredWidth() / 5, containerView.getMeasuredHeight());
} else {
pressedDrawable[a].setBounds(containerView.getMeasuredWidth() - containerView.getMeasuredWidth() / 5, 0, containerView.getMeasuredWidth(), containerView.getMeasuredHeight());
}
pressedDrawable[a].draw(canvas);
}
if (drawPressedDrawable[a]) {
if (pressedDrawableAlpha[a] < 1.0f) {
pressedDrawableAlpha[a] += dt / 180.0f;
if (pressedDrawableAlpha[a] > 1.0f) {
pressedDrawableAlpha[a] = 1.0f;
}
containerView.invalidate();
}
} else {
if (pressedDrawableAlpha[a] > 0.0f) {
pressedDrawableAlpha[a] -= dt / 180.0f;
if (pressedDrawableAlpha[a] < 0.0f) {
pressedDrawableAlpha[a] = 0.0f;
}
containerView.invalidate();
}
}
}
}
boolean drawProgress;
if (isCurrentVideo) {
drawProgress = (videoTimelineView == null || !videoTimelineView.isDragging()) && (sendPhotoType != SELECT_TYPE_AVATAR || manuallyPaused) && (videoPlayer == null || !videoPlayer.isPlaying());
} else {
drawProgress = true;
}
boolean drawMiniProgress = miniProgressView.getVisibility() == View.VISIBLE || miniProgressAnimator != null;
if (drawProgress) {
final float tx = !zoomAnimation && -translateX > maxX ? translateX + maxX : 0;
float ty = currentScale == 1.0f ? currentTranslationY : 0;
float progressAlpha = alpha;
if (drawMiniProgress) {
progressAlpha *= 1f - miniProgressView.getAlpha();
}
if (pipAnimationInProgress) {
progressAlpha *= actionBar.getAlpha();
} else if (photoProgressViews[0].backgroundState == PROGRESS_PAUSE) {
ty += AndroidUtilities.dpf2(8) * (1f - actionBar.getAlpha());
}
canvas.save();
canvas.translate(tx, ty);
photoProgressViews[0].setScale(1.0f - scaleDiff);
photoProgressViews[0].setAlpha(progressAlpha);
photoProgressViews[0].onDraw(canvas);
if (isActionBarVisible && allowShowFullscreenButton && fullscreenButton[0].getTag() == null) {
fullscreenButton[0].setAlpha(Math.min(fullscreenButton[0].getAlpha(), alpha));
}
canvas.restore();
}
if (drawMiniProgress && !pipAnimationInProgress) {
canvas.save();
canvas.translate(miniProgressView.getLeft() + translateX, miniProgressView.getTop() + currentTranslationY / currentScale);
miniProgressView.draw(canvas);
canvas.restore();
}
if (sideImage == leftImage) {
if (sideImage.hasBitmapImage()) {
canvas.save();
canvas.translate(containerWidth / 2, containerHeight / 2);
canvas.translate(-(containerWidth * (scale + 1) + AndroidUtilities.dp(30)) / 2 + currentTranslationX, 0);
int bitmapWidth = sideImage.getBitmapWidth();
int bitmapHeight = sideImage.getBitmapHeight();
float scaleX = containerWidth / (float) bitmapWidth;
float scaleY = containerHeight / (float) bitmapHeight;
float scale = Math.min(scaleX, scaleY);
int width = (int) (bitmapWidth * scale);
int height = (int) (bitmapHeight * scale);
sideImage.setAlpha(1.0f);
sideImage.setImageCoords(-width / 2, -height / 2, width, height);
sideImage.draw(canvas);
canvas.restore();
}
groupedPhotosListView.setMoveProgress(1.0f - alpha);
canvas.save();
canvas.translate(currentTranslationX, currentTranslationY / currentScale);
canvas.translate(-(containerWidth * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale);
photoProgressViews[2].setScale(1.0f);
photoProgressViews[2].setAlpha(1.0f);
photoProgressViews[2].onDraw(canvas);
if (isActionBarVisible) {
fullscreenButton[2].setAlpha(1.0f);
}
canvas.restore();
} else {
if (isActionBarVisible) {
fullscreenButton[2].setAlpha(0.0f);
}
}
if (waitingForDraw != 0) {
waitingForDraw--;
if (waitingForDraw == 0) {
if (textureImageView != null) {
try {
currentBitmap = Bitmaps.createBitmap(videoTextureView.getWidth(), videoTextureView.getHeight(), Bitmap.Config.ARGB_8888);
changedTextureView.getBitmap(currentBitmap);
} catch (Throwable e) {
if (currentBitmap != null) {
currentBitmap.recycle();
currentBitmap = null;
}
FileLog.e(e);
}
if (currentBitmap != null) {
textureImageView.setVisibility(View.VISIBLE);
textureImageView.setImageBitmap(currentBitmap);
} else {
textureImageView.setImageDrawable(null);
}
}
if (pipVideoView != null) {
pipVideoView.close();
pipVideoView = null;
}
} else {
containerView.invalidate();
}
}
if (padImageForHorizontalInsets) {
canvas.restore();
}
if (aspectRatioFrameLayout != null && videoForwardDrawable.isAnimating()) {
int h = (int) (aspectRatioFrameLayout.getMeasuredHeight() * (scale - 1.0f)) / 2;
videoForwardDrawable.setBounds(aspectRatioFrameLayout.getLeft(), aspectRatioFrameLayout.getTop() - h + (int) (currentTranslationY / currentScale), aspectRatioFrameLayout.getRight(), aspectRatioFrameLayout.getBottom() + h + (int) (currentTranslationY / currentScale));
videoForwardDrawable.draw(canvas);
}
}
Aggregations