use of org.telegram.messenger.camera.CameraView in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlertPhotoLayout method openPhotoViewer.
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);
parentAlert.updateCountButton(0);
adapter.notifyDataSetChanged();
cameraAttachAdapter.notifyDataSetChanged();
}
if (entry != null && !external && cameraPhotos.size() > 1) {
updatePhotosCounter(false);
if (cameraView != null) {
zoomControlView.setZoom(0.0f, false);
cameraZoom = 0.0f;
cameraView.setZoom(0.0f);
CameraController.getInstance().startPreview(cameraView.getCameraSession());
}
return;
}
if (cameraPhotos.isEmpty()) {
return;
}
cancelTakingPhotos = true;
PhotoViewer.getInstance().setParentActivity(parentAlert.baseFragment.getParentActivity(), resourcesProvider);
PhotoViewer.getInstance().setParentAlert(parentAlert);
PhotoViewer.getInstance().setMaxSelectedPhotos(parentAlert.maxSelectedPhotos, parentAlert.allowOrder);
ChatActivity chatActivity;
int type;
if (parentAlert.avatarPicker != 0) {
type = PhotoViewer.SELECT_TYPE_AVATAR;
chatActivity = null;
} else if (parentAlert.baseFragment instanceof ChatActivity) {
chatActivity = (ChatActivity) parentAlert.baseFragment;
type = 2;
} else {
chatActivity = null;
type = 5;
}
ArrayList<Object> arrayList;
int index;
if (parentAlert.avatarPicker != 0) {
arrayList = new ArrayList<>();
arrayList.add(entry);
index = 0;
} else {
arrayList = getAllPhotosArray();
index = cameraPhotos.size() - 1;
}
PhotoViewer.getInstance().openPhotoForSelect(arrayList, index, type, false, new BasePhotoProvider() {
@Override
public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
return null;
}
@Override
public boolean cancelButtonPressed() {
if (cameraOpened && cameraView != null) {
AndroidUtilities.runOnUIThread(() -> {
if (cameraView != null && !parentAlert.isDismissed() && Build.VERSION.SDK_INT >= 21) {
cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}, 1000);
zoomControlView.setZoom(0.0f, false);
cameraZoom = 0.0f;
cameraView.setZoom(0.0f);
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);
adapter.notifyDataSetChanged();
cameraAttachAdapter.notifyDataSetChanged();
parentAlert.updateCountButton(0);
}
return true;
}
@Override
public void needAddMorePhotos() {
cancelTakingPhotos = false;
if (mediaFromExternalCamera) {
parentAlert.delegate.didPressedButton(0, true, true, 0, false);
return;
}
if (!cameraOpened) {
openCamera(false);
}
counterTextView.setVisibility(View.VISIBLE);
cameraPhotoRecyclerView.setVisibility(View.VISIBLE);
counterTextView.setAlpha(1.0f);
updatePhotosCounter(false);
}
@Override
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
if (cameraPhotos.isEmpty() || parentAlert.baseFragment == null) {
return;
}
if (videoEditedInfo != null && index >= 0 && index < cameraPhotos.size()) {
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(index);
photoEntry.editedInfo = videoEditedInfo;
}
if (!(parentAlert.baseFragment instanceof ChatActivity) || !((ChatActivity) parentAlert.baseFragment).isSecretChat()) {
for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
AndroidUtilities.addMediaToGallery(((MediaController.PhotoEntry) cameraPhotos.get(a)).path);
}
}
parentAlert.applyCaption();
closeCamera(false);
parentAlert.delegate.didPressedButton(forceDocument ? 4 : 8, true, notify, scheduleDate, forceDocument);
cameraPhotos.clear();
selectedPhotosOrder.clear();
selectedPhotos.clear();
adapter.notifyDataSetChanged();
cameraAttachAdapter.notifyDataSetChanged();
parentAlert.dismiss();
}
@Override
public boolean scaleToFill() {
if (parentAlert.baseFragment == null || parentAlert.baseFragment.getParentActivity() == null) {
return false;
}
int locked = Settings.System.getInt(parentAlert.baseFragment.getParentActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
return sameTakePictureOrientation || locked == 1;
}
@Override
public void willHidePhotoViewer() {
int count = gridView.getChildCount();
for (int a = 0; a < count; a++) {
View view = gridView.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 parentAlert.maxSelectedPhotos != 1;
}
}, chatActivity);
}
Aggregations