2014-06-06 23:35:21 +00:00
|
|
|
/*
|
2015-10-29 17:10:07 +00:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2014-06-06 23:35:21 +00: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).
|
|
|
|
*
|
2016-01-11 17:19:48 +00:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2014-06-06 23:35:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2015-10-29 17:10:07 +00:00
|
|
|
import android.Manifest;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.app.Activity;
|
2014-11-17 22:04:31 +00:00
|
|
|
import android.app.AlertDialog;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.content.Context;
|
2015-02-26 01:32:51 +00:00
|
|
|
import android.content.DialogInterface;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.content.Intent;
|
2015-10-29 17:10:07 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Canvas;
|
2014-10-28 17:07:44 +00:00
|
|
|
import android.graphics.Paint;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.graphics.PixelFormat;
|
2014-08-22 14:24:33 +00:00
|
|
|
import android.graphics.Rect;
|
2014-10-28 17:07:44 +00:00
|
|
|
import android.graphics.RectF;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2014-10-24 13:43:45 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.net.Uri;
|
2015-02-26 01:32:51 +00:00
|
|
|
import android.os.Build;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.os.Bundle;
|
2016-03-06 01:49:31 +00:00
|
|
|
import android.text.SpannableStringBuilder;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.text.TextUtils;
|
2015-02-26 01:32:51 +00:00
|
|
|
import android.util.TypedValue;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.view.GestureDetector;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.view.Gravity;
|
2015-05-03 11:48:36 +00:00
|
|
|
import android.view.KeyEvent;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.view.MotionEvent;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.view.Surface;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.view.VelocityTracker;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.WindowManager;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2014-06-06 23:35:21 +00:00
|
|
|
import android.widget.FrameLayout;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.widget.ImageView;
|
2015-05-03 11:48:36 +00:00
|
|
|
import android.widget.ListView;
|
2014-06-21 21:46:11 +00:00
|
|
|
import android.widget.Scroller;
|
2014-06-10 23:05:54 +00:00
|
|
|
import android.widget.TextView;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2016-03-06 01:49:31 +00:00
|
|
|
import org.telegram.messenger.Emoji;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.ImageLoader;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.UserObject;
|
|
|
|
import org.telegram.messenger.query.SharedMediaQuery;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-06-10 23:05:54 +00:00
|
|
|
import org.telegram.messenger.FileLoader;
|
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2014-06-06 23:35:21 +00:00
|
|
|
import org.telegram.messenger.R;
|
2016-01-11 17:19:48 +00:00
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2014-06-10 23:05:54 +00:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.MessageObject;
|
2014-10-28 17:07:44 +00:00
|
|
|
import org.telegram.messenger.Utilities;
|
2015-05-03 11:48:36 +00:00
|
|
|
import org.telegram.ui.Adapters.MentionsAdapter;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.AnimationCompat.AnimatorListenerAdapterProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.AnimatorSetProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.ObjectAnimatorProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.ViewProxy;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2015-01-02 22:15:07 +00:00
|
|
|
import org.telegram.ui.Components.CheckBox;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.ui.Components.ClippingImageView;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.ImageReceiver;
|
2015-05-03 11:48:36 +00:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-02-26 01:32:51 +00:00
|
|
|
import org.telegram.ui.Components.PhotoCropView;
|
|
|
|
import org.telegram.ui.Components.PhotoFilterView;
|
2015-07-22 18:56:37 +00:00
|
|
|
import org.telegram.ui.Components.PickerBottomLayout;
|
2015-05-03 11:48:36 +00:00
|
|
|
import org.telegram.ui.Components.PhotoViewerCaptionEnterView;
|
2016-01-11 17:19:48 +00:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2015-06-29 17:12:11 +00:00
|
|
|
import org.telegram.ui.Components.SizeNotifierFrameLayoutPhoto;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2015-02-26 01:32:51 +00:00
|
|
|
import java.util.Date;
|
2014-06-10 23:05:54 +00:00
|
|
|
import java.util.HashMap;
|
2014-06-12 01:13:15 +00:00
|
|
|
import java.util.Locale;
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-11-26 21:04:02 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-06-10 23:05:54 +00:00
|
|
|
public class PhotoViewer implements NotificationCenter.NotificationCenterDelegate, GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
2014-11-17 02:44:57 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private int classGuid;
|
|
|
|
private PhotoViewerProvider placeProvider;
|
2015-05-03 11:48:36 +00:00
|
|
|
private boolean isVisible;
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
private Activity parentActivity;
|
|
|
|
|
2014-06-06 23:35:21 +00:00
|
|
|
private ActionBar actionBar;
|
|
|
|
private boolean isActionBarVisible = true;
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
private static Drawable[] progressDrawables;
|
2014-10-24 13:43:45 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private WindowManager.LayoutParams windowLayoutParams;
|
2014-06-12 15:53:20 +00:00
|
|
|
private FrameLayoutDrawer containerView;
|
|
|
|
private FrameLayoutTouchListener windowView;
|
2014-06-10 23:05:54 +00:00
|
|
|
private ClippingImageView animatingImageView;
|
|
|
|
private FrameLayout bottomLayout;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private TextView dateTextView;
|
|
|
|
private ActionBarMenuItem menuItem;
|
2015-02-26 01:32:51 +00:00
|
|
|
private ImageView shareButton;
|
2015-05-03 11:48:36 +00:00
|
|
|
private BackgroundDrawable backgroundDrawable = new BackgroundDrawable(0xff000000);
|
2015-01-02 22:15:07 +00:00
|
|
|
private CheckBox checkImageView;
|
2015-07-22 18:56:37 +00:00
|
|
|
private PickerBottomLayout pickerView;
|
|
|
|
private PickerBottomLayout editorDoneLayout;
|
2014-10-28 17:07:44 +00:00
|
|
|
private RadialProgressView radialProgressViews[] = new RadialProgressView[3];
|
2015-02-26 01:32:51 +00:00
|
|
|
private ActionBarMenuItem cropItem;
|
|
|
|
private ActionBarMenuItem tuneItem;
|
2015-05-03 11:48:36 +00:00
|
|
|
private ActionBarMenuItem captionItem;
|
|
|
|
private ActionBarMenuItem captionDoneItem;
|
2015-02-01 18:51:02 +00:00
|
|
|
private AnimatorSetProxy currentActionBarAnimation;
|
2015-02-26 01:32:51 +00:00
|
|
|
private PhotoCropView photoCropView;
|
|
|
|
private PhotoFilterView photoFilterView;
|
2015-05-03 11:48:36 +00:00
|
|
|
private AlertDialog visibleDialog;
|
|
|
|
private TextView captionTextView;
|
|
|
|
private TextView captionTextViewOld;
|
|
|
|
private TextView captionTextViewNew;
|
|
|
|
private PhotoViewerCaptionEnterView captionEditText;
|
2014-06-10 23:05:54 +00:00
|
|
|
private boolean canShowBottom = true;
|
2015-02-26 01:32:51 +00:00
|
|
|
private int sendPhotoType = 0;
|
2015-05-03 11:48:36 +00:00
|
|
|
private boolean needCaptionLayout;
|
|
|
|
|
|
|
|
private float animationValues[][] = new float[2][8];
|
|
|
|
|
|
|
|
private ChatActivity parentChatActivity;
|
|
|
|
private MentionsAdapter mentionsAdapter;
|
2016-01-11 17:19:48 +00:00
|
|
|
private RecyclerListView mentionListView;
|
|
|
|
private LinearLayoutManager mentionLayoutManager;
|
2015-05-03 11:48:36 +00:00
|
|
|
private AnimatorSetProxy mentionListAnimation;
|
|
|
|
private boolean allowMentions;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-12 15:53:20 +00:00
|
|
|
private int animationInProgress = 0;
|
2014-07-02 22:39:05 +00:00
|
|
|
private long transitionAnimationStartTime = 0;
|
|
|
|
private Runnable animationEndRunnable = null;
|
2014-06-13 18:26:05 +00:00
|
|
|
private PlaceProviderObject showAfterAnimation;
|
|
|
|
private PlaceProviderObject hideAfterAnimation;
|
2014-06-10 23:05:54 +00:00
|
|
|
private boolean disableShowCheck = false;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
private String lastTitle;
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
private int currentEditMode;
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private ImageReceiver leftImage = new ImageReceiver();
|
|
|
|
private ImageReceiver centerImage = new ImageReceiver();
|
|
|
|
private ImageReceiver rightImage = new ImageReceiver();
|
|
|
|
private int currentIndex;
|
|
|
|
private MessageObject currentMessageObject;
|
|
|
|
private TLRPC.FileLocation currentFileLocation;
|
2014-10-28 17:07:44 +00:00
|
|
|
private String currentFileNames[] = new String[3];
|
2014-06-10 23:05:54 +00:00
|
|
|
private PlaceProviderObject currentPlaceObject;
|
2014-06-12 01:13:15 +00:00
|
|
|
private String currentPathObject;
|
2014-06-10 23:05:54 +00:00
|
|
|
private Bitmap currentThumb = null;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private int avatarsUserId;
|
|
|
|
private long currentDialogId;
|
2015-11-26 21:04:02 +00:00
|
|
|
private long mergeDialogId;
|
2014-06-10 23:05:54 +00:00
|
|
|
private int totalImagesCount;
|
2015-11-26 21:04:02 +00:00
|
|
|
private int totalImagesCountMerge;
|
2014-06-10 23:05:54 +00:00
|
|
|
private boolean isFirstLoading;
|
|
|
|
private boolean needSearchImageInArr;
|
|
|
|
private boolean loadingMoreImages;
|
2015-11-26 21:04:02 +00:00
|
|
|
private boolean endReached[] = new boolean[] {false, true};
|
2014-06-10 23:05:54 +00:00
|
|
|
private boolean opennedFromMedia;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private boolean draggingDown = false;
|
|
|
|
private float dragY;
|
2016-03-06 01:49:31 +00:00
|
|
|
private float translationX;
|
|
|
|
private float translationY;
|
2014-06-10 23:05:54 +00:00
|
|
|
private float scale = 1;
|
|
|
|
private float animateToX;
|
|
|
|
private float animateToY;
|
|
|
|
private float animateToScale;
|
2015-02-26 01:32:51 +00:00
|
|
|
private float animationValue;
|
2016-03-06 01:49:31 +00:00
|
|
|
private int currentRotation;
|
2014-06-10 23:05:54 +00:00
|
|
|
private long animationStartTime;
|
2015-02-26 01:32:51 +00:00
|
|
|
private AnimatorSetProxy imageMoveAnimation;
|
2015-05-03 11:48:36 +00:00
|
|
|
private AnimatorSetProxy changeModeAnimation;
|
2014-06-10 23:05:54 +00:00
|
|
|
private GestureDetector gestureDetector;
|
2014-11-19 01:23:46 +00:00
|
|
|
private DecelerateInterpolator interpolator = new DecelerateInterpolator(1.5f);
|
2016-03-06 01:49:31 +00:00
|
|
|
private float pinchStartDistance;
|
2014-06-10 23:05:54 +00:00
|
|
|
private float pinchStartScale = 1;
|
|
|
|
private float pinchCenterX;
|
|
|
|
private float pinchCenterY;
|
|
|
|
private float pinchStartX;
|
|
|
|
private float pinchStartY;
|
|
|
|
private float moveStartX;
|
|
|
|
private float moveStartY;
|
|
|
|
private float minX;
|
|
|
|
private float maxX;
|
|
|
|
private float minY;
|
|
|
|
private float maxY;
|
|
|
|
private boolean canZoom = true;
|
|
|
|
private boolean changingPage = false;
|
|
|
|
private boolean zooming = false;
|
|
|
|
private boolean moving = false;
|
|
|
|
private boolean doubleTap = false;
|
|
|
|
private boolean invalidCoords = false;
|
|
|
|
private boolean canDragDown = true;
|
2014-06-10 23:33:45 +00:00
|
|
|
private boolean zoomAnimation = false;
|
2015-01-02 22:15:07 +00:00
|
|
|
private boolean discardTap = false;
|
2014-06-10 23:05:54 +00:00
|
|
|
private int switchImageAfterAnimation = 0;
|
|
|
|
private VelocityTracker velocityTracker = null;
|
2014-06-21 21:46:11 +00:00
|
|
|
private Scroller scroller = null;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
private ArrayList<MessageObject> imagesArrTemp = new ArrayList<>();
|
2015-11-26 21:04:02 +00:00
|
|
|
private HashMap<Integer, MessageObject>[] imagesByIdsTemp = new HashMap[] {new HashMap<>(), new HashMap<>()};
|
2015-01-02 22:15:07 +00:00
|
|
|
private ArrayList<MessageObject> imagesArr = new ArrayList<>();
|
2015-11-26 21:04:02 +00:00
|
|
|
private HashMap<Integer, MessageObject>[] imagesByIds = new HashMap[] {new HashMap<>(), new HashMap<>()};
|
2015-01-02 22:15:07 +00:00
|
|
|
private ArrayList<TLRPC.FileLocation> imagesArrLocations = new ArrayList<>();
|
|
|
|
private ArrayList<TLRPC.Photo> avatarsArr = new ArrayList<>();
|
|
|
|
private ArrayList<Integer> imagesArrLocationsSizes = new ArrayList<>();
|
|
|
|
private ArrayList<Object> imagesArrLocals = new ArrayList<>();
|
2014-08-22 14:24:33 +00:00
|
|
|
private TLRPC.FileLocation currentUserAvatarLocation = null;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private final static int gallery_menu_save = 1;
|
|
|
|
private final static int gallery_menu_showall = 2;
|
|
|
|
private final static int gallery_menu_send = 3;
|
2015-02-26 01:32:51 +00:00
|
|
|
private final static int gallery_menu_crop = 4;
|
|
|
|
private final static int gallery_menu_delete = 6;
|
|
|
|
private final static int gallery_menu_tune = 7;
|
2015-05-03 11:48:36 +00:00
|
|
|
private final static int gallery_menu_caption = 8;
|
|
|
|
private final static int gallery_menu_caption_done = 9;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
private final static int PAGE_SPACING = AndroidUtilities.dp(30);
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
private static DecelerateInterpolator decelerateInterpolator = null;
|
|
|
|
private static Paint progressPaint = null;
|
|
|
|
|
|
|
|
private class BackgroundDrawable extends ColorDrawable {
|
|
|
|
|
|
|
|
private Runnable drawRunnable;
|
|
|
|
|
|
|
|
public BackgroundDrawable(int color) {
|
|
|
|
super(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setAlpha(int alpha) {
|
|
|
|
if (parentActivity instanceof LaunchActivity) {
|
|
|
|
((LaunchActivity) parentActivity).drawerLayoutContainer.setAllowDrawContent(!isVisible || alpha != 255);
|
|
|
|
}
|
|
|
|
super.setAlpha(alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw(Canvas canvas) {
|
|
|
|
super.draw(canvas);
|
|
|
|
if (getAlpha() != 0) {
|
|
|
|
if (drawRunnable != null) {
|
|
|
|
drawRunnable.run();
|
|
|
|
drawRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class RadialProgressView {
|
2014-10-28 17:07:44 +00:00
|
|
|
|
|
|
|
private long lastUpdateTime = 0;
|
|
|
|
private float radOffset = 0;
|
|
|
|
private float currentProgress = 0;
|
|
|
|
private float animationProgressStart = 0;
|
|
|
|
private long currentProgressTime = 0;
|
|
|
|
private float animatedProgressValue = 0;
|
|
|
|
private RectF progressRect = new RectF();
|
|
|
|
private int backgroundState = -1;
|
|
|
|
private View parent = null;
|
|
|
|
private int size = AndroidUtilities.dp(64);
|
2014-10-30 21:27:41 +00:00
|
|
|
private int previousBackgroundState = -2;
|
|
|
|
private float animatedAlphaValue = 1.0f;
|
2015-01-02 22:15:07 +00:00
|
|
|
private float alpha = 1.0f;
|
|
|
|
private float scale = 1.0f;
|
2014-10-28 17:07:44 +00:00
|
|
|
|
|
|
|
public RadialProgressView(Context context, View parentView) {
|
|
|
|
if (decelerateInterpolator == null) {
|
2015-01-02 22:15:07 +00:00
|
|
|
decelerateInterpolator = new DecelerateInterpolator(1.5f);
|
2014-10-28 17:07:44 +00:00
|
|
|
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
progressPaint.setStyle(Paint.Style.STROKE);
|
|
|
|
progressPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
|
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
|
|
|
|
progressPaint.setColor(0xffffffff);
|
|
|
|
}
|
|
|
|
parent = parentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAnimation() {
|
|
|
|
long newTime = System.currentTimeMillis();
|
|
|
|
long dt = newTime - lastUpdateTime;
|
|
|
|
lastUpdateTime = newTime;
|
|
|
|
|
2014-10-30 21:27:41 +00:00
|
|
|
if (animatedProgressValue != 1) {
|
|
|
|
radOffset += 360 * dt / 3000.0f;
|
|
|
|
float progressDiff = currentProgress - animationProgressStart;
|
|
|
|
if (progressDiff > 0) {
|
|
|
|
currentProgressTime += dt;
|
|
|
|
if (currentProgressTime >= 300) {
|
|
|
|
animatedProgressValue = currentProgress;
|
|
|
|
animationProgressStart = currentProgress;
|
|
|
|
currentProgressTime = 0;
|
|
|
|
} else {
|
|
|
|
animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f);
|
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
2014-10-30 21:27:41 +00:00
|
|
|
parent.invalidate();
|
|
|
|
}
|
|
|
|
if (animatedProgressValue >= 1 && previousBackgroundState != -2) {
|
|
|
|
animatedAlphaValue -= dt / 200.0f;
|
|
|
|
if (animatedAlphaValue <= 0) {
|
|
|
|
animatedAlphaValue = 0.0f;
|
|
|
|
previousBackgroundState = -2;
|
|
|
|
}
|
|
|
|
parent.invalidate();
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-10-28 17:07:44 +00:00
|
|
|
public void setProgress(float value, boolean animated) {
|
|
|
|
if (!animated) {
|
|
|
|
animatedProgressValue = value;
|
|
|
|
animationProgressStart = value;
|
|
|
|
} else {
|
|
|
|
animationProgressStart = animatedProgressValue;
|
|
|
|
}
|
|
|
|
currentProgress = value;
|
|
|
|
currentProgressTime = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:27:41 +00:00
|
|
|
public void setBackgroundState(int state, boolean animated) {
|
2014-10-28 17:07:44 +00:00
|
|
|
lastUpdateTime = System.currentTimeMillis();
|
2014-10-30 21:27:41 +00:00
|
|
|
if (animated && backgroundState != state) {
|
|
|
|
previousBackgroundState = backgroundState;
|
|
|
|
animatedAlphaValue = 1.0f;
|
|
|
|
} else {
|
|
|
|
previousBackgroundState = -2;
|
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
backgroundState = state;
|
|
|
|
parent.invalidate();
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
public void setAlpha(float value) {
|
|
|
|
alpha = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScale(float value) {
|
|
|
|
scale = value;
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:07:44 +00:00
|
|
|
public void onDraw(Canvas canvas) {
|
2015-02-01 18:51:02 +00:00
|
|
|
int sizeScaled = (int) (size * scale);
|
2015-05-03 11:48:36 +00:00
|
|
|
int x = (getContainerViewWidth() - sizeScaled) / 2;
|
|
|
|
int y = (getContainerViewHeight() - sizeScaled) / 2;
|
2014-10-28 17:07:44 +00:00
|
|
|
|
2014-10-30 21:27:41 +00:00
|
|
|
if (previousBackgroundState >= 0 && previousBackgroundState < 4) {
|
|
|
|
Drawable drawable = progressDrawables[previousBackgroundState];
|
|
|
|
if (drawable != null) {
|
2015-02-01 18:51:02 +00:00
|
|
|
drawable.setAlpha((int) (255 * animatedAlphaValue * alpha));
|
2015-01-02 22:15:07 +00:00
|
|
|
drawable.setBounds(x, y, x + sizeScaled, y + sizeScaled);
|
2014-10-30 21:27:41 +00:00
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 21:27:41 +00:00
|
|
|
if (backgroundState >= 0 && backgroundState < 4) {
|
|
|
|
Drawable drawable = progressDrawables[backgroundState];
|
|
|
|
if (drawable != null) {
|
|
|
|
if (previousBackgroundState != -2) {
|
2015-02-01 18:51:02 +00:00
|
|
|
drawable.setAlpha((int) (255 * (1.0f - animatedAlphaValue) * alpha));
|
2014-10-30 21:27:41 +00:00
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
drawable.setAlpha((int) (255 * alpha));
|
2014-10-30 21:27:41 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
drawable.setBounds(x, y, x + sizeScaled, y + sizeScaled);
|
2014-10-30 21:27:41 +00:00
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backgroundState == 0 || backgroundState == 1 || previousBackgroundState == 0 || previousBackgroundState == 1) {
|
2014-10-28 17:07:44 +00:00
|
|
|
int diff = AndroidUtilities.dp(1);
|
2014-10-30 21:27:41 +00:00
|
|
|
if (previousBackgroundState != -2) {
|
2015-02-01 18:51:02 +00:00
|
|
|
progressPaint.setAlpha((int) (255 * animatedAlphaValue * alpha));
|
2014-10-30 21:27:41 +00:00
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
progressPaint.setAlpha((int) (255 * alpha));
|
2014-10-30 21:27:41 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
progressRect.set(x + diff, y + diff, x + sizeScaled - diff, y + sizeScaled - diff);
|
2014-10-28 17:07:44 +00:00
|
|
|
canvas.drawArc(progressRect, -90 + radOffset, Math.max(4, 360 * animatedProgressValue), false, progressPaint);
|
|
|
|
updateAnimation();
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
public static class PlaceProviderObject {
|
|
|
|
public ImageReceiver imageReceiver;
|
|
|
|
public int viewX;
|
|
|
|
public int viewY;
|
|
|
|
public View parentView;
|
|
|
|
public Bitmap thumb;
|
|
|
|
public int user_id;
|
|
|
|
public int index;
|
|
|
|
public int size;
|
2014-11-17 02:44:57 +00:00
|
|
|
public int radius;
|
2015-10-29 17:10:07 +00:00
|
|
|
public int clipBottomAddition;
|
2015-11-26 21:04:02 +00:00
|
|
|
public int clipTopAddition;
|
2015-10-29 17:10:07 +00:00
|
|
|
public float scale = 1.0f;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
public static class EmptyPhotoViewerProvider implements PhotoViewerProvider {
|
|
|
|
@Override
|
|
|
|
public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPhotoChecked(int index) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-29 17:10:07 +00:00
|
|
|
public boolean cancelButtonPressed() {
|
|
|
|
return true;
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updatePhotoAtIndex(int index) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
public interface PhotoViewerProvider {
|
|
|
|
PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
void willHidePhotoViewer();
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
boolean isPhotoChecked(int index);
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
void setPhotoChecked(int index);
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-10-29 17:10:07 +00:00
|
|
|
boolean cancelButtonPressed();
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
void sendButtonPressed(int index);
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
int getSelectedCount();
|
2015-02-26 01:32:51 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
void updatePhotoAtIndex(int index);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-10-10 17:16:39 +00:00
|
|
|
private class FrameLayoutTouchListener extends FrameLayout {
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
private boolean attachedToWindow;
|
|
|
|
private Runnable attachRunnable;
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
public FrameLayoutTouchListener(Context context) {
|
|
|
|
super(context);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return getInstance().onTouchEvent(event);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
getInstance().onLayout(changed, left, top, right, bottom);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
attachedToWindow = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
attachedToWindow = false;
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 17:12:11 +00:00
|
|
|
private class FrameLayoutDrawer extends SizeNotifierFrameLayoutPhoto {
|
2014-06-12 15:53:20 +00:00
|
|
|
public FrameLayoutDrawer(Context context) {
|
|
|
|
super(context);
|
|
|
|
setWillNotDraw(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-29 17:12:11 +00:00
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
2015-11-26 21:04:02 +00:00
|
|
|
if (heightSize > AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight) {
|
|
|
|
heightSize = AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
|
|
|
|
setMeasuredDimension(widthSize, heightSize);
|
|
|
|
|
|
|
|
int childCount = getChildCount();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (captionEditText.isPopupView(child)) {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
|
|
|
|
} else {
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 15:53:20 +00:00
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
@Override
|
2015-06-29 17:12:11 +00:00
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
final int count = getChildCount();
|
|
|
|
|
|
|
|
int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) ? captionEditText.getEmojiPadding() : 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
|
|
|
|
|
|
|
final int width = child.getMeasuredWidth();
|
|
|
|
final int height = child.getMeasuredHeight();
|
|
|
|
|
|
|
|
int childLeft;
|
|
|
|
int childTop;
|
|
|
|
|
|
|
|
int gravity = lp.gravity;
|
|
|
|
if (gravity == -1) {
|
|
|
|
gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
|
|
|
|
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
|
|
|
|
|
|
|
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
|
|
|
|
case Gravity.CENTER_HORIZONTAL:
|
|
|
|
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.RIGHT:
|
|
|
|
childLeft = r - width - lp.rightMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.LEFT:
|
|
|
|
default:
|
|
|
|
childLeft = lp.leftMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (verticalGravity) {
|
|
|
|
case Gravity.TOP:
|
|
|
|
childTop = lp.topMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.CENTER_VERTICAL:
|
|
|
|
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.BOTTOM:
|
|
|
|
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
childTop = lp.topMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child == mentionListView) {
|
|
|
|
if (!captionEditText.isPopupShowing() && !captionEditText.isKeyboardVisible() && captionEditText.getEmojiPadding() == 0) {
|
|
|
|
childTop += AndroidUtilities.dp(400);
|
|
|
|
} else {
|
|
|
|
childTop -= captionEditText.getMeasuredHeight();
|
|
|
|
}
|
|
|
|
} else if (child == captionEditText) {
|
|
|
|
if (!captionEditText.isPopupShowing() && !captionEditText.isKeyboardVisible() && captionEditText.getEmojiPadding() == 0) {
|
|
|
|
childTop += AndroidUtilities.dp(400);
|
|
|
|
}
|
|
|
|
} else if (child == pickerView || child == captionTextViewNew || child == captionTextViewOld) {
|
|
|
|
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
|
|
|
|
childTop += AndroidUtilities.dp(400);
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
} else if (captionEditText.isPopupView(child)) {
|
|
|
|
childTop = captionEditText.getBottom();
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
child.layout(childLeft, childTop, childLeft + width, childTop + height);
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
|
|
|
|
notifyHeightChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
getInstance().onDraw(canvas);
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
2014-06-12 15:53:20 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 23:35:21 +00:00
|
|
|
private static volatile PhotoViewer Instance = null;
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2014-06-06 23:35:21 +00:00
|
|
|
public static PhotoViewer getInstance() {
|
|
|
|
PhotoViewer localInstance = Instance;
|
|
|
|
if (localInstance == null) {
|
|
|
|
synchronized (PhotoViewer.class) {
|
|
|
|
localInstance = Instance;
|
|
|
|
if (localInstance == null) {
|
|
|
|
Instance = localInstance = new PhotoViewer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return localInstance;
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.FileDidFailedLoad) {
|
2015-02-01 18:51:02 +00:00
|
|
|
String location = (String) args[0];
|
2014-10-28 17:07:44 +00:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (currentFileNames[a] != null && currentFileNames[a].equals(location)) {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setProgress(1.0f, true);
|
|
|
|
checkProgress(a, true);
|
2014-10-28 17:07:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.FileDidLoaded) {
|
2015-02-01 18:51:02 +00:00
|
|
|
String location = (String) args[0];
|
2014-10-28 17:07:44 +00:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (currentFileNames[a] != null && currentFileNames[a].equals(location)) {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setProgress(1.0f, true);
|
|
|
|
checkProgress(a, true);
|
2014-10-28 17:07:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.FileLoadProgressChanged) {
|
2015-02-01 18:51:02 +00:00
|
|
|
String location = (String) args[0];
|
2014-10-28 17:07:44 +00:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (currentFileNames[a] != null && currentFileNames[a].equals(location)) {
|
|
|
|
Float progress = (Float) args[1];
|
|
|
|
radialProgressViews[a].setProgress(progress, true);
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.userPhotosLoaded) {
|
2015-02-01 18:51:02 +00:00
|
|
|
int guid = (Integer) args[4];
|
|
|
|
int uid = (Integer) args[0];
|
2014-06-10 23:05:54 +00:00
|
|
|
if (avatarsUserId == uid && classGuid == guid) {
|
2015-02-01 18:51:02 +00:00
|
|
|
boolean fromCache = (Boolean) args[3];
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
int setToImage = -1;
|
2015-02-01 18:51:02 +00:00
|
|
|
ArrayList<TLRPC.Photo> photos = (ArrayList<TLRPC.Photo>) args[5];
|
2014-06-10 23:05:54 +00:00
|
|
|
if (photos.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
imagesArrLocations.clear();
|
|
|
|
imagesArrLocationsSizes.clear();
|
2014-08-22 14:24:33 +00:00
|
|
|
avatarsArr.clear();
|
2014-06-10 23:05:54 +00:00
|
|
|
for (TLRPC.Photo photo : photos) {
|
2015-03-26 17:34:47 +00:00
|
|
|
if (photo == null || photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) {
|
2014-06-10 23:05:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-10-01 19:55:24 +00:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 640);
|
2014-06-10 23:05:54 +00:00
|
|
|
if (sizeFull != null) {
|
2014-06-14 08:36:01 +00:00
|
|
|
if (currentFileLocation != null) {
|
|
|
|
for (TLRPC.PhotoSize size : photo.sizes) {
|
|
|
|
if (size.location.local_id == currentFileLocation.local_id && size.location.volume_id == currentFileLocation.volume_id) {
|
|
|
|
setToImage = imagesArrLocations.size();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
imagesArrLocations.add(sizeFull.location);
|
|
|
|
imagesArrLocationsSizes.add(sizeFull.size);
|
2014-08-22 14:24:33 +00:00
|
|
|
avatarsArr.add(photo);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
if (!avatarsArr.isEmpty()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
menuItem.showSubItem(gallery_menu_delete);
|
2014-08-22 14:24:33 +00:00
|
|
|
} else {
|
2015-02-26 01:32:51 +00:00
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
needSearchImageInArr = false;
|
|
|
|
currentIndex = -1;
|
|
|
|
if (setToImage != -1) {
|
|
|
|
setImageIndex(setToImage, true);
|
|
|
|
} else {
|
2014-08-22 14:24:33 +00:00
|
|
|
avatarsArr.add(0, new TLRPC.TL_photoEmpty());
|
2014-06-13 18:26:05 +00:00
|
|
|
imagesArrLocations.add(0, currentFileLocation);
|
2014-06-14 08:36:01 +00:00
|
|
|
imagesArrLocationsSizes.add(0, 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
setImageIndex(0, true);
|
|
|
|
}
|
|
|
|
if (fromCache) {
|
2014-10-28 17:07:44 +00:00
|
|
|
MessagesController.getInstance().loadUserPhotos(avatarsUserId, 0, 80, 0, false, classGuid);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.mediaCountDidLoaded) {
|
2015-02-01 18:51:02 +00:00
|
|
|
long uid = (Long) args[0];
|
2015-11-26 21:04:02 +00:00
|
|
|
if (uid == currentDialogId || uid == mergeDialogId) {
|
|
|
|
if (uid == currentDialogId) {
|
|
|
|
totalImagesCount = (Integer) args[1];
|
2015-12-09 18:27:52 +00:00
|
|
|
/*if ((Boolean) args[2]) {
|
2015-11-26 21:04:02 +00:00
|
|
|
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, false);
|
2015-12-09 18:27:52 +00:00
|
|
|
}*/
|
2015-11-26 21:04:02 +00:00
|
|
|
} else if (uid == mergeDialogId) {
|
|
|
|
totalImagesCountMerge = (Integer) args[1];
|
2015-12-09 18:27:52 +00:00
|
|
|
/*if ((Boolean) args[2]) {
|
2015-11-26 21:04:02 +00:00
|
|
|
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, false);
|
2015-12-09 18:27:52 +00:00
|
|
|
}*/
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
if (needSearchImageInArr && isFirstLoading) {
|
|
|
|
isFirstLoading = false;
|
|
|
|
loadingMoreImages = true;
|
2015-10-29 17:10:07 +00:00
|
|
|
SharedMediaQuery.loadMedia(currentDialogId, 0, 80, 0, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (!imagesArr.isEmpty()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (opennedFromMedia) {
|
2015-11-26 21:04:02 +00:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
2015-02-26 01:32:51 +00:00
|
|
|
} else {
|
2015-11-26 21:04:02 +00:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.mediaDidLoaded) {
|
2015-02-01 18:51:02 +00:00
|
|
|
long uid = (Long) args[0];
|
2015-09-24 20:52:02 +00:00
|
|
|
int guid = (Integer) args[3];
|
2015-11-26 21:04:02 +00:00
|
|
|
if ((uid == currentDialogId || uid == mergeDialogId) && guid == classGuid) {
|
2014-06-10 23:05:54 +00:00
|
|
|
loadingMoreImages = false;
|
2015-11-26 21:04:02 +00:00
|
|
|
int loadIndex = uid == currentDialogId ? 0 : 1;
|
2015-02-01 18:51:02 +00:00
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[2];
|
2015-11-26 21:04:02 +00:00
|
|
|
endReached[loadIndex] = (Boolean) args[5];
|
2014-06-10 23:05:54 +00:00
|
|
|
if (needSearchImageInArr) {
|
2015-11-26 21:04:02 +00:00
|
|
|
if (arr.isEmpty() && (loadIndex != 0 || mergeDialogId == 0)) {
|
2014-06-10 23:05:54 +00:00
|
|
|
needSearchImageInArr = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int foundIndex = -1;
|
|
|
|
|
|
|
|
MessageObject currentMessage = imagesArr.get(currentIndex);
|
|
|
|
|
|
|
|
int added = 0;
|
2015-11-26 21:04:02 +00:00
|
|
|
for (int a = 0; a < arr.size(); a++) {
|
|
|
|
MessageObject message = arr.get(a);
|
|
|
|
if (!imagesByIdsTemp[loadIndex].containsKey(message.getId())) {
|
|
|
|
imagesByIdsTemp[loadIndex].put(message.getId(), message);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (opennedFromMedia) {
|
|
|
|
imagesArrTemp.add(message);
|
2015-03-18 23:09:45 +00:00
|
|
|
if (message.getId() == currentMessage.getId()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
foundIndex = added;
|
|
|
|
}
|
|
|
|
added++;
|
|
|
|
} else {
|
|
|
|
added++;
|
|
|
|
imagesArrTemp.add(0, message);
|
2015-03-18 23:09:45 +00:00
|
|
|
if (message.getId() == currentMessage.getId()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
foundIndex = arr.size() - added;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 21:04:02 +00:00
|
|
|
if (added == 0 && (loadIndex != 0 || mergeDialogId == 0)) {
|
2014-06-10 23:05:54 +00:00
|
|
|
totalImagesCount = imagesArr.size();
|
2015-11-26 21:04:02 +00:00
|
|
|
totalImagesCountMerge = 0;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (foundIndex != -1) {
|
|
|
|
imagesArr.clear();
|
|
|
|
imagesArr.addAll(imagesArrTemp);
|
2015-11-26 21:04:02 +00:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
imagesByIds[a].clear();
|
|
|
|
imagesByIds[a].putAll(imagesByIdsTemp[a]);
|
|
|
|
imagesByIdsTemp[a].clear();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
imagesArrTemp.clear();
|
|
|
|
needSearchImageInArr = false;
|
|
|
|
currentIndex = -1;
|
2014-07-22 23:27:00 +00:00
|
|
|
if (foundIndex >= imagesArr.size()) {
|
|
|
|
foundIndex = imagesArr.size() - 1;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
setImageIndex(foundIndex, true);
|
|
|
|
} else {
|
2015-11-26 21:04:02 +00:00
|
|
|
int loadFromMaxId;
|
|
|
|
if (opennedFromMedia) {
|
|
|
|
loadFromMaxId = imagesArrTemp.isEmpty() ? 0 : imagesArrTemp.get(imagesArrTemp.size() - 1).getId();
|
|
|
|
if (loadIndex == 0 && endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArrTemp.isEmpty() && imagesArrTemp.get(imagesArrTemp.size() - 1).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
loadFromMaxId = imagesArrTemp.isEmpty() ? 0 : imagesArrTemp.get(0).getId();
|
|
|
|
if (loadIndex == 0 && endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArrTemp.isEmpty() && imagesArrTemp.get(0).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!endReached[loadIndex]) {
|
2014-06-10 23:05:54 +00:00
|
|
|
loadingMoreImages = true;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (opennedFromMedia) {
|
2015-11-26 21:04:02 +00:00
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2015-02-26 01:32:51 +00:00
|
|
|
} else {
|
2015-11-26 21:04:02 +00:00
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int added = 0;
|
|
|
|
for (MessageObject message : arr) {
|
2015-11-26 21:04:02 +00:00
|
|
|
if (!imagesByIds[loadIndex].containsKey(message.getId())) {
|
2014-06-10 23:05:54 +00:00
|
|
|
added++;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (opennedFromMedia) {
|
|
|
|
imagesArr.add(message);
|
|
|
|
} else {
|
|
|
|
imagesArr.add(0, message);
|
|
|
|
}
|
2015-11-26 21:04:02 +00:00
|
|
|
imagesByIds[loadIndex].put(message.getId(), message);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (opennedFromMedia) {
|
|
|
|
if (added == 0) {
|
|
|
|
totalImagesCount = imagesArr.size();
|
2015-11-26 21:04:02 +00:00
|
|
|
totalImagesCountMerge = 0;
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (added != 0) {
|
|
|
|
int index = currentIndex;
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(index + added, true);
|
|
|
|
} else {
|
|
|
|
totalImagesCount = imagesArr.size();
|
2015-11-26 21:04:02 +00:00
|
|
|
totalImagesCountMerge = 0;
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoaded) {
|
|
|
|
if (captionTextView != null) {
|
|
|
|
captionTextView.invalidate();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
public void setParentActivity(final Activity activity) {
|
2014-07-03 14:55:04 +00:00
|
|
|
if (parentActivity == activity) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
parentActivity = activity;
|
|
|
|
|
2014-10-24 13:43:45 +00:00
|
|
|
if (progressDrawables == null) {
|
|
|
|
progressDrawables = new Drawable[4];
|
2014-10-28 17:07:44 +00:00
|
|
|
progressDrawables[0] = parentActivity.getResources().getDrawable(R.drawable.circle_big);
|
|
|
|
progressDrawables[1] = parentActivity.getResources().getDrawable(R.drawable.cancel_big);
|
|
|
|
progressDrawables[2] = parentActivity.getResources().getDrawable(R.drawable.load_big);
|
|
|
|
progressDrawables[3] = parentActivity.getResources().getDrawable(R.drawable.play_big);
|
2014-10-24 13:43:45 +00:00
|
|
|
}
|
|
|
|
|
2014-06-21 21:46:11 +00:00
|
|
|
scroller = new Scroller(activity);
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
windowView = new FrameLayoutTouchListener(activity) {
|
2015-10-29 17:10:07 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
@Override
|
|
|
|
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
|
|
|
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
2015-06-29 17:12:11 +00:00
|
|
|
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
|
2015-05-03 11:48:36 +00:00
|
|
|
closeCaptionEnter(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PhotoViewer.getInstance().closePhoto(true, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.dispatchKeyEventPreIme(event);
|
|
|
|
}
|
|
|
|
};
|
2014-06-12 15:53:20 +00:00
|
|
|
windowView.setBackgroundDrawable(backgroundDrawable);
|
|
|
|
windowView.setFocusable(false);
|
2016-03-16 12:26:32 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
windowView.setFitsSystemWindows(true); //TODO ?
|
|
|
|
}
|
2014-06-12 15:53:20 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
animatingImageView = new ClippingImageView(activity);
|
|
|
|
animatingImageView.setAnimationValues(animationValues);
|
|
|
|
windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40));
|
2014-06-12 15:53:20 +00:00
|
|
|
|
|
|
|
containerView = new FrameLayoutDrawer(activity);
|
2014-06-06 23:35:21 +00:00
|
|
|
containerView.setFocusable(false);
|
2015-05-03 11:48:36 +00:00
|
|
|
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
|
2014-06-06 23:35:21 +00:00
|
|
|
|
|
|
|
windowLayoutParams = new WindowManager.LayoutParams();
|
|
|
|
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
|
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
|
|
|
|
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
|
windowLayoutParams.gravity = Gravity.TOP;
|
2014-08-29 21:06:04 +00:00
|
|
|
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
|
2014-06-06 23:35:21 +00:00
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
|
|
|
|
actionBar = new ActionBar(activity);
|
2014-06-12 15:53:20 +00:00
|
|
|
actionBar.setBackgroundColor(0x7F000000);
|
2014-11-17 02:44:57 +00:00
|
|
|
actionBar.setOccupyStatusBar(false);
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setItemsBackground(R.drawable.bar_selector_white);
|
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-06-06 23:35:21 +00:00
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2015-06-29 17:12:11 +00:00
|
|
|
if (needCaptionLayout && (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible())) {
|
2015-05-03 11:48:36 +00:00
|
|
|
closeCaptionEnter(false);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(true, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (id == gallery_menu_save) {
|
2015-10-29 17:10:07 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:48:11 +00:00
|
|
|
File f = null;
|
|
|
|
if (currentMessageObject != null) {
|
|
|
|
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
} else if (currentFileLocation != null) {
|
2014-10-07 20:14:27 +00:00
|
|
|
f = FileLoader.getPathToAttach(currentFileLocation, avatarsUserId != 0);
|
2014-09-29 22:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (f != null && f.exists()) {
|
2016-03-06 01:49:31 +00:00
|
|
|
MediaController.saveFile(f.toString(), parentActivity, currentMessageObject != null && currentMessageObject.isVideo() ? 1 : 0, null);
|
2014-11-17 22:04:31 +00:00
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2015-03-18 23:09:45 +00:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-11-17 22:04:31 +00:00
|
|
|
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
|
2015-02-26 01:32:51 +00:00
|
|
|
showAlertDialog(builder);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} else if (id == gallery_menu_showall) {
|
|
|
|
if (opennedFromMedia) {
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(true, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (currentDialogId != 0) {
|
2015-02-01 18:51:02 +00:00
|
|
|
disableShowCheck = true;
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(false, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putLong("dialog_id", currentDialogId);
|
2015-02-01 18:51:02 +00:00
|
|
|
((LaunchActivity) parentActivity).presentFragment(new MediaActivity(args2), false, true);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} else if (id == gallery_menu_send) {
|
|
|
|
/*Intent intent = new Intent(this, MessagesActivity.class);
|
|
|
|
intent.putExtra("onlySelect", true);
|
|
|
|
startActivityForResult(intent, 10);
|
|
|
|
if (requestCode == 10) {
|
|
|
|
int chatId = data.getIntExtra("chatId", 0);
|
|
|
|
int userId = data.getIntExtra("userId", 0);
|
|
|
|
int dialog_id = 0;
|
|
|
|
if (chatId != 0) {
|
|
|
|
dialog_id = -chatId;
|
|
|
|
} else if (userId != 0) {
|
|
|
|
dialog_id = userId;
|
|
|
|
}
|
|
|
|
TLRPC.FileLocation location = getCurrentFile();
|
|
|
|
if (dialog_id != 0 && location != null) {
|
|
|
|
Intent intent = new Intent(GalleryImageViewer.this, ChatActivity.class);
|
|
|
|
if (chatId != 0) {
|
|
|
|
intent.putExtra("chatId", chatId);
|
|
|
|
} else {
|
|
|
|
intent.putExtra("userId", userId);
|
|
|
|
}
|
|
|
|
startActivity(intent);
|
|
|
|
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
|
|
|
|
finish();
|
|
|
|
if (withoutBottom) {
|
|
|
|
MessagesController.getInstance().sendMessage(location, dialog_id);
|
|
|
|
} else {
|
|
|
|
int item = mViewPager.getCurrentItem();
|
|
|
|
MessageObject obj = localPagerAdapter.imagesArr.get(item);
|
|
|
|
MessagesController.getInstance().sendMessage(obj, dialog_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
2015-02-26 01:32:51 +00:00
|
|
|
} else if (id == gallery_menu_crop) {
|
|
|
|
switchToEditMode(1);
|
|
|
|
} else if (id == gallery_menu_tune) {
|
|
|
|
switchToEditMode(2);
|
|
|
|
} else if (id == gallery_menu_delete) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
2015-02-01 18:51:02 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2016-03-06 01:49:31 +00:00
|
|
|
if (currentMessageObject != null && currentMessageObject.isVideo()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeleteVideo", R.string.AreYouSureDeleteVideo));
|
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeletePhoto", R.string.AreYouSureDeletePhoto));
|
|
|
|
}
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (!imagesArr.isEmpty()) {
|
|
|
|
if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageObject obj = imagesArr.get(currentIndex);
|
|
|
|
if (obj.isSent()) {
|
|
|
|
ArrayList<Integer> arr = new ArrayList<>();
|
2015-03-18 23:09:45 +00:00
|
|
|
arr.add(obj.getId());
|
2015-02-26 01:32:51 +00:00
|
|
|
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
TLRPC.EncryptedChat encryptedChat = null;
|
|
|
|
if ((int) obj.getDialogId() == 0 && obj.messageOwner.random_id != 0) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
random_ids.add(obj.messageOwner.random_id);
|
|
|
|
encryptedChat = MessagesController.getInstance().getEncryptedChat((int) (obj.getDialogId() >> 32));
|
|
|
|
}
|
|
|
|
|
2015-09-24 20:52:02 +00:00
|
|
|
MessagesController.getInstance().deleteMessages(arr, random_ids, encryptedChat, obj.messageOwner.to_id.channel_id);
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(false, false);
|
|
|
|
}
|
|
|
|
} else if (!avatarsArr.isEmpty()) {
|
|
|
|
if (currentIndex < 0 || currentIndex >= avatarsArr.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.Photo photo = avatarsArr.get(currentIndex);
|
|
|
|
TLRPC.FileLocation currentLocation = imagesArrLocations.get(currentIndex);
|
|
|
|
if (photo instanceof TLRPC.TL_photoEmpty) {
|
|
|
|
photo = null;
|
|
|
|
}
|
|
|
|
boolean current = false;
|
|
|
|
if (currentUserAvatarLocation != null) {
|
|
|
|
if (photo != null) {
|
|
|
|
for (TLRPC.PhotoSize size : photo.sizes) {
|
|
|
|
if (size.location.local_id == currentUserAvatarLocation.local_id && size.location.volume_id == currentUserAvatarLocation.volume_id) {
|
|
|
|
current = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (currentLocation.local_id == currentUserAvatarLocation.local_id && currentLocation.volume_id == currentUserAvatarLocation.volume_id) {
|
|
|
|
current = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (current) {
|
|
|
|
MessagesController.getInstance().deleteUserPhoto(null);
|
|
|
|
closePhoto(false, false);
|
|
|
|
} else if (photo != null) {
|
|
|
|
TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
|
|
|
|
inputPhoto.id = photo.id;
|
|
|
|
inputPhoto.access_hash = photo.access_hash;
|
|
|
|
MessagesController.getInstance().deleteUserPhoto(inputPhoto);
|
|
|
|
MessagesStorage.getInstance().clearUserPhoto(avatarsUserId, photo.id);
|
|
|
|
imagesArrLocations.remove(currentIndex);
|
|
|
|
imagesArrLocationsSizes.remove(currentIndex);
|
|
|
|
avatarsArr.remove(currentIndex);
|
|
|
|
if (imagesArrLocations.isEmpty()) {
|
|
|
|
closePhoto(false, false);
|
|
|
|
} else {
|
|
|
|
int index = currentIndex;
|
|
|
|
if (index >= avatarsArr.size()) {
|
|
|
|
index = avatarsArr.size() - 1;
|
|
|
|
}
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(index, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
2015-05-03 11:48:36 +00:00
|
|
|
} else if (id == gallery_menu_caption) {
|
|
|
|
if (imageMoveAnimation != null || changeModeAnimation != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cropItem.setVisibility(View.GONE);
|
|
|
|
tuneItem.setVisibility(View.GONE);
|
|
|
|
captionItem.setVisibility(View.GONE);
|
|
|
|
checkImageView.setVisibility(View.GONE);
|
|
|
|
captionDoneItem.setVisibility(View.VISIBLE);
|
|
|
|
pickerView.setVisibility(View.GONE);
|
2015-06-29 17:12:11 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) captionEditText.getLayoutParams();
|
|
|
|
layoutParams.bottomMargin = 0;
|
|
|
|
captionEditText.setLayoutParams(layoutParams);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) mentionListView.getLayoutParams();
|
|
|
|
layoutParams.bottomMargin = 0;
|
|
|
|
mentionListView.setLayoutParams(layoutParams);
|
2015-05-21 21:27:27 +00:00
|
|
|
captionTextView.clearAnimation();
|
2015-05-03 11:48:36 +00:00
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
captionEditText.openKeyboard();
|
|
|
|
lastTitle = actionBar.getTitle();
|
|
|
|
actionBar.setTitle(LocaleController.getString("PhotoCaption", R.string.PhotoCaption));
|
|
|
|
} else if (id == gallery_menu_caption_done) {
|
|
|
|
closeCaptionEnter(true);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canOpenMenu() {
|
2014-09-25 03:54:35 +00:00
|
|
|
if (currentMessageObject != null) {
|
|
|
|
File f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
if (f.exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (currentFileLocation != null) {
|
2014-10-07 20:14:27 +00:00
|
|
|
File f = FileLoader.getPathToAttach(currentFileLocation, avatarsUserId != 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
if (f.exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
return false;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2015-02-26 01:32:51 +00:00
|
|
|
|
2014-11-06 21:34:47 +00:00
|
|
|
menuItem = menu.addItem(0, R.drawable.ic_ab_other);
|
2014-06-10 23:05:54 +00:00
|
|
|
menuItem.addSubItem(gallery_menu_showall, LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia), 0);
|
2015-02-26 01:32:51 +00:00
|
|
|
menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery), 0);
|
|
|
|
menuItem.addSubItem(gallery_menu_delete, LocaleController.getString("Delete", R.string.Delete), 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
captionDoneItem = menu.addItemWithWidth(gallery_menu_caption_done, R.drawable.ic_done, AndroidUtilities.dp(56));
|
|
|
|
captionItem = menu.addItemWithWidth(gallery_menu_caption, R.drawable.photo_text, AndroidUtilities.dp(56));
|
2015-02-26 01:32:51 +00:00
|
|
|
cropItem = menu.addItemWithWidth(gallery_menu_crop, R.drawable.photo_crop, AndroidUtilities.dp(56));
|
2015-05-03 11:48:36 +00:00
|
|
|
tuneItem = menu.addItemWithWidth(gallery_menu_tune, R.drawable.photo_tools, AndroidUtilities.dp(56));
|
|
|
|
|
|
|
|
bottomLayout = new FrameLayout(parentActivity);
|
2015-02-26 01:32:51 +00:00
|
|
|
bottomLayout.setBackgroundColor(0x7f000000);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
captionTextViewOld = new TextView(parentActivity);
|
|
|
|
captionTextViewOld.setMaxLines(10);
|
|
|
|
captionTextViewOld.setBackgroundColor(0x7f000000);
|
|
|
|
captionTextViewOld.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(8), AndroidUtilities.dp(16), AndroidUtilities.dp(8));
|
|
|
|
captionTextViewOld.setLinkTextColor(0xffffffff);
|
|
|
|
captionTextViewOld.setTextColor(0xffffffff);
|
|
|
|
captionTextViewOld.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
|
|
|
|
captionTextViewOld.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
captionTextViewOld.setVisibility(View.INVISIBLE);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(captionTextViewOld, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
captionTextView = captionTextViewNew = new TextView(parentActivity);
|
|
|
|
captionTextViewNew.setMaxLines(10);
|
|
|
|
captionTextViewNew.setBackgroundColor(0x7f000000);
|
|
|
|
captionTextViewNew.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(8), AndroidUtilities.dp(16), AndroidUtilities.dp(8));
|
|
|
|
captionTextViewNew.setLinkTextColor(0xffffffff);
|
|
|
|
captionTextViewNew.setTextColor(0xffffffff);
|
|
|
|
captionTextViewNew.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
|
|
|
|
captionTextViewNew.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
captionTextViewNew.setVisibility(View.INVISIBLE);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(captionTextViewNew, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2014-10-28 17:07:44 +00:00
|
|
|
radialProgressViews[0] = new RadialProgressView(containerView.getContext(), containerView);
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[0].setBackgroundState(0, false);
|
2014-10-28 17:07:44 +00:00
|
|
|
radialProgressViews[1] = new RadialProgressView(containerView.getContext(), containerView);
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[1].setBackgroundState(0, false);
|
2014-10-28 17:07:44 +00:00
|
|
|
radialProgressViews[2] = new RadialProgressView(containerView.getContext(), containerView);
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[2].setBackgroundState(0, false);
|
2014-10-28 17:07:44 +00:00
|
|
|
|
2014-10-22 10:11:47 +00:00
|
|
|
shareButton = new ImageView(containerView.getContext());
|
2015-02-26 01:32:51 +00:00
|
|
|
shareButton.setImageResource(R.drawable.share);
|
2014-06-10 23:05:54 +00:00
|
|
|
shareButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
shareButton.setBackgroundResource(R.drawable.bar_selector_white);
|
2015-05-03 11:48:36 +00:00
|
|
|
bottomLayout.addView(shareButton, LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
|
2014-06-10 23:05:54 +00:00
|
|
|
shareButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2014-10-14 20:36:15 +00:00
|
|
|
File f = null;
|
2016-03-06 01:49:31 +00:00
|
|
|
boolean isVideo = false;
|
2014-10-14 20:36:15 +00:00
|
|
|
|
|
|
|
if (currentMessageObject != null) {
|
2016-03-06 01:49:31 +00:00
|
|
|
isVideo = currentMessageObject.isVideo();
|
2016-03-16 12:26:32 +00:00
|
|
|
/*if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
2016-03-06 01:49:31 +00:00
|
|
|
AndroidUtilities.openUrl(parentActivity, currentMessageObject.messageOwner.media.webpage.url);
|
2015-08-13 09:23:31 +00:00
|
|
|
return;
|
2016-03-16 12:26:32 +00:00
|
|
|
}*/
|
2014-10-14 20:36:15 +00:00
|
|
|
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
} else if (currentFileLocation != null) {
|
|
|
|
f = FileLoader.getPathToAttach(currentFileLocation, avatarsUserId != 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-10-14 20:36:15 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
if (f.exists()) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
2016-03-06 01:49:31 +00:00
|
|
|
if (isVideo) {
|
2014-06-10 23:05:54 +00:00
|
|
|
intent.setType("video/mp4");
|
|
|
|
} else {
|
|
|
|
intent.setType("image/jpeg");
|
|
|
|
}
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
|
2015-02-01 18:51:02 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
parentActivity.startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
|
2014-11-17 22:04:31 +00:00
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2015-03-18 23:09:45 +00:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-11-17 22:04:31 +00:00
|
|
|
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
|
2015-02-26 01:32:51 +00:00
|
|
|
showAlertDialog(builder);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
nameTextView = new TextView(containerView.getContext());
|
2015-02-26 01:32:51 +00:00
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2014-06-10 23:05:54 +00:00
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
nameTextView.setTextColor(0xffffffff);
|
2015-02-26 01:32:51 +00:00
|
|
|
nameTextView.setGravity(Gravity.LEFT);
|
2015-05-03 11:48:36 +00:00
|
|
|
bottomLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 5, 60, 0));
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
dateTextView = new TextView(containerView.getContext());
|
2015-02-26 01:32:51 +00:00
|
|
|
dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
2014-06-10 23:05:54 +00:00
|
|
|
dateTextView.setSingleLine(true);
|
|
|
|
dateTextView.setMaxLines(1);
|
|
|
|
dateTextView.setEllipsize(TextUtils.TruncateAt.END);
|
2015-02-26 01:32:51 +00:00
|
|
|
dateTextView.setTextColor(0xffffffff);
|
|
|
|
dateTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
dateTextView.setGravity(Gravity.LEFT);
|
2015-05-03 11:48:36 +00:00
|
|
|
bottomLayout.addView(dateTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 25, 50, 0));
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerView = new PickerBottomLayout(parentActivity);
|
2015-02-01 18:51:02 +00:00
|
|
|
pickerView.setBackgroundColor(0x7f000000);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(pickerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
|
2015-01-02 22:15:07 +00:00
|
|
|
pickerView.cancelButton.setOnClickListener(new View.OnClickListener() {
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (placeProvider != null) {
|
2015-10-29 17:10:07 +00:00
|
|
|
closePhoto(!placeProvider.cancelButtonPressed(), false);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-01-02 22:15:07 +00:00
|
|
|
pickerView.doneButton.setOnClickListener(new View.OnClickListener() {
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (placeProvider != null) {
|
|
|
|
placeProvider.sendButtonPressed(currentIndex);
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(false, false);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-22 18:56:37 +00:00
|
|
|
editorDoneLayout = new PickerBottomLayout(parentActivity);
|
2015-02-26 01:32:51 +00:00
|
|
|
editorDoneLayout.setBackgroundColor(0x7f000000);
|
|
|
|
editorDoneLayout.updateSelectedCount(0, false);
|
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(editorDoneLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
|
2015-02-26 01:32:51 +00:00
|
|
|
editorDoneLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
editorDoneLayout.doneButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
2015-05-03 11:48:36 +00:00
|
|
|
if (imageMoveAnimation != null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
|
|
|
applyCurrentEditMode();
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
2014-06-12 19:55:13 +00:00
|
|
|
|
2016-03-06 01:49:31 +00:00
|
|
|
ImageView rotateButton = new ImageView(parentActivity);
|
|
|
|
rotateButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
rotateButton.setImageResource(R.drawable.tool_rotate);
|
|
|
|
rotateButton.setBackgroundResource(R.drawable.bar_selector_white);
|
|
|
|
editorDoneLayout.addView(rotateButton, LayoutHelper.createFrame(48, 48, Gravity.CENTER));
|
|
|
|
rotateButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
centerImage.setOrientation(centerImage.getOrientation() - 90, false);
|
|
|
|
photoCropView.setOrientation(centerImage.getOrientation());
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
gestureDetector = new GestureDetector(containerView.getContext(), this);
|
|
|
|
gestureDetector.setOnDoubleTapListener(this);
|
|
|
|
|
2014-08-22 14:24:33 +00:00
|
|
|
centerImage.setParentView(containerView);
|
2015-05-03 11:48:36 +00:00
|
|
|
centerImage.setCrossfadeAlpha((byte) 2);
|
2015-05-21 21:27:27 +00:00
|
|
|
centerImage.setInvalidateAll(true);
|
2014-08-22 14:24:33 +00:00
|
|
|
leftImage.setParentView(containerView);
|
2015-05-03 11:48:36 +00:00
|
|
|
leftImage.setCrossfadeAlpha((byte) 2);
|
2015-05-21 21:27:27 +00:00
|
|
|
leftImage.setInvalidateAll(true);
|
2014-08-22 14:24:33 +00:00
|
|
|
rightImage.setParentView(containerView);
|
2015-05-03 11:48:36 +00:00
|
|
|
rightImage.setCrossfadeAlpha((byte) 2);
|
2015-05-21 21:27:27 +00:00
|
|
|
rightImage.setInvalidateAll(true);
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
checkImageView = new CheckBox(containerView.getContext(), R.drawable.selectphoto_large);
|
|
|
|
checkImageView.setDrawBackground(true);
|
|
|
|
checkImageView.setSize(45);
|
|
|
|
checkImageView.setCheckOffset(AndroidUtilities.dp(1));
|
|
|
|
checkImageView.setColor(0xff3ccaef);
|
2014-06-12 01:13:15 +00:00
|
|
|
checkImageView.setVisibility(View.GONE);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(checkImageView, LayoutHelper.createFrame(45, 45, Gravity.RIGHT | Gravity.TOP, 0, rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68, 10, 0));
|
2014-06-12 01:13:15 +00:00
|
|
|
checkImageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (placeProvider != null) {
|
|
|
|
placeProvider.setPhotoChecked(currentIndex);
|
2015-01-02 22:15:07 +00:00
|
|
|
checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), true);
|
2014-06-12 01:13:15 +00:00
|
|
|
updateSelectedCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 11:48:36 +00:00
|
|
|
|
2015-06-29 17:12:11 +00:00
|
|
|
captionEditText = new PhotoViewerCaptionEnterView(parentActivity, containerView);
|
2015-05-03 11:48:36 +00:00
|
|
|
captionEditText.setDelegate(new PhotoViewerCaptionEnterView.PhotoViewerCaptionEnterViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onCaptionEnter() {
|
|
|
|
closeCaptionEnter(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-29 17:12:11 +00:00
|
|
|
public void onTextChanged(CharSequence text) {
|
2015-05-03 11:48:36 +00:00
|
|
|
if (mentionsAdapter != null && captionEditText != null && parentChatActivity != null && text != null) {
|
|
|
|
mentionsAdapter.searchUsernameOrHashtag(text.toString(), captionEditText.getCursorPosition(), parentChatActivity.messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onWindowSizeChanged(int size) {
|
2016-01-11 17:19:48 +00:00
|
|
|
int height = AndroidUtilities.dp(36 * Math.min(3, mentionsAdapter.getItemCount()) + (mentionsAdapter.getItemCount() > 3 ? 18 : 0));
|
2015-07-22 18:56:37 +00:00
|
|
|
if (size - ActionBar.getCurrentActionBarHeight() * 2 < height) {
|
2015-05-03 11:48:36 +00:00
|
|
|
allowMentions = false;
|
|
|
|
if (mentionListView != null && mentionListView.getVisibility() == View.VISIBLE) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allowMentions = true;
|
|
|
|
if (mentionListView != null && mentionListView.getVisibility() == View.INVISIBLE) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(captionEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, -400));
|
2015-05-03 11:48:36 +00:00
|
|
|
|
2016-01-11 17:19:48 +00:00
|
|
|
mentionListView = new RecyclerListView(parentActivity);
|
|
|
|
mentionLayoutManager = new LinearLayoutManager(parentActivity) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
mentionListView.setLayoutManager(mentionLayoutManager);
|
2015-05-03 11:48:36 +00:00
|
|
|
mentionListView.setBackgroundColor(0x7f000000);
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
mentionListView.setClipToPadding(true);
|
|
|
|
if (Build.VERSION.SDK_INT > 8) {
|
|
|
|
mentionListView.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
|
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(mentionListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(parentActivity, true, new MentionsAdapter.MentionsAdapterDelegate() {
|
|
|
|
@Override
|
|
|
|
public void needChangePanelVisibility(boolean show) {
|
|
|
|
if (show) {
|
2015-06-29 17:12:11 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) mentionListView.getLayoutParams();
|
2016-01-11 17:19:48 +00:00
|
|
|
int height = 36 * Math.min(3, mentionsAdapter.getItemCount()) + (mentionsAdapter.getItemCount() > 3 ? 18 : 0);
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams3.height = AndroidUtilities.dp(height);
|
|
|
|
layoutParams3.topMargin = -AndroidUtilities.dp(height);
|
|
|
|
mentionListView.setLayoutParams(layoutParams3);
|
|
|
|
|
|
|
|
if (mentionListAnimation != null) {
|
|
|
|
mentionListAnimation.cancel();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mentionListView.getVisibility() == View.VISIBLE) {
|
|
|
|
ViewProxy.setAlpha(mentionListView, 1.0f);
|
|
|
|
return;
|
2016-01-11 17:19:48 +00:00
|
|
|
} else {
|
|
|
|
mentionLayoutManager.scrollToPositionWithOffset(0, 10000);
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
|
|
|
if (allowMentions) {
|
|
|
|
mentionListView.setVisibility(View.VISIBLE);
|
|
|
|
mentionListAnimation = new AnimatorSetProxy();
|
|
|
|
mentionListAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(mentionListView, "alpha", 0.0f, 1.0f)
|
|
|
|
);
|
|
|
|
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mentionListAnimation.setDuration(200);
|
|
|
|
mentionListAnimation.start();
|
|
|
|
} else {
|
|
|
|
ViewProxy.setAlpha(mentionListView, 1.0f);
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mentionListAnimation != null) {
|
|
|
|
mentionListAnimation.cancel();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mentionListView.getVisibility() == View.GONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (allowMentions) {
|
|
|
|
mentionListAnimation = new AnimatorSetProxy();
|
|
|
|
mentionListAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(mentionListView, "alpha", 0.0f)
|
|
|
|
);
|
|
|
|
mentionListAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mentionListAnimation.setDuration(200);
|
|
|
|
mentionListAnimation.start();
|
|
|
|
} else {
|
|
|
|
mentionListView.clearAnimation();
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 17:19:48 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContextSearch(boolean searching) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContextClick(TLRPC.BotInlineResult result) {
|
|
|
|
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
}));
|
|
|
|
|
2016-01-11 17:19:48 +00:00
|
|
|
mentionListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
2015-05-03 11:48:36 +00:00
|
|
|
@Override
|
2016-01-11 17:19:48 +00:00
|
|
|
public void onItemClick(View view, int position) {
|
2015-05-03 11:48:36 +00:00
|
|
|
Object object = mentionsAdapter.getItem(position);
|
|
|
|
int start = mentionsAdapter.getResultStartPosition();
|
|
|
|
int len = mentionsAdapter.getResultLength();
|
|
|
|
if (object instanceof TLRPC.User) {
|
|
|
|
TLRPC.User user = (TLRPC.User) object;
|
|
|
|
if (user != null) {
|
|
|
|
captionEditText.replaceWithText(start, len, "@" + user.username + " ");
|
|
|
|
}
|
|
|
|
} else if (object instanceof String) {
|
|
|
|
captionEditText.replaceWithText(start, len, object + " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-11 17:19:48 +00:00
|
|
|
mentionListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
|
2015-05-03 11:48:36 +00:00
|
|
|
@Override
|
2016-01-11 17:19:48 +00:00
|
|
|
public boolean onItemClick(View view, int position) {
|
2015-05-03 11:48:36 +00:00
|
|
|
Object object = mentionsAdapter.getItem(position);
|
|
|
|
if (object instanceof String) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
mentionsAdapter.clearRecentHashtags();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCaptionTextForCurrentPhoto(Object object) {
|
|
|
|
CharSequence caption = null;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
caption = ((MediaController.PhotoEntry) object).caption;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
caption = ((MediaController.SearchImage) object).caption;
|
|
|
|
}
|
|
|
|
if (caption == null || caption.length() == 0) {
|
|
|
|
captionEditText.setFieldText("");
|
|
|
|
} else {
|
|
|
|
captionEditText.setFieldText(caption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void closeCaptionEnter(boolean apply) {
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (apply) {
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
((MediaController.PhotoEntry) object).caption = captionEditText.getFieldCharSequence();
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
((MediaController.SearchImage) object).caption = captionEditText.getFieldCharSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (captionEditText.getFieldCharSequence().length() != 0 && !placeProvider.isPhotoChecked(currentIndex)) {
|
|
|
|
placeProvider.setPhotoChecked(currentIndex);
|
|
|
|
checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), true);
|
|
|
|
updateSelectedCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cropItem.setVisibility(View.VISIBLE);
|
|
|
|
captionItem.setVisibility(View.VISIBLE);
|
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
|
|
tuneItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
captionDoneItem.setVisibility(View.GONE);
|
|
|
|
pickerView.setVisibility(View.VISIBLE);
|
|
|
|
|
2015-06-29 17:12:11 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) captionEditText.getLayoutParams();
|
|
|
|
layoutParams.bottomMargin = -AndroidUtilities.dp(400);
|
|
|
|
captionEditText.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) mentionListView.getLayoutParams();
|
|
|
|
layoutParams.bottomMargin = -AndroidUtilities.dp(400);
|
|
|
|
mentionListView.setLayoutParams(layoutParams);
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
if (lastTitle != null) {
|
|
|
|
actionBar.setTitle(lastTitle);
|
|
|
|
lastTitle = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCaptionTextForCurrentPhoto(object);
|
|
|
|
setCurrentCaption(captionEditText.getFieldCharSequence());
|
2015-06-29 17:12:11 +00:00
|
|
|
if (captionEditText.isPopupShowing()) {
|
|
|
|
captionEditText.hidePopup();
|
2015-05-03 11:48:36 +00:00
|
|
|
} else {
|
|
|
|
captionEditText.closeKeyboard();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
private void showAlertDialog(AlertDialog.Builder builder) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
visibleDialog = builder.show();
|
|
|
|
visibleDialog.setCanceledOnTouchOutside(true);
|
|
|
|
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyCurrentEditMode() {
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
bitmap = photoCropView.getBitmap();
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
bitmap = photoFilterView.getBitmap();
|
|
|
|
}
|
|
|
|
if (bitmap != null) {
|
|
|
|
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false, 101, 101);
|
|
|
|
if (size != null) {
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry entry = (MediaController.PhotoEntry) object;
|
|
|
|
entry.imagePath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.dp(120), AndroidUtilities.dp(120), 70, false, 101, 101);
|
|
|
|
if (size != null) {
|
|
|
|
entry.thumbPath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
}
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage entry = (MediaController.SearchImage) object;
|
|
|
|
entry.imagePath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.dp(120), AndroidUtilities.dp(120), 70, false, 101, 101);
|
|
|
|
if (size != null) {
|
|
|
|
entry.thumbPath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sendPhotoType == 0 && placeProvider != null) {
|
|
|
|
placeProvider.updatePhotoAtIndex(currentIndex);
|
|
|
|
if (!placeProvider.isPhotoChecked(currentIndex)) {
|
|
|
|
placeProvider.setPhotoChecked(currentIndex);
|
|
|
|
checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), true);
|
|
|
|
updateSelectedCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
float scaleX = photoCropView.getRectSizeX() / (float) getContainerViewWidth();
|
|
|
|
float scaleY = photoCropView.getRectSizeY() / (float) getContainerViewHeight();
|
|
|
|
scale = scaleX > scaleY ? scaleX : scaleY;
|
|
|
|
translationX = photoCropView.getRectX() + photoCropView.getRectSizeX() / 2 - getContainerViewWidth() / 2;
|
|
|
|
translationY = photoCropView.getRectY() + photoCropView.getRectSizeY() / 2 - getContainerViewHeight() / 2;
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
centerImage.setParentView(null);
|
|
|
|
centerImage.setOrientation(0, true);
|
|
|
|
centerImage.setImageBitmap(bitmap);
|
|
|
|
centerImage.setParentView(containerView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchToEditMode(final int mode) {
|
2015-05-03 11:48:36 +00:00
|
|
|
if (currentEditMode == mode || centerImage.getBitmap() == null || changeModeAnimation != null || imageMoveAnimation != null || radialProgressViews[0].backgroundState != -1) {
|
2015-02-26 01:32:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mode == 0) {
|
|
|
|
if (currentEditMode == 2) {
|
|
|
|
if (photoFilterView.getToolsView().getVisibility() != View.VISIBLE) {
|
|
|
|
photoFilterView.switchToOrFromEditMode();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bitmap bitmap = centerImage.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(0) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(0) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
|
|
|
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
animateToX = 0;
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
animateToY = AndroidUtilities.dp(24);
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
animateToY = AndroidUtilities.dp(62);
|
|
|
|
}
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
imageMoveAnimation = new AnimatorSetProxy();
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48)),
|
|
|
|
ObjectAnimatorProxy.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
|
|
|
ObjectAnimatorProxy.ofFloat(photoCropView, "alpha", 0)
|
|
|
|
);
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
photoFilterView.shutdown();
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(photoFilterView.getToolsView(), "translationY", AndroidUtilities.dp(126)),
|
|
|
|
ObjectAnimatorProxy.ofFloat(PhotoViewer.this, "animationValue", 0, 1)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
imageMoveAnimation.setDuration(200);
|
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.clearAnimation();
|
|
|
|
editorDoneLayout.clearAnimation();
|
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
photoFilterView.getToolsView().clearAnimation();
|
|
|
|
containerView.removeView(photoFilterView);
|
|
|
|
photoFilterView = null;
|
|
|
|
}
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
|
|
|
|
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
|
|
|
ArrayList<Object> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(pickerView, "translationY", 0));
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(actionBar, "translationY", 0));
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(captionTextView, "translationY", 0));
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(checkImageView, "alpha", 1));
|
|
|
|
}
|
|
|
|
animatorSet.playTogether(arrayList);
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Object animation) {
|
|
|
|
pickerView.setVisibility(View.VISIBLE);
|
|
|
|
actionBar.setVisibility(View.VISIBLE);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.setVisibility(captionTextView.getTag() != null ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
pickerView.clearAnimation();
|
|
|
|
actionBar.clearAnimation();
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.clearAnimation();
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.clearAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
} else if (mode == 1) {
|
|
|
|
if (photoCropView == null) {
|
|
|
|
photoCropView = new PhotoCropView(parentActivity);
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(photoCropView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
|
2015-02-26 01:32:51 +00:00
|
|
|
photoCropView.setDelegate(new PhotoCropView.PhotoCropViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void needMoveImageTo(float x, float y, float s, boolean animated) {
|
|
|
|
if (animated) {
|
|
|
|
animateTo(s, x, y, true);
|
|
|
|
} else {
|
|
|
|
translationX = x;
|
|
|
|
translationY = y;
|
|
|
|
scale = s;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 12:26:32 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Bitmap getBitmap() {
|
|
|
|
return centerImage.getBitmap();
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
editorDoneLayout.doneButtonTextView.setText(LocaleController.getString("Crop", R.string.Crop));
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation = new AnimatorSetProxy();
|
2015-02-26 01:32:51 +00:00
|
|
|
ArrayList<Object> arrayList = new ArrayList<>();
|
2015-05-03 11:48:36 +00:00
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
|
2015-02-26 01:32:51 +00:00
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(checkImageView, "alpha", 1, 0));
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation.playTogether(arrayList);
|
|
|
|
changeModeAnimation.setDuration(200);
|
|
|
|
changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
2015-02-26 01:32:51 +00:00
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation = null;
|
2015-02-26 01:32:51 +00:00
|
|
|
pickerView.clearAnimation();
|
|
|
|
actionBar.clearAnimation();
|
|
|
|
pickerView.setVisibility(View.GONE);
|
|
|
|
actionBar.setVisibility(View.GONE);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.clearAnimation();
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.clearAnimation();
|
|
|
|
checkImageView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap bitmap = centerImage.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
photoCropView.setBitmap(bitmap, centerImage.getOrientation(), sendPhotoType != 1);
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(1) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(1) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
|
|
|
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = -AndroidUtilities.dp(24);
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
imageMoveAnimation = new AnimatorSetProxy();
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48), 0),
|
|
|
|
ObjectAnimatorProxy.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
|
|
|
ObjectAnimatorProxy.ofFloat(photoCropView, "alpha", 0, 1)
|
|
|
|
);
|
|
|
|
imageMoveAnimation.setDuration(200);
|
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Object animation) {
|
|
|
|
editorDoneLayout.setVisibility(View.VISIBLE);
|
|
|
|
photoCropView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
editorDoneLayout.clearAnimation();
|
|
|
|
photoCropView.clearAnimation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation.start();
|
2015-02-26 01:32:51 +00:00
|
|
|
} else if (mode == 2) {
|
|
|
|
if (photoFilterView == null) {
|
|
|
|
photoFilterView = new PhotoFilterView(parentActivity, centerImage.getBitmap(), centerImage.getOrientation());
|
2015-06-29 17:12:11 +00:00
|
|
|
containerView.addView(photoFilterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-02-26 01:32:51 +00:00
|
|
|
photoFilterView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
applyCurrentEditMode();
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
photoFilterView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (photoFilterView.hasChanges()) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setMessage(LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
} else {
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//photoFilterView.setEditViewFirst();
|
|
|
|
ViewProxy.setTranslationY(photoFilterView.getToolsView(), AndroidUtilities.dp(126));
|
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation = new AnimatorSetProxy();
|
2015-02-26 01:32:51 +00:00
|
|
|
ArrayList<Object> arrayList = new ArrayList<>();
|
2015-05-03 11:48:36 +00:00
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
|
2015-02-26 01:32:51 +00:00
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(checkImageView, "alpha", 1, 0));
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation.playTogether(arrayList);
|
|
|
|
changeModeAnimation.setDuration(200);
|
|
|
|
changeModeAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
2015-02-26 01:32:51 +00:00
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation = null;
|
2015-02-26 01:32:51 +00:00
|
|
|
pickerView.clearAnimation();
|
|
|
|
actionBar.clearAnimation();
|
|
|
|
pickerView.setVisibility(View.GONE);
|
|
|
|
actionBar.setVisibility(View.GONE);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.clearAnimation();
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.clearAnimation();
|
|
|
|
checkImageView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap bitmap = centerImage.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(2) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(2) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
|
|
|
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = -AndroidUtilities.dp(62);
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
imageMoveAnimation = new AnimatorSetProxy();
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
|
|
|
ObjectAnimatorProxy.ofFloat(photoFilterView.getToolsView(), "translationY", AndroidUtilities.dp(126), 0)
|
|
|
|
);
|
|
|
|
imageMoveAnimation.setDuration(200);
|
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Object animation) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
photoFilterView.init();
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
photoFilterView.getToolsView().clearAnimation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation.start();
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
private void toggleCheckImageView(boolean show) {
|
|
|
|
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
2015-02-26 01:32:51 +00:00
|
|
|
ArrayList<Object> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(pickerView, "alpha", show ? 1.0f : 0.0f));
|
2015-05-03 11:48:36 +00:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(captionTextView, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(checkImageView, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
}
|
|
|
|
animatorSet.playTogether(arrayList);
|
2015-01-02 22:15:07 +00:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
|
2015-02-01 18:51:02 +00:00
|
|
|
private void toggleActionBar(boolean show, final boolean animated) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (show) {
|
|
|
|
actionBar.setVisibility(View.VISIBLE);
|
|
|
|
if (canShowBottom) {
|
|
|
|
bottomLayout.setVisibility(View.VISIBLE);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
captionTextView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
isActionBarVisible = show;
|
|
|
|
actionBar.setEnabled(show);
|
|
|
|
bottomLayout.setEnabled(show);
|
|
|
|
|
2014-11-06 21:34:47 +00:00
|
|
|
if (animated) {
|
2015-05-03 11:48:36 +00:00
|
|
|
ArrayList<Object> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(actionBar, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(bottomLayout, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
arrayList.add(ObjectAnimatorProxy.ofFloat(captionTextView, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
currentActionBarAnimation = new AnimatorSetProxy();
|
2015-05-03 11:48:36 +00:00
|
|
|
currentActionBarAnimation.playTogether(arrayList);
|
2014-11-06 21:34:47 +00:00
|
|
|
if (!show) {
|
2015-02-01 18:51:02 +00:00
|
|
|
currentActionBarAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
2014-11-06 21:34:47 +00:00
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
2015-10-29 17:10:07 +00:00
|
|
|
if (currentActionBarAnimation != null && currentActionBarAnimation.equals(animation)) {
|
2015-02-01 18:51:02 +00:00
|
|
|
actionBar.setVisibility(View.GONE);
|
|
|
|
if (canShowBottom) {
|
2015-02-26 01:32:51 +00:00
|
|
|
bottomLayout.clearAnimation();
|
2015-02-01 18:51:02 +00:00
|
|
|
bottomLayout.setVisibility(View.GONE);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
captionTextView.clearAnimation();
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
}
|
|
|
|
currentActionBarAnimation = null;
|
2014-11-06 21:34:47 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-11-06 21:34:47 +00:00
|
|
|
});
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-11-06 21:34:47 +00:00
|
|
|
|
2015-02-01 18:51:02 +00:00
|
|
|
currentActionBarAnimation.setDuration(200);
|
|
|
|
currentActionBarAnimation.start();
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2014-11-06 21:34:47 +00:00
|
|
|
ViewProxy.setAlpha(actionBar, show ? 1.0f : 0.0f);
|
|
|
|
ViewProxy.setAlpha(bottomLayout, show ? 1.0f : 0.0f);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
ViewProxy.setAlpha(captionTextView, show ? 1.0f : 0.0f);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
if (!show) {
|
|
|
|
actionBar.setVisibility(View.GONE);
|
|
|
|
if (canShowBottom) {
|
2015-02-26 01:32:51 +00:00
|
|
|
bottomLayout.clearAnimation();
|
2014-06-10 23:05:54 +00:00
|
|
|
bottomLayout.setVisibility(View.GONE);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
captionTextView.clearAnimation();
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:07:44 +00:00
|
|
|
private String getFileName(int index) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (index < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
if (!imagesArrLocations.isEmpty() || !imagesArr.isEmpty()) {
|
|
|
|
if (!imagesArrLocations.isEmpty()) {
|
2016-03-06 01:49:31 +00:00
|
|
|
if (index >= imagesArrLocations.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
TLRPC.FileLocation location = imagesArrLocations.get(index);
|
|
|
|
return location.volume_id + "_" + location.local_id + ".jpg";
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (!imagesArr.isEmpty()) {
|
2016-03-06 01:49:31 +00:00
|
|
|
if (index >= imagesArr.size()) {
|
|
|
|
return null;
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2016-03-06 01:49:31 +00:00
|
|
|
return FileLoader.getMessageFileName(imagesArr.get(index).messageOwner);
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
} else if (!imagesArrLocals.isEmpty()) {
|
|
|
|
if (index >= imagesArrLocals.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Object object = imagesArrLocals.get(index);
|
|
|
|
if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = ((MediaController.SearchImage) object);
|
2016-01-11 17:19:48 +00:00
|
|
|
if (searchImage.document != null) {
|
|
|
|
return FileLoader.getAttachFileName(searchImage.document);
|
|
|
|
} else if (searchImage.type != 1 && searchImage.localUrl != null && searchImage.localUrl.length() > 0) {
|
2015-01-02 22:15:07 +00:00
|
|
|
File file = new File(searchImage.localUrl);
|
|
|
|
if (file.exists()) {
|
|
|
|
return file.getName();
|
|
|
|
} else {
|
|
|
|
searchImage.localUrl = "";
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2016-03-06 01:49:31 +00:00
|
|
|
return Utilities.MD5(searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.imageUrl, "jpg");
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private TLRPC.FileLocation getFileLocation(int index, int size[]) {
|
|
|
|
if (index < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!imagesArrLocations.isEmpty()) {
|
|
|
|
if (index >= imagesArrLocations.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
size[0] = imagesArrLocationsSizes.get(index);
|
|
|
|
return imagesArrLocations.get(index);
|
|
|
|
} else if (!imagesArr.isEmpty()) {
|
|
|
|
if (index >= imagesArr.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
MessageObject message = imagesArr.get(index);
|
|
|
|
if (message.messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
|
|
|
return message.messageOwner.action.newUserPhoto.photo_big;
|
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
|
2014-06-10 23:05:54 +00:00
|
|
|
if (sizeFull != null) {
|
|
|
|
size[0] = sizeFull.size;
|
2014-06-11 00:22:42 +00:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
return sizeFull.location;
|
2014-06-11 00:22:42 +00:00
|
|
|
} else {
|
|
|
|
size[0] = -1;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-13 09:23:31 +00:00
|
|
|
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null || message.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && message.messageOwner.media.webpage != null) {
|
2015-02-01 18:51:02 +00:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
|
2014-06-10 23:05:54 +00:00
|
|
|
if (sizeFull != null) {
|
|
|
|
size[0] = sizeFull.size;
|
2014-06-11 00:22:42 +00:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
return sizeFull.location;
|
2014-06-11 00:22:42 +00:00
|
|
|
} else {
|
|
|
|
size[0] = -1;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2016-03-06 01:49:31 +00:00
|
|
|
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaDocument && message.messageOwner.media.document != null && message.messageOwner.media.document.thumb != null) {
|
|
|
|
size[0] = message.messageOwner.media.document.thumb.size;
|
2014-06-11 00:22:42 +00:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2016-03-06 01:49:31 +00:00
|
|
|
return message.messageOwner.media.document.thumb.location;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
private void updateSelectedCount() {
|
|
|
|
if (placeProvider == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
pickerView.updateSelectedCount(placeProvider.getSelectedCount(), false);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList<MessageObject> messages, final ArrayList<Object> photos, int index, final PlaceProviderObject object) {
|
2014-06-10 23:05:54 +00:00
|
|
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
|
|
|
currentMessageObject = null;
|
|
|
|
currentFileLocation = null;
|
2014-06-12 01:13:15 +00:00
|
|
|
currentPathObject = null;
|
2014-06-10 23:05:54 +00:00
|
|
|
currentIndex = -1;
|
2014-10-28 17:07:44 +00:00
|
|
|
currentFileNames[0] = null;
|
|
|
|
currentFileNames[1] = null;
|
|
|
|
currentFileNames[2] = null;
|
2014-06-10 23:05:54 +00:00
|
|
|
avatarsUserId = 0;
|
|
|
|
totalImagesCount = 0;
|
2015-11-26 21:04:02 +00:00
|
|
|
totalImagesCountMerge = 0;
|
2015-02-26 01:32:51 +00:00
|
|
|
currentEditMode = 0;
|
2014-06-10 23:05:54 +00:00
|
|
|
isFirstLoading = true;
|
|
|
|
needSearchImageInArr = false;
|
|
|
|
loadingMoreImages = false;
|
2015-11-26 21:04:02 +00:00
|
|
|
endReached[0] = false;
|
|
|
|
endReached[1] = mergeDialogId == 0;
|
2014-06-10 23:05:54 +00:00
|
|
|
opennedFromMedia = false;
|
2015-05-03 11:48:36 +00:00
|
|
|
needCaptionLayout = false;
|
2014-06-12 01:13:15 +00:00
|
|
|
canShowBottom = true;
|
2014-06-10 23:05:54 +00:00
|
|
|
imagesArr.clear();
|
|
|
|
imagesArrLocations.clear();
|
|
|
|
imagesArrLocationsSizes.clear();
|
2014-08-22 14:24:33 +00:00
|
|
|
avatarsArr.clear();
|
2014-06-12 01:13:15 +00:00
|
|
|
imagesArrLocals.clear();
|
2015-11-26 21:04:02 +00:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
imagesByIds[a].clear();
|
|
|
|
imagesByIdsTemp[a].clear();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
imagesArrTemp.clear();
|
2014-08-22 14:24:33 +00:00
|
|
|
currentUserAvatarLocation = null;
|
2015-05-03 11:48:36 +00:00
|
|
|
containerView.setPadding(0, 0, 0, 0);
|
2015-02-26 01:32:51 +00:00
|
|
|
currentThumb = object != null ? object.thumb : null;
|
2014-06-12 01:13:15 +00:00
|
|
|
menuItem.setVisibility(View.VISIBLE);
|
|
|
|
bottomLayout.setVisibility(View.VISIBLE);
|
2015-02-26 01:32:51 +00:00
|
|
|
shareButton.setVisibility(View.GONE);
|
|
|
|
menuItem.hideSubItem(gallery_menu_showall);
|
|
|
|
ViewProxy.setTranslationY(actionBar, 0);
|
|
|
|
ViewProxy.setTranslationY(pickerView, 0);
|
2015-01-02 22:15:07 +00:00
|
|
|
ViewProxy.setAlpha(checkImageView, 1.0f);
|
2015-02-01 18:51:02 +00:00
|
|
|
ViewProxy.setAlpha(pickerView, 1.0f);
|
2015-01-02 22:15:07 +00:00
|
|
|
checkImageView.clearAnimation();
|
2015-02-01 18:51:02 +00:00
|
|
|
pickerView.clearAnimation();
|
2015-02-26 01:32:51 +00:00
|
|
|
editorDoneLayout.clearAnimation();
|
2014-06-12 01:13:15 +00:00
|
|
|
checkImageView.setVisibility(View.GONE);
|
|
|
|
pickerView.setVisibility(View.GONE);
|
2015-02-26 01:32:51 +00:00
|
|
|
cropItem.setVisibility(View.GONE);
|
|
|
|
tuneItem.setVisibility(View.GONE);
|
2015-05-03 11:48:36 +00:00
|
|
|
captionItem.setVisibility(View.GONE);
|
|
|
|
captionDoneItem.setVisibility(View.GONE);
|
|
|
|
captionEditText.clearAnimation();
|
|
|
|
captionEditText.setVisibility(View.GONE);
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
2015-02-26 01:32:51 +00:00
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
2015-05-03 11:48:36 +00:00
|
|
|
captionTextView.setTag(null);
|
2015-05-21 21:27:27 +00:00
|
|
|
captionTextView.clearAnimation();
|
2015-05-03 11:48:36 +00:00
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (photoCropView != null) {
|
|
|
|
photoCropView.clearAnimation();
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (photoFilterView != null) {
|
|
|
|
photoFilterView.clearAnimation();
|
|
|
|
photoFilterView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:07:44 +00:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (radialProgressViews[a] != null) {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(-1, false);
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
if (messageObject != null && messages == null) {
|
|
|
|
imagesArr.add(messageObject);
|
2015-08-13 09:23:31 +00:00
|
|
|
if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty)) {
|
2014-06-10 23:05:54 +00:00
|
|
|
needSearchImageInArr = true;
|
2015-11-26 21:04:02 +00:00
|
|
|
imagesByIds[0].put(messageObject.getId(), messageObject);
|
2014-06-10 23:05:54 +00:00
|
|
|
menuItem.showSubItem(gallery_menu_showall);
|
|
|
|
} else {
|
|
|
|
menuItem.hideSubItem(gallery_menu_showall);
|
|
|
|
}
|
|
|
|
setImageIndex(0, true);
|
|
|
|
} else if (fileLocation != null) {
|
|
|
|
avatarsUserId = object.user_id;
|
|
|
|
imagesArrLocations.add(fileLocation);
|
|
|
|
imagesArrLocationsSizes.add(object.size);
|
2014-08-22 14:24:33 +00:00
|
|
|
avatarsArr.add(new TLRPC.TL_photoEmpty());
|
2015-02-26 01:32:51 +00:00
|
|
|
bottomLayout.clearAnimation();
|
2014-10-22 10:11:47 +00:00
|
|
|
shareButton.setVisibility(View.VISIBLE);
|
2014-06-10 23:05:54 +00:00
|
|
|
menuItem.hideSubItem(gallery_menu_showall);
|
|
|
|
setImageIndex(0, true);
|
2014-08-22 14:24:33 +00:00
|
|
|
currentUserAvatarLocation = fileLocation;
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (messages != null) {
|
2015-02-26 01:32:51 +00:00
|
|
|
menuItem.showSubItem(gallery_menu_showall);
|
|
|
|
opennedFromMedia = true;
|
2014-06-10 23:05:54 +00:00
|
|
|
imagesArr.addAll(messages);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (!opennedFromMedia) {
|
|
|
|
Collections.reverse(imagesArr);
|
|
|
|
index = imagesArr.size() - index - 1;
|
|
|
|
}
|
2015-11-26 21:04:02 +00:00
|
|
|
for (int a = 0; a < imagesArr.size(); a++) {
|
|
|
|
MessageObject message = imagesArr.get(a);
|
|
|
|
imagesByIds[message.getDialogId() == currentDialogId ? 0 : 1].put(message.getId(), message);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
setImageIndex(index, true);
|
2014-06-12 01:13:15 +00:00
|
|
|
} else if (photos != null) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
menuItem.setVisibility(View.GONE);
|
|
|
|
imagesArrLocals.addAll(photos);
|
|
|
|
setImageIndex(index, true);
|
|
|
|
pickerView.setVisibility(View.VISIBLE);
|
2015-02-26 01:32:51 +00:00
|
|
|
bottomLayout.clearAnimation();
|
2014-06-12 19:55:13 +00:00
|
|
|
bottomLayout.setVisibility(View.GONE);
|
|
|
|
canShowBottom = false;
|
2015-02-26 01:32:51 +00:00
|
|
|
Object obj = imagesArrLocals.get(index);
|
|
|
|
cropItem.setVisibility(obj instanceof MediaController.PhotoEntry || obj instanceof MediaController.SearchImage && ((MediaController.SearchImage) obj).type == 0 ? View.VISIBLE : View.GONE);
|
2016-03-06 01:49:31 +00:00
|
|
|
if (parentChatActivity != null && (parentChatActivity.currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(parentChatActivity.currentEncryptedChat.layer) >= 46)) {
|
2015-05-03 11:48:36 +00:00
|
|
|
mentionsAdapter.setChatInfo(parentChatActivity.info);
|
|
|
|
mentionsAdapter.setNeedUsernames(parentChatActivity.currentChat != null);
|
2016-01-11 17:19:48 +00:00
|
|
|
mentionsAdapter.setNeedBotContext(false);
|
2015-05-03 11:48:36 +00:00
|
|
|
captionItem.setVisibility(cropItem.getVisibility());
|
|
|
|
captionEditText.setVisibility(cropItem.getVisibility());
|
|
|
|
needCaptionLayout = captionItem.getVisibility() == View.VISIBLE;
|
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionEditText.onCreate();
|
|
|
|
}
|
|
|
|
}
|
2015-02-27 19:57:58 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
2015-02-26 01:32:51 +00:00
|
|
|
tuneItem.setVisibility(cropItem.getVisibility());
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
updateSelectedCount();
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentDialogId != 0 && totalImagesCount == 0) {
|
2015-02-01 18:51:02 +00:00
|
|
|
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
|
2015-11-26 21:04:02 +00:00
|
|
|
if (mergeDialogId != 0) {
|
|
|
|
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (avatarsUserId != 0) {
|
2014-10-28 17:07:44 +00:00
|
|
|
MessagesController.getInstance().loadUserPhotos(avatarsUserId, 0, 80, 0, true, classGuid);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-01 18:51:02 +00:00
|
|
|
private void setImages() {
|
|
|
|
if (animationInProgress == 0) {
|
|
|
|
setIndexToImage(centerImage, currentIndex);
|
|
|
|
setIndexToImage(rightImage, currentIndex + 1);
|
|
|
|
setIndexToImage(leftImage, currentIndex - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setImageIndex(int index, boolean init) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (currentIndex == index) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!init) {
|
|
|
|
currentThumb = null;
|
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
currentFileNames[0] = getFileName(index);
|
|
|
|
currentFileNames[1] = getFileName(index + 1);
|
|
|
|
currentFileNames[2] = getFileName(index - 1);
|
2014-11-19 15:17:24 +00:00
|
|
|
placeProvider.willSwitchFromPhoto(currentMessageObject, currentFileLocation, currentIndex);
|
|
|
|
int prevIndex = currentIndex;
|
|
|
|
currentIndex = index;
|
2016-03-06 01:49:31 +00:00
|
|
|
boolean isVideo = false;
|
2014-08-29 21:06:04 +00:00
|
|
|
boolean sameImage = false;
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
if (!imagesArr.isEmpty()) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(false, false);
|
2015-01-02 22:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
currentMessageObject = imagesArr.get(currentIndex);
|
2016-03-06 01:49:31 +00:00
|
|
|
isVideo = currentMessageObject.isVideo();
|
2015-09-24 20:52:02 +00:00
|
|
|
if (currentMessageObject.canDeleteMessage(null)) {
|
|
|
|
menuItem.showSubItem(gallery_menu_delete);
|
|
|
|
} else {
|
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
|
|
|
}
|
2016-03-06 01:49:31 +00:00
|
|
|
if (currentMessageObject.isFromUser()) {
|
2015-09-24 20:52:02 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.from_id);
|
|
|
|
if (user != null) {
|
|
|
|
nameTextView.setText(UserObject.getUserName(user));
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2016-03-06 01:49:31 +00:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentMessageObject.messageOwner.to_id.channel_id);
|
2015-09-24 20:52:02 +00:00
|
|
|
if (chat != null) {
|
|
|
|
nameTextView.setText(chat.title);
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
long date = (long) currentMessageObject.messageOwner.date * 1000;
|
2015-11-26 21:04:02 +00:00
|
|
|
String dateString = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)));
|
2016-03-06 01:49:31 +00:00
|
|
|
if (currentFileNames[0] != null && isVideo) {
|
|
|
|
dateTextView.setText(String.format("%s (%s)", dateString, AndroidUtilities.formatFileSize(currentMessageObject.messageOwner.media.document.size)));
|
2014-10-28 17:07:44 +00:00
|
|
|
} else {
|
2015-02-26 01:32:51 +00:00
|
|
|
dateTextView.setText(dateString);
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
CharSequence caption = currentMessageObject.caption;
|
|
|
|
setCurrentCaption(caption);
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-11-26 21:04:02 +00:00
|
|
|
if (totalImagesCount + totalImagesCountMerge != 0 && !needSearchImageInArr) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (opennedFromMedia) {
|
2015-11-26 21:04:02 +00:00
|
|
|
if (imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && currentIndex > imagesArr.size() - 5) {
|
|
|
|
int loadFromMaxId = imagesArr.isEmpty() ? 0 : imagesArr.get(imagesArr.size() - 1).getId();
|
|
|
|
int loadIndex = 0;
|
|
|
|
if (endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArr.isEmpty() && imagesArr.get(imagesArr.size() - 1).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2015-02-26 01:32:51 +00:00
|
|
|
loadingMoreImages = true;
|
|
|
|
}
|
2015-11-26 21:04:02 +00:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
2015-02-26 01:32:51 +00:00
|
|
|
} else {
|
2015-11-26 21:04:02 +00:00
|
|
|
if (imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && currentIndex < 5) {
|
|
|
|
int loadFromMaxId = imagesArr.isEmpty() ? 0 : imagesArr.get(0).getId();
|
|
|
|
int loadIndex = 0;
|
|
|
|
if (endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArr.isEmpty() && imagesArr.get(0).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2015-02-26 01:32:51 +00:00
|
|
|
loadingMoreImages = true;
|
|
|
|
}
|
2015-11-26 21:04:02 +00:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2015-08-13 09:23:31 +00:00
|
|
|
} else if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
if (currentMessageObject.messageOwner.ttl != 0) {
|
|
|
|
menuItem.hideSubItem(gallery_menu_save);
|
|
|
|
shareButton.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
menuItem.showSubItem(gallery_menu_save);
|
|
|
|
shareButton.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (!imagesArrLocations.isEmpty()) {
|
2014-08-22 14:24:33 +00:00
|
|
|
nameTextView.setText("");
|
|
|
|
dateTextView.setText("");
|
|
|
|
if (avatarsUserId == UserConfig.getClientUserId() && !avatarsArr.isEmpty()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
menuItem.showSubItem(gallery_menu_delete);
|
2014-08-22 14:24:33 +00:00
|
|
|
} else {
|
2015-02-26 01:32:51 +00:00
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
2014-08-29 21:06:04 +00:00
|
|
|
TLRPC.FileLocation old = currentFileLocation;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (index < 0 || index >= imagesArrLocations.size()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(false, false);
|
2015-01-02 22:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
currentFileLocation = imagesArrLocations.get(index);
|
2014-08-29 21:06:04 +00:00
|
|
|
if (old != null && currentFileLocation != null && old.local_id == currentFileLocation.local_id && old.volume_id == currentFileLocation.volume_id) {
|
|
|
|
sameImage = true;
|
|
|
|
}
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, imagesArrLocations.size()));
|
2014-10-28 17:07:44 +00:00
|
|
|
menuItem.showSubItem(gallery_menu_save);
|
|
|
|
shareButton.setVisibility(View.VISIBLE);
|
2014-06-12 01:13:15 +00:00
|
|
|
} else if (!imagesArrLocals.isEmpty()) {
|
2015-01-02 22:15:07 +00:00
|
|
|
Object object = imagesArrLocals.get(index);
|
|
|
|
if (index < 0 || index >= imagesArrLocals.size()) {
|
2015-02-26 01:32:51 +00:00
|
|
|
closePhoto(false, false);
|
2015-01-02 22:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
boolean fromCamera = false;
|
2015-05-03 11:48:36 +00:00
|
|
|
CharSequence caption = null;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
currentPathObject = ((MediaController.PhotoEntry) object).path;
|
2015-02-26 01:32:51 +00:00
|
|
|
fromCamera = ((MediaController.PhotoEntry) object).bucketId == 0 && ((MediaController.PhotoEntry) object).dateTaken == 0 && imagesArrLocals.size() == 1;
|
2015-05-03 11:48:36 +00:00
|
|
|
caption = ((MediaController.PhotoEntry) object).caption;
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
2016-01-11 17:19:48 +00:00
|
|
|
MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
|
|
|
|
if (searchImage.document != null) {
|
|
|
|
currentPathObject = FileLoader.getPathToAttach(searchImage.document, true).getAbsolutePath();
|
|
|
|
} else {
|
|
|
|
currentPathObject = searchImage.imageUrl;
|
|
|
|
}
|
|
|
|
caption = searchImage.caption;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (fromCamera) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, imagesArrLocals.size()));
|
|
|
|
}
|
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), false);
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
|
|
|
|
setCurrentCaption(caption);
|
|
|
|
updateCaptionTextForCurrentPhoto(object);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 18:26:05 +00:00
|
|
|
|
2014-11-06 21:34:47 +00:00
|
|
|
if (currentPlaceObject != null) {
|
2014-06-13 18:26:05 +00:00
|
|
|
if (animationInProgress == 0) {
|
2014-06-10 23:05:54 +00:00
|
|
|
currentPlaceObject.imageReceiver.setVisible(true, true);
|
2014-06-13 18:26:05 +00:00
|
|
|
} else {
|
|
|
|
showAfterAnimation = currentPlaceObject;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
currentPlaceObject = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation, currentIndex);
|
2014-11-06 21:34:47 +00:00
|
|
|
if (currentPlaceObject != null) {
|
2014-06-13 18:26:05 +00:00
|
|
|
if (animationInProgress == 0) {
|
2014-06-10 23:05:54 +00:00
|
|
|
currentPlaceObject.imageReceiver.setVisible(false, true);
|
2014-06-13 18:26:05 +00:00
|
|
|
} else {
|
|
|
|
hideAfterAnimation = currentPlaceObject;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-29 21:06:04 +00:00
|
|
|
if (!sameImage) {
|
|
|
|
draggingDown = false;
|
|
|
|
translationX = 0;
|
|
|
|
translationY = 0;
|
|
|
|
scale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
animateToScale = 1;
|
|
|
|
animationStartTime = 0;
|
2015-02-26 01:32:51 +00:00
|
|
|
imageMoveAnimation = null;
|
2015-05-03 11:48:36 +00:00
|
|
|
changeModeAnimation = null;
|
2014-08-29 21:06:04 +00:00
|
|
|
|
|
|
|
pinchStartDistance = 0;
|
|
|
|
pinchStartScale = 1;
|
|
|
|
pinchCenterX = 0;
|
|
|
|
pinchCenterY = 0;
|
|
|
|
pinchStartX = 0;
|
|
|
|
pinchStartY = 0;
|
|
|
|
moveStartX = 0;
|
|
|
|
moveStartY = 0;
|
|
|
|
zooming = false;
|
|
|
|
moving = false;
|
|
|
|
doubleTap = false;
|
|
|
|
invalidCoords = false;
|
|
|
|
canDragDown = true;
|
|
|
|
changingPage = false;
|
|
|
|
switchImageAfterAnimation = 0;
|
2016-03-06 01:49:31 +00:00
|
|
|
canZoom = !imagesArrLocals.isEmpty() || (currentFileNames[0] != null && !isVideo && radialProgressViews[0].backgroundState != 0);
|
2014-08-29 21:06:04 +00:00
|
|
|
updateMinMax(scale);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
if (prevIndex == -1) {
|
2015-02-01 18:51:02 +00:00
|
|
|
setImages();
|
2014-11-19 01:23:46 +00:00
|
|
|
|
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
checkProgress(a, false);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2014-11-19 01:23:46 +00:00
|
|
|
checkProgress(0, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
if (prevIndex > currentIndex) {
|
|
|
|
ImageReceiver temp = rightImage;
|
|
|
|
rightImage = centerImage;
|
|
|
|
centerImage = leftImage;
|
|
|
|
leftImage = temp;
|
2014-11-19 01:23:46 +00:00
|
|
|
|
|
|
|
RadialProgressView tempProgress = radialProgressViews[0];
|
|
|
|
radialProgressViews[0] = radialProgressViews[2];
|
|
|
|
radialProgressViews[2] = tempProgress;
|
2014-06-10 23:05:54 +00:00
|
|
|
setIndexToImage(leftImage, currentIndex - 1);
|
2014-11-19 01:23:46 +00:00
|
|
|
|
|
|
|
checkProgress(1, false);
|
|
|
|
checkProgress(2, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (prevIndex < currentIndex) {
|
|
|
|
ImageReceiver temp = leftImage;
|
|
|
|
leftImage = centerImage;
|
|
|
|
centerImage = rightImage;
|
|
|
|
rightImage = temp;
|
2014-11-19 01:23:46 +00:00
|
|
|
|
|
|
|
RadialProgressView tempProgress = radialProgressViews[0];
|
|
|
|
radialProgressViews[0] = radialProgressViews[1];
|
|
|
|
radialProgressViews[1] = tempProgress;
|
2014-06-10 23:05:54 +00:00
|
|
|
setIndexToImage(rightImage, currentIndex + 1);
|
|
|
|
|
2014-11-19 01:23:46 +00:00
|
|
|
checkProgress(1, false);
|
|
|
|
checkProgress(2, false);
|
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
private void setCurrentCaption(final CharSequence caption) {
|
|
|
|
if (caption != null && caption.length() > 0) {
|
|
|
|
captionTextView = captionTextViewOld;
|
|
|
|
captionTextViewOld = captionTextViewNew;
|
|
|
|
captionTextViewNew = captionTextView;
|
|
|
|
|
|
|
|
captionItem.setIcon(R.drawable.photo_text2);
|
2016-03-16 12:26:32 +00:00
|
|
|
CharSequence str = Emoji.replaceEmoji(new SpannableStringBuilder(caption.toString()), MessageObject.getTextPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2016-03-06 01:49:31 +00:00
|
|
|
captionTextView.setTag(str);
|
|
|
|
captionTextView.setText(str);
|
2015-05-03 11:48:36 +00:00
|
|
|
ViewProxy.setAlpha(captionTextView, bottomLayout.getVisibility() == View.VISIBLE || pickerView.getVisibility() == View.VISIBLE ? 1.0f : 0.0f);
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
captionTextViewOld.setTag(null);
|
2015-05-21 21:27:27 +00:00
|
|
|
captionTextViewOld.clearAnimation();
|
2015-05-03 11:48:36 +00:00
|
|
|
captionTextViewOld.setVisibility(View.INVISIBLE);
|
|
|
|
captionTextViewNew.setVisibility(bottomLayout.getVisibility() == View.VISIBLE || pickerView.getVisibility() == View.VISIBLE ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
captionItem.setIcon(R.drawable.photo_text);
|
|
|
|
captionTextView.setTag(null);
|
|
|
|
captionTextView.clearAnimation();
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:27:41 +00:00
|
|
|
private void checkProgress(int a, boolean animated) {
|
2014-10-28 17:07:44 +00:00
|
|
|
if (currentFileNames[a] != null) {
|
|
|
|
int index = currentIndex;
|
|
|
|
if (a == 1) {
|
|
|
|
index += 1;
|
|
|
|
} else if (a == 2) {
|
|
|
|
index -= 1;
|
|
|
|
}
|
2014-09-25 03:54:35 +00:00
|
|
|
File f = null;
|
2016-03-06 01:49:31 +00:00
|
|
|
boolean isVideo = false;
|
2014-09-25 03:54:35 +00:00
|
|
|
if (currentMessageObject != null) {
|
2014-10-28 17:07:44 +00:00
|
|
|
MessageObject messageObject = imagesArr.get(index);
|
|
|
|
f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
2016-03-06 01:49:31 +00:00
|
|
|
isVideo = messageObject.isVideo();
|
2014-09-25 03:54:35 +00:00
|
|
|
} else if (currentFileLocation != null) {
|
2014-10-28 17:07:44 +00:00
|
|
|
TLRPC.FileLocation location = imagesArrLocations.get(index);
|
|
|
|
f = FileLoader.getPathToAttach(location, avatarsUserId != 0);
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (currentPathObject != null) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_DOCUMENT), currentFileNames[a]);
|
|
|
|
if (!f.exists()) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), currentFileNames[a]);
|
|
|
|
}
|
2014-09-25 03:54:35 +00:00
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
if (f != null && f.exists()) {
|
2016-03-06 01:49:31 +00:00
|
|
|
if (isVideo) {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(3, animated);
|
2014-10-28 17:07:44 +00:00
|
|
|
} else {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(-1, animated);
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2016-03-06 01:49:31 +00:00
|
|
|
if (isVideo) {
|
2014-10-28 17:07:44 +00:00
|
|
|
if (!FileLoader.getInstance().isLoadingFile(currentFileNames[a])) {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(2, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(1, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(0, animated);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
Float progress = ImageLoader.getInstance().getFileProgress(currentFileNames[a]);
|
2014-10-28 17:07:44 +00:00
|
|
|
if (progress == null) {
|
|
|
|
progress = 0.0f;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
radialProgressViews[a].setProgress(progress, false);
|
|
|
|
}
|
|
|
|
if (a == 0) {
|
2016-03-06 01:49:31 +00:00
|
|
|
canZoom = !imagesArrLocals.isEmpty() || (currentFileNames[0] != null && !isVideo && radialProgressViews[0].backgroundState != 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(-1, animated);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setIndexToImage(ImageReceiver imageReceiver, int index) {
|
2015-02-26 01:32:51 +00:00
|
|
|
imageReceiver.setOrientation(0, false);
|
2014-06-12 01:13:15 +00:00
|
|
|
if (!imagesArrLocals.isEmpty()) {
|
2015-02-01 18:51:02 +00:00
|
|
|
imageReceiver.setParentMessageObject(null);
|
2014-06-12 01:13:15 +00:00
|
|
|
if (index >= 0 && index < imagesArrLocals.size()) {
|
2015-01-02 22:15:07 +00:00
|
|
|
Object object = imagesArrLocals.get(index);
|
|
|
|
int size = (int) (AndroidUtilities.getPhotoSize() / AndroidUtilities.density);
|
2014-06-12 01:13:15 +00:00
|
|
|
Bitmap placeHolder = null;
|
|
|
|
if (currentThumb != null && imageReceiver == centerImage) {
|
|
|
|
placeHolder = currentThumb;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
if (placeHolder == null) {
|
|
|
|
placeHolder = placeProvider.getThumbForPhoto(null, null, index);
|
|
|
|
}
|
|
|
|
String path = null;
|
2016-01-11 17:19:48 +00:00
|
|
|
TLRPC.Document document = null;
|
2015-01-02 22:15:07 +00:00
|
|
|
int imageSize = 0;
|
2016-01-11 17:19:48 +00:00
|
|
|
String filter = null;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
2015-02-26 01:32:51 +00:00
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
|
|
|
|
if (photoEntry.imagePath != null) {
|
|
|
|
path = photoEntry.imagePath;
|
|
|
|
} else {
|
|
|
|
imageReceiver.setOrientation(photoEntry.orientation, false);
|
|
|
|
path = photoEntry.path;
|
|
|
|
}
|
2016-01-11 17:19:48 +00:00
|
|
|
filter = String.format(Locale.US, "%d_%d", size, size);
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
2015-02-26 01:32:51 +00:00
|
|
|
MediaController.SearchImage photoEntry = (MediaController.SearchImage) object;
|
|
|
|
if (photoEntry.imagePath != null) {
|
|
|
|
path = photoEntry.imagePath;
|
2016-01-11 17:19:48 +00:00
|
|
|
} else if (photoEntry.document != null) {
|
|
|
|
document = photoEntry.document;
|
|
|
|
imageSize = photoEntry.document.size;
|
2015-02-26 01:32:51 +00:00
|
|
|
} else {
|
|
|
|
path = photoEntry.imageUrl;
|
2016-01-11 17:19:48 +00:00
|
|
|
imageSize = photoEntry.size;
|
2015-02-26 01:32:51 +00:00
|
|
|
}
|
2016-01-11 17:19:48 +00:00
|
|
|
filter = "d";
|
|
|
|
}
|
|
|
|
if (document != null) {
|
|
|
|
imageReceiver.setImage(document, null, "d", placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, placeHolder == null ? document.thumb.location : null, String.format(Locale.US, "%d_%d", size, size), imageSize, null, false);
|
|
|
|
} else {
|
|
|
|
imageReceiver.setImage(path, filter, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, null, imageSize);
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
|
|
|
imageReceiver.setImageBitmap((Bitmap) null);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
|
|
|
int size[] = new int[1];
|
|
|
|
TLRPC.FileLocation fileLocation = getFileLocation(index, size);
|
|
|
|
|
|
|
|
if (fileLocation != null) {
|
|
|
|
MessageObject messageObject = null;
|
|
|
|
if (!imagesArr.isEmpty()) {
|
|
|
|
messageObject = imagesArr.get(index);
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
imageReceiver.setParentMessageObject(messageObject);
|
|
|
|
if (messageObject != null) {
|
|
|
|
imageReceiver.setShouldGenerateQualityThumb(true);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2016-03-06 01:49:31 +00:00
|
|
|
if (messageObject != null && messageObject.isVideo()) {
|
2015-02-01 18:51:02 +00:00
|
|
|
imageReceiver.setNeedsQualityThumb(true);
|
2016-03-06 01:49:31 +00:00
|
|
|
if (messageObject.photoThumbs != null && !messageObject.photoThumbs.isEmpty()) {
|
2014-06-12 01:13:15 +00:00
|
|
|
Bitmap placeHolder = null;
|
|
|
|
if (currentThumb != null && imageReceiver == centerImage) {
|
|
|
|
placeHolder = currentThumb;
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
TLRPC.PhotoSize thumbLocation = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
|
2015-05-21 21:27:27 +00:00
|
|
|
imageReceiver.setImage(null, null, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, thumbLocation.location, "b", 0, null, true);
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
|
|
|
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
|
|
|
|
}
|
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
imageReceiver.setNeedsQualityThumb(false);
|
2014-06-10 23:05:54 +00:00
|
|
|
Bitmap placeHolder = null;
|
|
|
|
if (currentThumb != null && imageReceiver == centerImage) {
|
|
|
|
placeHolder = currentThumb;
|
|
|
|
}
|
2014-09-29 22:48:11 +00:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
TLRPC.PhotoSize thumbLocation = messageObject != null ? FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100) : null;
|
2015-05-21 21:27:27 +00:00
|
|
|
imageReceiver.setImage(fileLocation, null, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, thumbLocation != null ? thumbLocation.location : null, "b", size[0], null, avatarsUserId != 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
imageReceiver.setNeedsQualityThumb(false);
|
|
|
|
imageReceiver.setParentMessageObject(null);
|
2014-06-12 01:13:15 +00:00
|
|
|
if (size[0] == 0) {
|
|
|
|
imageReceiver.setImageBitmap((Bitmap) null);
|
|
|
|
} else {
|
|
|
|
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-11 00:22:42 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingImage(MessageObject object) {
|
2015-03-18 23:09:45 +00:00
|
|
|
return isVisible && !disableShowCheck && object != null && currentMessageObject != null && currentMessageObject.getId() == object.getId();
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingImage(TLRPC.FileLocation object) {
|
2014-11-06 21:34:47 +00:00
|
|
|
return isVisible && !disableShowCheck && object != null && currentFileLocation != null && object.local_id == currentFileLocation.local_id && object.volume_id == currentFileLocation.volume_id && object.dc_id == currentFileLocation.dc_id;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
public boolean isShowingImage(String object) {
|
2014-11-06 21:34:47 +00:00
|
|
|
return isVisible && !disableShowCheck && object != null && currentPathObject != null && object.equals(currentPathObject);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 21:04:02 +00:00
|
|
|
public void openPhoto(final MessageObject messageObject, long dialogId, long mergeDialogId, final PhotoViewerProvider provider) {
|
|
|
|
openPhoto(messageObject, null, null, null, 0, provider, null, dialogId, mergeDialogId);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void openPhoto(final TLRPC.FileLocation fileLocation, final PhotoViewerProvider provider) {
|
2015-11-26 21:04:02 +00:00
|
|
|
openPhoto(null, fileLocation, null, null, 0, provider, null, 0, 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-26 21:04:02 +00:00
|
|
|
public void openPhoto(final ArrayList<MessageObject> messages, final int index, long dialogId, long mergeDialogId, final PhotoViewerProvider provider) {
|
|
|
|
openPhoto(messages.get(index), null, messages, null, index, provider, null, dialogId, mergeDialogId);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
public void openPhotoForSelect(final ArrayList<Object> photos, final int index, int type, final PhotoViewerProvider provider, ChatActivity chatActivity) {
|
2015-02-26 01:32:51 +00:00
|
|
|
sendPhotoType = type;
|
|
|
|
if (pickerView != null) {
|
|
|
|
pickerView.doneButtonTextView.setText(sendPhotoType == 1 ? LocaleController.getString("Set", R.string.Set).toUpperCase() : LocaleController.getString("Send", R.string.Send).toUpperCase());
|
|
|
|
}
|
2015-11-26 21:04:02 +00:00
|
|
|
openPhoto(null, null, null, photos, index, provider, chatActivity, 0, 0);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
private boolean checkAnimation() {
|
|
|
|
if (animationInProgress != 0) {
|
|
|
|
if (Math.abs(transitionAnimationStartTime - System.currentTimeMillis()) >= 500) {
|
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
|
|
|
}
|
|
|
|
animationInProgress = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return animationInProgress != 0;
|
|
|
|
}
|
|
|
|
|
2015-11-26 21:04:02 +00:00
|
|
|
public void openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index, final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (parentActivity == null || isVisible || provider == null && checkAnimation() || messageObject == null && fileLocation == null && messages == null && photos == null) {
|
2014-06-10 23:05:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (object == null && photos == null) {
|
2014-06-06 23:35:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
if (windowView.attachedToWindow) {
|
|
|
|
try {
|
|
|
|
wm.removeView(windowView);
|
|
|
|
} catch (Exception e) {
|
|
|
|
//don't promt
|
|
|
|
}
|
2014-07-22 23:27:00 +00:00
|
|
|
}
|
|
|
|
|
2014-11-21 10:59:05 +00:00
|
|
|
try {
|
2015-10-29 17:10:07 +00:00
|
|
|
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED;
|
|
|
|
windowView.setFocusable(false);
|
|
|
|
containerView.setFocusable(false);
|
2014-11-21 10:59:05 +00:00
|
|
|
wm.addView(windowView, windowLayoutParams);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
parentChatActivity = chatActivity;
|
|
|
|
|
2014-11-21 10:59:05 +00:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.userPhotosLoaded);
|
2015-05-03 11:48:36 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
2014-11-21 10:59:05 +00:00
|
|
|
|
|
|
|
placeProvider = provider;
|
2015-11-26 21:04:02 +00:00
|
|
|
mergeDialogId = mDialogId;
|
|
|
|
currentDialogId = dialogId;
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
if (velocityTracker == null) {
|
|
|
|
velocityTracker = VelocityTracker.obtain();
|
|
|
|
}
|
|
|
|
|
|
|
|
isVisible = true;
|
|
|
|
toggleActionBar(true, false);
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (object != null) {
|
|
|
|
disableShowCheck = true;
|
|
|
|
animationInProgress = 1;
|
|
|
|
onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
|
2014-11-06 21:34:47 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
final Rect drawRegion = object.imageReceiver.getDrawRegion();
|
|
|
|
int orientation = object.imageReceiver.getOrientation();
|
2014-07-02 22:39:05 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
animatingImageView.setVisibility(View.VISIBLE);
|
|
|
|
animatingImageView.setRadius(object.radius);
|
|
|
|
animatingImageView.setOrientation(orientation);
|
|
|
|
animatingImageView.setNeedRadius(object.radius != 0);
|
|
|
|
animatingImageView.setImageBitmap(object.thumb);
|
|
|
|
|
|
|
|
ViewProxy.setAlpha(animatingImageView, 1.0f);
|
|
|
|
ViewProxy.setPivotX(animatingImageView, 0.0f);
|
|
|
|
ViewProxy.setPivotY(animatingImageView, 0.0f);
|
2015-10-29 17:10:07 +00:00
|
|
|
ViewProxy.setScaleX(animatingImageView, object.scale);
|
|
|
|
ViewProxy.setScaleY(animatingImageView, object.scale);
|
|
|
|
ViewProxy.setTranslationX(animatingImageView, object.viewX + drawRegion.left * object.scale);
|
|
|
|
ViewProxy.setTranslationY(animatingImageView, object.viewY + drawRegion.top * object.scale);
|
2015-02-26 01:32:51 +00:00
|
|
|
final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
|
2015-10-29 17:10:07 +00:00
|
|
|
layoutParams.width = (drawRegion.right - drawRegion.left);
|
|
|
|
layoutParams.height = (drawRegion.bottom - drawRegion.top);
|
2015-02-26 01:32:51 +00:00
|
|
|
animatingImageView.setLayoutParams(layoutParams);
|
2014-11-06 21:34:47 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
|
|
|
|
float scaleY = (float) (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight) / layoutParams.height;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float width = layoutParams.width * scale;
|
|
|
|
float height = layoutParams.height * scale;
|
|
|
|
float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
|
|
|
|
float yPos = (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight - height) / 2.0f;
|
|
|
|
int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
|
|
|
|
int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());
|
|
|
|
|
|
|
|
int coords2[] = new int[2];
|
|
|
|
object.parentView.getLocationInWindow(coords2);
|
2015-11-26 21:04:02 +00:00
|
|
|
int clipTop = coords2[1] - AndroidUtilities.statusBarHeight - (object.viewY + drawRegion.top) + object.clipTopAddition;
|
2015-05-03 11:48:36 +00:00
|
|
|
if (clipTop < 0) {
|
|
|
|
clipTop = 0;
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
int clipBottom = (object.viewY + drawRegion.top + layoutParams.height) - (coords2[1] + object.parentView.getHeight() - AndroidUtilities.statusBarHeight) + object.clipBottomAddition;
|
2015-05-03 11:48:36 +00:00
|
|
|
if (clipBottom < 0) {
|
|
|
|
clipBottom = 0;
|
|
|
|
}
|
|
|
|
clipTop = Math.max(clipTop, clipVertical);
|
|
|
|
clipBottom = Math.max(clipBottom, clipVertical);
|
|
|
|
|
|
|
|
animationValues[0][0] = ViewProxy.getScaleX(animatingImageView);
|
|
|
|
animationValues[0][1] = ViewProxy.getScaleY(animatingImageView);
|
|
|
|
animationValues[0][2] = ViewProxy.getTranslationX(animatingImageView);
|
|
|
|
animationValues[0][3] = ViewProxy.getTranslationY(animatingImageView);
|
2015-10-29 17:10:07 +00:00
|
|
|
animationValues[0][4] = clipHorizontal * object.scale;
|
|
|
|
animationValues[0][5] = clipTop * object.scale;
|
|
|
|
animationValues[0][6] = clipBottom * object.scale;
|
2015-05-03 11:48:36 +00:00
|
|
|
animationValues[0][7] = animatingImageView.getRadius();
|
|
|
|
|
|
|
|
animationValues[1][0] = scale;
|
|
|
|
animationValues[1][1] = scale;
|
|
|
|
animationValues[1][2] = xPos;
|
|
|
|
animationValues[1][3] = yPos;
|
|
|
|
animationValues[1][4] = 0;
|
|
|
|
animationValues[1][5] = 0;
|
|
|
|
animationValues[1][6] = 0;
|
|
|
|
animationValues[1][7] = 0;
|
|
|
|
|
|
|
|
animatingImageView.setAnimationProgress(0);
|
|
|
|
backgroundDrawable.setAlpha(0);
|
|
|
|
ViewProxy.setAlpha(containerView, 0);
|
|
|
|
|
|
|
|
final AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
|
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0, 255),
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f, 1.0f)
|
|
|
|
);
|
2015-02-26 01:32:51 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
animationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (containerView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
animationInProgress = 0;
|
|
|
|
transitionAnimationStartTime = 0;
|
|
|
|
setImages();
|
|
|
|
containerView.invalidate();
|
|
|
|
animatingImageView.setVisibility(View.GONE);
|
|
|
|
if (showAfterAnimation != null) {
|
|
|
|
showAfterAnimation.imageReceiver.setVisible(true, true);
|
|
|
|
}
|
|
|
|
if (hideAfterAnimation != null) {
|
|
|
|
hideAfterAnimation.imageReceiver.setVisible(false, true);
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
if (photos != null) {
|
|
|
|
windowLayoutParams.flags = 0;
|
|
|
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
|
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
wm.updateViewLayout(windowView, windowLayoutParams);
|
|
|
|
windowView.setFocusable(true);
|
|
|
|
containerView.setFocusable(true);
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
|
|
|
};
|
2015-02-26 01:32:51 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2015-02-26 01:32:51 +00:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-21 21:27:27 +00:00
|
|
|
NotificationCenter.getInstance().setAnimationInProgress(false);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
});
|
2015-05-03 11:48:36 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
});
|
2015-05-03 11:48:36 +00:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-21 21:27:27 +00:00
|
|
|
NotificationCenter.getInstance().setAnimationInProgress(true);
|
2015-05-03 11:48:36 +00:00
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 17:12:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
backgroundDrawable.drawRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
disableShowCheck = false;
|
|
|
|
object.imageReceiver.setVisible(false, true);
|
|
|
|
}
|
|
|
|
};
|
2015-02-26 01:32:51 +00:00
|
|
|
} else {
|
2015-10-29 17:10:07 +00:00
|
|
|
if (photos != null) {
|
|
|
|
windowLayoutParams.flags = 0;
|
|
|
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
|
|
|
|
wm.updateViewLayout(windowView, windowLayoutParams);
|
|
|
|
windowView.setFocusable(true);
|
|
|
|
containerView.setFocusable(true);
|
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
backgroundDrawable.setAlpha(255);
|
2015-02-26 01:32:51 +00:00
|
|
|
ViewProxy.setAlpha(containerView, 1.0f);
|
|
|
|
onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
|
|
|
|
}
|
|
|
|
}
|
2014-11-06 21:34:47 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
public void closePhoto(boolean animated, boolean fromEditMode) {
|
|
|
|
if (!fromEditMode && currentEditMode != 0) {
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
|
|
|
switchToEditMode(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-11-06 21:34:47 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode != 0) {
|
|
|
|
if (currentEditMode == 2) {
|
|
|
|
photoFilterView.shutdown();
|
|
|
|
containerView.removeView(photoFilterView);
|
|
|
|
photoFilterView = null;
|
|
|
|
} else if (currentEditMode == 1) {
|
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
2014-11-06 21:34:47 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
currentEditMode = 0;
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
if (parentActivity == null || !isVisible || checkAnimation() || placeProvider == null) {
|
2014-06-06 23:35:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
captionEditText.onDestroy();
|
|
|
|
parentChatActivity = null;
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileLoadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.userPhotosLoaded);
|
2015-05-03 11:48:36 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
2015-09-24 20:52:02 +00:00
|
|
|
ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
isActionBarVisible = false;
|
|
|
|
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.recycle();
|
|
|
|
velocityTracker = null;
|
|
|
|
}
|
2015-09-24 20:52:02 +00:00
|
|
|
ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
final PlaceProviderObject object = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation, currentIndex);
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-02-01 18:51:02 +00:00
|
|
|
if (animated) {
|
2014-06-12 15:53:20 +00:00
|
|
|
animationInProgress = 1;
|
2014-06-06 23:35:21 +00:00
|
|
|
animatingImageView.setVisibility(View.VISIBLE);
|
2014-06-12 19:55:13 +00:00
|
|
|
containerView.invalidate();
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-11-06 21:34:47 +00:00
|
|
|
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
|
2014-08-22 14:24:33 +00:00
|
|
|
Rect drawRegion = null;
|
2015-02-26 01:32:51 +00:00
|
|
|
animatingImageView.setOrientation(centerImage.getOrientation());
|
2014-06-10 23:05:54 +00:00
|
|
|
if (object != null) {
|
2014-11-17 02:44:57 +00:00
|
|
|
animatingImageView.setNeedRadius(object.radius != 0);
|
2014-08-22 14:24:33 +00:00
|
|
|
drawRegion = object.imageReceiver.getDrawRegion();
|
|
|
|
layoutParams.width = drawRegion.right - drawRegion.left;
|
|
|
|
layoutParams.height = drawRegion.bottom - drawRegion.top;
|
2014-06-10 23:05:54 +00:00
|
|
|
animatingImageView.setImageBitmap(object.thumb);
|
|
|
|
} else {
|
2014-11-17 02:44:57 +00:00
|
|
|
animatingImageView.setNeedRadius(false);
|
2014-08-22 14:24:33 +00:00
|
|
|
layoutParams.width = centerImage.getImageWidth();
|
|
|
|
layoutParams.height = centerImage.getImageHeight();
|
2014-06-10 23:05:54 +00:00
|
|
|
animatingImageView.setImageBitmap(centerImage.getBitmap());
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
animatingImageView.setLayoutParams(layoutParams);
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
|
|
|
|
float scaleY = (float) (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight) / layoutParams.height;
|
2014-06-10 23:05:54 +00:00
|
|
|
float scale2 = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float width = layoutParams.width * scale * scale2;
|
|
|
|
float height = layoutParams.height * scale * scale2;
|
2014-07-02 22:39:05 +00:00
|
|
|
float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
|
|
|
|
float yPos = (AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight - height) / 2.0f;
|
2014-11-06 21:34:47 +00:00
|
|
|
ViewProxy.setTranslationX(animatingImageView, xPos + translationX);
|
|
|
|
ViewProxy.setTranslationY(animatingImageView, yPos + translationY);
|
|
|
|
ViewProxy.setScaleX(animatingImageView, scale * scale2);
|
|
|
|
ViewProxy.setScaleY(animatingImageView, scale * scale2);
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
if (object != null) {
|
2014-11-06 21:34:47 +00:00
|
|
|
object.imageReceiver.setVisible(false, true);
|
2014-08-22 14:24:33 +00:00
|
|
|
int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
|
|
|
|
int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
int coords2[] = new int[2];
|
|
|
|
object.parentView.getLocationInWindow(coords2);
|
2015-11-26 21:04:02 +00:00
|
|
|
int clipTop = coords2[1] - AndroidUtilities.statusBarHeight - (object.viewY + drawRegion.top) + object.clipTopAddition;
|
2014-06-10 23:05:54 +00:00
|
|
|
if (clipTop < 0) {
|
|
|
|
clipTop = 0;
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
int clipBottom = (object.viewY + drawRegion.top + (drawRegion.bottom - drawRegion.top)) - (coords2[1] + object.parentView.getHeight() - AndroidUtilities.statusBarHeight) + object.clipBottomAddition;
|
2014-06-10 23:05:54 +00:00
|
|
|
if (clipBottom < 0) {
|
|
|
|
clipBottom = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
clipTop = Math.max(clipTop, clipVertical);
|
|
|
|
clipBottom = Math.max(clipBottom, clipVertical);
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
animationValues[0][0] = ViewProxy.getScaleX(animatingImageView);
|
|
|
|
animationValues[0][1] = ViewProxy.getScaleY(animatingImageView);
|
|
|
|
animationValues[0][2] = ViewProxy.getTranslationX(animatingImageView);
|
|
|
|
animationValues[0][3] = ViewProxy.getTranslationY(animatingImageView);
|
|
|
|
animationValues[0][4] = 0;
|
|
|
|
animationValues[0][5] = 0;
|
|
|
|
animationValues[0][6] = 0;
|
|
|
|
animationValues[0][7] = 0;
|
|
|
|
|
2015-10-29 17:10:07 +00:00
|
|
|
animationValues[1][0] = object.scale;
|
|
|
|
animationValues[1][1] = object.scale;
|
|
|
|
animationValues[1][2] = object.viewX + drawRegion.left * object.scale;
|
|
|
|
animationValues[1][3] = object.viewY + drawRegion.top * object.scale;
|
|
|
|
animationValues[1][4] = clipHorizontal * object.scale;
|
|
|
|
animationValues[1][5] = clipTop * object.scale;
|
|
|
|
animationValues[1][6] = clipBottom * object.scale;
|
2015-05-03 11:48:36 +00:00
|
|
|
animationValues[1][7] = object.radius;
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
animatorSet.playTogether(
|
2015-05-03 11:48:36 +00:00
|
|
|
ObjectAnimatorProxy.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
|
2014-11-06 21:34:47 +00:00
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0),
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f)
|
2014-06-10 23:05:54 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
animatorSet.playTogether(
|
2014-11-06 21:34:47 +00:00
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0),
|
|
|
|
ObjectAnimatorProxy.ofFloat(animatingImageView, "alpha", 0.0f),
|
|
|
|
ObjectAnimatorProxy.ofFloat(animatingImageView, "translationY", translationY >= 0 ? AndroidUtilities.displaySize.y : -AndroidUtilities.displaySize.y),
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f)
|
2014-06-10 23:05:54 +00:00
|
|
|
);
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
animationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-06-29 17:12:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
animationInProgress = 0;
|
|
|
|
onPhotoClosed(object);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-06 21:34:47 +00:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
|
2014-06-06 23:35:21 +00:00
|
|
|
@Override
|
2014-11-06 21:34:47 +00:00
|
|
|
public void onAnimationEnd(Object animation) {
|
2015-05-03 11:48:36 +00:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
});
|
2014-07-02 22:39:05 +00:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
2015-06-29 17:12:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
2015-02-01 18:51:02 +00:00
|
|
|
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "scaleX", 0.9f),
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "scaleY", 0.9f),
|
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0),
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "alpha", 0.0f)
|
|
|
|
);
|
2014-06-12 15:53:20 +00:00
|
|
|
animationInProgress = 2;
|
2014-07-02 22:39:05 +00:00
|
|
|
animationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-03 11:48:36 +00:00
|
|
|
if (containerView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 17:12:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
animationInProgress = 0;
|
|
|
|
onPhotoClosed(object);
|
|
|
|
ViewProxy.setScaleX(containerView, 1.0f);
|
|
|
|
ViewProxy.setScaleY(containerView, 1.0f);
|
|
|
|
containerView.clearAnimation();
|
2014-07-02 22:39:05 +00:00
|
|
|
}
|
|
|
|
};
|
2015-02-01 18:51:02 +00:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
|
2014-06-12 15:53:20 +00:00
|
|
|
@Override
|
2015-02-01 18:51:02 +00:00
|
|
|
public void onAnimationEnd(Object animation) {
|
2014-07-02 22:39:05 +00:00
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
2014-06-12 22:37:05 +00:00
|
|
|
}
|
2014-06-12 15:53:20 +00:00
|
|
|
}
|
|
|
|
});
|
2014-07-02 22:39:05 +00:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
2015-06-29 17:12:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
animatorSet.start();
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:14:13 +00:00
|
|
|
public void destroyPhotoViewer() {
|
|
|
|
if (parentActivity == null || windowView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (windowView.getParent() != null) {
|
2014-07-22 23:27:00 +00:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
2014-07-11 22:14:13 +00:00
|
|
|
wm.removeViewImmediate(windowView);
|
|
|
|
}
|
|
|
|
windowView = null;
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
if (captionEditText != null) {
|
|
|
|
captionEditText.onDestroy();
|
|
|
|
}
|
2014-07-11 22:14:13 +00:00
|
|
|
Instance = null;
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private void onPhotoClosed(PlaceProviderObject object) {
|
2014-12-04 20:27:06 +00:00
|
|
|
isVisible = false;
|
2014-06-11 00:22:42 +00:00
|
|
|
disableShowCheck = true;
|
2014-06-10 23:05:54 +00:00
|
|
|
currentMessageObject = null;
|
|
|
|
currentFileLocation = null;
|
2014-06-12 01:13:15 +00:00
|
|
|
currentPathObject = null;
|
2014-06-10 23:05:54 +00:00
|
|
|
currentThumb = null;
|
2014-10-28 17:07:44 +00:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (radialProgressViews[a] != null) {
|
2014-10-30 21:27:41 +00:00
|
|
|
radialProgressViews[a].setBackgroundState(-1, false);
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-01 18:51:02 +00:00
|
|
|
centerImage.setImageBitmap((Bitmap) null);
|
|
|
|
leftImage.setImageBitmap((Bitmap) null);
|
|
|
|
rightImage.setImageBitmap((Bitmap) null);
|
2014-06-10 23:05:54 +00:00
|
|
|
containerView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-06-11 00:22:42 +00:00
|
|
|
animatingImageView.setImageBitmap(null);
|
2014-06-12 15:53:20 +00:00
|
|
|
try {
|
|
|
|
if (windowView.getParent() != null) {
|
2014-07-22 23:27:00 +00:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
2014-06-12 15:53:20 +00:00
|
|
|
wm.removeView(windowView);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
});
|
2014-06-11 00:22:42 +00:00
|
|
|
if (placeProvider != null) {
|
|
|
|
placeProvider.willHidePhotoViewer();
|
|
|
|
}
|
|
|
|
placeProvider = null;
|
|
|
|
disableShowCheck = false;
|
2014-12-04 20:27:06 +00:00
|
|
|
if (object != null) {
|
|
|
|
object.imageReceiver.setVisible(true, true);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
private void redraw(final int count) {
|
|
|
|
if (count < 6) {
|
|
|
|
if (containerView != null) {
|
|
|
|
containerView.invalidate();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
redraw(count + 1);
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onResume() {
|
|
|
|
redraw(0); //workaround for camera bug
|
|
|
|
}
|
|
|
|
|
2014-06-06 23:35:21 +00:00
|
|
|
public boolean isVisible() {
|
2015-01-02 22:15:07 +00:00
|
|
|
return isVisible && placeProvider != null;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private void updateMinMax(float scale) {
|
2015-02-26 01:32:51 +00:00
|
|
|
int maxW = (int) (centerImage.getImageWidth() * scale - getContainerViewWidth()) / 2;
|
|
|
|
int maxH = (int) (centerImage.getImageHeight() * scale - getContainerViewHeight()) / 2;
|
2014-06-10 23:05:54 +00:00
|
|
|
if (maxW > 0) {
|
|
|
|
minX = -maxW;
|
|
|
|
maxX = maxW;
|
|
|
|
} else {
|
|
|
|
minX = maxX = 0;
|
|
|
|
}
|
|
|
|
if (maxH > 0) {
|
|
|
|
minY = -maxH;
|
|
|
|
maxY = maxH;
|
|
|
|
} else {
|
|
|
|
minY = maxY = 0;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
maxX += photoCropView.getLimitX();
|
|
|
|
maxY += photoCropView.getLimitY();
|
|
|
|
minX -= photoCropView.getLimitWidth();
|
|
|
|
minY -= photoCropView.getLimitHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getAdditionX() {
|
|
|
|
if (currentEditMode != 0) {
|
|
|
|
return AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getAdditionY() {
|
|
|
|
if (currentEditMode != 0) {
|
|
|
|
return AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewWidth() {
|
|
|
|
return getContainerViewWidth(currentEditMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewWidth(int mode) {
|
|
|
|
int width = containerView.getWidth();
|
|
|
|
if (mode != 0) {
|
|
|
|
width -= AndroidUtilities.dp(28);
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewHeight() {
|
|
|
|
return getContainerViewHeight(currentEditMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewHeight(int mode) {
|
2015-05-03 11:48:36 +00:00
|
|
|
//int height = containerView.getHeight();
|
|
|
|
int height = AndroidUtilities.displaySize.y - AndroidUtilities.statusBarHeight;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (mode == 1) {
|
|
|
|
height -= AndroidUtilities.dp(76);
|
|
|
|
} else if (mode == 2) {
|
|
|
|
height -= AndroidUtilities.dp(154);
|
|
|
|
}
|
|
|
|
return height;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-06 23:35:21 +00:00
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private boolean onTouchEvent(MotionEvent ev) {
|
2014-06-12 15:53:20 +00:00
|
|
|
if (animationInProgress != 0 || animationStartTime != 0) {
|
2014-11-19 15:17:24 +00:00
|
|
|
return false;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 2) {
|
|
|
|
photoFilterView.onTouch(ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
if (ev.getPointerCount() == 1) {
|
|
|
|
if (photoCropView.onTouch(ev)) {
|
|
|
|
updateMinMax(scale);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
photoCropView.onTouch(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 17:12:11 +00:00
|
|
|
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
|
2015-05-03 11:48:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 0 && ev.getPointerCount() == 1 && gestureDetector.onTouchEvent(ev)) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (doubleTap) {
|
|
|
|
doubleTap = false;
|
|
|
|
moving = false;
|
|
|
|
zooming = false;
|
|
|
|
checkMinMax(false);
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN || ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
discardTap = false;
|
2014-06-21 21:46:11 +00:00
|
|
|
if (!scroller.isFinished()) {
|
|
|
|
scroller.abortAnimation();
|
|
|
|
}
|
2014-11-19 15:17:24 +00:00
|
|
|
if (!draggingDown && !changingPage) {
|
|
|
|
if (canZoom && ev.getPointerCount() == 2) {
|
2014-06-10 23:05:54 +00:00
|
|
|
pinchStartDistance = (float) Math.hypot(ev.getX(1) - ev.getX(0), ev.getY(1) - ev.getY(0));
|
|
|
|
pinchStartScale = scale;
|
|
|
|
pinchCenterX = (ev.getX(0) + ev.getX(1)) / 2.0f;
|
|
|
|
pinchCenterY = (ev.getY(0) + ev.getY(1)) / 2.0f;
|
|
|
|
pinchStartX = translationX;
|
|
|
|
pinchStartY = translationY;
|
|
|
|
zooming = true;
|
|
|
|
moving = false;
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.clear();
|
|
|
|
}
|
|
|
|
} else if (ev.getPointerCount() == 1) {
|
|
|
|
moveStartX = ev.getX();
|
|
|
|
dragY = moveStartY = ev.getY();
|
|
|
|
draggingDown = false;
|
|
|
|
canDragDown = true;
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
if (canZoom && ev.getPointerCount() == 2 && !draggingDown && zooming && !changingPage) {
|
2015-02-01 18:51:02 +00:00
|
|
|
discardTap = true;
|
|
|
|
scale = (float) Math.hypot(ev.getX(1) - ev.getX(0), ev.getY(1) - ev.getY(0)) / pinchStartDistance * pinchStartScale;
|
2015-02-26 01:32:51 +00:00
|
|
|
translationX = (pinchCenterX - getContainerViewWidth() / 2) - ((pinchCenterX - getContainerViewWidth() / 2) - pinchStartX) * (scale / pinchStartScale);
|
|
|
|
translationY = (pinchCenterY - getContainerViewHeight() / 2) - ((pinchCenterY - getContainerViewHeight() / 2) - pinchStartY) * (scale / pinchStartScale);
|
2014-06-10 23:05:54 +00:00
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
} else if (ev.getPointerCount() == 1) {
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.addMovement(ev);
|
|
|
|
}
|
2014-06-20 00:18:13 +00:00
|
|
|
float dx = Math.abs(ev.getX() - moveStartX);
|
|
|
|
float dy = Math.abs(ev.getY() - dragY);
|
2015-02-01 18:51:02 +00:00
|
|
|
if (dx > AndroidUtilities.dp(3) || dy > AndroidUtilities.dp(3)) {
|
|
|
|
discardTap = true;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (!(placeProvider instanceof EmptyPhotoViewerProvider) && currentEditMode == 0 && canDragDown && !draggingDown && scale == 1 && dy >= AndroidUtilities.dp(30) && dy / 2 > dx) {
|
2014-06-06 23:35:21 +00:00
|
|
|
draggingDown = true;
|
2014-06-10 23:05:54 +00:00
|
|
|
moving = false;
|
2014-06-06 23:35:21 +00:00
|
|
|
dragY = ev.getY();
|
2014-08-29 21:06:04 +00:00
|
|
|
if (isActionBarVisible && canShowBottom) {
|
2014-06-06 23:35:21 +00:00
|
|
|
toggleActionBar(false, true);
|
2015-02-26 01:32:51 +00:00
|
|
|
} else if (pickerView.getVisibility() == View.VISIBLE) {
|
2015-02-01 18:51:02 +00:00
|
|
|
toggleActionBar(false, true);
|
2015-01-02 22:15:07 +00:00
|
|
|
toggleCheckImageView(false);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
return true;
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (draggingDown) {
|
|
|
|
translationY = ev.getY() - dragY;
|
|
|
|
containerView.invalidate();
|
2014-11-19 15:17:24 +00:00
|
|
|
} else if (!invalidCoords && animationStartTime == 0) {
|
2014-06-10 23:05:54 +00:00
|
|
|
float moveDx = moveStartX - ev.getX();
|
|
|
|
float moveDy = moveStartY - ev.getY();
|
2015-02-26 01:32:51 +00:00
|
|
|
if (moving || currentEditMode != 0 || scale == 1 && Math.abs(moveDy) + AndroidUtilities.dp(12) < Math.abs(moveDx) || scale != 1) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (!moving) {
|
|
|
|
moveDx = 0;
|
|
|
|
moveDy = 0;
|
|
|
|
moving = true;
|
|
|
|
canDragDown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
moveStartX = ev.getX();
|
|
|
|
moveStartY = ev.getY();
|
|
|
|
updateMinMax(scale);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (translationX < minX && (currentEditMode != 0 || !rightImage.hasImage()) || translationX > maxX && (currentEditMode != 0 || !leftImage.hasImage())) {
|
2014-06-10 23:05:54 +00:00
|
|
|
moveDx /= 3.0f;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (maxY == 0 && minY == 0 && currentEditMode == 0) {
|
2014-06-21 21:46:11 +00:00
|
|
|
if (translationY - moveDy < minY) {
|
|
|
|
translationY = minY;
|
|
|
|
moveDy = 0;
|
|
|
|
} else if (translationY - moveDy > maxY) {
|
|
|
|
translationY = maxY;
|
|
|
|
moveDy = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (translationY < minY || translationY > maxY) {
|
|
|
|
moveDy /= 3.0f;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
translationX -= moveDx;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (scale != 1 || currentEditMode != 0) {
|
2014-06-10 23:05:54 +00:00
|
|
|
translationY -= moveDy;
|
|
|
|
}
|
|
|
|
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
invalidCoords = false;
|
|
|
|
moveStartX = ev.getX();
|
|
|
|
moveStartY = ev.getY();
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
} else if (ev.getActionMasked() == MotionEvent.ACTION_CANCEL || ev.getActionMasked() == MotionEvent.ACTION_UP || ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.startAnimationRunnable();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
if (zooming) {
|
|
|
|
invalidCoords = true;
|
|
|
|
if (scale < 1.0f) {
|
|
|
|
updateMinMax(1.0f);
|
2014-06-10 23:33:45 +00:00
|
|
|
animateTo(1.0f, 0, 0, true);
|
2015-02-01 18:51:02 +00:00
|
|
|
} else if (scale > 3.0f) {
|
2015-02-26 01:32:51 +00:00
|
|
|
float atx = (pinchCenterX - getContainerViewWidth() / 2) - ((pinchCenterX - getContainerViewWidth() / 2) - pinchStartX) * (3.0f / pinchStartScale);
|
|
|
|
float aty = (pinchCenterY - getContainerViewHeight() / 2) - ((pinchCenterY - getContainerViewHeight() / 2) - pinchStartY) * (3.0f / pinchStartScale);
|
2014-06-10 23:05:54 +00:00
|
|
|
updateMinMax(3.0f);
|
|
|
|
if (atx < minX) {
|
|
|
|
atx = minX;
|
|
|
|
} else if (atx > maxX) {
|
|
|
|
atx = maxX;
|
|
|
|
}
|
|
|
|
if (aty < minY) {
|
|
|
|
aty = minY;
|
|
|
|
} else if (aty > maxY) {
|
|
|
|
aty = maxY;
|
|
|
|
}
|
2014-06-10 23:33:45 +00:00
|
|
|
animateTo(3.0f, atx, aty, true);
|
|
|
|
} else {
|
|
|
|
checkMinMax(true);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
zooming = false;
|
2014-06-06 23:35:21 +00:00
|
|
|
} else if (draggingDown) {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (Math.abs(dragY - ev.getY()) > getContainerViewHeight() / 6.0f) {
|
|
|
|
closePhoto(true, false);
|
2014-06-06 23:35:21 +00:00
|
|
|
} else {
|
2015-02-26 01:32:51 +00:00
|
|
|
if (pickerView.getVisibility() == View.VISIBLE) {
|
2015-02-01 18:51:02 +00:00
|
|
|
toggleActionBar(true, true);
|
2015-01-02 22:15:07 +00:00
|
|
|
toggleCheckImageView(true);
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
animateTo(1, 0, 0, false);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
draggingDown = false;
|
2014-06-10 23:05:54 +00:00
|
|
|
} else if (moving) {
|
|
|
|
float moveToX = translationX;
|
|
|
|
float moveToY = translationY;
|
|
|
|
updateMinMax(scale);
|
|
|
|
moving = false;
|
|
|
|
canDragDown = true;
|
|
|
|
float velocity = 0;
|
|
|
|
if (velocityTracker != null && scale == 1) {
|
|
|
|
velocityTracker.computeCurrentVelocity(1000);
|
|
|
|
velocity = velocityTracker.getXVelocity();
|
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 0) {
|
|
|
|
if ((translationX < minX - getContainerViewWidth() / 3 || velocity < -AndroidUtilities.dp(650)) && rightImage.hasImage()) {
|
|
|
|
goToNext();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((translationX > maxX + getContainerViewWidth() / 3 || velocity > AndroidUtilities.dp(650)) && leftImage.hasImage()) {
|
|
|
|
goToPrev();
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (translationX < minX) {
|
|
|
|
moveToX = minX;
|
|
|
|
} else if (translationX > maxX) {
|
|
|
|
moveToX = maxX;
|
|
|
|
}
|
|
|
|
if (translationY < minY) {
|
|
|
|
moveToY = minY;
|
|
|
|
} else if (translationY > maxY) {
|
|
|
|
moveToY = maxY;
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
animateTo(scale, moveToX, moveToY, false);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:33:45 +00:00
|
|
|
private void checkMinMax(boolean zoom) {
|
|
|
|
float moveToX = translationX;
|
|
|
|
float moveToY = translationY;
|
|
|
|
updateMinMax(scale);
|
|
|
|
if (translationX < minX) {
|
|
|
|
moveToX = minX;
|
|
|
|
} else if (translationX > maxX) {
|
|
|
|
moveToX = maxX;
|
|
|
|
}
|
|
|
|
if (translationY < minY) {
|
|
|
|
moveToY = minY;
|
|
|
|
} else if (translationY > maxY) {
|
|
|
|
moveToY = maxY;
|
|
|
|
}
|
|
|
|
animateTo(scale, moveToX, moveToY, zoom);
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private void goToNext() {
|
|
|
|
float extra = 0;
|
|
|
|
if (scale != 1) {
|
2015-02-26 01:32:51 +00:00
|
|
|
extra = (getContainerViewWidth() - centerImage.getImageWidth()) / 2 * scale;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
switchImageAfterAnimation = 1;
|
2015-02-26 01:32:51 +00:00
|
|
|
animateTo(scale, minX - getContainerViewWidth() - extra - PAGE_SPACING / 2, translationY, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void goToPrev() {
|
|
|
|
float extra = 0;
|
|
|
|
if (scale != 1) {
|
2015-02-26 01:32:51 +00:00
|
|
|
extra = (getContainerViewWidth() - centerImage.getImageWidth()) / 2 * scale;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
switchImageAfterAnimation = 2;
|
2015-02-26 01:32:51 +00:00
|
|
|
animateTo(scale, maxX + getContainerViewWidth() + extra + PAGE_SPACING / 2, translationY, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
private void animateTo(float newScale, float newTx, float newTy, boolean isZoom) {
|
|
|
|
animateTo(newScale, newTx, newTy, isZoom, 250);
|
2014-06-10 23:33:45 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
private void animateTo(float newScale, float newTx, float newTy, boolean isZoom, int duration) {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (scale == newScale && translationX == newTx && translationY == newTy) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-10 23:33:45 +00:00
|
|
|
zoomAnimation = isZoom;
|
2014-06-10 23:05:54 +00:00
|
|
|
animateToScale = newScale;
|
|
|
|
animateToX = newTx;
|
|
|
|
animateToY = newTy;
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
2015-02-26 01:32:51 +00:00
|
|
|
imageMoveAnimation = new AnimatorSetProxy();
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(this, "animationValue", 0, 1)
|
|
|
|
);
|
|
|
|
imageMoveAnimation.setInterpolator(interpolator);
|
|
|
|
imageMoveAnimation.setDuration(duration);
|
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
public void setAnimationValue(float value) {
|
|
|
|
animationValue = value;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getAnimationValue() {
|
|
|
|
return animationValue;
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
private void onDraw(Canvas canvas) {
|
2014-06-12 15:53:20 +00:00
|
|
|
if (animationInProgress == 1 || !isVisible && animationInProgress != 2) {
|
2014-06-10 23:05:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float currentTranslationY;
|
|
|
|
float currentTranslationX;
|
2015-01-02 22:15:07 +00:00
|
|
|
float currentScale;
|
2014-06-10 23:05:54 +00:00
|
|
|
float aty = -1;
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (imageMoveAnimation != null) {
|
2014-06-21 21:46:11 +00:00
|
|
|
if (!scroller.isFinished()) {
|
|
|
|
scroller.abortAnimation();
|
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
float ts = scale + (animateToScale - scale) * animationValue;
|
|
|
|
float tx = translationX + (animateToX - translationX) * animationValue;
|
|
|
|
float ty = translationY + (animateToY - translationY) * animationValue;
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.setAnimationProgress(animationValue);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
|
|
|
|
if (animateToScale == 1 && scale == 1 && translationX == 0) {
|
|
|
|
aty = ty;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
currentScale = ts;
|
|
|
|
currentTranslationY = ty;
|
2014-06-10 23:05:54 +00:00
|
|
|
currentTranslationX = tx;
|
|
|
|
containerView.invalidate();
|
2014-06-06 23:35:21 +00:00
|
|
|
} else {
|
2014-06-10 23:05:54 +00:00
|
|
|
if (animationStartTime != 0) {
|
|
|
|
translationX = animateToX;
|
|
|
|
translationY = animateToY;
|
|
|
|
scale = animateToScale;
|
|
|
|
animationStartTime = 0;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.setAnimationProgress(1);
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
updateMinMax(scale);
|
2014-06-10 23:33:45 +00:00
|
|
|
zoomAnimation = false;
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-06-21 21:46:11 +00:00
|
|
|
if (!scroller.isFinished()) {
|
|
|
|
if (scroller.computeScrollOffset()) {
|
|
|
|
if (scroller.getStartX() < maxX && scroller.getStartX() > minX) {
|
|
|
|
translationX = scroller.getCurrX();
|
|
|
|
}
|
|
|
|
if (scroller.getStartY() < maxY && scroller.getStartY() > minY) {
|
|
|
|
translationY = scroller.getCurrY();
|
|
|
|
}
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
if (switchImageAfterAnimation != 0) {
|
|
|
|
if (switchImageAfterAnimation == 1) {
|
|
|
|
setImageIndex(currentIndex + 1, false);
|
|
|
|
} else if (switchImageAfterAnimation == 2) {
|
|
|
|
setImageIndex(currentIndex - 1, false);
|
|
|
|
}
|
|
|
|
switchImageAfterAnimation = 0;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
currentScale = scale;
|
|
|
|
currentTranslationY = translationY;
|
2014-06-10 23:05:54 +00:00
|
|
|
currentTranslationX = translationX;
|
|
|
|
if (!moving) {
|
|
|
|
aty = translationY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 0 && scale == 1 && aty != -1 && !zoomAnimation) {
|
|
|
|
float maxValue = getContainerViewHeight() / 4.0f;
|
2014-06-10 23:05:54 +00:00
|
|
|
backgroundDrawable.setAlpha((int) Math.max(127, 255 * (1.0f - (Math.min(Math.abs(aty), maxValue) / maxValue))));
|
|
|
|
} else {
|
|
|
|
backgroundDrawable.setAlpha(255);
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
ImageReceiver sideImage = null;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 0) {
|
|
|
|
if (scale >= 1.0f && !zoomAnimation && !zooming) {
|
|
|
|
if (currentTranslationX > maxX + AndroidUtilities.dp(5)) {
|
|
|
|
sideImage = leftImage;
|
|
|
|
} else if (currentTranslationX < minX - AndroidUtilities.dp(5)) {
|
|
|
|
sideImage = rightImage;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
changingPage = sideImage != null;
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sideImage == rightImage) {
|
|
|
|
float tranlateX = currentTranslationX;
|
|
|
|
float scaleDiff = 0;
|
|
|
|
float alpha = 1;
|
|
|
|
if (!zoomAnimation && tranlateX < minX) {
|
|
|
|
alpha = Math.min(1.0f, (minX - tranlateX) / canvas.getWidth());
|
|
|
|
scaleDiff = (1.0f - alpha) * 0.3f;
|
|
|
|
tranlateX = -canvas.getWidth() - PAGE_SPACING / 2;
|
|
|
|
}
|
|
|
|
|
2016-01-11 17:19:48 +00:00
|
|
|
if (sideImage.hasBitmapImage()) {
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.save();
|
2015-02-26 01:32:51 +00:00
|
|
|
canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2);
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.translate(canvas.getWidth() + PAGE_SPACING / 2 + tranlateX, 0);
|
|
|
|
canvas.scale(1.0f - scaleDiff, 1.0f - scaleDiff);
|
2015-02-26 01:32:51 +00:00
|
|
|
int bitmapWidth = sideImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = sideImage.getBitmapHeight();
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
2015-01-02 22:15:07 +00:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
int width = (int) (bitmapWidth * scale);
|
|
|
|
int height = (int) (bitmapHeight * scale);
|
|
|
|
|
|
|
|
sideImage.setAlpha(alpha);
|
|
|
|
sideImage.setImageCoords(-width / 2, -height / 2, width, height);
|
|
|
|
sideImage.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(tranlateX, currentTranslationY / currentScale);
|
|
|
|
canvas.translate((canvas.getWidth() * (scale + 1) + PAGE_SPACING) / 2, -currentTranslationY / currentScale);
|
|
|
|
radialProgressViews[1].setScale(1.0f - scaleDiff);
|
|
|
|
radialProgressViews[1].setAlpha(alpha);
|
|
|
|
radialProgressViews[1].onDraw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
float tranlateX = currentTranslationX;
|
|
|
|
float scaleDiff = 0;
|
|
|
|
float alpha = 1;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (!zoomAnimation && tranlateX > maxX && currentEditMode == 0) {
|
2015-01-02 22:15:07 +00:00
|
|
|
alpha = Math.min(1.0f, (tranlateX - maxX) / canvas.getWidth());
|
|
|
|
scaleDiff = alpha * 0.3f;
|
|
|
|
alpha = 1.0f - alpha;
|
|
|
|
tranlateX = maxX;
|
|
|
|
}
|
2016-01-11 17:19:48 +00:00
|
|
|
if (centerImage.hasBitmapImage()) {
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.save();
|
2015-02-26 01:32:51 +00:00
|
|
|
canvas.translate(getContainerViewWidth() / 2 + getAdditionX(), getContainerViewHeight() / 2 + getAdditionY());
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.translate(tranlateX, currentTranslationY);
|
|
|
|
canvas.scale(currentScale - scaleDiff, currentScale - scaleDiff);
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.setBitmapParams(currentScale, tranlateX, currentTranslationY);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
2014-06-10 23:05:54 +00:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
int width = (int) (bitmapWidth * scale);
|
|
|
|
int height = (int) (bitmapHeight * scale);
|
|
|
|
|
2016-01-11 17:19:48 +00:00
|
|
|
centerImage.setAlpha(alpha);
|
|
|
|
centerImage.setImageCoords(-width / 2, -height / 2, width, height);
|
|
|
|
centerImage.draw(canvas);
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.restore();
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
2014-10-28 17:07:44 +00:00
|
|
|
canvas.save();
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.translate(tranlateX, currentTranslationY / currentScale);
|
|
|
|
radialProgressViews[0].setScale(1.0f - scaleDiff);
|
|
|
|
radialProgressViews[0].setAlpha(alpha);
|
2014-10-28 17:07:44 +00:00
|
|
|
radialProgressViews[0].onDraw(canvas);
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.restore();
|
|
|
|
|
|
|
|
if (sideImage == leftImage) {
|
2016-01-11 17:19:48 +00:00
|
|
|
if (sideImage.hasBitmapImage()) {
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.save();
|
2015-02-26 01:32:51 +00:00
|
|
|
canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2);
|
2015-01-02 22:15:07 +00:00
|
|
|
canvas.translate(-(canvas.getWidth() * (scale + 1) + PAGE_SPACING) / 2 + currentTranslationX, 0);
|
2015-02-26 01:32:51 +00:00
|
|
|
int bitmapWidth = sideImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = sideImage.getBitmapHeight();
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
2015-01-02 22:15:07 +00:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
int width = (int) (bitmapWidth * scale);
|
|
|
|
int height = (int) (bitmapHeight * scale);
|
2014-10-28 17:07:44 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
sideImage.setAlpha(1.0f);
|
|
|
|
sideImage.setImageCoords(-width / 2, -height / 2, width, height);
|
|
|
|
sideImage.draw(canvas);
|
|
|
|
canvas.restore();
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(currentTranslationX, currentTranslationY / currentScale);
|
|
|
|
canvas.translate(-(canvas.getWidth() * (scale + 1) + PAGE_SPACING) / 2, -currentTranslationY / currentScale);
|
|
|
|
radialProgressViews[2].setScale(1.0f);
|
|
|
|
radialProgressViews[2].setAlpha(1.0f);
|
|
|
|
radialProgressViews[2].onDraw(canvas);
|
|
|
|
canvas.restore();
|
2014-10-28 17:07:44 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@SuppressLint("DrawAllocation")
|
2014-06-10 23:05:54 +00:00
|
|
|
private void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
2015-02-01 18:51:02 +00:00
|
|
|
if (changed) {
|
2014-06-10 23:05:54 +00:00
|
|
|
scale = 1;
|
|
|
|
translationX = 0;
|
|
|
|
translationY = 0;
|
|
|
|
updateMinMax(scale);
|
2014-06-12 01:13:15 +00:00
|
|
|
|
|
|
|
if (checkImageView != null) {
|
2015-05-03 11:48:36 +00:00
|
|
|
checkImageView.post(new Runnable() {
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
2015-05-03 11:48:36 +00:00
|
|
|
public void run() {
|
2015-06-29 17:12:11 +00:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkImageView.getLayoutParams();
|
2015-02-01 18:51:02 +00:00
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
2014-06-12 01:13:15 +00:00
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams.topMargin = AndroidUtilities.dp(rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68);
|
2014-06-12 01:13:15 +00:00
|
|
|
checkImageView.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:07:44 +00:00
|
|
|
private void onActionClick() {
|
|
|
|
if (currentMessageObject == null || currentFileNames[0] == null) {
|
2014-06-10 23:05:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean loadFile = false;
|
|
|
|
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
File f = new File(currentMessageObject.messageOwner.attachPath);
|
|
|
|
if (f.exists()) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
|
2015-02-26 01:32:51 +00:00
|
|
|
parentActivity.startActivityForResult(intent, 500);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
|
|
|
loadFile = true;
|
|
|
|
}
|
|
|
|
} else {
|
2014-09-25 03:54:35 +00:00
|
|
|
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
2014-06-10 23:05:54 +00:00
|
|
|
if (cacheFile.exists()) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setDataAndType(Uri.fromFile(cacheFile), "video/mp4");
|
2015-02-26 01:32:51 +00:00
|
|
|
parentActivity.startActivityForResult(intent, 500);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
|
|
|
loadFile = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (loadFile) {
|
2014-10-28 17:07:44 +00:00
|
|
|
if (!FileLoader.getInstance().isLoadingFile(currentFileNames[0])) {
|
2016-03-06 01:49:31 +00:00
|
|
|
FileLoader.getInstance().loadFile(currentMessageObject.messageOwner.media.document, true, false);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2016-03-06 01:49:31 +00:00
|
|
|
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.document);
|
2014-06-10 23:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDown(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowPress(MotionEvent e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapUp(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLongPress(MotionEvent e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
2014-06-21 21:46:11 +00:00
|
|
|
if (scale != 1) {
|
|
|
|
scroller.abortAnimation();
|
|
|
|
scroller.fling(Math.round(translationX), Math.round(translationY), Math.round(velocityX), Math.round(velocityY), (int) minX, (int) maxX, (int) minY, (int) maxY);
|
|
|
|
containerView.postInvalidate();
|
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (discardTap) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-29 21:06:04 +00:00
|
|
|
if (canShowBottom) {
|
2014-10-28 17:07:44 +00:00
|
|
|
if (radialProgressViews[0] != null && containerView != null) {
|
|
|
|
int state = radialProgressViews[0].backgroundState;
|
|
|
|
if (state > 0 && state <= 3) {
|
|
|
|
float x = e.getX();
|
|
|
|
float y = e.getY();
|
2015-02-26 01:32:51 +00:00
|
|
|
if (x >= (getContainerViewWidth() - AndroidUtilities.dp(64)) / 2.0f && x <= (getContainerViewWidth() + AndroidUtilities.dp(64)) / 2.0f &&
|
|
|
|
y >= (getContainerViewHeight() - AndroidUtilities.dp(64)) / 2.0f && y <= (getContainerViewHeight() + AndroidUtilities.dp(64)) / 2.0f) {
|
2014-10-28 17:07:44 +00:00
|
|
|
onActionClick();
|
2014-10-30 21:27:41 +00:00
|
|
|
checkProgress(0, true);
|
2014-10-28 17:07:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-29 21:06:04 +00:00
|
|
|
toggleActionBar(!isActionBarVisible, true);
|
2015-02-26 01:32:51 +00:00
|
|
|
} else if (sendPhotoType == 0) {
|
2014-08-30 19:30:42 +00:00
|
|
|
checkImageView.performClick();
|
2014-08-29 21:06:04 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTap(MotionEvent e) {
|
|
|
|
if (!canZoom || scale == 1.0f && (translationY != 0 || translationX != 0)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-19 01:23:46 +00:00
|
|
|
if (animationStartTime != 0 || animationInProgress != 0) {
|
2014-06-10 23:05:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (scale == 1.0f) {
|
2015-02-26 01:32:51 +00:00
|
|
|
float atx = (e.getX() - getContainerViewWidth() / 2) - ((e.getX() - getContainerViewWidth() / 2) - translationX) * (3.0f / scale);
|
|
|
|
float aty = (e.getY() - getContainerViewHeight() / 2) - ((e.getY() - getContainerViewHeight() / 2) - translationY) * (3.0f / scale);
|
2014-06-10 23:05:54 +00:00
|
|
|
updateMinMax(3.0f);
|
|
|
|
if (atx < minX) {
|
|
|
|
atx = minX;
|
|
|
|
} else if (atx > maxX) {
|
|
|
|
atx = maxX;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
if (aty < minY) {
|
|
|
|
aty = minY;
|
|
|
|
} else if (aty > maxY) {
|
|
|
|
aty = maxY;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
animateTo(3.0f, atx, aty, true);
|
2014-06-10 23:05:54 +00:00
|
|
|
} else {
|
2015-01-02 22:15:07 +00:00
|
|
|
animateTo(1.0f, 0, 0, true);
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
doubleTap = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
|
|
|
return false;
|
2014-06-06 23:35:21 +00:00
|
|
|
}
|
|
|
|
}
|