2016-05-25 23:49:47 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2016-05-25 23:49:47 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2016-05-25 23:49:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Components;
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.Context;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.content.Intent;
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.PackageManager;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Canvas;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.graphics.Paint;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.hardware.Camera;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.media.MediaMetadataRetriever;
|
|
|
|
import android.media.ThumbnailUtils;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.provider.MediaStore;
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.exifinterface.media.ExifInterface;
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.os.Build;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.provider.Settings;
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.annotation.Keep;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.HapticFeedbackConstants;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.view.KeyEvent;
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.SoundEffectConstants;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewAnimationUtils;
|
|
|
|
import android.view.ViewConfiguration;
|
|
|
|
import android.view.ViewGroup;
|
2019-05-14 14:08:05 +02:00
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.BuildVars;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.ChatObject;
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.messenger.MediaDataController;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.ImageReceiver;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.ContactsController;
|
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessageObject;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.VideoEditedInfo;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.messenger.camera.*;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.Cells.PhotoAttachCameraCell;
|
|
|
|
import org.telegram.ui.Cells.PhotoAttachPhotoCell;
|
|
|
|
import org.telegram.ui.Cells.ShadowSectionCell;
|
|
|
|
import org.telegram.ui.ChatActivity;
|
|
|
|
import org.telegram.ui.PhotoViewer;
|
|
|
|
|
|
|
|
import java.io.File;
|
2018-07-30 04:07:02 +02:00
|
|
|
import java.io.FileOutputStream;
|
2016-05-25 23:49:47 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public class ChatAttachAlert extends BottomSheet implements NotificationCenter.NotificationCenterDelegate, BottomSheet.BottomSheetDelegateInterface {
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
public interface ChatAttachViewDelegate {
|
|
|
|
void didPressedButton(int button);
|
|
|
|
View getRevealView();
|
|
|
|
void didSelectBot(TLRPC.User user);
|
2017-03-31 01:58:05 +02:00
|
|
|
void onCameraOpened();
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean allowGroupPhotos();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private class InnerAnimator {
|
|
|
|
private AnimatorSet animatorSet;
|
|
|
|
private float startRadius;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private BaseFragment baseFragment;
|
2016-05-25 23:49:47 +02:00
|
|
|
private AttachButton sendPhotosButton;
|
2017-07-08 18:32:04 +02:00
|
|
|
private AttachButton sendDocumentsButton;
|
2019-05-14 14:08:05 +02:00
|
|
|
private View[] views = new View[20];
|
2016-05-25 23:49:47 +02:00
|
|
|
private RecyclerListView attachPhotoRecyclerView;
|
2018-07-30 04:07:02 +02:00
|
|
|
private LinearLayoutManager attachPhotoLayoutManager;
|
|
|
|
private PhotoAttachAdapter photoAttachAdapter;
|
|
|
|
private RecyclerListView cameraPhotoRecyclerView;
|
|
|
|
private boolean cameraPhotoRecyclerViewIgnoreLayout;
|
|
|
|
private LinearLayoutManager cameraPhotoLayoutManager;
|
|
|
|
private PhotoAttachAdapter cameraAttachAdapter;
|
2016-05-25 23:49:47 +02:00
|
|
|
private View lineView;
|
|
|
|
private EmptyTextProgressView progressView;
|
|
|
|
private RecyclerListView listView;
|
|
|
|
private LinearLayoutManager layoutManager;
|
|
|
|
private Drawable shadowDrawable;
|
|
|
|
private ViewGroup attachView;
|
2017-07-08 18:32:04 +02:00
|
|
|
private ArrayList<AttachButton> attachButtons = new ArrayList<>();
|
2016-05-25 23:49:47 +02:00
|
|
|
private ListAdapter adapter;
|
|
|
|
private TextView hintTextView;
|
|
|
|
private ArrayList<InnerAnimator> innerAnimators = new ArrayList<>();
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean requestingPermissions;
|
|
|
|
private Paint ciclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
2016-05-25 23:49:47 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private MessageObject editingMessageObject;
|
|
|
|
|
|
|
|
private boolean buttonPressed;
|
|
|
|
|
|
|
|
private int currentAccount = UserConfig.selectedAccount;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private CorrectlyMeasuringTextView mediaBanTooltip;
|
|
|
|
|
|
|
|
private boolean mediaEnabled = true;
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private CameraView cameraView;
|
|
|
|
private FrameLayout cameraIcon;
|
2018-07-30 04:07:02 +02:00
|
|
|
private ImageView cameraImageView;
|
2016-10-11 13:57:01 +02:00
|
|
|
private TextView recordTime;
|
|
|
|
private ImageView[] flashModeButton = new ImageView[2];
|
|
|
|
private boolean flashAnimationInProgress;
|
|
|
|
private int[] cameraViewLocation = new int[2];
|
2017-03-31 01:58:05 +02:00
|
|
|
private int[] viewPosition = new int[2];
|
2016-10-11 13:57:01 +02:00
|
|
|
private int cameraViewOffsetX;
|
|
|
|
private int cameraViewOffsetY;
|
|
|
|
private boolean cameraOpened;
|
|
|
|
private boolean cameraInitied;
|
|
|
|
private boolean cameraAnimationInProgress;
|
|
|
|
private float cameraOpenProgress;
|
|
|
|
private int[] animateCameraValues = new int[5];
|
|
|
|
private int videoRecordTime;
|
|
|
|
private Runnable videoRecordRunnable;
|
|
|
|
private DecelerateInterpolator interpolator = new DecelerateInterpolator(1.5f);
|
|
|
|
private FrameLayout cameraPanel;
|
|
|
|
private ShutterButton shutterButton;
|
2018-07-30 04:07:02 +02:00
|
|
|
private TextView counterTextView;
|
2016-10-11 13:57:01 +02:00
|
|
|
private ImageView switchCameraButton;
|
|
|
|
private boolean takingPhoto;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean mediaCaptured;
|
2018-07-30 04:07:02 +02:00
|
|
|
private static boolean mediaFromExternalCamera;
|
|
|
|
private static ArrayList<Object> cameraPhotos = new ArrayList<>();
|
|
|
|
private static HashMap<Object, Object> selectedPhotos = new HashMap<>();
|
|
|
|
private static ArrayList<Object> selectedPhotosOrder = new ArrayList<>();
|
|
|
|
private static int lastImageId = -1;
|
|
|
|
private boolean cancelTakingPhotos;
|
|
|
|
|
|
|
|
private int maxSelectedPhotos = -1;
|
|
|
|
private boolean openWithFrontFaceCamera;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
private float lastY;
|
|
|
|
private boolean pressed;
|
|
|
|
private boolean maybeStartDraging;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean dragging;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatorSet currentHintAnimation;
|
2016-05-25 23:49:47 +02:00
|
|
|
private boolean hintShowed;
|
|
|
|
private Runnable hideHintRunnable;
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean deviceHasGoodCamera;
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
private DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
|
|
|
|
|
|
|
|
private boolean loading = true;
|
|
|
|
|
|
|
|
private ChatAttachViewDelegate delegate;
|
|
|
|
|
|
|
|
private int scrollOffsetY;
|
|
|
|
private boolean ignoreLayout;
|
|
|
|
|
|
|
|
private boolean useRevealAnimation;
|
|
|
|
private float revealRadius;
|
|
|
|
private int revealX;
|
|
|
|
private int revealY;
|
|
|
|
private boolean revealAnimationInProgress;
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean paused;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private class BasePhotoProvider extends PhotoViewer.EmptyPhotoViewerProvider {
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) {
|
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(index);
|
|
|
|
return photoEntry != null && selectedPhotos.containsKey(photoEntry.imageId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo) {
|
|
|
|
if (maxSelectedPhotos >= 0 && selectedPhotos.size() >= maxSelectedPhotos && !isPhotoChecked(index)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(index);
|
|
|
|
if (photoEntry == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
boolean add = true;
|
|
|
|
int num;
|
|
|
|
if ((num = addToSelectedPhotos(photoEntry, -1)) == -1) {
|
|
|
|
num = selectedPhotosOrder.indexOf(photoEntry.imageId);
|
|
|
|
} else {
|
|
|
|
add = false;
|
|
|
|
photoEntry.editedInfo = null;
|
|
|
|
}
|
|
|
|
photoEntry.editedInfo = videoEditedInfo;
|
|
|
|
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
int tag = (Integer) view.getTag();
|
|
|
|
if (tag == index) {
|
|
|
|
if (baseFragment instanceof ChatActivity && maxSelectedPhotos < 0) {
|
|
|
|
((PhotoAttachPhotoCell) view).setChecked(num, add, false);
|
|
|
|
} else {
|
|
|
|
((PhotoAttachPhotoCell) view).setChecked(-1, add, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count = cameraPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = cameraPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
int tag = (Integer) view.getTag();
|
|
|
|
if (tag == index) {
|
|
|
|
if (baseFragment instanceof ChatActivity && maxSelectedPhotos < 0) {
|
|
|
|
((PhotoAttachPhotoCell) view).setChecked(num, add, false);
|
|
|
|
} else {
|
|
|
|
((PhotoAttachPhotoCell) view).setChecked(-1, add, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updatePhotosButton();
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean allowGroupPhotos() {
|
|
|
|
return delegate.allowGroupPhotos();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() {
|
|
|
|
return selectedPhotos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<Object> getSelectedPhotosOrder() {
|
|
|
|
return selectedPhotosOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HashMap<Object, Object> getSelectedPhotos() {
|
|
|
|
return selectedPhotos;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPhotoIndex(int index) {
|
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(index);
|
|
|
|
if (photoEntry == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return selectedPhotosOrder.indexOf(photoEntry.imageId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private PhotoViewer.PhotoViewerProvider photoViewerProvider = new BasePhotoProvider() {
|
2017-12-08 18:35:59 +01:00
|
|
|
@Override
|
2019-03-03 21:40:48 +01:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
|
2017-12-08 18:35:59 +01:00
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
|
|
|
if (cell != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
int[] coords = new int[2];
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.getImageView().getLocationInWindow(coords);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (Build.VERSION.SDK_INT < 26) {
|
|
|
|
coords[0] -= getLeftInset();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
|
|
|
object.viewY = coords[1];
|
|
|
|
object.parentView = attachPhotoRecyclerView;
|
|
|
|
object.imageReceiver = cell.getImageView().getImageReceiver();
|
2018-07-30 04:07:02 +02:00
|
|
|
object.thumb = object.imageReceiver.getBitmapSafe();
|
2017-12-08 18:35:59 +01:00
|
|
|
object.scale = cell.getImageView().getScaleX();
|
|
|
|
cell.showCheck(false);
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updatePhotoAtIndex(int index) {
|
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
|
|
|
if (cell != null) {
|
|
|
|
cell.getImageView().setOrientation(0, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(index);
|
|
|
|
if (photoEntry == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
cell.getImageView().setImage(photoEntry.thumbPath, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.path != null) {
|
|
|
|
cell.getImageView().setOrientation(photoEntry.orientation, true);
|
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
cell.getImageView().setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else {
|
|
|
|
cell.getImageView().setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cell.getImageView().setImageResource(R.drawable.nophotos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2017-12-08 18:35:59 +01:00
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
|
|
|
if (cell != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return cell.getImageView().getImageReceiver().getBitmapSafe();
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
|
|
|
if (cell != null) {
|
|
|
|
cell.showCheck(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
|
|
|
cell.showCheck(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean cancelButtonPressed() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(index);
|
|
|
|
if (photoEntry != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
photoEntry.editedInfo = videoEditedInfo;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (selectedPhotos.isEmpty() && photoEntry != null) {
|
|
|
|
addToSelectedPhotos(photoEntry, -1);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
delegate.didPressedButton(7);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private void updateCheckedPhotoIndices() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!(baseFragment instanceof ChatActivity)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition((Integer) cell.getTag());
|
|
|
|
if (photoEntry != null) {
|
|
|
|
cell.setNum(selectedPhotosOrder.indexOf(photoEntry.imageId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count = cameraPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = cameraPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition((Integer) cell.getTag());
|
|
|
|
if (photoEntry != null) {
|
|
|
|
cell.setNum(selectedPhotosOrder.indexOf(photoEntry.imageId));
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private MediaController.PhotoEntry getPhotoEntryAtPosition(int position) {
|
|
|
|
if (position < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
int cameraCount = cameraPhotos.size();
|
|
|
|
if (position < cameraCount) {
|
|
|
|
return (MediaController.PhotoEntry) cameraPhotos.get(position);
|
|
|
|
}
|
|
|
|
position -= cameraCount;
|
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (position < albumEntry.photos.size()) {
|
|
|
|
return albumEntry.photos.get(position);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private ArrayList<Object> getAllPhotosArray() {
|
|
|
|
ArrayList<Object> arrayList;
|
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (albumEntry != null) {
|
|
|
|
if (!cameraPhotos.isEmpty()) {
|
|
|
|
arrayList = new ArrayList<>(albumEntry.photos.size() + cameraPhotos.size());
|
|
|
|
arrayList.addAll(cameraPhotos);
|
|
|
|
arrayList.addAll(albumEntry.photos);
|
|
|
|
} else {
|
|
|
|
arrayList = (ArrayList) albumEntry.photos;
|
|
|
|
}
|
|
|
|
} else if (!cameraPhotos.isEmpty()) {
|
|
|
|
arrayList = cameraPhotos;
|
|
|
|
} else {
|
|
|
|
arrayList = new ArrayList<>(0);
|
|
|
|
}
|
|
|
|
return arrayList;
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
private class AttachButton extends FrameLayout {
|
|
|
|
|
|
|
|
private TextView textView;
|
|
|
|
private ImageView imageView;
|
|
|
|
|
|
|
|
public AttachButton(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
imageView = new ImageView(context);
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
2018-07-30 04:07:02 +02:00
|
|
|
addView(imageView, LayoutHelper.createFrame(54, 54, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 5, 0, 0));
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
textView = new TextView(context);
|
2019-01-23 18:03:33 +01:00
|
|
|
textView.setMaxLines(2);
|
2016-05-25 23:49:47 +02:00
|
|
|
textView.setGravity(Gravity.CENTER_HORIZONTAL);
|
|
|
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
2017-03-31 01:58:05 +02:00
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
|
2016-05-25 23:49:47 +02:00
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
2019-01-23 18:03:33 +01:00
|
|
|
textView.setLineSpacing(-AndroidUtilities.dp(2), 1.0f);
|
2016-05-25 23:49:47 +02:00
|
|
|
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 64, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2019-01-23 18:03:33 +01:00
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(85), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(92), MeasureSpec.EXACTLY));
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setTextAndIcon(CharSequence text, Drawable drawable) {
|
|
|
|
textView.setText(text);
|
|
|
|
imageView.setBackgroundDrawable(drawable);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasOverlappingRendering() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class AttachBotButton extends FrameLayout {
|
|
|
|
|
|
|
|
private BackupImageView imageView;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private AvatarDrawable avatarDrawable = new AvatarDrawable();
|
|
|
|
private boolean pressed;
|
|
|
|
|
|
|
|
private boolean checkingForLongPress = false;
|
|
|
|
private CheckForLongPress pendingCheckForLongPress = null;
|
|
|
|
private int pressCount = 0;
|
|
|
|
private CheckForTap pendingCheckForTap = null;
|
|
|
|
|
|
|
|
private TLRPC.User currentUser;
|
|
|
|
|
|
|
|
private final class CheckForTap implements Runnable {
|
|
|
|
public void run() {
|
|
|
|
if (pendingCheckForLongPress == null) {
|
|
|
|
pendingCheckForLongPress = new CheckForLongPress();
|
|
|
|
}
|
|
|
|
pendingCheckForLongPress.currentPressCount = ++pressCount;
|
|
|
|
postDelayed(pendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() - ViewConfiguration.getTapTimeout());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CheckForLongPress implements Runnable {
|
|
|
|
public int currentPressCount;
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
|
|
|
|
checkingForLongPress = false;
|
|
|
|
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
|
|
|
onLongPress();
|
|
|
|
MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
|
|
|
|
onTouchEvent(event);
|
|
|
|
event.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public AttachBotButton(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
imageView = new BackupImageView(context);
|
|
|
|
imageView.setRoundRadius(AndroidUtilities.dp(27));
|
|
|
|
addView(imageView, LayoutHelper.createFrame(54, 54, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));
|
|
|
|
|
|
|
|
nameTextView = new TextView(context);
|
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
|
|
|
nameTextView.setMaxLines(2);
|
|
|
|
nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
|
|
|
|
nameTextView.setLines(2);
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 65, 6, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(85), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onLongPress() {
|
|
|
|
if (baseFragment == null || currentUser == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.formatString("ChatHintsDelete", R.string.ChatHintsDelete, ContactsController.formatName(currentUser.first_name, currentUser.last_name)));
|
2019-07-18 15:01:39 +02:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> MediaDataController.getInstance(currentAccount).removeInline(currentUser.id));
|
2016-05-25 23:49:47 +02:00
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUser(TLRPC.User user) {
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
nameTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
|
2016-05-25 23:49:47 +02:00
|
|
|
currentUser = user;
|
|
|
|
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
|
|
|
|
avatarDrawable.setInfo(user);
|
2019-05-14 14:08:05 +02:00
|
|
|
imageView.setImage(ImageLocation.getForUser(user, false), "50_50", avatarDrawable, user);
|
2016-05-25 23:49:47 +02:00
|
|
|
requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
boolean result = false;
|
|
|
|
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
pressed = true;
|
|
|
|
invalidate();
|
|
|
|
result = true;
|
|
|
|
} else if (pressed) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
pressed = false;
|
|
|
|
playSoundEffect(SoundEffectConstants.CLICK);
|
2019-07-18 15:01:39 +02:00
|
|
|
delegate.didSelectBot(MessagesController.getInstance(currentAccount).getUser(MediaDataController.getInstance(currentAccount).inlineBots.get((Integer) getTag()).peer.user_id));
|
2016-05-25 23:49:47 +02:00
|
|
|
setUseRevealAnimation(false);
|
|
|
|
dismiss();
|
|
|
|
setUseRevealAnimation(true);
|
|
|
|
invalidate();
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
pressed = false;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result) {
|
|
|
|
result = super.onTouchEvent(event);
|
|
|
|
} else {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
startCheckLongPress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event.getAction() != MotionEvent.ACTION_DOWN && event.getAction() != MotionEvent.ACTION_MOVE) {
|
|
|
|
cancelCheckLongPress();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void startCheckLongPress() {
|
|
|
|
if (checkingForLongPress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
checkingForLongPress = true;
|
|
|
|
if (pendingCheckForTap == null) {
|
|
|
|
pendingCheckForTap = new CheckForTap();
|
|
|
|
}
|
|
|
|
postDelayed(pendingCheckForTap, ViewConfiguration.getTapTimeout());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void cancelCheckLongPress() {
|
|
|
|
checkingForLongPress = false;
|
|
|
|
if (pendingCheckForLongPress != null) {
|
|
|
|
removeCallbacks(pendingCheckForLongPress);
|
|
|
|
}
|
|
|
|
if (pendingCheckForTap != null) {
|
|
|
|
removeCallbacks(pendingCheckForTap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public ChatAttachAlert(Context context, final BaseFragment parentFragment) {
|
2019-05-14 14:08:05 +02:00
|
|
|
super(context, false, 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
baseFragment = parentFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
ciclePaint.setColor(Theme.getColor(Theme.key_dialogBackground));
|
2016-05-25 23:49:47 +02:00
|
|
|
setDelegate(this);
|
|
|
|
setUseRevealAnimation(true);
|
2016-10-11 13:57:01 +02:00
|
|
|
checkCamera(false);
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.albumsDidLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.reloadInlineHints);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.cameraInitied);
|
2017-03-31 01:58:05 +02:00
|
|
|
shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate();
|
2018-07-30 04:07:02 +02:00
|
|
|
Theme.setDrawableColor(shadowDrawable, Theme.getColor(Theme.key_dialogBackground));
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
containerView = listView = new RecyclerListView(context) {
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
private int lastWidth;
|
|
|
|
private int lastHeight;
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (ignoreLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (cameraAnimationInProgress) {
|
|
|
|
return true;
|
|
|
|
} else if (cameraOpened) {
|
|
|
|
return processTouchEvent(ev);
|
|
|
|
} else if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
|
2016-05-25 23:49:47 +02:00
|
|
|
dismiss();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
if (cameraAnimationInProgress) {
|
|
|
|
return true;
|
|
|
|
} else if (cameraOpened) {
|
|
|
|
return processTouchEvent(event);
|
|
|
|
}
|
|
|
|
return !isDismissed() && super.onTouchEvent(event);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
height -= AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
int h;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
2019-01-23 18:03:33 +01:00
|
|
|
h = 298;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
h = 203;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
int contentSize = backgroundPaddingTop + AndroidUtilities.dp(h) + (MediaDataController.getInstance(currentAccount).inlineBots.isEmpty() ? 0 : ((int) Math.ceil(MediaDataController.getInstance(currentAccount).inlineBots.size() / 4.0f) * AndroidUtilities.dp(100) + AndroidUtilities.dp(12)));
|
2018-07-30 04:07:02 +02:00
|
|
|
int padding = contentSize == AndroidUtilities.dp(h) ? 0 : Math.max(0, (height - AndroidUtilities.dp(h)));
|
2016-06-24 12:27:15 +02:00
|
|
|
if (padding != 0 && contentSize < height) {
|
|
|
|
padding -= (height - contentSize);
|
|
|
|
}
|
|
|
|
if (padding == 0) {
|
|
|
|
padding = backgroundPaddingTop;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
if (getPaddingTop() != padding) {
|
|
|
|
ignoreLayout = true;
|
|
|
|
setPadding(backgroundPaddingLeft, padding, backgroundPaddingLeft, 0);
|
|
|
|
ignoreLayout = false;
|
|
|
|
}
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
2016-10-11 13:57:01 +02:00
|
|
|
int width = right - left;
|
|
|
|
int height = bottom - top;
|
|
|
|
|
|
|
|
int newPosition = -1;
|
|
|
|
int newTop = 0;
|
|
|
|
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
int lastVisibleItemPosition = -1;
|
|
|
|
int lastVisibleItemPositionTop = 0;
|
|
|
|
if (count > 0) {
|
|
|
|
View child = listView.getChildAt(listView.getChildCount() - 1);
|
|
|
|
Holder holder = (Holder) listView.findContainingViewHolder(child);
|
|
|
|
if (holder != null) {
|
|
|
|
lastVisibleItemPosition = holder.getAdapterPosition();
|
|
|
|
lastVisibleItemPositionTop = child.getTop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastVisibleItemPosition >= 0 && height - lastHeight != 0) {
|
|
|
|
newPosition = lastVisibleItemPosition;
|
|
|
|
newTop = lastVisibleItemPositionTop + height - lastHeight - getPaddingTop();
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
if (newPosition != -1) {
|
|
|
|
ignoreLayout = true;
|
|
|
|
layoutManager.scrollToPositionWithOffset(newPosition, newTop);
|
|
|
|
super.onLayout(false, left, top, right, bottom);
|
|
|
|
ignoreLayout = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastHeight = height;
|
|
|
|
lastWidth = width;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
updateLayout();
|
2016-10-11 13:57:01 +02:00
|
|
|
checkCameraViewPosition();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDraw(Canvas canvas) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (useRevealAnimation && Build.VERSION.SDK_INT <= 19) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.clipRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight());
|
|
|
|
if (revealAnimationInProgress) {
|
|
|
|
canvas.drawCircle(revealX, revealY, revealRadius, ciclePaint);
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
2016-06-24 12:27:15 +02:00
|
|
|
canvas.drawRect(backgroundPaddingLeft, scrollOffsetY, getMeasuredWidth() - backgroundPaddingLeft, getMeasuredHeight(), ciclePaint);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
canvas.restore();
|
|
|
|
} else {
|
|
|
|
shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(), getMeasuredHeight());
|
|
|
|
shadowDrawable.draw(canvas);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setTranslationY(float translationY) {
|
|
|
|
super.setTranslationY(translationY);
|
|
|
|
checkCameraViewPosition();
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
};
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
nestedScrollChild = listView;
|
2016-10-11 13:57:01 +02:00
|
|
|
listView.setWillNotDraw(false);
|
2016-06-24 12:27:15 +02:00
|
|
|
listView.setClipToPadding(false);
|
2016-05-25 23:49:47 +02:00
|
|
|
listView.setLayoutManager(layoutManager = new LinearLayoutManager(getContext()));
|
|
|
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
listView.setAdapter(adapter = new ListAdapter(context));
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
listView.setEnabled(true);
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow));
|
2016-05-25 23:49:47 +02:00
|
|
|
listView.addItemDecoration(new RecyclerView.ItemDecoration() {
|
|
|
|
@Override
|
|
|
|
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
|
|
|
outRect.left = 0;
|
|
|
|
outRect.right = 0;
|
|
|
|
outRect.top = 0;
|
|
|
|
outRect.bottom = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
if (listView.getChildCount() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hintShowed) {
|
|
|
|
if (layoutManager.findLastVisibleItemPosition() > 1) {
|
|
|
|
hideHint();
|
|
|
|
hintShowed = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
MessagesController.getGlobalMainSettings().edit().putBoolean("bothint", true).commit();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
updateLayout();
|
2016-10-11 13:57:01 +02:00
|
|
|
checkCameraViewPosition();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
});
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);
|
2019-05-14 14:08:05 +02:00
|
|
|
containerView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
attachView = new FrameLayout(context) {
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (baseFragment instanceof ChatActivity) {
|
2019-01-23 18:03:33 +01:00
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(298), MeasureSpec.EXACTLY));
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(203), MeasureSpec.EXACTLY));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
int width = right - left;
|
|
|
|
int height = bottom - top;
|
|
|
|
int t = AndroidUtilities.dp(8);
|
|
|
|
attachPhotoRecyclerView.layout(0, t, width, t + attachPhotoRecyclerView.getMeasuredHeight());
|
|
|
|
progressView.layout(0, t, width, t + progressView.getMeasuredHeight());
|
|
|
|
lineView.layout(0, AndroidUtilities.dp(96), width, AndroidUtilities.dp(96) + lineView.getMeasuredHeight());
|
|
|
|
hintTextView.layout(width - hintTextView.getMeasuredWidth() - AndroidUtilities.dp(5), height - hintTextView.getMeasuredHeight() - AndroidUtilities.dp(5), width - AndroidUtilities.dp(5), height - AndroidUtilities.dp(5));
|
2017-07-08 18:32:04 +02:00
|
|
|
int x = (width - mediaBanTooltip.getMeasuredWidth()) / 2;
|
|
|
|
int y = t + (attachPhotoRecyclerView.getMeasuredHeight() - mediaBanTooltip.getMeasuredHeight()) / 2;
|
|
|
|
mediaBanTooltip.layout(x, y, x + mediaBanTooltip.getMeasuredWidth(), y + mediaBanTooltip.getMeasuredHeight());
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
int diff = (width - AndroidUtilities.dp(85 * 4 + 20)) / 3;
|
2018-07-30 04:07:02 +02:00
|
|
|
int num = 0;
|
2016-05-25 23:49:47 +02:00
|
|
|
for (int a = 0; a < 8; a++) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (views[a] == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
y = AndroidUtilities.dp(105 + 97 * (num / 4));
|
2018-07-30 04:07:02 +02:00
|
|
|
x = AndroidUtilities.dp(10) + (num % 4) * (AndroidUtilities.dp(85) + diff);
|
2016-05-25 23:49:47 +02:00
|
|
|
views[a].layout(x, y, x + views[a].getMeasuredWidth(), y + views[a].getMeasuredHeight());
|
2018-07-30 04:07:02 +02:00
|
|
|
num++;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
views[8] = attachPhotoRecyclerView = new RecyclerListView(context);
|
|
|
|
attachPhotoRecyclerView.setVerticalScrollBarEnabled(true);
|
2018-07-30 04:07:02 +02:00
|
|
|
attachPhotoRecyclerView.setAdapter(photoAttachAdapter = new PhotoAttachAdapter(context, true));
|
2016-05-25 23:49:47 +02:00
|
|
|
attachPhotoRecyclerView.setClipToPadding(false);
|
|
|
|
attachPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
|
|
|
|
attachPhotoRecyclerView.setItemAnimator(null);
|
|
|
|
attachPhotoRecyclerView.setLayoutAnimation(null);
|
2016-06-24 12:27:15 +02:00
|
|
|
attachPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
2016-05-25 23:49:47 +02:00
|
|
|
attachView.addView(attachPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
|
|
|
|
attachPhotoLayoutManager = new LinearLayoutManager(context) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
attachPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
|
attachPhotoRecyclerView.setLayoutManager(attachPhotoLayoutManager);
|
2018-08-27 10:33:11 +02:00
|
|
|
attachPhotoRecyclerView.setOnItemClickListener((view, position) -> {
|
|
|
|
if (baseFragment == null || baseFragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!deviceHasGoodCamera || position != 0) {
|
|
|
|
if (deviceHasGoodCamera) {
|
|
|
|
position--;
|
|
|
|
}
|
|
|
|
ArrayList<Object> arrayList = getAllPhotosArray();
|
|
|
|
if (position < 0 || position >= arrayList.size()) {
|
2016-05-25 23:49:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
|
|
|
|
PhotoViewer.getInstance().setParentAlert(ChatAttachAlert.this);
|
|
|
|
PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos);
|
|
|
|
ChatActivity chatActivity;
|
|
|
|
int type;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
chatActivity = (ChatActivity) baseFragment;
|
|
|
|
type = 0;
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
2018-08-27 10:33:11 +02:00
|
|
|
type = 4;
|
|
|
|
chatActivity = null;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, type, photoViewerProvider, chatActivity);
|
|
|
|
AndroidUtilities.hideKeyboard(baseFragment.getFragmentView().findFocus());
|
|
|
|
} else {
|
|
|
|
openCamera(true);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
});
|
2016-10-11 13:57:01 +02:00
|
|
|
attachPhotoRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
checkCameraViewPosition();
|
|
|
|
}
|
|
|
|
});
|
2016-05-25 23:49:47 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
views[11] = mediaBanTooltip = new CorrectlyMeasuringTextView(context);
|
2019-05-14 14:08:05 +02:00
|
|
|
mediaBanTooltip.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(3), Theme.getColor(Theme.key_chat_attachMediaBanBackground)));
|
|
|
|
mediaBanTooltip.setTextColor(Theme.getColor(Theme.key_chat_attachMediaBanText));
|
2017-07-08 18:32:04 +02:00
|
|
|
mediaBanTooltip.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
|
|
|
|
mediaBanTooltip.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
mediaBanTooltip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
mediaBanTooltip.setVisibility(View.INVISIBLE);
|
|
|
|
attachView.addView(mediaBanTooltip, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 14, 0, 14, 0));
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
views[9] = progressView = new EmptyTextProgressView(context);
|
|
|
|
if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
progressView.setText(LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
|
|
|
|
progressView.setTextSize(16);
|
|
|
|
} else {
|
|
|
|
progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
|
|
|
|
progressView.setTextSize(20);
|
|
|
|
}
|
|
|
|
attachView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
|
|
|
|
attachPhotoRecyclerView.setEmptyView(progressView);
|
|
|
|
|
|
|
|
views[10] = lineView = new View(getContext()) {
|
|
|
|
@Override
|
|
|
|
public boolean hasOverlappingRendering() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2017-03-31 01:58:05 +02:00
|
|
|
lineView.setBackgroundColor(Theme.getColor(Theme.key_dialogGrayLine));
|
2016-05-25 23:49:47 +02:00
|
|
|
attachView.addView(lineView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.TOP | Gravity.LEFT));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
CharSequence[] items = new CharSequence[]{
|
|
|
|
LocaleController.getString("ChatCamera", R.string.ChatCamera),
|
|
|
|
LocaleController.getString("ChatGallery", R.string.ChatGallery),
|
|
|
|
LocaleController.getString("ChatVideo", R.string.ChatVideo),
|
|
|
|
LocaleController.getString("AttachMusic", R.string.AttachMusic),
|
|
|
|
LocaleController.getString("ChatDocument", R.string.ChatDocument),
|
|
|
|
LocaleController.getString("AttachContact", R.string.AttachContact),
|
|
|
|
LocaleController.getString("ChatLocation", R.string.ChatLocation),
|
|
|
|
""
|
|
|
|
};
|
|
|
|
for (int a = 0; a < 8; a++) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!(baseFragment instanceof ChatActivity)) {
|
|
|
|
if (a == 2 || a == 3 || a == 5 || a == 6) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
AttachButton attachButton = new AttachButton(context);
|
2017-07-08 18:32:04 +02:00
|
|
|
attachButtons.add(attachButton);
|
2017-03-31 01:58:05 +02:00
|
|
|
attachButton.setTextAndIcon(items[a], Theme.chat_attachButtonDrawables[a]);
|
2019-01-23 18:03:33 +01:00
|
|
|
attachView.addView(attachButton, LayoutHelper.createFrame(85, 91, Gravity.LEFT | Gravity.TOP));
|
2016-05-25 23:49:47 +02:00
|
|
|
attachButton.setTag(a);
|
|
|
|
views[a] = attachButton;
|
|
|
|
if (a == 7) {
|
|
|
|
sendPhotosButton = attachButton;
|
|
|
|
sendPhotosButton.imageView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (a == 4) {
|
|
|
|
sendDocumentsButton = attachButton;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
attachButton.setOnClickListener(v -> {
|
|
|
|
if (buttonPressed) {
|
|
|
|
return;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
Integer num = (Integer) v.getTag();
|
|
|
|
if (deviceHasGoodCamera && num == 0 && baseFragment instanceof ChatActivity && ((ChatActivity) parentFragment).isSecretChat()) {
|
|
|
|
openCamera(true);
|
|
|
|
} else {
|
|
|
|
buttonPressed = true;
|
|
|
|
delegate.didPressedButton(num);
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
hintTextView = new TextView(context);
|
2017-03-31 01:58:05 +02:00
|
|
|
hintTextView.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(3), Theme.getColor(Theme.key_chat_gifSaveHintBackground)));
|
|
|
|
hintTextView.setTextColor(Theme.getColor(Theme.key_chat_gifSaveHintText));
|
2016-05-25 23:49:47 +02:00
|
|
|
hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
hintTextView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
|
|
|
|
hintTextView.setText(LocaleController.getString("AttachBotsHelp", R.string.AttachBotsHelp));
|
|
|
|
hintTextView.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
hintTextView.setVisibility(View.INVISIBLE);
|
|
|
|
hintTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.scroll_tip, 0, 0, 0);
|
|
|
|
hintTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
|
|
|
|
attachView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.RIGHT | Gravity.BOTTOM, 5, 0, 5, 5));
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
progressView.showProgress();
|
|
|
|
} else {
|
|
|
|
progressView.showTextView();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
recordTime = new TextView(context);
|
|
|
|
recordTime.setBackgroundResource(R.drawable.system);
|
|
|
|
recordTime.getBackground().setColorFilter(new PorterDuffColorFilter(0x66000000, PorterDuff.Mode.MULTIPLY));
|
|
|
|
recordTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
|
|
|
|
recordTime.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
recordTime.setAlpha(0.0f);
|
|
|
|
recordTime.setTextColor(0xffffffff);
|
|
|
|
recordTime.setPadding(AndroidUtilities.dp(10), AndroidUtilities.dp(5), AndroidUtilities.dp(10), AndroidUtilities.dp(5));
|
|
|
|
container.addView(recordTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 16, 0, 0));
|
|
|
|
|
|
|
|
cameraPanel = new FrameLayout(context) {
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
int cx = getMeasuredWidth() / 2;
|
|
|
|
int cy = getMeasuredHeight() / 2;
|
|
|
|
int cx2;
|
|
|
|
int cy2;
|
|
|
|
shutterButton.layout(cx - shutterButton.getMeasuredWidth() / 2, cy - shutterButton.getMeasuredHeight() / 2, cx + shutterButton.getMeasuredWidth() / 2, cy + shutterButton.getMeasuredHeight() / 2);
|
|
|
|
if (getMeasuredWidth() == AndroidUtilities.dp(100)) {
|
|
|
|
cx = cx2 = getMeasuredWidth() / 2;
|
|
|
|
cy2 = cy + cy / 2 + AndroidUtilities.dp(17);
|
|
|
|
cy = cy / 2 - AndroidUtilities.dp(17);
|
|
|
|
} else {
|
|
|
|
cx2 = cx + cx / 2 + AndroidUtilities.dp(17);
|
|
|
|
cx = cx / 2 - AndroidUtilities.dp(17);
|
|
|
|
cy = cy2 = getMeasuredHeight() / 2;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
switchCameraButton.layout(cx2 - switchCameraButton.getMeasuredWidth() / 2, cy2 - switchCameraButton.getMeasuredHeight() / 2, cx2 + switchCameraButton.getMeasuredWidth() / 2, cy2 + switchCameraButton.getMeasuredHeight() / 2);
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
flashModeButton[a].layout(cx - flashModeButton[a].getMeasuredWidth() / 2, cy - flashModeButton[a].getMeasuredHeight() / 2, cx + flashModeButton[a].getMeasuredWidth() / 2, cy + flashModeButton[a].getMeasuredHeight() / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cameraPanel.setVisibility(View.GONE);
|
|
|
|
cameraPanel.setAlpha(0.0f);
|
|
|
|
container.addView(cameraPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100, Gravity.LEFT | Gravity.BOTTOM));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
counterTextView = new TextView(context);
|
|
|
|
counterTextView.setBackgroundResource(R.drawable.photos_rounded);
|
|
|
|
counterTextView.setVisibility(View.GONE);
|
|
|
|
counterTextView.setTextColor(0xffffffff);
|
|
|
|
counterTextView.setGravity(Gravity.CENTER);
|
|
|
|
counterTextView.setPivotX(0);
|
|
|
|
counterTextView.setPivotY(0);
|
|
|
|
counterTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
counterTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.photos_arrow, 0);
|
|
|
|
counterTextView.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
counterTextView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
|
|
|
|
container.addView(counterTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 38, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 100 + 16));
|
2018-08-27 10:33:11 +02:00
|
|
|
counterTextView.setOnClickListener(v -> {
|
|
|
|
if (cameraView == null) {
|
|
|
|
return;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
openPhotoViewer(null, false, false);
|
|
|
|
CameraController.getInstance().stopPreview(cameraView.getCameraSession());
|
2018-07-30 04:07:02 +02:00
|
|
|
});
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
shutterButton = new ShutterButton(context);
|
|
|
|
cameraPanel.addView(shutterButton, LayoutHelper.createFrame(84, 84, Gravity.CENTER));
|
|
|
|
shutterButton.setDelegate(new ShutterButton.ShutterButtonDelegate() {
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
private File outputFile;
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@Override
|
|
|
|
public boolean shutterLongPressed() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!(baseFragment instanceof ChatActivity) || mediaCaptured || takingPhoto || baseFragment == null || baseFragment.getParentActivity() == null || cameraView == null) {
|
2017-07-23 14:56:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
if (baseFragment.getParentActivity().checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
requestingPermissions = true;
|
|
|
|
baseFragment.getParentActivity().requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 21);
|
2017-03-31 01:58:05 +02:00
|
|
|
return false;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
flashModeButton[a].setAlpha(0.0f);
|
|
|
|
}
|
|
|
|
switchCameraButton.setAlpha(0.0f);
|
2019-01-23 18:03:33 +01:00
|
|
|
outputFile = AndroidUtilities.generateVideoPath(baseFragment instanceof ChatActivity && ((ChatActivity) baseFragment).isSecretChat());
|
2017-07-23 14:56:38 +02:00
|
|
|
recordTime.setAlpha(1.0f);
|
2017-12-08 18:35:59 +01:00
|
|
|
recordTime.setText(String.format("%02d:%02d", 0, 0));
|
2017-07-23 14:56:38 +02:00
|
|
|
videoRecordTime = 0;
|
2018-08-27 10:33:11 +02:00
|
|
|
videoRecordRunnable = () -> {
|
|
|
|
if (videoRecordRunnable == null) {
|
|
|
|
return;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
videoRecordTime++;
|
|
|
|
recordTime.setText(String.format("%02d:%02d", videoRecordTime / 60, videoRecordTime % 60));
|
|
|
|
AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000);
|
2017-07-23 14:56:38 +02:00
|
|
|
};
|
|
|
|
AndroidUtilities.lockOrientation(parentFragment.getParentActivity());
|
2018-08-27 10:33:11 +02:00
|
|
|
CameraController.getInstance().recordVideo(cameraView.getCameraSession(), outputFile, (thumbPath, duration) -> {
|
|
|
|
if (outputFile == null || baseFragment == null) {
|
|
|
|
return;
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
mediaFromExternalCamera = false;
|
|
|
|
MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, lastImageId--, 0, outputFile.getAbsolutePath(), 0, true);
|
|
|
|
photoEntry.duration = (int) duration;
|
|
|
|
photoEntry.thumbPath = thumbPath;
|
|
|
|
openPhotoViewer(photoEntry, false, false);
|
|
|
|
}, () -> AndroidUtilities.runOnUIThread(videoRecordRunnable, 1000));
|
2017-07-23 14:56:38 +02:00
|
|
|
shutterButton.setState(ShutterButton.State.RECORDING, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void shutterCancel() {
|
|
|
|
if (mediaCaptured) {
|
|
|
|
return;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (outputFile != null) {
|
|
|
|
outputFile.delete();
|
|
|
|
outputFile = null;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
resetRecordState();
|
|
|
|
CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), true);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@Override
|
|
|
|
public void shutterReleased() {
|
|
|
|
if (takingPhoto || cameraView == null || mediaCaptured || cameraView.getCameraSession() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mediaCaptured = true;
|
|
|
|
if (shutterButton.getState() == ShutterButton.State.RECORDING) {
|
|
|
|
resetRecordState();
|
|
|
|
CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), false);
|
|
|
|
shutterButton.setState(ShutterButton.State.DEFAULT, true);
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
final File cameraFile = AndroidUtilities.generatePicturePath(baseFragment instanceof ChatActivity && ((ChatActivity) baseFragment).isSecretChat());
|
2017-07-23 14:56:38 +02:00
|
|
|
final boolean sameTakePictureOrientation = cameraView.getCameraSession().isSameTakePictureOrientation();
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraView.getCameraSession().setFlipFront(parentFragment instanceof ChatActivity);
|
2018-08-27 10:33:11 +02:00
|
|
|
takingPhoto = CameraController.getInstance().takePicture(cameraFile, cameraView.getCameraSession(), () -> {
|
|
|
|
takingPhoto = false;
|
|
|
|
if (cameraFile == null || baseFragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int orientation = 0;
|
|
|
|
try {
|
|
|
|
ExifInterface ei = new ExifInterface(cameraFile.getAbsolutePath());
|
|
|
|
int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
|
|
|
switch (exif) {
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_90:
|
|
|
|
orientation = 90;
|
|
|
|
break;
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_180:
|
|
|
|
orientation = 180;
|
|
|
|
break;
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_270:
|
|
|
|
orientation = 270;
|
|
|
|
break;
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
mediaFromExternalCamera = false;
|
2019-01-23 18:03:33 +01:00
|
|
|
MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, lastImageId--, 0, cameraFile.getAbsolutePath(), orientation, false);
|
|
|
|
photoEntry.canDeleteAfter = true;
|
|
|
|
openPhotoViewer(photoEntry, sameTakePictureOrientation, false);
|
2017-07-23 14:56:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-05-14 14:08:05 +02:00
|
|
|
shutterButton.setFocusable(true);
|
|
|
|
shutterButton.setContentDescription(LocaleController.getString("AccDescrShutter", R.string.AccDescrShutter));
|
2017-07-23 14:56:38 +02:00
|
|
|
|
|
|
|
switchCameraButton = new ImageView(context);
|
|
|
|
switchCameraButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
cameraPanel.addView(switchCameraButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.CENTER_VERTICAL));
|
2018-08-27 10:33:11 +02:00
|
|
|
switchCameraButton.setOnClickListener(v -> {
|
|
|
|
if (takingPhoto || cameraView == null || !cameraView.isInitied()) {
|
|
|
|
return;
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
cameraInitied = false;
|
|
|
|
cameraView.switchCamera();
|
|
|
|
ObjectAnimator animator = ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 0.0f).setDuration(100);
|
|
|
|
animator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
switchCameraButton.setImageResource(cameraView != null && cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2);
|
|
|
|
ObjectAnimator.ofFloat(switchCameraButton, "scaleX", 1.0f).setDuration(100).start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animator.start();
|
2017-07-23 14:56:38 +02:00
|
|
|
});
|
2019-05-14 14:08:05 +02:00
|
|
|
switchCameraButton.setContentDescription(LocaleController.getString("AccDescrSwitchCamera", R.string.AccDescrSwitchCamera));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
flashModeButton[a] = new ImageView(context);
|
|
|
|
flashModeButton[a].setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
flashModeButton[a].setVisibility(View.INVISIBLE);
|
|
|
|
cameraPanel.addView(flashModeButton[a], LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
|
2018-08-27 10:33:11 +02:00
|
|
|
flashModeButton[a].setOnClickListener(currentImage -> {
|
|
|
|
if (flashAnimationInProgress || cameraView == null || !cameraView.isInitied() || !cameraOpened) {
|
|
|
|
return;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
String current = cameraView.getCameraSession().getCurrentFlashMode();
|
|
|
|
String next = cameraView.getCameraSession().getNextFlashMode();
|
|
|
|
if (current.equals(next)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cameraView.getCameraSession().setCurrentFlashMode(next);
|
|
|
|
flashAnimationInProgress = true;
|
|
|
|
ImageView nextImage = flashModeButton[0] == currentImage ? flashModeButton[1] : flashModeButton[0];
|
|
|
|
nextImage.setVisibility(View.VISIBLE);
|
|
|
|
setCameraFlashModeIcon(nextImage, next);
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(currentImage, "translationY", 0, AndroidUtilities.dp(48)),
|
|
|
|
ObjectAnimator.ofFloat(nextImage, "translationY", -AndroidUtilities.dp(48), 0),
|
|
|
|
ObjectAnimator.ofFloat(currentImage, "alpha", 1.0f, 0.0f),
|
|
|
|
ObjectAnimator.ofFloat(nextImage, "alpha", 0.0f, 1.0f));
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
flashAnimationInProgress = false;
|
|
|
|
currentImage.setVisibility(View.INVISIBLE);
|
2019-05-14 14:08:05 +02:00
|
|
|
nextImage.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
|
2018-08-27 10:33:11 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
2016-10-11 13:57:01 +02:00
|
|
|
});
|
2019-05-14 14:08:05 +02:00
|
|
|
flashModeButton[a].setContentDescription("flash mode "+a);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
cameraPhotoRecyclerView = new RecyclerListView(context) {
|
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (cameraPhotoRecyclerViewIgnoreLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cameraPhotoRecyclerView.setVerticalScrollBarEnabled(true);
|
|
|
|
cameraPhotoRecyclerView.setAdapter(cameraAttachAdapter = new PhotoAttachAdapter(context, false));
|
|
|
|
cameraPhotoRecyclerView.setClipToPadding(false);
|
|
|
|
cameraPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
|
|
|
|
cameraPhotoRecyclerView.setItemAnimator(null);
|
|
|
|
cameraPhotoRecyclerView.setLayoutAnimation(null);
|
|
|
|
cameraPhotoRecyclerView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
|
|
|
cameraPhotoRecyclerView.setVisibility(View.INVISIBLE);
|
|
|
|
cameraPhotoRecyclerView.setAlpha(0.0f);
|
|
|
|
container.addView(cameraPhotoRecyclerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 80));
|
|
|
|
cameraPhotoLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cameraPhotoRecyclerView.setLayoutManager(cameraPhotoLayoutManager);
|
2018-08-27 10:33:11 +02:00
|
|
|
cameraPhotoRecyclerView.setOnItemClickListener((view, position) -> {
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
((PhotoAttachPhotoCell) view).callDelegate();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void show() {
|
|
|
|
super.show();
|
|
|
|
buttonPressed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEditingMessageObject(MessageObject messageObject) {
|
|
|
|
if (editingMessageObject == messageObject) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
editingMessageObject = messageObject;
|
|
|
|
if (editingMessageObject != null) {
|
|
|
|
maxSelectedPhotos = 1;
|
|
|
|
} else {
|
|
|
|
maxSelectedPhotos = -1;
|
|
|
|
}
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
boolean enabled;
|
2019-01-23 18:03:33 +01:00
|
|
|
AttachButton attachButton = attachButtons.get(3 + a);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (a < 2) {
|
|
|
|
enabled = editingMessageObject == null || !editingMessageObject.hasValidGroupId();
|
|
|
|
} else {
|
|
|
|
enabled = editingMessageObject == null;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
attachButton.setEnabled(enabled);
|
|
|
|
attachButton.setAlpha(enabled ? 1.0f : 0.2f);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
updatePollMusicButton();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public MessageObject getEditingMessageObject() {
|
|
|
|
return editingMessageObject;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private void updatePollMusicButton() {
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
if (attachButtons.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean allowPoll;
|
|
|
|
if (editingMessageObject != null) {
|
|
|
|
allowPoll = false;
|
|
|
|
} else {
|
|
|
|
TLRPC.Chat currentChat = ((ChatActivity) baseFragment).getCurrentChat();
|
|
|
|
allowPoll = currentChat != null && ChatObject.canSendPolls(currentChat);
|
|
|
|
}
|
|
|
|
String text = allowPoll ? LocaleController.getString("Poll", R.string.Poll) : LocaleController.getString("AttachMusic", R.string.AttachMusic);
|
|
|
|
AttachButton attachButton = attachButtons.get(3);
|
|
|
|
attachButton.setTag(allowPoll ? 9 : 3);
|
|
|
|
attachButton.setTextAndIcon(text, Theme.chat_attachButtonDrawables[allowPoll ? 9 : 3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void updatePhotosCounter() {
|
|
|
|
if (counterTextView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean hasVideo = false;
|
|
|
|
for (HashMap.Entry<Object, Object> entry : selectedPhotos.entrySet()) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry.getValue();
|
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
hasVideo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasVideo) {
|
|
|
|
counterTextView.setText(LocaleController.formatPluralString("Media", selectedPhotos.size()).toUpperCase());
|
|
|
|
} else {
|
|
|
|
counterTextView.setText(LocaleController.formatPluralString("Photos", selectedPhotos.size()).toUpperCase());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openPhotoViewer(MediaController.PhotoEntry entry, final boolean sameTakePictureOrientation, boolean external) {
|
|
|
|
if (entry != null) {
|
|
|
|
cameraPhotos.add(entry);
|
|
|
|
selectedPhotos.put(entry.imageId, entry);
|
|
|
|
selectedPhotosOrder.add(entry.imageId);
|
|
|
|
updatePhotosButton();
|
|
|
|
photoAttachAdapter.notifyDataSetChanged();
|
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (entry != null && !external && cameraPhotos.size() > 1) {
|
|
|
|
updatePhotosCounter();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (cameraView != null) {
|
|
|
|
CameraController.getInstance().startPreview(cameraView.getCameraSession());
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
mediaCaptured = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cameraPhotos.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cancelTakingPhotos = true;
|
|
|
|
PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
|
|
|
|
PhotoViewer.getInstance().setParentAlert(ChatAttachAlert.this);
|
|
|
|
PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos);
|
|
|
|
|
|
|
|
ChatActivity chatActivity;
|
|
|
|
int type;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
chatActivity = (ChatActivity) baseFragment;
|
|
|
|
type = 2;
|
|
|
|
} else {
|
|
|
|
chatActivity = null;
|
|
|
|
type = 5;
|
|
|
|
}
|
|
|
|
PhotoViewer.getInstance().openPhotoForSelect(getAllPhotosArray(), cameraPhotos.size() - 1, type, new BasePhotoProvider() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean cancelButtonPressed() {
|
|
|
|
if (cameraOpened && cameraView != null) {
|
2018-08-27 10:33:11 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (cameraView != null && !isDismissed() && Build.VERSION.SDK_INT >= 21) {
|
|
|
|
cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
CameraController.getInstance().startPreview(cameraView.getCameraSession());
|
|
|
|
}
|
|
|
|
if (cancelTakingPhotos && cameraPhotos.size() == 1) {
|
|
|
|
for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(a);
|
|
|
|
new File(photoEntry.path).delete();
|
|
|
|
if (photoEntry.imagePath != null) {
|
|
|
|
new File(photoEntry.imagePath).delete();
|
|
|
|
}
|
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
new File(photoEntry.thumbPath).delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cameraPhotos.clear();
|
|
|
|
selectedPhotosOrder.clear();
|
|
|
|
selectedPhotos.clear();
|
|
|
|
counterTextView.setVisibility(View.INVISIBLE);
|
|
|
|
cameraPhotoRecyclerView.setVisibility(View.GONE);
|
|
|
|
photoAttachAdapter.notifyDataSetChanged();
|
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
|
|
|
updatePhotosButton();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void needAddMorePhotos() {
|
|
|
|
cancelTakingPhotos = false;
|
|
|
|
if (mediaFromExternalCamera) {
|
|
|
|
delegate.didPressedButton(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!cameraOpened) {
|
|
|
|
openCamera(false);
|
|
|
|
}
|
|
|
|
counterTextView.setVisibility(View.VISIBLE);
|
|
|
|
cameraPhotoRecyclerView.setVisibility(View.VISIBLE);
|
|
|
|
counterTextView.setAlpha(1.0f);
|
|
|
|
updatePhotosCounter();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
|
|
|
|
if (cameraPhotos.isEmpty() || baseFragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (videoEditedInfo != null && index >= 0 && index < cameraPhotos.size()) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(index);
|
|
|
|
photoEntry.editedInfo = videoEditedInfo;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!(baseFragment instanceof ChatActivity) || !((ChatActivity) baseFragment).isSecretChat()) {
|
|
|
|
for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
|
|
|
|
AndroidUtilities.addMediaToGallery(((MediaController.PhotoEntry) cameraPhotos.get(a)).path);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
delegate.didPressedButton(8);
|
|
|
|
cameraPhotos.clear();
|
|
|
|
selectedPhotosOrder.clear();
|
|
|
|
selectedPhotos.clear();
|
|
|
|
photoAttachAdapter.notifyDataSetChanged();
|
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
|
|
|
closeCamera(false);
|
|
|
|
dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean scaleToFill() {
|
|
|
|
if (baseFragment == null || baseFragment.getParentActivity() == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int locked = Settings.System.getInt(baseFragment.getParentActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
|
|
|
|
return sameTakePictureOrientation || locked == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
mediaCaptured = false;
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
|
|
|
cell.showImage();
|
|
|
|
cell.showCheck(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canScrollAway() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canCaptureMorePhotos() {
|
|
|
|
return maxSelectedPhotos != 1;
|
|
|
|
}
|
|
|
|
}, chatActivity);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean processTouchEvent(MotionEvent event) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (event == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (!pressed && event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
|
|
|
|
if (!takingPhoto) {
|
|
|
|
pressed = true;
|
|
|
|
maybeStartDraging = true;
|
|
|
|
lastY = event.getY();
|
|
|
|
}
|
|
|
|
} else if (pressed) {
|
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
|
|
|
float newY = event.getY();
|
|
|
|
float dy = (newY - lastY);
|
|
|
|
if (maybeStartDraging) {
|
|
|
|
if (Math.abs(dy) > AndroidUtilities.getPixelsInCM(0.4f, false)) {
|
|
|
|
maybeStartDraging = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
dragging = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (dragging) {
|
|
|
|
if (cameraView != null) {
|
|
|
|
cameraView.setTranslationY(cameraView.getTranslationY() + dy);
|
|
|
|
lastY = newY;
|
|
|
|
if (cameraPanel.getTag() == null) {
|
|
|
|
cameraPanel.setTag(1);
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(cameraPanel, "alpha", 0.0f),
|
2018-07-30 04:07:02 +02:00
|
|
|
ObjectAnimator.ofFloat(counterTextView, "alpha", 0.0f),
|
2017-03-31 01:58:05 +02:00
|
|
|
ObjectAnimator.ofFloat(flashModeButton[0], "alpha", 0.0f),
|
2018-07-30 04:07:02 +02:00
|
|
|
ObjectAnimator.ofFloat(flashModeButton[1], "alpha", 0.0f),
|
|
|
|
ObjectAnimator.ofFloat(cameraPhotoRecyclerView, "alpha", 0.0f));
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL || event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
|
|
|
|
pressed = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (dragging) {
|
|
|
|
dragging = false;
|
|
|
|
if (cameraView != null) {
|
|
|
|
if (Math.abs(cameraView.getTranslationY()) > cameraView.getMeasuredHeight() / 6.0f) {
|
|
|
|
closeCamera(true);
|
|
|
|
} else {
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(cameraView, "translationY", 0.0f),
|
|
|
|
ObjectAnimator.ofFloat(cameraPanel, "alpha", 1.0f),
|
2018-07-30 04:07:02 +02:00
|
|
|
ObjectAnimator.ofFloat(counterTextView, "alpha", 1.0f),
|
2017-03-31 01:58:05 +02:00
|
|
|
ObjectAnimator.ofFloat(flashModeButton[0], "alpha", 1.0f),
|
2018-07-30 04:07:02 +02:00
|
|
|
ObjectAnimator.ofFloat(flashModeButton[1], "alpha", 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(cameraPhotoRecyclerView, "alpha", 1.0f));
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.setDuration(250);
|
|
|
|
animatorSet.setInterpolator(interpolator);
|
|
|
|
animatorSet.start();
|
|
|
|
cameraPanel.setTag(null);
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (cameraView != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
cameraView.getLocationOnScreen(viewPosition);
|
|
|
|
float viewX = event.getRawX() - viewPosition[0];
|
|
|
|
float viewY = event.getRawY() - viewPosition[1];
|
|
|
|
cameraView.focusToPoint((int) viewX, (int) viewY);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onContainerTouchEvent(MotionEvent event) {
|
|
|
|
return cameraOpened && processTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void checkColors() {
|
|
|
|
for (int a = 0, count = attachButtons.size(); a < count; a++) {
|
|
|
|
attachButtons.get(a).textView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
|
|
|
|
}
|
|
|
|
lineView.setBackgroundColor(Theme.getColor(Theme.key_dialogGrayLine));
|
|
|
|
if (hintTextView != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
Theme.setDrawableColor(hintTextView.getBackground(), Theme.getColor(Theme.key_chat_gifSaveHintBackground));
|
2018-07-30 04:07:02 +02:00
|
|
|
hintTextView.setTextColor(Theme.getColor(Theme.key_chat_gifSaveHintText));
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (mediaBanTooltip != null) {
|
|
|
|
Theme.setDrawableColor(mediaBanTooltip.getBackground(), Theme.getColor(Theme.key_chat_attachMediaBanBackground));
|
|
|
|
mediaBanTooltip.setTextColor(Theme.getColor(Theme.key_chat_attachMediaBanText));
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (listView != null) {
|
|
|
|
listView.setGlowColor(Theme.getColor(Theme.key_dialogScrollGlow));
|
|
|
|
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(1);
|
|
|
|
if (holder != null) {
|
|
|
|
holder.itemView.setBackgroundColor(Theme.getColor(Theme.key_dialogBackgroundGray));
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
|
|
|
adapter.notifyItemChanged(1);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ciclePaint != null) {
|
|
|
|
ciclePaint.setColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
}
|
|
|
|
Theme.setDrawableColor(shadowDrawable, Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
if (cameraImageView != null) {
|
|
|
|
cameraImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogCameraIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
}
|
|
|
|
if (attachPhotoRecyclerView != null) {
|
|
|
|
RecyclerView.ViewHolder holder = attachPhotoRecyclerView.findViewHolderForAdapterPosition(0);
|
|
|
|
if (holder != null && holder.itemView instanceof PhotoAttachCameraCell) {
|
|
|
|
((PhotoAttachCameraCell) holder.itemView).getImageView().setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogCameraIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
containerView.invalidate();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void resetRecordState() {
|
|
|
|
if (baseFragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
flashModeButton[a].setAlpha(1.0f);
|
|
|
|
}
|
|
|
|
switchCameraButton.setAlpha(1.0f);
|
|
|
|
recordTime.setAlpha(0.0f);
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(videoRecordRunnable);
|
|
|
|
videoRecordRunnable = null;
|
|
|
|
AndroidUtilities.unlockOrientation(baseFragment.getParentActivity());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setCameraFlashModeIcon(ImageView imageView, String mode) {
|
|
|
|
switch (mode) {
|
|
|
|
case Camera.Parameters.FLASH_MODE_OFF:
|
|
|
|
imageView.setImageResource(R.drawable.flash_off);
|
2019-05-14 14:08:05 +02:00
|
|
|
imageView.setContentDescription(LocaleController.getString("AccDescrCameraFlashOff", R.string.AccDescrCameraFlashOff));
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case Camera.Parameters.FLASH_MODE_ON:
|
|
|
|
imageView.setImageResource(R.drawable.flash_on);
|
2019-05-14 14:08:05 +02:00
|
|
|
imageView.setContentDescription(LocaleController.getString("AccDescrCameraFlashOn", R.string.AccDescrCameraFlashOn));
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case Camera.Parameters.FLASH_MODE_AUTO:
|
|
|
|
imageView.setImageResource(R.drawable.flash_auto);
|
2019-05-14 14:08:05 +02:00
|
|
|
imageView.setContentDescription(LocaleController.getString("AccDescrCameraFlashAuto", R.string.AccDescrCameraFlashAuto));
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onCustomMeasure(View view, int width, int height) {
|
|
|
|
boolean isPortrait = width < height;
|
|
|
|
if (view == cameraView) {
|
|
|
|
if (cameraOpened && !cameraAnimationInProgress) {
|
|
|
|
cameraView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (view == cameraPanel) {
|
|
|
|
if (isPortrait) {
|
|
|
|
cameraPanel.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), View.MeasureSpec.EXACTLY));
|
|
|
|
} else {
|
|
|
|
cameraPanel.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
return true;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (view == cameraPhotoRecyclerView) {
|
|
|
|
cameraPhotoRecyclerViewIgnoreLayout = true;
|
|
|
|
if (isPortrait) {
|
|
|
|
cameraPhotoRecyclerView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), View.MeasureSpec.EXACTLY));
|
|
|
|
if (cameraPhotoLayoutManager.getOrientation() != LinearLayoutManager.HORIZONTAL) {
|
|
|
|
cameraPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
|
|
|
|
cameraPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cameraPhotoRecyclerView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
|
|
|
|
if (cameraPhotoLayoutManager.getOrientation() != LinearLayoutManager.VERTICAL) {
|
|
|
|
cameraPhotoRecyclerView.setPadding(0, AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8));
|
|
|
|
cameraPhotoLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cameraPhotoRecyclerViewIgnoreLayout = false;
|
|
|
|
return true;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onCustomLayout(View view, int left, int top, int right, int bottom) {
|
|
|
|
int width = (right - left);
|
|
|
|
int height = (bottom - top);
|
|
|
|
boolean isPortrait = width < height;
|
|
|
|
if (view == cameraPanel) {
|
|
|
|
if (isPortrait) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (cameraPhotoRecyclerView.getVisibility() == View.VISIBLE) {
|
|
|
|
cameraPanel.layout(0, bottom - AndroidUtilities.dp(100 + 96), width, bottom - AndroidUtilities.dp(96));
|
|
|
|
} else {
|
|
|
|
cameraPanel.layout(0, bottom - AndroidUtilities.dp(100), width, bottom);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (cameraPhotoRecyclerView.getVisibility() == View.VISIBLE) {
|
|
|
|
cameraPanel.layout(right - AndroidUtilities.dp(100 + 96), 0, right - AndroidUtilities.dp(96), height);
|
|
|
|
} else {
|
|
|
|
cameraPanel.layout(right - AndroidUtilities.dp(100), 0, right, height);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
return true;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (view == counterTextView) {
|
|
|
|
int cx;
|
|
|
|
int cy;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (isPortrait) {
|
2018-07-30 04:07:02 +02:00
|
|
|
cx = (width - counterTextView.getMeasuredWidth()) / 2;
|
|
|
|
cy = bottom - AndroidUtilities.dp(100 + 16 + 38);
|
|
|
|
counterTextView.setRotation(0);
|
|
|
|
if (cameraPhotoRecyclerView.getVisibility() == View.VISIBLE) {
|
|
|
|
cy -= AndroidUtilities.dp(96);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
cx = right - AndroidUtilities.dp(100 + 16 + 38);
|
|
|
|
cy = height / 2 + counterTextView.getMeasuredWidth() / 2;
|
|
|
|
counterTextView.setRotation(-90);
|
|
|
|
if (cameraPhotoRecyclerView.getVisibility() == View.VISIBLE) {
|
|
|
|
cx -= AndroidUtilities.dp(96);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
counterTextView.layout(cx, cy, cx + counterTextView.getMeasuredWidth(), cy + counterTextView.getMeasuredHeight());
|
|
|
|
return true;
|
|
|
|
} else if (view == cameraPhotoRecyclerView) {
|
|
|
|
if (isPortrait) {
|
|
|
|
int cy = height - AndroidUtilities.dp(88);
|
|
|
|
view.layout(0, cy, view.getMeasuredWidth(), cy + view.getMeasuredHeight());
|
|
|
|
} else {
|
|
|
|
int cx = left + width - AndroidUtilities.dp(88);
|
|
|
|
view.layout(cx, 0, cx + view.getMeasuredWidth(), view.getMeasuredHeight());
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void hideHint() {
|
|
|
|
if (hideHintRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(hideHintRunnable);
|
|
|
|
hideHintRunnable = null;
|
|
|
|
}
|
|
|
|
if (hintTextView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
currentHintAnimation = new AnimatorSet();
|
2016-05-25 23:49:47 +02:00
|
|
|
currentHintAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(hintTextView, "alpha", 0.0f)
|
2016-05-25 23:49:47 +02:00
|
|
|
);
|
|
|
|
currentHintAnimation.setInterpolator(decelerateInterpolator);
|
2017-03-31 01:58:05 +02:00
|
|
|
currentHintAnimation.addListener(new AnimatorListenerAdapter() {
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2016-05-25 23:49:47 +02:00
|
|
|
if (currentHintAnimation == null || !currentHintAnimation.equals(animation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentHintAnimation = null;
|
|
|
|
if (hintTextView != null) {
|
|
|
|
hintTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationCancel(Animator animation) {
|
2016-05-25 23:49:47 +02:00
|
|
|
if (currentHintAnimation != null && currentHintAnimation.equals(animation)) {
|
|
|
|
currentHintAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
currentHintAnimation.setDuration(300);
|
|
|
|
currentHintAnimation.start();
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void onPause() {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (shutterButton == null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (!requestingPermissions) {
|
|
|
|
if (cameraView != null && shutterButton.getState() == ShutterButton.State.RECORDING) {
|
|
|
|
resetRecordState();
|
|
|
|
CameraController.getInstance().stopVideoRecording(cameraView.getCameraSession(), false);
|
|
|
|
shutterButton.setState(ShutterButton.State.DEFAULT, true);
|
|
|
|
}
|
|
|
|
if (cameraOpened) {
|
|
|
|
closeCamera(false);
|
|
|
|
}
|
|
|
|
hideCamera(true);
|
|
|
|
} else {
|
|
|
|
if (cameraView != null && shutterButton.getState() == ShutterButton.State.RECORDING) {
|
|
|
|
shutterButton.setState(ShutterButton.State.DEFAULT, true);
|
|
|
|
}
|
|
|
|
requestingPermissions = false;
|
|
|
|
}
|
|
|
|
paused = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onResume() {
|
|
|
|
paused = false;
|
|
|
|
if (isShowing() && !isDismissed()) {
|
|
|
|
checkCamera(false);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void openCamera(boolean animated) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (cameraView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (cameraPhotos.isEmpty()) {
|
|
|
|
counterTextView.setVisibility(View.INVISIBLE);
|
|
|
|
cameraPhotoRecyclerView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
counterTextView.setVisibility(View.VISIBLE);
|
|
|
|
cameraPhotoRecyclerView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
cameraPanel.setVisibility(View.VISIBLE);
|
|
|
|
cameraPanel.setTag(null);
|
2016-10-11 13:57:01 +02:00
|
|
|
animateCameraValues[0] = 0;
|
|
|
|
animateCameraValues[1] = AndroidUtilities.dp(80) - cameraViewOffsetX;
|
|
|
|
animateCameraValues[2] = AndroidUtilities.dp(80) - cameraViewOffsetY;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (animated) {
|
|
|
|
cameraAnimationInProgress = true;
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
|
|
|
animators.add(ObjectAnimator.ofFloat(ChatAttachAlert.this, "cameraOpenProgress", 0.0f, 1.0f));
|
2019-05-14 14:08:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(cameraPanel, View.ALPHA, 1.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(counterTextView, View.ALPHA, 1.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(cameraPhotoRecyclerView, View.ALPHA, 1.0f));
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
if (flashModeButton[a].getVisibility() == View.VISIBLE) {
|
2019-05-14 14:08:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(flashModeButton[a], View.ALPHA, 1.0f));
|
2018-07-30 04:07:02 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
cameraAnimationInProgress = false;
|
|
|
|
if (cameraOpened) {
|
|
|
|
delegate.onCameraOpened();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
|
|
|
setCameraOpenProgress(1.0f);
|
|
|
|
cameraPanel.setAlpha(1.0f);
|
|
|
|
counterTextView.setAlpha(1.0f);
|
|
|
|
cameraPhotoRecyclerView.setAlpha(1.0f);
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
if (flashModeButton[a].getVisibility() == View.VISIBLE) {
|
|
|
|
flashModeButton[a].setAlpha(1.0f);
|
|
|
|
break;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
delegate.onCameraOpened();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|
|
|
}
|
|
|
|
cameraOpened = true;
|
2019-05-14 14:08:05 +02:00
|
|
|
cameraView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
|
if (Build.VERSION.SDK_INT >= 19) {
|
|
|
|
attachPhotoRecyclerView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
|
|
|
|
for (AttachButton button : attachButtons) {
|
|
|
|
button.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void onActivityResultFragment(int requestCode, Intent data, String currentPicturePath) {
|
|
|
|
if (baseFragment == null || baseFragment.getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mediaFromExternalCamera = true;
|
|
|
|
if (requestCode == 0) {
|
|
|
|
PhotoViewer.getInstance().setParentActivity(baseFragment.getParentActivity());
|
|
|
|
PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos);
|
|
|
|
final ArrayList<Object> arrayList = new ArrayList<>();
|
|
|
|
int orientation = 0;
|
|
|
|
try {
|
|
|
|
ExifInterface ei = new ExifInterface(currentPicturePath);
|
|
|
|
int exif = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
|
|
|
|
switch (exif) {
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_90:
|
|
|
|
orientation = 90;
|
|
|
|
break;
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_180:
|
|
|
|
orientation = 180;
|
|
|
|
break;
|
|
|
|
case ExifInterface.ORIENTATION_ROTATE_270:
|
|
|
|
orientation = 270;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
MediaController.PhotoEntry photoEntry = new MediaController.PhotoEntry(0, lastImageId--, 0, currentPicturePath, orientation, false);
|
|
|
|
photoEntry.canDeleteAfter = true;
|
|
|
|
openPhotoViewer(photoEntry, false, true);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (requestCode == 2) {
|
|
|
|
String videoPath = null;
|
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("pic path " + currentPicturePath);
|
|
|
|
}
|
|
|
|
if (data != null && currentPicturePath != null) {
|
|
|
|
if (new File(currentPicturePath).exists()) {
|
|
|
|
data = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data != null) {
|
|
|
|
Uri uri = data.getData();
|
|
|
|
if (uri != null) {
|
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("video record uri " + uri.toString());
|
|
|
|
}
|
|
|
|
videoPath = AndroidUtilities.getPath(uri);
|
|
|
|
if (BuildVars.LOGS_ENABLED) {
|
|
|
|
FileLog.d("resolved path = " + videoPath);
|
|
|
|
}
|
|
|
|
if (videoPath == null || !(new File(videoPath).exists())) {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!(baseFragment instanceof ChatActivity) || !((ChatActivity) baseFragment).isSecretChat()) {
|
|
|
|
AndroidUtilities.addMediaToGallery(currentPicturePath);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
currentPicturePath = null;
|
|
|
|
}
|
|
|
|
if (videoPath == null && currentPicturePath != null) {
|
|
|
|
File f = new File(currentPicturePath);
|
|
|
|
if (f.exists()) {
|
|
|
|
videoPath = currentPicturePath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaMetadataRetriever mediaMetadataRetriever = null;
|
|
|
|
long duration = 0;
|
|
|
|
try {
|
|
|
|
mediaMetadataRetriever = new MediaMetadataRetriever();
|
|
|
|
mediaMetadataRetriever.setDataSource(videoPath);
|
|
|
|
String d = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
|
|
|
if (d != null) {
|
|
|
|
duration = (int) Math.ceil(Long.parseLong(d) / 1000.0f);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (mediaMetadataRetriever != null) {
|
|
|
|
mediaMetadataRetriever.release();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MINI_KIND);
|
|
|
|
String fileName = Integer.MIN_VALUE + "_" + SharedConfig.getLastLocalId() + ".jpg";
|
|
|
|
final File cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
|
|
|
try {
|
|
|
|
FileOutputStream stream = new FileOutputStream(cacheFile);
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 55, stream);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
SharedConfig.saveConfig();
|
|
|
|
|
|
|
|
MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, lastImageId--, 0, videoPath, 0, true);
|
|
|
|
entry.duration = (int) duration;
|
|
|
|
entry.thumbPath = cacheFile.getAbsolutePath();
|
|
|
|
openPhotoViewer(entry, false, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void closeCamera(boolean animated) {
|
|
|
|
if (takingPhoto || cameraView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
animateCameraValues[1] = AndroidUtilities.dp(80) - cameraViewOffsetX;
|
|
|
|
animateCameraValues[2] = AndroidUtilities.dp(80) - cameraViewOffsetY;
|
|
|
|
if (animated) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) cameraView.getLayoutParams();
|
|
|
|
animateCameraValues[0] = layoutParams.topMargin = (int) cameraView.getTranslationY();
|
|
|
|
cameraView.setLayoutParams(layoutParams);
|
|
|
|
cameraView.setTranslationY(0);
|
|
|
|
|
|
|
|
cameraAnimationInProgress = true;
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
|
|
|
animators.add(ObjectAnimator.ofFloat(ChatAttachAlert.this, "cameraOpenProgress", 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(cameraPanel, "alpha", 0.0f));
|
2018-07-30 04:07:02 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(counterTextView, "alpha", 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(cameraPhotoRecyclerView, "alpha", 0.0f));
|
2016-10-11 13:57:01 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
if (flashModeButton[a].getVisibility() == View.VISIBLE) {
|
|
|
|
animators.add(ObjectAnimator.ofFloat(flashModeButton[a], "alpha", 0.0f));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animator) {
|
|
|
|
cameraAnimationInProgress = false;
|
|
|
|
cameraOpened = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (cameraPanel != null) {
|
|
|
|
cameraPanel.setVisibility(View.GONE);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (cameraPhotoRecyclerView != null) {
|
|
|
|
cameraPhotoRecyclerView.setVisibility(View.GONE);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21 && cameraView != null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
|
|
|
animateCameraValues[0] = 0;
|
|
|
|
setCameraOpenProgress(0);
|
|
|
|
cameraPanel.setAlpha(0);
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraPhotoRecyclerView.setAlpha(0);
|
|
|
|
counterTextView.setAlpha(0);
|
2016-10-11 13:57:01 +02:00
|
|
|
cameraPanel.setVisibility(View.GONE);
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraPhotoRecyclerView.setVisibility(View.GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
if (flashModeButton[a].getVisibility() == View.VISIBLE) {
|
|
|
|
flashModeButton[a].setAlpha(0.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cameraOpened = false;
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
cameraView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
|
|
|
|
if (Build.VERSION.SDK_INT >= 19) {
|
|
|
|
attachPhotoRecyclerView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
|
|
|
|
for (AttachButton button : attachButtons) {
|
|
|
|
button.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
2016-10-11 13:57:01 +02:00
|
|
|
public void setCameraOpenProgress(float value) {
|
|
|
|
if (cameraView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cameraOpenProgress = value;
|
|
|
|
float startWidth = animateCameraValues[1];
|
|
|
|
float startHeight = animateCameraValues[2];
|
|
|
|
boolean isPortrait = AndroidUtilities.displaySize.x < AndroidUtilities.displaySize.y;
|
|
|
|
float endWidth;
|
|
|
|
float endHeight;
|
|
|
|
if (isPortrait) {
|
2019-05-14 14:08:05 +02:00
|
|
|
endWidth = container.getWidth() - getLeftInset() - getRightInset();
|
|
|
|
endHeight = container.getHeight();
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
endWidth = container.getWidth() - getLeftInset() - getRightInset();
|
2016-10-11 13:57:01 +02:00
|
|
|
endHeight = container.getHeight();
|
|
|
|
}
|
|
|
|
if (value == 0) {
|
|
|
|
cameraView.setClipLeft(cameraViewOffsetX);
|
|
|
|
cameraView.setClipTop(cameraViewOffsetY);
|
|
|
|
cameraView.setTranslationX(cameraViewLocation[0]);
|
|
|
|
cameraView.setTranslationY(cameraViewLocation[1]);
|
|
|
|
cameraIcon.setTranslationX(cameraViewLocation[0]);
|
|
|
|
cameraIcon.setTranslationY(cameraViewLocation[1]);
|
|
|
|
} else if (cameraView.getTranslationX() != 0 || cameraView.getTranslationY() != 0) {
|
|
|
|
cameraView.setTranslationX(0);
|
|
|
|
cameraView.setTranslationY(0);
|
|
|
|
}
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) cameraView.getLayoutParams();
|
|
|
|
layoutParams.width = (int) (startWidth + (endWidth - startWidth) * value);
|
|
|
|
layoutParams.height = (int) (startHeight + (endHeight - startHeight) * value);
|
|
|
|
if (value != 0) {
|
|
|
|
cameraView.setClipLeft((int) (cameraViewOffsetX * (1.0f - value)));
|
|
|
|
cameraView.setClipTop((int) (cameraViewOffsetY * (1.0f - value)));
|
|
|
|
layoutParams.leftMargin = (int) (cameraViewLocation[0] * (1.0f - value));
|
|
|
|
layoutParams.topMargin = (int) (animateCameraValues[0] + (cameraViewLocation[1] - animateCameraValues[0]) * (1.0f - value));
|
|
|
|
} else {
|
|
|
|
layoutParams.leftMargin = 0;
|
|
|
|
layoutParams.topMargin = 0;
|
|
|
|
}
|
|
|
|
cameraView.setLayoutParams(layoutParams);
|
|
|
|
if (value <= 0.5f) {
|
|
|
|
cameraIcon.setAlpha(1.0f - value / 0.5f);
|
|
|
|
} else {
|
|
|
|
cameraIcon.setAlpha(0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
2016-10-11 13:57:01 +02:00
|
|
|
public float getCameraOpenProgress() {
|
|
|
|
return cameraOpenProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkCameraViewPosition() {
|
|
|
|
if (!deviceHasGoodCamera) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (child instanceof PhotoAttachCameraCell) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 19) {
|
|
|
|
if (!child.isAttachedToWindow()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
child.getLocationInWindow(cameraViewLocation);
|
2017-03-31 01:58:05 +02:00
|
|
|
cameraViewLocation[0] -= getLeftInset();
|
|
|
|
float listViewX = listView.getX() + backgroundPaddingLeft - getLeftInset();
|
2016-10-11 13:57:01 +02:00
|
|
|
if (cameraViewLocation[0] < listViewX) {
|
|
|
|
cameraViewOffsetX = (int) (listViewX - cameraViewLocation[0]);
|
|
|
|
if (cameraViewOffsetX >= AndroidUtilities.dp(80)) {
|
|
|
|
cameraViewOffsetX = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
cameraViewLocation[0] = AndroidUtilities.dp(-150);
|
2016-10-11 13:57:01 +02:00
|
|
|
cameraViewLocation[1] = 0;
|
|
|
|
} else {
|
|
|
|
cameraViewLocation[0] += cameraViewOffsetX;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cameraViewOffsetX = 0;
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && cameraViewLocation[1] < AndroidUtilities.statusBarHeight) {
|
|
|
|
cameraViewOffsetY = AndroidUtilities.statusBarHeight - cameraViewLocation[1];
|
|
|
|
if (cameraViewOffsetY >= AndroidUtilities.dp(80)) {
|
|
|
|
cameraViewOffsetY = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
cameraViewLocation[0] = AndroidUtilities.dp(-150);
|
2016-10-11 13:57:01 +02:00
|
|
|
cameraViewLocation[1] = 0;
|
|
|
|
} else {
|
|
|
|
cameraViewLocation[1] += cameraViewOffsetY;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cameraViewOffsetY = 0;
|
|
|
|
}
|
|
|
|
applyCameraViewPosition();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cameraViewOffsetX = 0;
|
|
|
|
cameraViewOffsetY = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
cameraViewLocation[0] = AndroidUtilities.dp(-150);
|
2016-10-11 13:57:01 +02:00
|
|
|
cameraViewLocation[1] = 0;
|
|
|
|
applyCameraViewPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyCameraViewPosition() {
|
|
|
|
if (cameraView != null) {
|
|
|
|
if (!cameraOpened) {
|
|
|
|
cameraView.setTranslationX(cameraViewLocation[0]);
|
|
|
|
cameraView.setTranslationY(cameraViewLocation[1]);
|
|
|
|
}
|
|
|
|
cameraIcon.setTranslationX(cameraViewLocation[0]);
|
|
|
|
cameraIcon.setTranslationY(cameraViewLocation[1]);
|
|
|
|
int finalWidth = AndroidUtilities.dp(80) - cameraViewOffsetX;
|
|
|
|
int finalHeight = AndroidUtilities.dp(80) - cameraViewOffsetY;
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams;
|
|
|
|
if (!cameraOpened) {
|
|
|
|
cameraView.setClipLeft(cameraViewOffsetX);
|
|
|
|
cameraView.setClipTop(cameraViewOffsetY);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) cameraView.getLayoutParams();
|
|
|
|
if (layoutParams.height != finalHeight || layoutParams.width != finalWidth) {
|
|
|
|
layoutParams.width = finalWidth;
|
|
|
|
layoutParams.height = finalHeight;
|
|
|
|
cameraView.setLayoutParams(layoutParams);
|
|
|
|
final FrameLayout.LayoutParams layoutParamsFinal = layoutParams;
|
2018-08-27 10:33:11 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (cameraView != null) {
|
|
|
|
cameraView.setLayoutParams(layoutParamsFinal);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) cameraIcon.getLayoutParams();
|
|
|
|
if (layoutParams.height != finalHeight || layoutParams.width != finalWidth) {
|
|
|
|
layoutParams.width = finalWidth;
|
|
|
|
layoutParams.height = finalHeight;
|
|
|
|
cameraIcon.setLayoutParams(layoutParams);
|
|
|
|
final FrameLayout.LayoutParams layoutParamsFinal = layoutParams;
|
2018-08-27 10:33:11 +02:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (cameraIcon != null) {
|
|
|
|
cameraIcon.setLayoutParams(layoutParamsFinal);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showCamera() {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (paused || !mediaEnabled) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (cameraView == null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraView = new CameraView(baseFragment.getParentActivity(), openWithFrontFaceCamera);
|
2019-05-14 14:08:05 +02:00
|
|
|
cameraView.setFocusable(true);
|
|
|
|
cameraView.setContentDescription(LocaleController.getString("AccDescrInstantCamera", R.string.AccDescrInstantCamera));
|
2016-10-11 13:57:01 +02:00
|
|
|
container.addView(cameraView, 1, LayoutHelper.createFrame(80, 80));
|
|
|
|
cameraView.setDelegate(new CameraView.CameraViewDelegate() {
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public void onCameraCreated(Camera camera) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void onCameraInit() {
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (child instanceof PhotoAttachCameraCell) {
|
|
|
|
child.setVisibility(View.INVISIBLE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String current = cameraView.getCameraSession().getCurrentFlashMode();
|
|
|
|
String next = cameraView.getCameraSession().getNextFlashMode();
|
|
|
|
if (current.equals(next)) {
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
flashModeButton[a].setVisibility(View.INVISIBLE);
|
|
|
|
flashModeButton[a].setAlpha(0.0f);
|
|
|
|
flashModeButton[a].setTranslationY(0.0f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setCameraFlashModeIcon(flashModeButton[0], cameraView.getCameraSession().getCurrentFlashMode());
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
flashModeButton[a].setVisibility(a == 0 ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
flashModeButton[a].setAlpha(a == 0 && cameraOpened ? 1.0f : 0.0f);
|
|
|
|
flashModeButton[a].setTranslationY(0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switchCameraButton.setImageResource(cameraView.isFrontface() ? R.drawable.camera_revert1 : R.drawable.camera_revert2);
|
|
|
|
switchCameraButton.setVisibility(cameraView.hasFrontFaceCamera() ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (cameraIcon == null) {
|
|
|
|
cameraIcon = new FrameLayout(baseFragment.getParentActivity());
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraImageView = new ImageView(baseFragment.getParentActivity());
|
|
|
|
cameraImageView.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
cameraImageView.setImageResource(R.drawable.instant_camera);
|
|
|
|
cameraImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogCameraIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
cameraIcon.addView(cameraImageView, LayoutHelper.createFrame(80, 80, Gravity.RIGHT | Gravity.BOTTOM));
|
|
|
|
}
|
|
|
|
container.addView(cameraIcon, 2, LayoutHelper.createFrame(80, 80));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
cameraView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
|
|
|
|
cameraView.setEnabled(mediaEnabled);
|
|
|
|
cameraIcon.setAlpha(mediaEnabled ? 1.0f : 0.2f);
|
|
|
|
cameraIcon.setEnabled(mediaEnabled);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
cameraView.setTranslationX(cameraViewLocation[0]);
|
|
|
|
cameraView.setTranslationY(cameraViewLocation[1]);
|
|
|
|
cameraIcon.setTranslationX(cameraViewLocation[0]);
|
|
|
|
cameraIcon.setTranslationY(cameraViewLocation[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideCamera(boolean async) {
|
|
|
|
if (!deviceHasGoodCamera || cameraView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
cameraView.destroy(async, null);
|
2016-10-11 13:57:01 +02:00
|
|
|
container.removeView(cameraView);
|
|
|
|
container.removeView(cameraIcon);
|
|
|
|
cameraView = null;
|
|
|
|
cameraIcon = null;
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (child instanceof PhotoAttachCameraCell) {
|
|
|
|
child.setVisibility(View.VISIBLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
private void showHint() {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (editingMessageObject != null || !(baseFragment instanceof ChatActivity) || MediaDataController.getInstance(currentAccount).inlineBots.isEmpty()) {
|
2016-05-25 23:49:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
2016-05-25 23:49:47 +02:00
|
|
|
if (preferences.getBoolean("bothint", false)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hintShowed = true;
|
|
|
|
|
|
|
|
hintTextView.setVisibility(View.VISIBLE);
|
2016-06-24 12:27:15 +02:00
|
|
|
currentHintAnimation = new AnimatorSet();
|
2016-05-25 23:49:47 +02:00
|
|
|
currentHintAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(hintTextView, "alpha", 0.0f, 1.0f)
|
2016-05-25 23:49:47 +02:00
|
|
|
);
|
|
|
|
currentHintAnimation.setInterpolator(decelerateInterpolator);
|
2017-03-31 01:58:05 +02:00
|
|
|
currentHintAnimation.addListener(new AnimatorListenerAdapter() {
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2016-05-25 23:49:47 +02:00
|
|
|
if (currentHintAnimation == null || !currentHintAnimation.equals(animation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentHintAnimation = null;
|
|
|
|
AndroidUtilities.runOnUIThread(hideHintRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (hideHintRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideHintRunnable = null;
|
|
|
|
hideHint();
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationCancel(Animator animation) {
|
2016-05-25 23:49:47 +02:00
|
|
|
if (currentHintAnimation != null && currentHintAnimation.equals(animation)) {
|
|
|
|
currentHintAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
currentHintAnimation.setDuration(300);
|
|
|
|
currentHintAnimation.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (id == NotificationCenter.albumsDidLoad) {
|
2016-05-25 23:49:47 +02:00
|
|
|
if (photoAttachAdapter != null) {
|
|
|
|
loading = false;
|
|
|
|
progressView.showTextView();
|
|
|
|
photoAttachAdapter.notifyDataSetChanged();
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
2019-05-14 14:08:05 +02:00
|
|
|
if (!selectedPhotosOrder.isEmpty()) {
|
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (albumEntry != null) {
|
|
|
|
for (int a = 0, N = selectedPhotosOrder.size(); a < N; a++) {
|
|
|
|
int imageId = (Integer) selectedPhotosOrder.get(a);
|
|
|
|
MediaController.PhotoEntry entry = albumEntry.photosByIds.get(imageId);
|
|
|
|
if (entry != null) {
|
|
|
|
selectedPhotos.put(imageId, entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.reloadInlineHints) {
|
|
|
|
if (adapter != null) {
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (id == NotificationCenter.cameraInitied) {
|
|
|
|
checkCamera(false);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
private void updateLayout() {
|
|
|
|
if (listView.getChildCount() <= 0) {
|
|
|
|
listView.setTopGlowOffset(scrollOffsetY = listView.getPaddingTop());
|
2016-10-11 13:57:01 +02:00
|
|
|
listView.invalidate();
|
2016-05-25 23:49:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
View child = listView.getChildAt(0);
|
2017-03-31 01:58:05 +02:00
|
|
|
RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.findContainingViewHolder(child);
|
2016-05-25 23:49:47 +02:00
|
|
|
int top = child.getTop();
|
|
|
|
int newOffset = 0;
|
|
|
|
if (top >= 0 && holder != null && holder.getAdapterPosition() == 0) {
|
|
|
|
newOffset = top;
|
|
|
|
}
|
|
|
|
if (scrollOffsetY != newOffset) {
|
|
|
|
listView.setTopGlowOffset(scrollOffsetY = newOffset);
|
2016-10-11 13:57:01 +02:00
|
|
|
listView.invalidate();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canDismissWithSwipe() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePhotosButton() {
|
2018-07-30 04:07:02 +02:00
|
|
|
int count = selectedPhotos.size();
|
2016-05-25 23:49:47 +02:00
|
|
|
if (count == 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
sendPhotosButton.imageView.setBackgroundDrawable(Theme.chat_attachButtonDrawables[7]);
|
2016-05-25 23:49:47 +02:00
|
|
|
sendPhotosButton.textView.setText("");
|
2019-05-14 14:08:05 +02:00
|
|
|
sendPhotosButton.textView.setContentDescription(LocaleController.getString("Close", R.string.Close));
|
2018-07-30 04:07:02 +02:00
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
sendDocumentsButton.textView.setText(LocaleController.getString("ChatDocument", R.string.ChatDocument));
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
sendPhotosButton.imageView.setBackgroundDrawable(Theme.chat_attachButtonDrawables[8]);
|
2019-05-14 14:08:05 +02:00
|
|
|
sendPhotosButton.textView.setContentDescription(null);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
sendPhotosButton.textView.setText(LocaleController.formatString("SendItems", R.string.SendItems, String.format("(%d)", count)));
|
|
|
|
if (editingMessageObject == null || !editingMessageObject.hasValidGroupId()) {
|
|
|
|
sendDocumentsButton.textView.setText(count == 1 ? LocaleController.getString("SendAsFile", R.string.SendAsFile) : LocaleController.getString("SendAsFiles", R.string.SendAsFiles));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendPhotosButton.textView.setText(LocaleController.formatString("UploadItems", R.string.UploadItems, String.format("(%d)", count)));
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 23 && getContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
progressView.setText(LocaleController.getString("PermissionStorage", R.string.PermissionStorage));
|
|
|
|
progressView.setTextSize(16);
|
|
|
|
} else {
|
|
|
|
progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
|
|
|
|
progressView.setTextSize(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(ChatAttachViewDelegate chatAttachViewDelegate) {
|
|
|
|
delegate = chatAttachViewDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadGalleryPhotos() {
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (albumEntry == null && Build.VERSION.SDK_INT >= 21) {
|
2016-05-25 23:49:47 +02:00
|
|
|
MediaController.loadGalleryPhotosAlbums(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void init() {
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (albumEntry != null) {
|
|
|
|
for (int a = 0; a < Math.min(100, albumEntry.photos.size()); a++) {
|
|
|
|
MediaController.PhotoEntry photoEntry = albumEntry.photos.get(a);
|
2017-07-23 14:56:38 +02:00
|
|
|
photoEntry.reset();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentHintAnimation != null) {
|
|
|
|
currentHintAnimation.cancel();
|
|
|
|
currentHintAnimation = null;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
hintTextView.setAlpha(0.0f);
|
2016-05-25 23:49:47 +02:00
|
|
|
hintTextView.setVisibility(View.INVISIBLE);
|
|
|
|
attachPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
|
2018-07-30 04:07:02 +02:00
|
|
|
cameraPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
|
|
|
|
clearSelectedPhotos();
|
2016-05-25 23:49:47 +02:00
|
|
|
layoutManager.scrollToPositionWithOffset(0, 1000000);
|
|
|
|
updatePhotosButton();
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public HashMap<Object, Object> getSelectedPhotos() {
|
2018-07-30 04:07:02 +02:00
|
|
|
return selectedPhotos;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<Object> getSelectedPhotosOrder() {
|
2018-07-30 04:07:02 +02:00
|
|
|
return selectedPhotosOrder;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDestroy() {
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.albumsDidLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.reloadInlineHints);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.cameraInitied);
|
2016-05-25 23:49:47 +02:00
|
|
|
baseFragment = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private PhotoAttachPhotoCell getCellForIndex(int index) {
|
|
|
|
int count = attachPhotoRecyclerView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = attachPhotoRecyclerView.getChildAt(a);
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
2018-07-30 04:07:02 +02:00
|
|
|
if ((Integer) cell.getImageView().getTag() == index) {
|
2016-05-25 23:49:47 +02:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onRevealAnimationEnd(boolean open) {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).setAnimationInProgress(false);
|
2016-05-25 23:49:47 +02:00
|
|
|
revealAnimationInProgress = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (open && Build.VERSION.SDK_INT <= 19 && albumEntry == null) {
|
2016-05-25 23:49:47 +02:00
|
|
|
MediaController.loadGalleryPhotosAlbums(0);
|
|
|
|
}
|
|
|
|
if (open) {
|
2016-10-11 13:57:01 +02:00
|
|
|
checkCamera(true);
|
2016-05-25 23:49:47 +02:00
|
|
|
showHint();
|
2019-05-14 14:08:05 +02:00
|
|
|
AndroidUtilities.makeAccessibilityAnnouncement(LocaleController.getString("AccDescrAttachButton", R.string.AccDescrAttachButton));
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void checkCamera(boolean request) {
|
|
|
|
if (baseFragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean old = deviceHasGoodCamera;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!SharedConfig.inappCamera) {
|
2017-12-08 18:35:59 +01:00
|
|
|
deviceHasGoodCamera = false;
|
|
|
|
} else {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
if (baseFragment.getParentActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (request) {
|
2018-07-30 04:07:02 +02:00
|
|
|
try {
|
|
|
|
baseFragment.getParentActivity().requestPermissions(new String[]{Manifest.permission.CAMERA}, 17);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
deviceHasGoodCamera = false;
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (request || SharedConfig.hasCameraCache) {
|
|
|
|
CameraController.getInstance().initCamera(null);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
deviceHasGoodCamera = CameraController.getInstance().isCameraInitied();
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (request || SharedConfig.hasCameraCache) {
|
|
|
|
CameraController.getInstance().initCamera(null);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
deviceHasGoodCamera = CameraController.getInstance().isCameraInitied();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (old != deviceHasGoodCamera && photoAttachAdapter != null) {
|
|
|
|
photoAttachAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (isShowing() && deviceHasGoodCamera && baseFragment != null && backDrawable.getAlpha() != 0 && !revealAnimationInProgress && !cameraOpened) {
|
2016-10-11 13:57:01 +02:00
|
|
|
showCamera();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
|
|
|
public void onOpenAnimationEnd() {
|
|
|
|
onRevealAnimationEnd(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOpenAnimationStart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean canDismiss() {
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public void setAllowDrawContent(boolean value) {
|
|
|
|
super.setAllowDrawContent(value);
|
|
|
|
checkCameraViewPosition();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
|
|
|
view = attachView;
|
|
|
|
break;
|
2017-07-08 18:32:04 +02:00
|
|
|
case 1: {
|
|
|
|
FrameLayout frameLayout = new FrameLayout(mContext);
|
|
|
|
frameLayout.addView(new ShadowSectionCell(mContext), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
view = frameLayout;
|
2016-05-25 23:49:47 +02:00
|
|
|
break;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
default:
|
|
|
|
FrameLayout frameLayout = new FrameLayout(mContext) {
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
int diff = (right - left - AndroidUtilities.dp(85 * 4 + 20)) / 3;
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
int x = AndroidUtilities.dp(10) + (a % 4) * (AndroidUtilities.dp(85) + diff);
|
|
|
|
View child = getChildAt(a);
|
|
|
|
child.layout(x, 0, x + child.getMeasuredWidth(), child.getMeasuredHeight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
frameLayout.addView(new AttachBotButton(mContext));
|
|
|
|
}
|
|
|
|
view = frameLayout;
|
|
|
|
frameLayout.setLayoutParams(new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, AndroidUtilities.dp(100)));
|
|
|
|
break;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (position == 1) {
|
|
|
|
holder.itemView.setBackgroundColor(Theme.getColor(Theme.key_dialogBackgroundGray));
|
|
|
|
} else if (position > 1) {
|
2016-05-25 23:49:47 +02:00
|
|
|
position -= 2;
|
|
|
|
position *= 4;
|
|
|
|
FrameLayout frameLayout = (FrameLayout) holder.itemView;
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
AttachBotButton child = (AttachBotButton) frameLayout.getChildAt(a);
|
2019-07-18 15:01:39 +02:00
|
|
|
if (position + a >= MediaDataController.getInstance(currentAccount).inlineBots.size()) {
|
2016-05-25 23:49:47 +02:00
|
|
|
child.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
|
|
|
child.setVisibility(View.VISIBLE);
|
|
|
|
child.setTag(position + a);
|
2019-07-18 15:01:39 +02:00
|
|
|
child.setUser(MessagesController.getInstance(currentAccount).getUser(MediaDataController.getInstance(currentAccount).inlineBots.get(position + a).peer.user_id));
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (editingMessageObject == null && baseFragment instanceof ChatActivity) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return 1 + (!MediaDataController.getInstance(currentAccount).inlineBots.isEmpty() ? 1 + (int) Math.ceil(MediaDataController.getInstance(currentAccount).inlineBots.size() / 4.0f) : 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
switch (position) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setMaxSelectedPhotos(int value) {
|
|
|
|
maxSelectedPhotos = value;
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setOpenWithFrontFaceCamera(boolean value) {
|
|
|
|
openWithFrontFaceCamera = value;
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int addToSelectedPhotos(MediaController.PhotoEntry object, int index) {
|
|
|
|
Object key = object.imageId;
|
|
|
|
if (selectedPhotos.containsKey(key)) {
|
|
|
|
selectedPhotos.remove(key);
|
|
|
|
int position = selectedPhotosOrder.indexOf(key);
|
|
|
|
if (position >= 0) {
|
|
|
|
selectedPhotosOrder.remove(position);
|
|
|
|
}
|
|
|
|
updatePhotosCounter();
|
|
|
|
updateCheckedPhotoIndices();
|
|
|
|
if (index >= 0) {
|
|
|
|
object.reset();
|
|
|
|
photoViewerProvider.updatePhotoAtIndex(index);
|
|
|
|
}
|
|
|
|
return position;
|
|
|
|
} else {
|
|
|
|
selectedPhotos.put(key, object);
|
|
|
|
selectedPhotosOrder.add(key);
|
|
|
|
updatePhotosCounter();
|
|
|
|
return -1;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void clearSelectedPhotos() {
|
|
|
|
boolean changed = false;
|
|
|
|
if (!selectedPhotos.isEmpty()) {
|
|
|
|
for (HashMap.Entry<Object, Object> entry : selectedPhotos.entrySet()) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry.getValue();
|
|
|
|
photoEntry.reset();
|
|
|
|
}
|
|
|
|
selectedPhotos.clear();
|
|
|
|
selectedPhotosOrder.clear();
|
|
|
|
updatePhotosButton();
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (!cameraPhotos.isEmpty()) {
|
|
|
|
for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(a);
|
|
|
|
new File(photoEntry.path).delete();
|
|
|
|
if (photoEntry.imagePath != null) {
|
|
|
|
new File(photoEntry.imagePath).delete();
|
|
|
|
}
|
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
new File(photoEntry.thumbPath).delete();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
cameraPhotos.clear();
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
photoAttachAdapter.notifyDataSetChanged();
|
|
|
|
cameraAttachAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class PhotoAttachAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
private boolean needCamera;
|
|
|
|
private ArrayList<RecyclerListView.Holder> viewsCache = new ArrayList<>(8);
|
|
|
|
|
|
|
|
public PhotoAttachAdapter(Context context, boolean camera) {
|
|
|
|
mContext = context;
|
|
|
|
needCamera = camera;
|
|
|
|
for (int a = 0; a < 8; a++) {
|
|
|
|
viewsCache.add(createHolder());
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public RecyclerListView.Holder createHolder() {
|
2016-05-25 23:49:47 +02:00
|
|
|
PhotoAttachPhotoCell cell = new PhotoAttachPhotoCell(mContext);
|
2018-08-27 10:33:11 +02:00
|
|
|
cell.setDelegate(v -> {
|
|
|
|
if (!mediaEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int index = (Integer) v.getTag();
|
|
|
|
MediaController.PhotoEntry photoEntry = v.getPhotoEntry();
|
|
|
|
boolean added = !selectedPhotos.containsKey(photoEntry.imageId);
|
|
|
|
if (added && maxSelectedPhotos >= 0 && selectedPhotos.size() >= maxSelectedPhotos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int num = added ? selectedPhotosOrder.size() : -1;
|
|
|
|
if (baseFragment instanceof ChatActivity && maxSelectedPhotos < 0) {
|
|
|
|
v.setChecked(num, added, true);
|
|
|
|
} else {
|
|
|
|
v.setChecked(-1, added, true);
|
|
|
|
}
|
|
|
|
addToSelectedPhotos(photoEntry, index);
|
|
|
|
int updateIndex = index;
|
|
|
|
if (PhotoAttachAdapter.this == cameraAttachAdapter) {
|
|
|
|
if (photoAttachAdapter.needCamera && deviceHasGoodCamera) {
|
|
|
|
updateIndex++;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
photoAttachAdapter.notifyItemChanged(updateIndex);
|
|
|
|
} else {
|
|
|
|
cameraAttachAdapter.notifyItemChanged(updateIndex);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
updatePhotosButton();
|
2016-05-25 23:49:47 +02:00
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(cell);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!needCamera || !deviceHasGoodCamera || position != 0) {
|
|
|
|
if (needCamera && deviceHasGoodCamera) {
|
2016-05-25 23:49:47 +02:00
|
|
|
position--;
|
|
|
|
}
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) holder.itemView;
|
2018-07-30 04:07:02 +02:00
|
|
|
MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition(position);
|
|
|
|
cell.setPhotoEntry(photoEntry, needCamera, position == getItemCount() - 1);
|
|
|
|
if (baseFragment instanceof ChatActivity && maxSelectedPhotos < 0) {
|
|
|
|
cell.setChecked(selectedPhotosOrder.indexOf(photoEntry.imageId), selectedPhotos.containsKey(photoEntry.imageId), false);
|
|
|
|
} else {
|
|
|
|
cell.setChecked(-1, selectedPhotos.containsKey(photoEntry.imageId), false);
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
cell.getImageView().setTag(position);
|
|
|
|
cell.setTag(position);
|
2018-07-30 04:07:02 +02:00
|
|
|
cell.setIsVertical(this == cameraAttachAdapter && cameraPhotoLayoutManager.getOrientation() == LinearLayoutManager.VERTICAL);
|
|
|
|
} else if (needCamera && deviceHasGoodCamera && position == 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (cameraView != null && cameraView.isInitied()) {
|
|
|
|
holder.itemView.setVisibility(View.INVISIBLE);
|
|
|
|
} else {
|
|
|
|
holder.itemView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2017-03-31 01:58:05 +02:00
|
|
|
RecyclerListView.Holder holder;
|
2016-05-25 23:49:47 +02:00
|
|
|
switch (viewType) {
|
|
|
|
case 1:
|
2017-03-31 01:58:05 +02:00
|
|
|
holder = new RecyclerListView.Holder(new PhotoAttachCameraCell(mContext));
|
2016-05-25 23:49:47 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!viewsCache.isEmpty()) {
|
|
|
|
holder = viewsCache.get(0);
|
|
|
|
viewsCache.remove(0);
|
|
|
|
} else {
|
|
|
|
holder = createHolder();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
int count = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (needCamera && deviceHasGoodCamera) {
|
2016-05-25 23:49:47 +02:00
|
|
|
count++;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
count += cameraPhotos.size();
|
|
|
|
MediaController.AlbumEntry albumEntry;
|
|
|
|
if (baseFragment instanceof ChatActivity) {
|
|
|
|
albumEntry = MediaController.allMediaAlbumEntry;
|
|
|
|
} else {
|
|
|
|
albumEntry = MediaController.allPhotosAlbumEntry;
|
|
|
|
}
|
|
|
|
if (albumEntry != null) {
|
|
|
|
count += albumEntry.photos.size();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (needCamera && deviceHasGoodCamera && position == 0) {
|
2016-05-25 23:49:47 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setUseRevealAnimation(boolean value) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!value || value && Build.VERSION.SDK_INT >= 18 && !AndroidUtilities.isTablet() && AndroidUtilities.shouldEnableAnimation() && baseFragment instanceof ChatActivity) {
|
2016-05-25 23:49:47 +02:00
|
|
|
useRevealAnimation = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
2016-05-25 23:49:47 +02:00
|
|
|
@SuppressLint("NewApi")
|
|
|
|
protected void setRevealRadius(float radius) {
|
|
|
|
revealRadius = radius;
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
2016-10-11 13:57:01 +02:00
|
|
|
listView.invalidate();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
if (!isDismissed()) {
|
|
|
|
for (int a = 0; a < innerAnimators.size(); a++) {
|
|
|
|
InnerAnimator innerAnimator = innerAnimators.get(a);
|
|
|
|
if (innerAnimator.startRadius > radius) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
innerAnimator.animatorSet.start();
|
|
|
|
innerAnimators.remove(a);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
2016-05-25 23:49:47 +02:00
|
|
|
protected float getRevealRadius() {
|
|
|
|
return revealRadius;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
private void startRevealAnimation(final boolean open) {
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setTranslationY(0);
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
final AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
|
|
|
|
View view = delegate.getRevealView();
|
|
|
|
if (view.getVisibility() == View.VISIBLE && ((ViewGroup) view.getParent()).getVisibility() == View.VISIBLE) {
|
2019-05-14 14:08:05 +02:00
|
|
|
final int[] coords = new int[2];
|
2016-05-25 23:49:47 +02:00
|
|
|
view.getLocationInWindow(coords);
|
|
|
|
float top;
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
top = AndroidUtilities.displaySize.y - containerView.getMeasuredHeight() - AndroidUtilities.statusBarHeight;
|
|
|
|
} else {
|
|
|
|
top = containerView.getY();
|
|
|
|
}
|
|
|
|
revealX = coords[0] + view.getMeasuredWidth() / 2;
|
|
|
|
revealY = (int) (coords[1] + view.getMeasuredHeight() / 2 - top);
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
revealY -= AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
revealX = AndroidUtilities.displaySize.x / 2 + backgroundPaddingLeft;
|
|
|
|
revealY = (int) (AndroidUtilities.displaySize.y - containerView.getY());
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
int[][] corners = new int[][]{
|
2016-05-25 23:49:47 +02:00
|
|
|
{0, 0},
|
|
|
|
{0, AndroidUtilities.dp(304)},
|
|
|
|
{containerView.getMeasuredWidth(), 0},
|
|
|
|
{containerView.getMeasuredWidth(), AndroidUtilities.dp(304)}
|
|
|
|
};
|
|
|
|
int finalRevealRadius = 0;
|
|
|
|
int y = revealY - scrollOffsetY + backgroundPaddingTop;
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
finalRevealRadius = Math.max(finalRevealRadius, (int) Math.ceil(Math.sqrt((revealX - corners[a][0]) * (revealX - corners[a][0]) + (y - corners[a][1]) * (y - corners[a][1]))));
|
|
|
|
}
|
|
|
|
int finalRevealX = revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth();
|
|
|
|
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>(3);
|
|
|
|
animators.add(ObjectAnimator.ofFloat(this, "revealRadius", open ? 0 : finalRevealRadius, open ? finalRevealRadius : 0));
|
|
|
|
animators.add(ObjectAnimator.ofInt(backDrawable, "alpha", open ? 51 : 0));
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
try {
|
|
|
|
animators.add(ViewAnimationUtils.createCircularReveal(containerView, finalRevealX, revealY, open ? 0 : finalRevealRadius, open ? finalRevealRadius : 0));
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
animatorSet.setDuration(320);
|
|
|
|
} else {
|
|
|
|
if (!open) {
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
containerView.setPivotX(revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth());
|
|
|
|
containerView.setPivotY(revealY);
|
2019-05-14 14:08:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(containerView, View.SCALE_X, 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(containerView, View.SCALE_Y, 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(containerView, View.ALPHA, 0.0f));
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
|
|
|
animatorSet.setDuration(250);
|
|
|
|
containerView.setScaleX(1);
|
|
|
|
containerView.setScaleY(1);
|
|
|
|
containerView.setAlpha(1);
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
animatorSet.setStartDelay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
|
|
|
|
currentSheetAnimation = null;
|
|
|
|
onRevealAnimationEnd(open);
|
|
|
|
containerView.invalidate();
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
2016-05-25 23:49:47 +02:00
|
|
|
if (!open) {
|
|
|
|
try {
|
|
|
|
dismissInternal();
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 512);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (currentSheetAnimation != null && animatorSet.equals(animation)) {
|
|
|
|
currentSheetAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (open) {
|
|
|
|
innerAnimators.clear();
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.dialogsNeedReload});
|
|
|
|
NotificationCenter.getInstance(currentAccount).setAnimationInProgress(true);
|
2016-05-25 23:49:47 +02:00
|
|
|
revealAnimationInProgress = true;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
int count = Build.VERSION.SDK_INT <= 19 ? 12 : 8;
|
2016-05-25 23:49:47 +02:00
|
|
|
for (int a = 0; a < count; a++) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (views[a] == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
if (a < 8) {
|
|
|
|
views[a].setScaleX(0.1f);
|
|
|
|
views[a].setScaleY(0.1f);
|
|
|
|
}
|
|
|
|
views[a].setAlpha(0.0f);
|
|
|
|
} else {
|
|
|
|
views[a].setScaleX(0.7f);
|
|
|
|
views[a].setScaleY(0.7f);
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerAnimator innerAnimator = new InnerAnimator();
|
|
|
|
|
|
|
|
int buttonX = views[a].getLeft() + views[a].getMeasuredWidth() / 2;
|
|
|
|
int buttonY = views[a].getTop() + attachView.getTop() + views[a].getMeasuredHeight() / 2;
|
|
|
|
float dist = (float) Math.sqrt((revealX - buttonX) * (revealX - buttonX) + (revealY - buttonY) * (revealY - buttonY));
|
|
|
|
float vecX = (revealX - buttonX) / dist;
|
|
|
|
float vecY = (revealY - buttonY) / dist;
|
|
|
|
views[a].setPivotX(views[a].getMeasuredWidth() / 2 + vecX * AndroidUtilities.dp(20));
|
|
|
|
views[a].setPivotY(views[a].getMeasuredHeight() / 2 + vecY * AndroidUtilities.dp(20));
|
|
|
|
innerAnimator.startRadius = dist - AndroidUtilities.dp(27 * 3);
|
|
|
|
|
|
|
|
views[a].setTag(R.string.AppName, 1);
|
|
|
|
animators = new ArrayList<>();
|
|
|
|
final AnimatorSet animatorSetInner;
|
|
|
|
if (a < 8) {
|
2019-05-14 14:08:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(views[a], View.SCALE_X, 0.7f, 1.05f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(views[a], View.SCALE_Y, 0.7f, 1.05f));
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
animatorSetInner = new AnimatorSet();
|
|
|
|
animatorSetInner.playTogether(
|
2019-05-14 14:08:05 +02:00
|
|
|
ObjectAnimator.ofFloat(views[a], View.SCALE_X, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(views[a], View.SCALE_Y, 1.0f));
|
2016-05-25 23:49:47 +02:00
|
|
|
animatorSetInner.setDuration(100);
|
2019-05-14 14:08:05 +02:00
|
|
|
animatorSetInner.setInterpolator(CubicBezierInterpolator.EASE_OUT);
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
|
|
|
animatorSetInner = null;
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
2019-05-14 14:08:05 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(views[a], View.ALPHA, 1.0f));
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
innerAnimator.animatorSet = new AnimatorSet();
|
|
|
|
innerAnimator.animatorSet.playTogether(animators);
|
|
|
|
innerAnimator.animatorSet.setDuration(150);
|
2019-05-14 14:08:05 +02:00
|
|
|
innerAnimator.animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
|
2016-05-25 23:49:47 +02:00
|
|
|
innerAnimator.animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animatorSetInner != null) {
|
|
|
|
animatorSetInner.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
innerAnimators.add(innerAnimator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentSheetAnimation = animatorSet;
|
2019-07-18 15:01:39 +02:00
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
|
2016-05-25 23:49:47 +02:00
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void dismissInternal() {
|
|
|
|
if (containerView != null) {
|
|
|
|
containerView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
super.dismissInternal();
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
@Override
|
|
|
|
protected boolean onCustomOpenAnimation() {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (useRevealAnimation) {
|
|
|
|
setUseRevealAnimation(true);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (baseFragment instanceof ChatActivity) {
|
2019-01-23 18:03:33 +01:00
|
|
|
updatePollMusicButton();
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = ((ChatActivity) baseFragment).getCurrentChat();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (chat != null) {
|
|
|
|
mediaEnabled = ChatObject.canSendMedia(chat);
|
2017-07-08 18:32:04 +02:00
|
|
|
for (int a = 0; a < 5; a++) {
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean enabled;
|
|
|
|
if (a > 2 && editingMessageObject != null && editingMessageObject.hasValidGroupId()) {
|
2019-06-04 12:14:50 +02:00
|
|
|
attachButtons.get(a).setEnabled(false);
|
|
|
|
attachButtons.get(a).setAlpha(0.2f);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
AttachButton attachButton = attachButtons.get(a);
|
|
|
|
Integer tag = (Integer) attachButton.getTag();
|
|
|
|
attachButton.setAlpha(mediaEnabled || tag == 9 ? 1.0f : 0.2f);
|
|
|
|
attachButton.setEnabled(mediaEnabled || tag == 9);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
attachPhotoRecyclerView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
|
|
|
|
attachPhotoRecyclerView.setEnabled(mediaEnabled);
|
|
|
|
if (!mediaEnabled) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (ChatObject.isActionBannedByDefault(chat, ChatObject.ACTION_SEND_MEDIA)) {
|
|
|
|
mediaBanTooltip.setText(LocaleController.getString("GlobalAttachMediaRestricted", R.string.GlobalAttachMediaRestricted));
|
|
|
|
} else if (AndroidUtilities.isBannedForever(chat.banned_rights)) {
|
2017-07-08 18:32:04 +02:00
|
|
|
mediaBanTooltip.setText(LocaleController.formatString("AttachMediaRestrictedForever", R.string.AttachMediaRestrictedForever));
|
|
|
|
} else {
|
|
|
|
mediaBanTooltip.setText(LocaleController.formatString("AttachMediaRestricted", R.string.AttachMediaRestricted, LocaleController.formatDateForBan(chat.banned_rights.until_date)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mediaBanTooltip.setVisibility(mediaEnabled ? View.INVISIBLE : View.VISIBLE);
|
|
|
|
if (cameraView != null) {
|
|
|
|
cameraView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
|
|
|
|
cameraView.setEnabled(mediaEnabled);
|
|
|
|
}
|
|
|
|
if (cameraIcon != null) {
|
|
|
|
cameraIcon.setAlpha(mediaEnabled ? 1.0f : 0.2f);
|
|
|
|
cameraIcon.setEnabled(mediaEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
if (useRevealAnimation) {
|
|
|
|
startRevealAnimation(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean onCustomCloseAnimation() {
|
|
|
|
if (useRevealAnimation) {
|
2019-01-23 18:03:33 +01:00
|
|
|
setUseRevealAnimation(true);
|
|
|
|
}
|
|
|
|
if (useRevealAnimation) {
|
2016-05-25 23:49:47 +02:00
|
|
|
backDrawable.setAlpha(51);
|
|
|
|
startRevealAnimation(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismissWithButtonClick(int item) {
|
|
|
|
super.dismissWithButtonClick(item);
|
|
|
|
hideCamera(item != 0 && item != 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canDismissWithTouchOutside() {
|
|
|
|
return !cameraOpened;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismiss() {
|
|
|
|
if (cameraAnimationInProgress) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cameraOpened) {
|
|
|
|
closeCamera(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideCamera(true);
|
|
|
|
super.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
if (cameraOpened && (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
|
|
|
|
shutterButton.getDelegate().shutterReleased();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|