2014-06-04 01:31:48 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2014-06-04 01:31:48 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-06-04 01:31:48 +02:00
|
|
|
*/
|
|
|
|
|
2014-11-13 21:10:14 +01:00
|
|
|
package org.telegram.ui.ActionBar;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.animation.Animator;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.annotation.TargetApi;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.app.Activity;
|
2014-06-04 20:57:11 +02:00
|
|
|
import android.content.Context;
|
2014-06-12 17:53:20 +02:00
|
|
|
import android.content.Intent;
|
2014-11-11 23:16:17 +01:00
|
|
|
import android.graphics.Canvas;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.graphics.Color;
|
|
|
|
import android.graphics.Outline;
|
2014-11-11 23:16:17 +01:00
|
|
|
import android.graphics.Paint;
|
2016-04-25 21:26:41 +02:00
|
|
|
import android.graphics.Rect;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2014-11-11 23:16:17 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.os.Build;
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.annotation.Keep;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.Gravity;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.view.HapticFeedbackConstants;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.KeyEvent;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.view.Menu;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.VelocityTracker;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.view.ViewOutlineProvider;
|
2014-11-11 23:16:17 +01:00
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2019-03-03 21:40:48 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.messenger.R;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
2021-02-23 12:53:38 +01:00
|
|
|
import org.telegram.ui.Components.Bulletin;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Components.CubicBezierInterpolator;
|
2020-12-23 08:48:30 +01:00
|
|
|
import org.telegram.ui.Components.GroupCallPip;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public class ActionBarLayout extends FrameLayout {
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface ActionBarLayoutDelegate {
|
|
|
|
boolean onPreIme();
|
|
|
|
boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout);
|
|
|
|
boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout);
|
|
|
|
boolean needCloseLastFragment(ActionBarLayout layout);
|
2018-07-30 04:07:02 +02:00
|
|
|
void onRebuildAllFragments(ActionBarLayout layout, boolean last);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public class LayoutContainer extends FrameLayout {
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2016-04-25 21:26:41 +02:00
|
|
|
private Rect rect = new Rect();
|
|
|
|
private boolean isKeyboardVisible;
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
private int fragmentPanTranslationOffset;
|
|
|
|
private Paint backgroundPaint = new Paint();
|
|
|
|
private int backgroundColor;
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
public LayoutContainer(Context context) {
|
2014-11-11 23:16:17 +01:00
|
|
|
super(context);
|
2020-09-30 15:48:47 +02:00
|
|
|
setWillNotDraw(false);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
@Override
|
2014-11-11 23:16:17 +01:00
|
|
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (child instanceof ActionBar) {
|
|
|
|
return super.drawChild(canvas, child, drawingTime);
|
|
|
|
} else {
|
|
|
|
int actionBarHeight = 0;
|
2020-02-13 19:26:53 +01:00
|
|
|
int actionBarY = 0;
|
2014-11-17 03:44:57 +01:00
|
|
|
int childCount = getChildCount();
|
|
|
|
for (int a = 0; a < childCount; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view == child) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
if (view instanceof ActionBar && view.getVisibility() == VISIBLE) {
|
2015-02-01 19:51:02 +01:00
|
|
|
if (((ActionBar) view).getCastShadows()) {
|
|
|
|
actionBarHeight = view.getMeasuredHeight();
|
2020-02-13 19:26:53 +01:00
|
|
|
actionBarY = (int) view.getY();
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean result = super.drawChild(canvas, child, drawingTime);
|
|
|
|
if (actionBarHeight != 0 && headerShadowDrawable != null) {
|
2020-02-13 19:26:53 +01:00
|
|
|
headerShadowDrawable.setBounds(0, actionBarY + actionBarHeight, getMeasuredWidth(), actionBarY + actionBarHeight + headerShadowDrawable.getIntrinsicHeight());
|
2014-11-17 03:44:57 +01:00
|
|
|
headerShadowDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasOverlappingRendering() {
|
2018-08-27 10:33:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-25 21:26:41 +02:00
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
int count = getChildCount();
|
|
|
|
int actionBarHeight = 0;
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = getChildAt(a);
|
|
|
|
if (child instanceof ActionBar) {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
|
|
|
|
actionBarHeight = child.getMeasuredHeight();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = getChildAt(a);
|
|
|
|
if (!(child instanceof ActionBar)) {
|
2020-08-14 18:58:22 +02:00
|
|
|
if (child.getFitsSystemWindows()) {
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
} else {
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, actionBarHeight);
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
setMeasuredDimension(width, height);
|
|
|
|
}
|
|
|
|
|
2016-04-25 21:26:41 +02:00
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
2020-02-13 19:26:53 +01:00
|
|
|
int count = getChildCount();
|
|
|
|
int actionBarHeight = 0;
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = getChildAt(a);
|
|
|
|
if (child instanceof ActionBar) {
|
|
|
|
actionBarHeight = child.getMeasuredHeight();
|
|
|
|
child.layout(0, 0, child.getMeasuredWidth(), actionBarHeight);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = getChildAt(a);
|
|
|
|
if (!(child instanceof ActionBar)) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) child.getLayoutParams();
|
2020-08-14 18:58:22 +02:00
|
|
|
if (child.getFitsSystemWindows()) {
|
|
|
|
child.layout(layoutParams.leftMargin, layoutParams.topMargin, layoutParams.leftMargin + child.getMeasuredWidth(), layoutParams.topMargin + child.getMeasuredHeight());
|
|
|
|
} else {
|
|
|
|
child.layout(layoutParams.leftMargin, layoutParams.topMargin + actionBarHeight, layoutParams.leftMargin + child.getMeasuredWidth(), layoutParams.topMargin + actionBarHeight + child.getMeasuredHeight());
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-25 21:26:41 +02:00
|
|
|
|
|
|
|
View rootView = getRootView();
|
|
|
|
getWindowVisibleDisplayFrame(rect);
|
|
|
|
int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
|
|
|
|
isKeyboardVisible = usableViewHeight - (rect.bottom - rect.top) > 0;
|
|
|
|
if (waitingForKeyboardCloseRunnable != null && !containerView.isKeyboardVisible && !containerViewBack.isKeyboardVisible) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
|
|
|
|
waitingForKeyboardCloseRunnable.run();
|
|
|
|
waitingForKeyboardCloseRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
if ((inPreviewMode || transitionAnimationPreviewMode) && (ev.getActionMasked() == MotionEvent.ACTION_DOWN || ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
try {
|
|
|
|
return (!inPreviewMode || this != containerView) && super.dispatchTouchEvent(ev);
|
2019-03-03 21:40:48 +01:00
|
|
|
} catch (Throwable e) {
|
|
|
|
FileLog.e(e);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
|
|
|
|
@Override
|
2020-09-30 15:48:47 +02:00
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
if (fragmentPanTranslationOffset != 0) {
|
|
|
|
int color = Theme.getColor(Theme.key_windowBackgroundWhite);
|
|
|
|
if (backgroundColor != color) {
|
|
|
|
backgroundPaint.setColor(backgroundColor = Theme.getColor(Theme.key_windowBackgroundWhite));
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
canvas.drawRect(0, getMeasuredHeight() - fragmentPanTranslationOffset - 3, getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
super.onDraw(canvas);
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public void setFragmentPanTranslationOffset(int fragmentPanTranslationOffset) {
|
|
|
|
this.fragmentPanTranslationOffset = fragmentPanTranslationOffset;
|
|
|
|
invalidate();
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Drawable headerShadowDrawable;
|
|
|
|
private static Drawable layerShadowDrawable;
|
|
|
|
private static Paint scrimPaint;
|
|
|
|
|
2016-04-25 21:26:41 +02:00
|
|
|
private Runnable waitingForKeyboardCloseRunnable;
|
2016-05-25 23:49:47 +02:00
|
|
|
private Runnable delayedOpenAnimationRunnable;
|
2016-04-25 21:26:41 +02:00
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
private boolean inBubbleMode;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean inPreviewMode;
|
2020-02-13 19:26:53 +01:00
|
|
|
private boolean previewOpenAnimationInProgress;
|
2018-07-30 04:07:02 +02:00
|
|
|
private ColorDrawable previewBackgroundDrawable;
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
private LayoutContainer containerView;
|
|
|
|
private LayoutContainer containerViewBack;
|
2014-11-07 11:23:17 +01:00
|
|
|
private DrawerLayoutContainer drawerLayoutContainer;
|
2014-11-11 23:16:17 +01:00
|
|
|
private ActionBar currentActionBar;
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
private BaseFragment newFragment;
|
|
|
|
private BaseFragment oldFragment;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatorSet currentAnimation;
|
2015-05-03 13:48:36 +02:00
|
|
|
private DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);
|
|
|
|
private AccelerateDecelerateInterpolator accelerateDecelerateInterpolator = new AccelerateDecelerateInterpolator();
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
public float innerTranslationX;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
private boolean maybeStartTracking;
|
|
|
|
protected boolean startedTracking;
|
2014-06-04 01:31:48 +02:00
|
|
|
private int startedTrackingX;
|
2014-06-20 02:18:13 +02:00
|
|
|
private int startedTrackingY;
|
2014-11-17 03:44:57 +01:00
|
|
|
protected boolean animationInProgress;
|
|
|
|
private VelocityTracker velocityTracker;
|
2020-02-13 19:26:53 +01:00
|
|
|
private View layoutToIgnore;
|
2014-11-17 03:44:57 +01:00
|
|
|
private boolean beginTrackingSent;
|
|
|
|
private boolean transitionAnimationInProgress;
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean transitionAnimationPreviewMode;
|
2020-01-23 07:15:40 +01:00
|
|
|
private ArrayList<int[]> animateStartColors = new ArrayList<>();
|
|
|
|
private ArrayList<int[]> animateEndColors = new ArrayList<>();
|
2020-04-24 11:21:58 +02:00
|
|
|
private ArrayList<ArrayList<ThemeDescription>> themeAnimatorDescriptions = new ArrayList<>();
|
|
|
|
private ArrayList<ThemeDescription> presentingFragmentDescriptions;
|
2020-01-23 07:15:40 +01:00
|
|
|
private ArrayList<ThemeDescription.ThemeDescriptionDelegate> themeAnimatorDelegate = new ArrayList<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private AnimatorSet themeAnimatorSet;
|
|
|
|
private float themeAnimationValue;
|
|
|
|
private boolean animateThemeAfterAnimation;
|
|
|
|
private Theme.ThemeInfo animateSetThemeAfterAnimation;
|
2019-02-08 03:30:32 +01:00
|
|
|
private boolean animateSetThemeNightAfterAnimation;
|
2019-12-31 14:08:08 +01:00
|
|
|
private int animateSetThemeAccentIdAfterAnimation;
|
2017-07-08 18:32:04 +02:00
|
|
|
private boolean rebuildAfterAnimation;
|
|
|
|
private boolean rebuildLastAfterAnimation;
|
|
|
|
private boolean showLastAfterAnimation;
|
2014-06-04 01:31:48 +02:00
|
|
|
private long transitionAnimationStartTime;
|
2014-11-17 03:44:57 +01:00
|
|
|
private boolean inActionMode;
|
2014-06-07 01:35:21 +02:00
|
|
|
private int startedTrackingPointerId;
|
2014-11-17 03:44:57 +01:00
|
|
|
private Runnable onCloseAnimationEndRunnable;
|
|
|
|
private Runnable onOpenAnimationEndRunnable;
|
|
|
|
private boolean useAlphaAnimations;
|
2014-09-24 04:17:27 +02:00
|
|
|
private View backgroundView;
|
2014-11-17 03:44:57 +01:00
|
|
|
private boolean removeActionBarExtraHeight;
|
2015-10-29 18:10:07 +01:00
|
|
|
private Runnable animationRunnable;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private float animationProgress;
|
2015-05-03 13:48:36 +02:00
|
|
|
private long lastFrameTime;
|
|
|
|
|
2014-11-18 06:01:04 +01:00
|
|
|
private String titleOverlayText;
|
2019-01-23 18:03:33 +01:00
|
|
|
private int titleOverlayTextId;
|
2017-07-08 18:32:04 +02:00
|
|
|
private Runnable overlayAction;
|
2014-11-18 06:01:04 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private ActionBarLayoutDelegate delegate;
|
|
|
|
protected Activity parentActivity;
|
2014-06-04 20:57:11 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public ArrayList<BaseFragment> fragmentsStack;
|
2020-10-02 23:48:16 +02:00
|
|
|
private Rect rect = new Rect();
|
2020-12-23 08:48:30 +01:00
|
|
|
private boolean delayedAnimationResumed;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public ActionBarLayout(Context context) {
|
|
|
|
super(context);
|
2014-11-11 23:16:17 +01:00
|
|
|
parentActivity = (Activity) context;
|
|
|
|
|
|
|
|
if (layerShadowDrawable == null) {
|
|
|
|
layerShadowDrawable = getResources().getDrawable(R.drawable.layer_shadow);
|
2017-03-31 01:58:05 +02:00
|
|
|
headerShadowDrawable = getResources().getDrawable(R.drawable.header_shadow).mutate();
|
2014-11-11 23:16:17 +01:00
|
|
|
scrimPaint = new Paint();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void init(ArrayList<BaseFragment> stack) {
|
|
|
|
fragmentsStack = stack;
|
2020-02-13 19:26:53 +01:00
|
|
|
containerViewBack = new LayoutContainer(parentActivity);
|
2014-09-24 04:17:27 +02:00
|
|
|
addView(containerViewBack);
|
2014-11-11 23:16:17 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) containerViewBack.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2014-11-11 23:16:17 +01:00
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
containerViewBack.setLayoutParams(layoutParams);
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
containerView = new LayoutContainer(parentActivity);
|
2014-09-24 04:17:27 +02:00
|
|
|
addView(containerView);
|
2014-11-11 23:16:17 +01:00
|
|
|
layoutParams = (FrameLayout.LayoutParams) containerView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2014-11-11 23:16:17 +01:00
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
containerView.setLayoutParams(layoutParams);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
for (BaseFragment fragment : fragmentsStack) {
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(this);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
if (!fragmentsStack.isEmpty()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int a = 0, N = fragmentsStack.size(); a < N; a++) {
|
|
|
|
BaseFragment fragment = fragmentsStack.get(a);
|
|
|
|
fragment.onConfigurationChanged(newConfig);
|
|
|
|
if (fragment.visibleDialog instanceof BottomSheet) {
|
|
|
|
((BottomSheet) fragment.visibleDialog).onConfigurationChanged(newConfig);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public void drawHeaderShadow(Canvas canvas, int y) {
|
2020-02-13 19:26:53 +01:00
|
|
|
drawHeaderShadow(canvas, 255, y);
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
public void setInBubbleMode(boolean value) {
|
|
|
|
inBubbleMode = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInBubbleMode() {
|
|
|
|
return inBubbleMode;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
public void drawHeaderShadow(Canvas canvas, int alpha, int y) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (headerShadowDrawable != null) {
|
2020-02-13 19:26:53 +01:00
|
|
|
headerShadowDrawable.setAlpha(alpha);
|
2015-06-29 19:12:11 +02:00
|
|
|
headerShadowDrawable.setBounds(0, y, getMeasuredWidth(), y + headerShadowDrawable.getIntrinsicHeight());
|
|
|
|
headerShadowDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
2014-11-11 23:16:17 +01:00
|
|
|
public void setInnerTranslationX(float value) {
|
|
|
|
innerTranslationX = value;
|
|
|
|
invalidate();
|
2021-04-14 03:44:46 +02:00
|
|
|
|
|
|
|
if (fragmentsStack.size() >= 2) {
|
|
|
|
BaseFragment prevFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
prevFragment.onSlideProgress(false, value / containerView.getMeasuredWidth());
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
2014-11-11 23:16:17 +01:00
|
|
|
public float getInnerTranslationX() {
|
|
|
|
return innerTranslationX;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void dismissDialogs() {
|
|
|
|
if (!fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2020-07-26 10:03:38 +02:00
|
|
|
lastFragment.dismissCurrentDialog();
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void onResume() {
|
2014-06-13 17:03:06 +02:00
|
|
|
if (transitionAnimationInProgress) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
currentAnimation.cancel();
|
|
|
|
currentAnimation = null;
|
|
|
|
}
|
2020-08-14 18:58:22 +02:00
|
|
|
if (animationRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(animationRunnable);
|
|
|
|
animationRunnable = null;
|
|
|
|
}
|
|
|
|
if (waitingForKeyboardCloseRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
|
|
|
|
waitingForKeyboardCloseRunnable = null;
|
|
|
|
}
|
2014-06-13 17:03:06 +02:00
|
|
|
if (onCloseAnimationEndRunnable != null) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onCloseAnimationEnd();
|
2014-06-13 17:03:06 +02:00
|
|
|
} else if (onOpenAnimationEndRunnable != null) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onOpenAnimationEnd();
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
if (!fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
lastFragment.onResume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void onPause() {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (!fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
lastFragment.onPause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return animationInProgress || checkTransitionAnimation() || onTouchEvent(ev);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
|
|
|
onTouchEvent(null);
|
|
|
|
super.requestDisallowInterceptTouchEvent(disallowIntercept);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
2014-09-24 04:17:27 +02:00
|
|
|
return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
|
|
|
|
}
|
|
|
|
return super.dispatchKeyEventPreIme(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-11-11 23:16:17 +01:00
|
|
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (drawerLayoutContainer != null && drawerLayoutContainer.isDrawCurrentPreviewFragmentAbove()) {
|
|
|
|
if (inPreviewMode || transitionAnimationPreviewMode || previewOpenAnimationInProgress) {
|
|
|
|
if (child == (oldFragment != null && oldFragment.inPreviewMode ? containerViewBack : containerView)) {
|
|
|
|
drawerLayoutContainer.invalidate();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
int width = getWidth() - getPaddingLeft() - getPaddingRight();
|
|
|
|
int translationX = (int) innerTranslationX + getPaddingRight();
|
|
|
|
int clipLeft = getPaddingLeft();
|
|
|
|
int clipRight = width + getPaddingLeft();
|
2014-11-11 23:16:17 +01:00
|
|
|
|
|
|
|
if (child == containerViewBack) {
|
2020-09-30 15:48:47 +02:00
|
|
|
clipRight = translationX + AndroidUtilities.dp(1);
|
2014-11-11 23:16:17 +01:00
|
|
|
} else if (child == containerView) {
|
|
|
|
clipLeft = translationX;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int restoreCount = canvas.save();
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!transitionAnimationInProgress && !inPreviewMode) {
|
2014-11-11 23:16:17 +01:00
|
|
|
canvas.clipRect(clipLeft, 0, clipRight, getHeight());
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if ((inPreviewMode || transitionAnimationPreviewMode) && child == containerView) {
|
2020-09-30 15:48:47 +02:00
|
|
|
drawPreviewDrawables(canvas, containerView);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
final boolean result = super.drawChild(canvas, child, drawingTime);
|
|
|
|
canvas.restoreToCount(restoreCount);
|
|
|
|
|
|
|
|
if (translationX != 0) {
|
|
|
|
if (child == containerView) {
|
|
|
|
final float alpha = Math.max(0, Math.min((width - translationX) / (float) AndroidUtilities.dp(20), 1.0f));
|
|
|
|
layerShadowDrawable.setBounds(translationX - layerShadowDrawable.getIntrinsicWidth(), child.getTop(), translationX, child.getBottom());
|
|
|
|
layerShadowDrawable.setAlpha((int) (0xff * alpha));
|
|
|
|
layerShadowDrawable.draw(canvas);
|
|
|
|
} else if (child == containerViewBack) {
|
2015-06-29 19:12:11 +02:00
|
|
|
float opacity = Math.min(0.8f, (width - translationX) / (float)width);
|
|
|
|
if (opacity < 0) {
|
|
|
|
opacity = 0;
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * opacity) << 24);
|
|
|
|
canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public float getCurrentPreviewFragmentAlpha() {
|
|
|
|
if (inPreviewMode || transitionAnimationPreviewMode || previewOpenAnimationInProgress) {
|
|
|
|
return (oldFragment != null && oldFragment.inPreviewMode ? containerViewBack : containerView).getAlpha();
|
|
|
|
} else {
|
|
|
|
return 0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawCurrentPreviewFragment(Canvas canvas, Drawable foregroundDrawable) {
|
|
|
|
if (inPreviewMode || transitionAnimationPreviewMode || previewOpenAnimationInProgress) {
|
|
|
|
final ViewGroup v = oldFragment != null && oldFragment.inPreviewMode ? containerViewBack : containerView;
|
|
|
|
drawPreviewDrawables(canvas, v);
|
|
|
|
if (v.getAlpha() < 1f) {
|
|
|
|
canvas.saveLayerAlpha(0, 0, getWidth(), getHeight(), (int) (v.getAlpha() * 255), Canvas.ALL_SAVE_FLAG);
|
|
|
|
} else {
|
|
|
|
canvas.save();
|
|
|
|
}
|
|
|
|
canvas.concat(v.getMatrix());
|
|
|
|
v.draw(canvas);
|
|
|
|
if (foregroundDrawable != null) {
|
|
|
|
final View child = v.getChildAt(0);
|
|
|
|
if (child != null) {
|
|
|
|
final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
|
|
|
|
final Rect rect = new Rect();
|
|
|
|
child.getLocalVisibleRect(rect);
|
|
|
|
rect.offset(lp.leftMargin, lp.topMargin);
|
|
|
|
rect.top += Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight - 1 : 0;
|
|
|
|
foregroundDrawable.setAlpha((int) (v.getAlpha() * 255));
|
|
|
|
foregroundDrawable.setBounds(rect);
|
|
|
|
foregroundDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void drawPreviewDrawables(Canvas canvas, ViewGroup containerView) {
|
|
|
|
View view = containerView.getChildAt(0);
|
|
|
|
if (view != null) {
|
|
|
|
previewBackgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
|
|
|
|
previewBackgroundDrawable.draw(canvas);
|
|
|
|
int x = (getMeasuredWidth() - AndroidUtilities.dp(24)) / 2;
|
|
|
|
int y = (int) (view.getTop() + containerView.getTranslationY() - AndroidUtilities.dp(12 + (Build.VERSION.SDK_INT < 21 ? 20 : 0)));
|
|
|
|
Theme.moveUpDrawable.setBounds(x, y, x + AndroidUtilities.dp(24), y + AndroidUtilities.dp(24));
|
|
|
|
Theme.moveUpDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public void setDelegate(ActionBarLayoutDelegate actionBarLayoutDelegate) {
|
|
|
|
delegate = actionBarLayoutDelegate;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
private void onSlideAnimationEnd(final boolean backAnimation) {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (!backAnimation) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (fragmentsStack.size() < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2021-04-14 03:44:46 +02:00
|
|
|
lastFragment.prepareFragmentToSlide(true, false);
|
2014-06-04 01:31:48 +02:00
|
|
|
lastFragment.onPause();
|
|
|
|
lastFragment.onFragmentDestroy();
|
2014-09-24 04:17:27 +02:00
|
|
|
lastFragment.setParentLayout(null);
|
2021-04-14 03:44:46 +02:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentsStack.remove(fragmentsStack.size() - 1);
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
LayoutContainer temp = containerView;
|
2014-06-04 01:31:48 +02:00
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
2020-09-30 15:48:47 +02:00
|
|
|
bringChildToFront(containerView);
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2014-11-19 02:23:46 +01:00
|
|
|
currentActionBar = lastFragment.actionBar;
|
2014-06-04 01:31:48 +02:00
|
|
|
lastFragment.onResume();
|
2015-06-29 19:12:11 +02:00
|
|
|
lastFragment.onBecomeFullyVisible();
|
2021-04-14 03:44:46 +02:00
|
|
|
lastFragment.prepareFragmentToSlide(false, false);
|
2020-02-13 19:26:53 +01:00
|
|
|
|
|
|
|
layoutToIgnore = containerView;
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (fragmentsStack.size() >= 2) {
|
2021-04-14 03:44:46 +02:00
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
lastFragment.prepareFragmentToSlide(true, false);
|
|
|
|
|
|
|
|
lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
lastFragment.prepareFragmentToSlide(false, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
lastFragment.onPause();
|
|
|
|
if (lastFragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) lastFragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
lastFragment.onRemoveFromParent();
|
2019-12-31 14:08:08 +01:00
|
|
|
parent.removeViewInLayout(lastFragment.fragmentView);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
if (lastFragment.actionBar != null && lastFragment.actionBar.shouldAddToContainer()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
ViewGroup parent = (ViewGroup) lastFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
parent.removeViewInLayout(lastFragment.actionBar);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = null;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
containerViewBack.setVisibility(View.INVISIBLE);
|
2014-06-04 01:31:48 +02:00
|
|
|
startedTracking = false;
|
|
|
|
animationInProgress = false;
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setTranslationX(0);
|
|
|
|
containerViewBack.setTranslationX(0);
|
2014-11-11 23:16:17 +01:00
|
|
|
setInnerTranslationX(0);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-07 01:35:21 +02:00
|
|
|
private void prepareForMoving(MotionEvent ev) {
|
|
|
|
maybeStartTracking = false;
|
|
|
|
startedTracking = true;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = containerViewBack;
|
2014-06-07 01:35:21 +02:00
|
|
|
startedTrackingX = (int) ev.getX();
|
|
|
|
containerViewBack.setVisibility(View.VISIBLE);
|
|
|
|
beginTrackingSent = false;
|
|
|
|
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
2015-04-09 20:00:14 +02:00
|
|
|
View fragmentView = lastFragment.fragmentView;
|
|
|
|
if (fragmentView == null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
fragmentView = lastFragment.createView(parentActivity);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
lastFragment.onRemoveFromParent();
|
2014-11-11 23:16:17 +01:00
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
containerViewBack.addView(fragmentView);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fragmentView.getLayoutParams();
|
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
|
|
|
if (lastFragment.actionBar != null && lastFragment.actionBar.shouldAddToContainer()) {
|
2014-11-11 23:16:17 +01:00
|
|
|
parent = (ViewGroup) lastFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(lastFragment.actionBar);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
if (removeActionBarExtraHeight) {
|
|
|
|
lastFragment.actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
containerViewBack.addView(lastFragment.actionBar);
|
2019-01-23 18:03:33 +01:00
|
|
|
lastFragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, overlayAction);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!lastFragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
lastFragment.onResume();
|
2019-07-18 15:01:39 +02:00
|
|
|
if (themeAnimatorSet != null) {
|
|
|
|
presentingFragmentDescriptions = lastFragment.getThemeDescriptions();
|
|
|
|
}
|
2021-04-14 03:44:46 +02:00
|
|
|
|
|
|
|
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
currentFragment.prepareFragmentToSlide(true, true);
|
|
|
|
lastFragment.prepareFragmentToSlide(false, true);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 20:57:11 +02:00
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (!checkTransitionAnimation() && !inActionMode && !animationInProgress) {
|
2014-11-07 11:23:17 +01:00
|
|
|
if (fragmentsStack.size() > 1) {
|
|
|
|
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
|
|
|
|
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2020-02-13 19:26:53 +01:00
|
|
|
if (!currentFragment.isSwipeBackEnabled(ev)) {
|
2014-11-07 11:23:17 +01:00
|
|
|
return false;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
startedTrackingPointerId = ev.getPointerId(0);
|
|
|
|
maybeStartTracking = true;
|
|
|
|
startedTrackingX = (int) ev.getX();
|
|
|
|
startedTrackingY = (int) ev.getY();
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.clear();
|
|
|
|
}
|
|
|
|
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
|
|
|
|
if (velocityTracker == null) {
|
|
|
|
velocityTracker = VelocityTracker.obtain();
|
|
|
|
}
|
|
|
|
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
|
|
|
|
int dy = Math.abs((int) ev.getY() - startedTrackingY);
|
|
|
|
velocityTracker.addMovement(ev);
|
2020-07-26 10:03:38 +02:00
|
|
|
if (!transitionAnimationInProgress && !inPreviewMode && maybeStartTracking && !startedTracking && dx >= AndroidUtilities.getPixelsInCM(0.4f, true) && Math.abs(dx) / 3 > dy) {
|
2019-05-14 14:08:05 +02:00
|
|
|
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2020-10-02 23:48:16 +02:00
|
|
|
if (currentFragment.canBeginSlide() && findScrollingChild(this, ev.getX(), ev.getY()) == null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
prepareForMoving(ev);
|
|
|
|
} else {
|
|
|
|
maybeStartTracking = false;
|
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
} else if (startedTracking) {
|
|
|
|
if (!beginTrackingSent) {
|
|
|
|
if (parentActivity.getCurrentFocus() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
|
|
|
}
|
|
|
|
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
currentFragment.onBeginSlide();
|
|
|
|
beginTrackingSent = true;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setTranslationX(dx);
|
2014-11-11 23:16:17 +01:00
|
|
|
setInnerTranslationX(dx);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
} else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
|
|
|
|
if (velocityTracker == null) {
|
|
|
|
velocityTracker = VelocityTracker.obtain();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
velocityTracker.computeCurrentVelocity(1000);
|
2019-06-04 12:14:50 +02:00
|
|
|
BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2020-02-13 19:26:53 +01:00
|
|
|
if (!inPreviewMode && !transitionAnimationPreviewMode && !startedTracking && currentFragment.isSwipeBackEnabled(ev)) {
|
2014-11-07 11:23:17 +01:00
|
|
|
float velX = velocityTracker.getXVelocity();
|
|
|
|
float velY = velocityTracker.getYVelocity();
|
2019-06-04 12:14:50 +02:00
|
|
|
if (velX >= 3500 && velX > Math.abs(velY) && currentFragment.canBeginSlide()) {
|
2014-11-07 11:23:17 +01:00
|
|
|
prepareForMoving(ev);
|
2014-11-07 21:10:12 +01:00
|
|
|
if (!beginTrackingSent) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (((Activity) getContext()).getCurrentFocus() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
|
2014-11-07 21:10:12 +01:00
|
|
|
}
|
|
|
|
beginTrackingSent = true;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
}
|
|
|
|
if (startedTracking) {
|
2016-06-24 12:27:15 +02:00
|
|
|
float x = containerView.getX();
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
2014-11-07 11:23:17 +01:00
|
|
|
float velX = velocityTracker.getXVelocity();
|
|
|
|
float velY = velocityTracker.getYVelocity();
|
|
|
|
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
|
2015-05-21 23:27:27 +02:00
|
|
|
float distToMove;
|
2014-11-07 11:23:17 +01:00
|
|
|
if (!backAnimation) {
|
|
|
|
distToMove = containerView.getMeasuredWidth() - x;
|
2021-04-14 03:44:46 +02:00
|
|
|
int duration = Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50);
|
2014-11-07 11:23:17 +01:00
|
|
|
animatorSet.playTogether(
|
2021-04-14 03:44:46 +02:00
|
|
|
ObjectAnimator.ofFloat(containerView, View.TRANSLATION_X, containerView.getMeasuredWidth()).setDuration(duration),
|
|
|
|
ObjectAnimator.ofFloat(this, "innerTranslationX", (float) containerView.getMeasuredWidth()).setDuration(duration)
|
2014-11-07 11:23:17 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
distToMove = x;
|
2021-04-14 03:44:46 +02:00
|
|
|
int duration = Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50);
|
2014-11-07 11:23:17 +01:00
|
|
|
animatorSet.playTogether(
|
2021-04-14 03:44:46 +02:00
|
|
|
ObjectAnimator.ofFloat(containerView, View.TRANSLATION_X, 0).setDuration(duration),
|
|
|
|
ObjectAnimator.ofFloat(this, "innerTranslationX", 0.0f).setDuration(duration)
|
2014-11-07 11:23:17 +01:00
|
|
|
);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
|
2021-04-14 03:44:46 +02:00
|
|
|
Animator customTransition = currentFragment.getCustomSlideTransition(false, backAnimation, distToMove);
|
|
|
|
if (customTransition != null) {
|
|
|
|
animatorSet.playTogether(customTransition);
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
if (lastFragment != null) {
|
|
|
|
customTransition = lastFragment.getCustomSlideTransition(false, backAnimation, distToMove);
|
|
|
|
if (customTransition != null) {
|
|
|
|
animatorSet.playTogether(customTransition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2014-11-07 11:23:17 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animator) {
|
2014-11-07 11:23:17 +01:00
|
|
|
onSlideAnimationEnd(backAnimation);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
|
|
|
animationInProgress = true;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = containerViewBack;
|
2014-11-07 11:23:17 +01:00
|
|
|
} else {
|
|
|
|
maybeStartTracking = false;
|
|
|
|
startedTracking = false;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = null;
|
2014-11-07 11:23:17 +01:00
|
|
|
}
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.recycle();
|
|
|
|
velocityTracker = null;
|
|
|
|
}
|
|
|
|
} else if (ev == null) {
|
2014-06-07 01:35:21 +02:00
|
|
|
maybeStartTracking = false;
|
|
|
|
startedTracking = false;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = null;
|
2014-11-07 11:23:17 +01:00
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.recycle();
|
|
|
|
velocityTracker = null;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-06-04 20:57:11 +02:00
|
|
|
return startedTracking;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-06-04 20:57:11 +02:00
|
|
|
return false;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onBackPressed() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (transitionAnimationPreviewMode || startedTracking || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
if (GroupCallPip.onBackPressed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentActionBar != null && !currentActionBar.isActionModeShowed() && currentActionBar.isSearchFieldVisible) {
|
2014-11-11 23:16:17 +01:00
|
|
|
currentActionBar.closeSearchField();
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
if (lastFragment.onBackPressed()) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (!fragmentsStack.isEmpty()) {
|
2014-06-13 17:03:06 +02:00
|
|
|
closeLastFragment(true);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onLowMemory() {
|
|
|
|
for (BaseFragment fragment : fragmentsStack) {
|
|
|
|
fragment.onLowMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:29:17 +02:00
|
|
|
private void onAnimationEndCheck(boolean byCheck) {
|
|
|
|
onCloseAnimationEnd();
|
|
|
|
onOpenAnimationEnd();
|
2016-04-25 21:26:41 +02:00
|
|
|
if (waitingForKeyboardCloseRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
|
|
|
|
waitingForKeyboardCloseRunnable = null;
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
if (byCheck) {
|
|
|
|
currentAnimation.cancel();
|
|
|
|
}
|
|
|
|
currentAnimation = null;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (animationRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(animationRunnable);
|
|
|
|
animationRunnable = null;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
setAlpha(1.0f);
|
|
|
|
containerView.setAlpha(1.0f);
|
|
|
|
containerView.setScaleX(1.0f);
|
|
|
|
containerView.setScaleY(1.0f);
|
|
|
|
containerViewBack.setAlpha(1.0f);
|
|
|
|
containerViewBack.setScaleX(1.0f);
|
|
|
|
containerViewBack.setScaleY(1.0f);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public BaseFragment getLastFragment() {
|
|
|
|
if (fragmentsStack.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public boolean checkTransitionAnimation() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (transitionAnimationPreviewMode) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-25 21:26:41 +02:00
|
|
|
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 1500) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onAnimationEndCheck(true);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
return transitionAnimationInProgress;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
public boolean isPreviewOpenAnimationInProgress() {
|
|
|
|
return previewOpenAnimationInProgress;
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public boolean isTransitionAnimationInProgress() {
|
|
|
|
return transitionAnimationInProgress || animationInProgress;
|
|
|
|
}
|
|
|
|
|
2014-06-13 00:37:05 +02:00
|
|
|
private void presentFragmentInternalRemoveOld(boolean removeLast, final BaseFragment fragment) {
|
2014-06-04 01:31:48 +02:00
|
|
|
if (fragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
fragment.onBecomeFullyHidden();
|
2014-06-04 01:31:48 +02:00
|
|
|
fragment.onPause();
|
|
|
|
if (removeLast) {
|
|
|
|
fragment.onFragmentDestroy();
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(null);
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentsStack.remove(fragment);
|
|
|
|
} else {
|
|
|
|
if (fragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) fragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
fragment.onRemoveFromParent();
|
2021-01-01 05:38:45 +01:00
|
|
|
try {
|
|
|
|
parent.removeViewInLayout(fragment.fragmentView);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
try {
|
|
|
|
parent.removeView(fragment.fragmentView);
|
|
|
|
} catch (Exception e2) {
|
|
|
|
FileLog.e(e2);
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
if (fragment.actionBar != null && fragment.actionBar.shouldAddToContainer()) {
|
2014-11-11 23:16:17 +01:00
|
|
|
ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
parent.removeViewInLayout(fragment.actionBar);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
containerViewBack.setVisibility(View.INVISIBLE);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public boolean presentFragmentAsPreview(BaseFragment fragment) {
|
|
|
|
return presentFragment(fragment, false, false, true, true);
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public boolean presentFragment(BaseFragment fragment) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return presentFragment(fragment, false, false, true, false);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean presentFragment(BaseFragment fragment, boolean removeLast) {
|
2018-07-30 04:07:02 +02:00
|
|
|
return presentFragment(fragment, removeLast, false, true, false);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void startLayoutAnimation(final boolean open, final boolean first, final boolean preview) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (first) {
|
|
|
|
animationProgress = 0.0f;
|
|
|
|
lastFrameTime = System.nanoTime() / 1000000;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
AndroidUtilities.runOnUIThread(animationRunnable = new Runnable() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (animationRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
animationRunnable = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (first) {
|
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
long newTime = System.nanoTime() / 1000000;
|
|
|
|
long dt = newTime - lastFrameTime;
|
|
|
|
if (dt > 18) {
|
|
|
|
dt = 18;
|
|
|
|
}
|
|
|
|
lastFrameTime = newTime;
|
|
|
|
animationProgress += dt / 150.0f;
|
|
|
|
if (animationProgress > 1.0f) {
|
|
|
|
animationProgress = 1.0f;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
if (newFragment != null) {
|
|
|
|
newFragment.onTransitionAnimationProgress(true, animationProgress);
|
|
|
|
}
|
|
|
|
if (oldFragment != null) {
|
|
|
|
oldFragment.onTransitionAnimationProgress(false, animationProgress);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
float interpolated = decelerateInterpolator.getInterpolation(animationProgress);
|
|
|
|
if (open) {
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setAlpha(interpolated);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (preview) {
|
|
|
|
containerView.setScaleX(0.9f + 0.1f * interpolated);
|
|
|
|
containerView.setScaleY(0.9f + 0.1f * interpolated);
|
2020-06-04 18:47:15 +02:00
|
|
|
previewBackgroundDrawable.setAlpha((int) (0x2e * interpolated));
|
2018-07-30 04:07:02 +02:00
|
|
|
Theme.moveUpDrawable.setAlpha((int) (255 * interpolated));
|
|
|
|
containerView.invalidate();
|
|
|
|
invalidate();
|
|
|
|
} else {
|
|
|
|
containerView.setTranslationX(AndroidUtilities.dp(48) * (1.0f - interpolated));
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2016-06-24 12:27:15 +02:00
|
|
|
containerViewBack.setAlpha(1.0f - interpolated);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (preview) {
|
|
|
|
containerViewBack.setScaleX(0.9f + 0.1f * (1.0f - interpolated));
|
|
|
|
containerViewBack.setScaleY(0.9f + 0.1f * (1.0f - interpolated));
|
2020-06-04 18:47:15 +02:00
|
|
|
previewBackgroundDrawable.setAlpha((int) (0x2e * (1.0f - interpolated)));
|
2018-07-30 04:07:02 +02:00
|
|
|
Theme.moveUpDrawable.setAlpha((int) (255 * (1.0f - interpolated)));
|
|
|
|
containerView.invalidate();
|
|
|
|
invalidate();
|
|
|
|
} else {
|
|
|
|
containerViewBack.setTranslationX(AndroidUtilities.dp(48) * interpolated);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (animationProgress < 1) {
|
2018-07-30 04:07:02 +02:00
|
|
|
startLayoutAnimation(open, false, preview);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2017-07-23 19:29:17 +02:00
|
|
|
onAnimationEndCheck(false);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
public void resumeDelayedFragmentAnimation() {
|
2020-12-23 08:48:30 +01:00
|
|
|
delayedAnimationResumed = true;
|
|
|
|
if (delayedOpenAnimationRunnable == null || waitingForKeyboardCloseRunnable != null) {
|
2016-05-25 23:49:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(delayedOpenAnimationRunnable);
|
|
|
|
delayedOpenAnimationRunnable.run();
|
|
|
|
delayedOpenAnimationRunnable = null;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public boolean isInPreviewMode() {
|
|
|
|
return inPreviewMode || transitionAnimationPreviewMode;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation, boolean check, final boolean preview) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (fragment == null || checkTransitionAnimation() || delegate != null && check && !delegate.needPresentFragment(fragment, removeLast, forceWithoutAnimation, this) || !fragment.onFragmentCreate()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
fragment.setInPreviewMode(preview);
|
2020-06-04 18:47:15 +02:00
|
|
|
if (parentActivity.getCurrentFocus() != null && fragment.hideKeyboardOnShow()) {
|
2014-09-24 04:17:27 +02:00
|
|
|
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean needAnimation = preview || !forceWithoutAnimation && MessagesController.getGlobalMainSettings().getBoolean("view_animations", true);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
final BaseFragment currentFragment = !fragmentsStack.isEmpty() ? fragmentsStack.get(fragmentsStack.size() - 1) : null;
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(this);
|
2015-04-09 20:00:14 +02:00
|
|
|
View fragmentView = fragment.fragmentView;
|
|
|
|
if (fragmentView == null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
fragmentView = fragment.createView(parentActivity);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
fragment.onRemoveFromParent();
|
2015-04-09 20:00:14 +02:00
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
containerViewBack.addView(fragmentView);
|
2020-02-13 19:26:53 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fragmentView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (preview) {
|
2020-10-30 11:26:29 +01:00
|
|
|
int height = fragment.getPreviewHeight();
|
|
|
|
int statusBarHeight = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
|
|
|
if (height > 0 && height < getMeasuredHeight() - statusBarHeight) {
|
|
|
|
layoutParams.height = height;
|
|
|
|
layoutParams.topMargin = statusBarHeight + (getMeasuredHeight() - statusBarHeight - height) / 2;
|
|
|
|
} else {
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = AndroidUtilities.dp(46);
|
|
|
|
layoutParams.topMargin += AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(8);
|
|
|
|
} else {
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
2020-02-13 19:26:53 +01:00
|
|
|
if (fragment.actionBar != null && fragment.actionBar.shouldAddToContainer()) {
|
|
|
|
if (removeActionBarExtraHeight) {
|
|
|
|
fragment.actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
|
|
|
ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragment.actionBar);
|
|
|
|
}
|
|
|
|
containerViewBack.addView(fragment.actionBar);
|
|
|
|
fragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, overlayAction);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentsStack.add(fragment);
|
|
|
|
fragment.onResume();
|
2014-11-11 23:16:17 +01:00
|
|
|
currentActionBar = fragment.actionBar;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!fragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
LayoutContainer temp = containerView;
|
2014-06-13 20:26:05 +02:00
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
|
|
|
containerView.setVisibility(View.VISIBLE);
|
2015-02-26 02:32:51 +01:00
|
|
|
setInnerTranslationX(0);
|
2018-07-30 04:07:02 +02:00
|
|
|
containerView.setTranslationY(0);
|
|
|
|
|
|
|
|
if (preview) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
fragmentView.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setRoundRect(0, AndroidUtilities.statusBarHeight, view.getMeasuredWidth(), view.getMeasuredHeight(), AndroidUtilities.dp(6));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fragmentView.setClipToOutline(true);
|
|
|
|
fragmentView.setElevation(AndroidUtilities.dp(4));
|
|
|
|
}
|
|
|
|
if (previewBackgroundDrawable == null) {
|
2020-06-04 18:47:15 +02:00
|
|
|
previewBackgroundDrawable = new ColorDrawable(0x2e000000);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
previewBackgroundDrawable.setAlpha(0);
|
|
|
|
Theme.moveUpDrawable.setAlpha(0);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
bringChildToFront(containerView);
|
2014-06-13 20:26:05 +02:00
|
|
|
if (!needAnimation) {
|
|
|
|
presentFragmentInternalRemoveOld(removeLast, currentFragment);
|
2014-09-28 15:37:26 +02:00
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.setVisibility(VISIBLE);
|
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
if (themeAnimatorSet != null) {
|
|
|
|
presentingFragmentDescriptions = fragment.getThemeDescriptions();
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
if (needAnimation || preview) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (useAlphaAnimations && fragmentsStack.size() == 1) {
|
|
|
|
presentFragmentInternalRemoveOld(removeLast, currentFragment);
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
transitionAnimationInProgress = true;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = containerView;
|
2018-08-27 10:33:11 +02:00
|
|
|
onOpenAnimationEndRunnable = () -> {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationEnd(false, false);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
fragment.onTransitionAnimationEnd(true, false);
|
|
|
|
fragment.onBecomeFullyVisible();
|
2015-05-03 13:48:36 +02:00
|
|
|
};
|
2016-06-24 12:27:15 +02:00
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
2020-02-13 19:26:53 +01:00
|
|
|
animators.add(ObjectAnimator.ofFloat(this, View.ALPHA, 0.0f, 1.0f));
|
2014-09-24 04:17:27 +02:00
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.setVisibility(VISIBLE);
|
2020-02-13 19:26:53 +01:00
|
|
|
animators.add(ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 0.0f, 1.0f));
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationStart(false, false);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
2016-06-24 12:27:15 +02:00
|
|
|
currentAnimation = new AnimatorSet();
|
2014-11-11 23:16:17 +01:00
|
|
|
currentAnimation.playTogether(animators);
|
2015-05-03 13:48:36 +02:00
|
|
|
currentAnimation.setInterpolator(accelerateDecelerateInterpolator);
|
2014-11-11 23:16:17 +01:00
|
|
|
currentAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
currentAnimation.addListener(new AnimatorListenerAdapter() {
|
2014-11-11 23:16:17 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onAnimationEndCheck(false);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
currentAnimation.start();
|
2014-09-24 04:17:27 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
transitionAnimationPreviewMode = preview;
|
2014-09-24 04:17:27 +02:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
transitionAnimationInProgress = true;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = containerView;
|
2018-08-27 10:33:11 +02:00
|
|
|
onOpenAnimationEndRunnable = () -> {
|
|
|
|
if (preview) {
|
|
|
|
inPreviewMode = true;
|
|
|
|
transitionAnimationPreviewMode = false;
|
|
|
|
containerView.setScaleX(1.0f);
|
|
|
|
containerView.setScaleY(1.0f);
|
|
|
|
} else {
|
|
|
|
presentFragmentInternalRemoveOld(removeLast, currentFragment);
|
|
|
|
containerView.setTranslationX(0);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationEnd(false, false);
|
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
fragment.onTransitionAnimationEnd(true, false);
|
|
|
|
fragment.onBecomeFullyVisible();
|
2014-09-24 04:17:27 +02:00
|
|
|
};
|
2020-10-30 13:41:45 +01:00
|
|
|
boolean noDelay;
|
|
|
|
if (noDelay = !fragment.needDelayOpenAnimation()) {
|
2020-07-26 10:03:38 +02:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationStart(false, false);
|
|
|
|
}
|
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
|
|
|
|
delayedAnimationResumed = false;
|
2020-06-04 18:47:15 +02:00
|
|
|
oldFragment = currentFragment;
|
|
|
|
newFragment = fragment;
|
2018-07-30 04:07:02 +02:00
|
|
|
AnimatorSet animation = null;
|
|
|
|
if (!preview) {
|
2018-08-27 10:33:11 +02:00
|
|
|
animation = fragment.onCustomTransitionAnimation(true, () -> onAnimationEndCheck(false));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (animation == null) {
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setAlpha(0.0f);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (preview) {
|
|
|
|
containerView.setTranslationX(0.0f);
|
|
|
|
containerView.setScaleX(0.9f);
|
|
|
|
containerView.setScaleY(0.9f);
|
|
|
|
} else {
|
|
|
|
containerView.setTranslationX(48.0f);
|
|
|
|
containerView.setScaleX(1.0f);
|
|
|
|
containerView.setScaleY(1.0f);
|
|
|
|
}
|
2016-04-25 21:26:41 +02:00
|
|
|
if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) {
|
2020-12-23 08:48:30 +01:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.saveKeyboardPositionBeforeTransition();
|
|
|
|
}
|
2016-04-25 21:26:41 +02:00
|
|
|
waitingForKeyboardCloseRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (waitingForKeyboardCloseRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
waitingForKeyboardCloseRunnable = null;
|
2020-12-23 08:48:30 +01:00
|
|
|
if (noDelay) {
|
2020-10-30 13:41:45 +01:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationStart(false, false);
|
|
|
|
}
|
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
2020-12-23 08:48:30 +01:00
|
|
|
startLayoutAnimation(true, true, preview);
|
|
|
|
} else if (delayedOpenAnimationRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(delayedOpenAnimationRunnable);
|
|
|
|
if (delayedAnimationResumed) {
|
|
|
|
delayedOpenAnimationRunnable.run();
|
|
|
|
} else {
|
|
|
|
AndroidUtilities.runOnUIThread(delayedOpenAnimationRunnable, 200);
|
|
|
|
}
|
2020-10-30 13:41:45 +01:00
|
|
|
}
|
2016-04-25 21:26:41 +02:00
|
|
|
}
|
|
|
|
};
|
2020-12-23 08:48:30 +01:00
|
|
|
if (fragment.needDelayOpenAnimation()) {
|
|
|
|
delayedOpenAnimationRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (delayedOpenAnimationRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delayedOpenAnimationRunnable = null;
|
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationStart(false, false);
|
|
|
|
}
|
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
|
|
|
startLayoutAnimation(true, true, preview);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, SharedConfig.smoothKeyboard ? 250 : 200);
|
2016-05-25 23:49:47 +02:00
|
|
|
} else if (fragment.needDelayOpenAnimation()) {
|
|
|
|
delayedOpenAnimationRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (delayedOpenAnimationRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delayedOpenAnimationRunnable = null;
|
2020-07-26 10:03:38 +02:00
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
startLayoutAnimation(true, true, preview);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
AndroidUtilities.runOnUIThread(delayedOpenAnimationRunnable, 200);
|
2016-04-25 21:26:41 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
startLayoutAnimation(true, true, preview);
|
2016-04-25 21:26:41 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
2020-12-23 08:48:30 +01:00
|
|
|
if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible && currentFragment != null) {
|
|
|
|
currentFragment.saveKeyboardPositionBeforeTransition();
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
currentAnimation = animation;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2014-11-17 23:04:31 +01:00
|
|
|
if (backgroundView != null) {
|
2016-06-24 12:27:15 +02:00
|
|
|
backgroundView.setAlpha(1.0f);
|
2014-11-17 23:04:31 +01:00
|
|
|
backgroundView.setVisibility(VISIBLE);
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentFragment != null) {
|
|
|
|
currentFragment.onTransitionAnimationStart(false, false);
|
|
|
|
currentFragment.onTransitionAnimationEnd(false, false);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
|
|
|
fragment.onTransitionAnimationEnd(true, false);
|
2015-06-29 19:12:11 +02:00
|
|
|
fragment.onBecomeFullyVisible();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-04 18:00:42 +02:00
|
|
|
public boolean addFragmentToStack(BaseFragment fragment) {
|
2014-09-30 00:48:11 +02:00
|
|
|
return addFragmentToStack(fragment, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean addFragmentToStack(BaseFragment fragment, int position) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (delegate != null && !delegate.needAddFragmentToStack(fragment, this) || !fragment.onFragmentCreate()) {
|
2014-06-04 18:00:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(this);
|
2014-09-30 00:48:11 +02:00
|
|
|
if (position == -1) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (!fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
previousFragment.onPause();
|
2020-02-13 19:26:53 +01:00
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.shouldAddToContainer()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(previousFragment.actionBar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (previousFragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
previousFragment.onRemoveFromParent();
|
2015-02-26 02:32:51 +01:00
|
|
|
parent.removeView(previousFragment.fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
fragmentsStack.add(fragment);
|
|
|
|
} else {
|
|
|
|
fragmentsStack.add(position, fragment);
|
|
|
|
}
|
2014-06-04 18:00:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
private void closeLastFragmentInternalRemoveOld(BaseFragment fragment) {
|
|
|
|
fragment.onPause();
|
|
|
|
fragment.onFragmentDestroy();
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(null);
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentsStack.remove(fragment);
|
2019-12-31 14:08:08 +01:00
|
|
|
containerViewBack.setVisibility(View.INVISIBLE);
|
2020-10-30 11:26:29 +01:00
|
|
|
containerViewBack.setTranslationY(0);
|
2014-11-11 23:16:17 +01:00
|
|
|
bringChildToFront(containerView);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void movePreviewFragment(float dy) {
|
|
|
|
if (!inPreviewMode || transitionAnimationPreviewMode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float currentTranslation = containerView.getTranslationY();
|
|
|
|
float nextTranslation = -dy;
|
|
|
|
if (nextTranslation > 0) {
|
|
|
|
nextTranslation = 0;
|
|
|
|
} else if (nextTranslation < -AndroidUtilities.dp(60)) {
|
2020-02-13 19:26:53 +01:00
|
|
|
previewOpenAnimationInProgress = true;
|
2018-07-30 04:07:02 +02:00
|
|
|
inPreviewMode = false;
|
|
|
|
nextTranslation = 0;
|
|
|
|
|
|
|
|
BaseFragment prevFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
BaseFragment fragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
fragment.fragmentView.setOutlineProvider(null);
|
|
|
|
fragment.fragmentView.setClipToOutline(false);
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fragment.fragmentView.getLayoutParams();
|
2018-07-30 04:07:02 +02:00
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
2020-10-30 11:26:29 +01:00
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2018-07-30 04:07:02 +02:00
|
|
|
fragment.fragmentView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
presentFragmentInternalRemoveOld(false, prevFragment);
|
|
|
|
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(
|
2020-02-13 19:26:53 +01:00
|
|
|
ObjectAnimator.ofFloat(fragment.fragmentView, View.SCALE_X, 1.0f, 1.05f, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(fragment.fragmentView, View.SCALE_Y, 1.0f, 1.05f, 1.0f));
|
2018-07-30 04:07:02 +02:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.setInterpolator(new CubicBezierInterpolator(0.42, 0.0, 0.58, 1.0));
|
2020-02-13 19:26:53 +01:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
previewOpenAnimationInProgress = false;
|
2020-09-30 15:48:47 +02:00
|
|
|
fragment.onPreviewOpenAnimationEnd();
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
});
|
2018-07-30 04:07:02 +02:00
|
|
|
animatorSet.start();
|
|
|
|
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
|
|
|
|
|
|
|
fragment.setInPreviewMode(false);
|
|
|
|
}
|
|
|
|
if (currentTranslation != nextTranslation) {
|
|
|
|
containerView.setTranslationY(nextTranslation);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishPreviewFragment() {
|
|
|
|
if (!inPreviewMode && !transitionAnimationPreviewMode) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
if (delayedOpenAnimationRunnable != null) {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(delayedOpenAnimationRunnable);
|
|
|
|
delayedOpenAnimationRunnable = null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
closeLastFragment(true);
|
|
|
|
}
|
|
|
|
|
2014-06-13 17:03:06 +02:00
|
|
|
public void closeLastFragment(boolean animated) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
if (parentActivity.getCurrentFocus() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
setInnerTranslationX(0);
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean needAnimation = inPreviewMode || transitionAnimationPreviewMode || animated && MessagesController.getGlobalMainSettings().getBoolean("view_animations", true);
|
2014-06-04 01:31:48 +02:00
|
|
|
final BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2014-09-24 04:17:27 +02:00
|
|
|
BaseFragment previousFragment = null;
|
|
|
|
if (fragmentsStack.size() > 1) {
|
|
|
|
previousFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (previousFragment != null) {
|
2020-02-13 19:26:53 +01:00
|
|
|
LayoutContainer temp = containerView;
|
2014-09-24 04:17:27 +02:00
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
|
|
|
|
|
|
|
previousFragment.setParentLayout(this);
|
2015-04-09 20:00:14 +02:00
|
|
|
View fragmentView = previousFragment.fragmentView;
|
|
|
|
if (fragmentView == null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
fragmentView = previousFragment.createView(parentActivity);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
|
|
|
|
if (!inPreviewMode) {
|
|
|
|
containerView.setVisibility(View.VISIBLE);
|
|
|
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
2014-11-19 11:32:27 +01:00
|
|
|
if (parent != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
previousFragment.onRemoveFromParent();
|
|
|
|
try {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2014-11-19 11:32:27 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
containerView.addView(fragmentView);
|
2020-02-13 19:26:53 +01:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fragmentView.getLayoutParams();
|
2019-05-14 14:08:05 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
2020-02-13 19:26:53 +01:00
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.shouldAddToContainer()) {
|
|
|
|
if (removeActionBarExtraHeight) {
|
|
|
|
previousFragment.actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
|
|
|
parent = (ViewGroup) previousFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(previousFragment.actionBar);
|
|
|
|
}
|
|
|
|
containerView.addView(previousFragment.actionBar);
|
|
|
|
previousFragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, overlayAction);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
newFragment = previousFragment;
|
|
|
|
oldFragment = currentFragment;
|
2015-10-29 18:10:07 +01:00
|
|
|
previousFragment.onTransitionAnimationStart(true, true);
|
2019-08-22 01:53:26 +02:00
|
|
|
currentFragment.onTransitionAnimationStart(false, true);
|
2014-09-24 04:17:27 +02:00
|
|
|
previousFragment.onResume();
|
2019-07-18 15:01:39 +02:00
|
|
|
if (themeAnimatorSet != null) {
|
|
|
|
presentingFragmentDescriptions = previousFragment.getThemeDescriptions();
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
currentActionBar = previousFragment.actionBar;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
if (!needAnimation) {
|
|
|
|
closeLastFragmentInternalRemoveOld(currentFragment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needAnimation) {
|
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
transitionAnimationInProgress = true;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = containerView;
|
2015-06-29 19:12:11 +02:00
|
|
|
final BaseFragment previousFragmentFinal = previousFragment;
|
2018-08-27 10:33:11 +02:00
|
|
|
onCloseAnimationEndRunnable = () -> {
|
|
|
|
if (inPreviewMode || transitionAnimationPreviewMode) {
|
|
|
|
containerViewBack.setScaleX(1.0f);
|
|
|
|
containerViewBack.setScaleY(1.0f);
|
|
|
|
inPreviewMode = false;
|
|
|
|
transitionAnimationPreviewMode = false;
|
|
|
|
} else {
|
|
|
|
containerViewBack.setTranslationX(0);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
closeLastFragmentInternalRemoveOld(currentFragment);
|
2019-08-22 01:53:26 +02:00
|
|
|
currentFragment.onTransitionAnimationEnd(false, true);
|
2018-08-27 10:33:11 +02:00
|
|
|
previousFragmentFinal.onTransitionAnimationEnd(true, true);
|
|
|
|
previousFragmentFinal.onBecomeFullyVisible();
|
2014-09-24 04:17:27 +02:00
|
|
|
};
|
2018-07-30 04:07:02 +02:00
|
|
|
AnimatorSet animation = null;
|
|
|
|
if (!inPreviewMode && !transitionAnimationPreviewMode) {
|
2018-08-27 10:33:11 +02:00
|
|
|
animation = currentFragment.onCustomTransitionAnimation(false, () -> onAnimationEndCheck(false));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (animation == null) {
|
2016-04-25 21:26:41 +02:00
|
|
|
if (containerView.isKeyboardVisible || containerViewBack.isKeyboardVisible) {
|
|
|
|
waitingForKeyboardCloseRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (waitingForKeyboardCloseRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
waitingForKeyboardCloseRunnable = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
startLayoutAnimation(false, true, false);
|
2016-04-25 21:26:41 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 200);
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
startLayoutAnimation(false, true, inPreviewMode || transitionAnimationPreviewMode);
|
2016-04-25 21:26:41 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
|
|
|
currentAnimation = animation;
|
2021-02-23 12:53:38 +01:00
|
|
|
if (Bulletin.getVisibleBulletin() != null && Bulletin.getVisibleBulletin().isShowing()) {
|
|
|
|
Bulletin.getVisibleBulletin().hide();
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
2019-08-22 01:53:26 +02:00
|
|
|
currentFragment.onTransitionAnimationEnd(false, true);
|
2015-10-29 18:10:07 +01:00
|
|
|
previousFragment.onTransitionAnimationEnd(true, true);
|
2015-06-29 19:12:11 +02:00
|
|
|
previousFragment.onBecomeFullyVisible();
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (useAlphaAnimations) {
|
2014-09-24 04:17:27 +02:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
transitionAnimationInProgress = true;
|
2020-02-13 19:26:53 +01:00
|
|
|
layoutToIgnore = containerView;
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2018-08-27 10:33:11 +02:00
|
|
|
onCloseAnimationEndRunnable = () -> {
|
|
|
|
removeFragmentFromStackInternal(currentFragment);
|
|
|
|
setVisibility(GONE);
|
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
if (drawerLayoutContainer != null) {
|
|
|
|
drawerLayoutContainer.setAllowOpenDrawer(true, false);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
};
|
2014-11-11 23:16:17 +01:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
2020-02-13 19:26:53 +01:00
|
|
|
animators.add(ObjectAnimator.ofFloat(this, View.ALPHA, 1.0f, 0.0f));
|
2014-11-11 23:16:17 +01:00
|
|
|
if (backgroundView != null) {
|
2020-02-13 19:26:53 +01:00
|
|
|
animators.add(ObjectAnimator.ofFloat(backgroundView, View.ALPHA, 1.0f, 0.0f));
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
currentAnimation = new AnimatorSet();
|
2014-11-11 23:16:17 +01:00
|
|
|
currentAnimation.playTogether(animators);
|
2015-05-03 13:48:36 +02:00
|
|
|
currentAnimation.setInterpolator(accelerateDecelerateInterpolator);
|
2014-11-11 23:16:17 +01:00
|
|
|
currentAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
currentAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationStart(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onAnimationEndCheck(false);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
currentAnimation.start();
|
2014-09-24 04:17:27 +02:00
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
removeFragmentFromStackInternal(currentFragment);
|
2015-06-29 19:12:11 +02:00
|
|
|
setVisibility(GONE);
|
2014-09-24 04:17:27 +02:00
|
|
|
if (backgroundView != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
backgroundView.setVisibility(GONE);
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showLastFragment() {
|
2014-09-14 01:40:36 +02:00
|
|
|
if (fragmentsStack.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
for (int a = 0; a < fragmentsStack.size() - 1; a++) {
|
|
|
|
BaseFragment previousFragment = fragmentsStack.get(a);
|
2020-02-13 19:26:53 +01:00
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.shouldAddToContainer()) {
|
2015-10-29 18:10:07 +01:00
|
|
|
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(previousFragment.actionBar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (previousFragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) previousFragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
previousFragment.onPause();
|
2017-07-08 18:32:04 +02:00
|
|
|
previousFragment.onRemoveFromParent();
|
2015-10-29 18:10:07 +01:00
|
|
|
parent.removeView(previousFragment.fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
BaseFragment previousFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
2014-09-24 04:17:27 +02:00
|
|
|
previousFragment.setParentLayout(this);
|
2015-04-09 20:00:14 +02:00
|
|
|
View fragmentView = previousFragment.fragmentView;
|
|
|
|
if (fragmentView == null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
fragmentView = previousFragment.createView(parentActivity);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup) fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
previousFragment.onRemoveFromParent();
|
2015-04-09 20:00:14 +02:00
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
containerView.addView(fragmentView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.shouldAddToContainer()) {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (removeActionBarExtraHeight) {
|
|
|
|
previousFragment.actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
2014-11-17 23:04:31 +01:00
|
|
|
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(previousFragment.actionBar);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
containerView.addView(previousFragment.actionBar);
|
2019-01-23 18:03:33 +01:00
|
|
|
previousFragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, overlayAction);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
previousFragment.onResume();
|
2014-11-11 23:16:17 +01:00
|
|
|
currentActionBar = previousFragment.actionBar;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (!previousFragment.hasOwnBackground && fragmentView.getBackground() == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
private void removeFragmentFromStackInternal(BaseFragment fragment) {
|
2014-07-03 00:39:05 +02:00
|
|
|
fragment.onPause();
|
2014-06-04 01:31:48 +02:00
|
|
|
fragment.onFragmentDestroy();
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(null);
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentsStack.remove(fragment);
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void removeFragmentFromStack(int num) {
|
|
|
|
if (num >= fragmentsStack.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
removeFragmentFromStackInternal(fragmentsStack.get(num));
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public void removeFragmentFromStack(BaseFragment fragment) {
|
|
|
|
if (useAlphaAnimations && fragmentsStack.size() == 1 && AndroidUtilities.isTablet()) {
|
|
|
|
closeLastFragment(true);
|
|
|
|
} else {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (delegate != null && fragmentsStack.size() == 1 && AndroidUtilities.isTablet()) {
|
|
|
|
delegate.needCloseLastFragment(this);
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
removeFragmentFromStackInternal(fragment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void removeAllFragments() {
|
|
|
|
for (int a = 0; a < fragmentsStack.size(); a++) {
|
2015-11-26 22:04:02 +01:00
|
|
|
removeFragmentFromStackInternal(fragmentsStack.get(a));
|
2014-09-24 04:17:27 +02:00
|
|
|
a--;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Keep
|
|
|
|
public void setThemeAnimationValue(float value) {
|
|
|
|
themeAnimationValue = value;
|
2020-01-23 07:15:40 +01:00
|
|
|
for (int j = 0, N = themeAnimatorDescriptions.size(); j < N; j++) {
|
2020-04-24 11:21:58 +02:00
|
|
|
ArrayList<ThemeDescription> descriptions = themeAnimatorDescriptions.get(j);
|
2020-01-23 07:15:40 +01:00
|
|
|
int[] startColors = animateStartColors.get(j);
|
|
|
|
int[] endColors = animateEndColors.get(j);
|
|
|
|
int rE, gE, bE, aE, rS, gS, bS, aS, a, r, g, b;
|
2020-04-24 11:21:58 +02:00
|
|
|
for (int i = 0, N2 = descriptions.size(); i < N2; i++) {
|
2020-01-23 07:15:40 +01:00
|
|
|
rE = Color.red(endColors[i]);
|
|
|
|
gE = Color.green(endColors[i]);
|
|
|
|
bE = Color.blue(endColors[i]);
|
|
|
|
aE = Color.alpha(endColors[i]);
|
|
|
|
|
|
|
|
rS = Color.red(startColors[i]);
|
|
|
|
gS = Color.green(startColors[i]);
|
|
|
|
bS = Color.blue(startColors[i]);
|
|
|
|
aS = Color.alpha(startColors[i]);
|
|
|
|
|
|
|
|
a = Math.min(255, (int) (aS + (aE - aS) * value));
|
|
|
|
r = Math.min(255, (int) (rS + (rE - rS) * value));
|
|
|
|
g = Math.min(255, (int) (gS + (gE - gS) * value));
|
|
|
|
b = Math.min(255, (int) (bS + (bE - bS) * value));
|
|
|
|
int color = Color.argb(a, r, g, b);
|
2020-04-24 11:21:58 +02:00
|
|
|
ThemeDescription description = descriptions.get(i);
|
|
|
|
Theme.setAnimatedColor(description.getCurrentKey(), color);
|
|
|
|
description.setColor(color, false, false);
|
2020-01-23 07:15:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int j = 0, N = themeAnimatorDelegate.size(); j < N; j++) {
|
|
|
|
ThemeDescription.ThemeDescriptionDelegate delegate = themeAnimatorDelegate.get(j);
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didSetColor();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (presentingFragmentDescriptions != null) {
|
2020-04-24 11:21:58 +02:00
|
|
|
for (int i = 0, N = presentingFragmentDescriptions.size(); i < N; i++) {
|
|
|
|
ThemeDescription description = presentingFragmentDescriptions.get(i);
|
|
|
|
String key = description.getCurrentKey();
|
|
|
|
description.setColor(Theme.getColor(key), false, false);
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Keep
|
|
|
|
public float getThemeAnimationValue() {
|
|
|
|
return themeAnimationValue;
|
|
|
|
}
|
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
private void addStartDescriptions(ArrayList<ThemeDescription> descriptions) {
|
2020-01-23 07:15:40 +01:00
|
|
|
if (descriptions == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
themeAnimatorDescriptions.add(descriptions);
|
2020-04-24 11:21:58 +02:00
|
|
|
int[] startColors = new int[descriptions.size()];
|
2020-01-23 07:15:40 +01:00
|
|
|
animateStartColors.add(startColors);
|
2020-04-24 11:21:58 +02:00
|
|
|
for (int a = 0, N = descriptions.size(); a < N; a++) {
|
|
|
|
ThemeDescription description = descriptions.get(a);
|
|
|
|
startColors[a] = description.getSetColor();
|
|
|
|
ThemeDescription.ThemeDescriptionDelegate delegate = description.setDelegateDisabled();
|
2020-01-23 07:15:40 +01:00
|
|
|
if (delegate != null && !themeAnimatorDelegate.contains(delegate)) {
|
|
|
|
themeAnimatorDelegate.add(delegate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
private void addEndDescriptions(ArrayList<ThemeDescription> descriptions) {
|
2020-01-23 07:15:40 +01:00
|
|
|
if (descriptions == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-24 11:21:58 +02:00
|
|
|
int[] endColors = new int[descriptions.size()];
|
2020-01-23 07:15:40 +01:00
|
|
|
animateEndColors.add(endColors);
|
2020-04-24 11:21:58 +02:00
|
|
|
for (int a = 0, N = descriptions.size(); a < N; a++) {
|
|
|
|
endColors[a] = descriptions.get(a).getSetColor();
|
2020-01-23 07:15:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public void animateThemedValues(Theme.ThemeInfo theme, int accentId, boolean nightTheme, boolean instant) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (transitionAnimationInProgress || startedTracking) {
|
|
|
|
animateThemeAfterAnimation = true;
|
|
|
|
animateSetThemeAfterAnimation = theme;
|
2019-02-08 03:30:32 +01:00
|
|
|
animateSetThemeNightAfterAnimation = nightTheme;
|
2019-12-31 14:08:08 +01:00
|
|
|
animateSetThemeAccentIdAfterAnimation = accentId;
|
2018-07-30 04:07:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (themeAnimatorSet != null) {
|
|
|
|
themeAnimatorSet.cancel();
|
|
|
|
themeAnimatorSet = null;
|
|
|
|
}
|
|
|
|
boolean startAnimation = false;
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
BaseFragment fragment;
|
|
|
|
if (i == 0) {
|
|
|
|
fragment = getLastFragment();
|
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (!inPreviewMode && !transitionAnimationPreviewMode || fragmentsStack.size() <= 1) {
|
2018-07-30 04:07:02 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
}
|
|
|
|
if (fragment != null) {
|
|
|
|
startAnimation = true;
|
2020-04-24 11:21:58 +02:00
|
|
|
ArrayList<ThemeDescription> descriptions = fragment.getThemeDescriptions();
|
2020-01-23 07:15:40 +01:00
|
|
|
addStartDescriptions(descriptions);
|
|
|
|
if (fragment.visibleDialog instanceof BottomSheet) {
|
|
|
|
BottomSheet sheet = (BottomSheet) fragment.visibleDialog;
|
|
|
|
addStartDescriptions(sheet.getThemeDescriptions());
|
|
|
|
} else if (fragment.visibleDialog instanceof AlertDialog) {
|
|
|
|
AlertDialog dialog = (AlertDialog) fragment.visibleDialog;
|
|
|
|
addStartDescriptions(dialog.getThemeDescriptions());
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (i == 0) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (accentId != -1) {
|
|
|
|
theme.setCurrentAccentId(accentId);
|
|
|
|
Theme.saveThemeAccents(theme, true, false, true, false);
|
|
|
|
}
|
2019-02-08 03:30:32 +01:00
|
|
|
Theme.applyTheme(theme, nightTheme);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2020-01-23 07:15:40 +01:00
|
|
|
addEndDescriptions(descriptions);
|
|
|
|
if (fragment.visibleDialog instanceof BottomSheet) {
|
|
|
|
addEndDescriptions(((BottomSheet) fragment.visibleDialog).getThemeDescriptions());
|
|
|
|
} else if (fragment.visibleDialog instanceof AlertDialog) {
|
|
|
|
addEndDescriptions(((AlertDialog) fragment.visibleDialog).getThemeDescriptions());
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startAnimation) {
|
2019-12-31 14:08:08 +01:00
|
|
|
int count = fragmentsStack.size() - (inPreviewMode || transitionAnimationPreviewMode ? 2 : 1);
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
BaseFragment fragment = fragmentsStack.get(a);
|
|
|
|
fragment.clearViews();
|
|
|
|
fragment.setParentLayout(this);
|
|
|
|
}
|
|
|
|
if (instant) {
|
|
|
|
setThemeAnimationValue(1.0f);
|
2020-01-23 07:15:40 +01:00
|
|
|
themeAnimatorDescriptions.clear();
|
|
|
|
animateStartColors.clear();
|
|
|
|
animateEndColors.clear();
|
|
|
|
themeAnimatorDelegate.clear();
|
2019-12-31 14:08:08 +01:00
|
|
|
presentingFragmentDescriptions = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Theme.setAnimatingColor(true);
|
2018-07-30 04:07:02 +02:00
|
|
|
themeAnimatorSet = new AnimatorSet();
|
|
|
|
themeAnimatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(themeAnimatorSet)) {
|
2020-01-23 07:15:40 +01:00
|
|
|
themeAnimatorDescriptions.clear();
|
|
|
|
animateStartColors.clear();
|
|
|
|
animateEndColors.clear();
|
|
|
|
themeAnimatorDelegate.clear();
|
2019-06-04 12:14:50 +02:00
|
|
|
Theme.setAnimatingColor(false);
|
2019-07-18 15:01:39 +02:00
|
|
|
presentingFragmentDescriptions = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
themeAnimatorSet = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(themeAnimatorSet)) {
|
2020-01-23 07:15:40 +01:00
|
|
|
themeAnimatorDescriptions.clear();
|
|
|
|
animateStartColors.clear();
|
|
|
|
animateEndColors.clear();
|
|
|
|
themeAnimatorDelegate.clear();
|
2019-06-04 12:14:50 +02:00
|
|
|
Theme.setAnimatingColor(false);
|
2019-07-18 15:01:39 +02:00
|
|
|
presentingFragmentDescriptions = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
themeAnimatorSet = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-06-04 12:14:50 +02:00
|
|
|
themeAnimatorSet.playTogether(ObjectAnimator.ofFloat(this, "themeAnimationValue", 0.0f, 1.0f));
|
|
|
|
themeAnimatorSet.setDuration(200);
|
|
|
|
themeAnimatorSet.start();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public void rebuildAllFragmentViews(boolean last, boolean showLastAfter) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (transitionAnimationInProgress || startedTracking) {
|
2017-07-08 18:32:04 +02:00
|
|
|
rebuildAfterAnimation = true;
|
|
|
|
rebuildLastAfterAnimation = last;
|
|
|
|
showLastAfterAnimation = showLastAfter;
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
int size = fragmentsStack.size();
|
|
|
|
if (!last) {
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
if (inPreviewMode) {
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < size; a++) {
|
2015-06-29 19:12:11 +02:00
|
|
|
fragmentsStack.get(a).clearViews();
|
2014-09-24 04:17:27 +02:00
|
|
|
fragmentsStack.get(a).setParentLayout(this);
|
|
|
|
}
|
|
|
|
if (delegate != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
delegate.onRebuildAllFragments(this, last);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (showLastAfter) {
|
|
|
|
showLastFragment();
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && !checkTransitionAnimation() && !startedTracking && currentActionBar != null) {
|
|
|
|
currentActionBar.onMenuButtonPressed();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public void onActionModeStarted(Object mode) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (currentActionBar != null) {
|
|
|
|
currentActionBar.setVisibility(GONE);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
inActionMode = true;
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public void onActionModeFinished(Object mode) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (currentActionBar != null) {
|
|
|
|
currentActionBar.setVisibility(VISIBLE);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
inActionMode = false;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2017-07-23 19:29:17 +02:00
|
|
|
private void onCloseAnimationEnd() {
|
2014-06-13 17:03:06 +02:00
|
|
|
if (transitionAnimationInProgress && onCloseAnimationEndRunnable != null) {
|
|
|
|
transitionAnimationInProgress = false;
|
2020-09-30 15:48:47 +02:00
|
|
|
layoutToIgnore = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
transitionAnimationPreviewMode = false;
|
2014-06-13 17:03:06 +02:00
|
|
|
transitionAnimationStartTime = 0;
|
2020-06-04 18:47:15 +02:00
|
|
|
newFragment = null;
|
|
|
|
oldFragment = null;
|
|
|
|
Runnable endRunnable = onCloseAnimationEndRunnable;
|
2017-07-23 19:29:17 +02:00
|
|
|
onCloseAnimationEndRunnable = null;
|
2020-06-04 18:47:15 +02:00
|
|
|
endRunnable.run();
|
|
|
|
checkNeedRebuild();
|
2017-07-08 18:32:04 +02:00
|
|
|
checkNeedRebuild();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkNeedRebuild() {
|
|
|
|
if (rebuildAfterAnimation) {
|
|
|
|
rebuildAllFragmentViews(rebuildLastAfterAnimation, showLastAfterAnimation);
|
|
|
|
rebuildAfterAnimation = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (animateThemeAfterAnimation) {
|
2019-12-31 14:08:08 +01:00
|
|
|
animateThemedValues(animateSetThemeAfterAnimation, animateSetThemeAccentIdAfterAnimation, animateSetThemeNightAfterAnimation, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
animateSetThemeAfterAnimation = null;
|
|
|
|
animateThemeAfterAnimation = false;
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:29:17 +02:00
|
|
|
private void onOpenAnimationEnd() {
|
2014-06-13 17:03:06 +02:00
|
|
|
if (transitionAnimationInProgress && onOpenAnimationEndRunnable != null) {
|
|
|
|
transitionAnimationInProgress = false;
|
2020-09-30 15:48:47 +02:00
|
|
|
layoutToIgnore = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
transitionAnimationPreviewMode = false;
|
2014-06-13 17:03:06 +02:00
|
|
|
transitionAnimationStartTime = 0;
|
2020-06-04 18:47:15 +02:00
|
|
|
newFragment = null;
|
|
|
|
oldFragment = null;
|
|
|
|
Runnable endRunnable = onOpenAnimationEndRunnable;
|
2017-07-23 19:29:17 +02:00
|
|
|
onOpenAnimationEndRunnable = null;
|
2020-06-04 18:47:15 +02:00
|
|
|
endRunnable.run();
|
2017-07-08 18:32:04 +02:00
|
|
|
checkNeedRebuild();
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startActivityForResult(final Intent intent, final int requestCode) {
|
2014-10-01 00:36:18 +02:00
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-13 17:03:06 +02:00
|
|
|
if (transitionAnimationInProgress) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
currentAnimation.cancel();
|
|
|
|
currentAnimation = null;
|
|
|
|
}
|
2014-06-13 17:03:06 +02:00
|
|
|
if (onCloseAnimationEndRunnable != null) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onCloseAnimationEnd();
|
2014-06-13 17:03:06 +02:00
|
|
|
} else if (onOpenAnimationEndRunnable != null) {
|
2017-07-23 19:29:17 +02:00
|
|
|
onOpenAnimationEnd();
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
|
|
|
containerView.invalidate();
|
2020-07-26 10:03:38 +02:00
|
|
|
}
|
|
|
|
if (intent != null) {
|
|
|
|
parentActivity.startActivityForResult(intent, requestCode);
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
|
|
|
|
public void setUseAlphaAnimations(boolean value) {
|
|
|
|
useAlphaAnimations = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBackgroundView(View view) {
|
|
|
|
backgroundView = view;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2014-11-07 21:10:12 +01:00
|
|
|
public void setDrawerLayoutContainer(DrawerLayoutContainer layout) {
|
2014-11-07 11:23:17 +01:00
|
|
|
drawerLayoutContainer = layout;
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
|
2014-11-07 21:10:12 +01:00
|
|
|
public DrawerLayoutContainer getDrawerLayoutContainer() {
|
|
|
|
return drawerLayoutContainer;
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
public void setRemoveActionBarExtraHeight(boolean value) {
|
|
|
|
removeActionBarExtraHeight = value;
|
|
|
|
}
|
2014-11-18 06:01:04 +01:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void setTitleOverlayText(String title, int titleId, Runnable action) {
|
2017-07-08 18:32:04 +02:00
|
|
|
titleOverlayText = title;
|
2019-01-23 18:03:33 +01:00
|
|
|
titleOverlayTextId = titleId;
|
2017-07-08 18:32:04 +02:00
|
|
|
overlayAction = action;
|
|
|
|
for (int a = 0; a < fragmentsStack.size(); a++) {
|
|
|
|
BaseFragment fragment = fragmentsStack.get(a);
|
2014-11-18 06:01:04 +01:00
|
|
|
if (fragment.actionBar != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
fragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, action);
|
2014-11-18 06:01:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean extendActionMode(Menu menu) {
|
|
|
|
return !fragmentsStack.isEmpty() && fragmentsStack.get(fragmentsStack.size() - 1).extendActionMode(menu);
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
@Override
|
|
|
|
public boolean hasOverlappingRendering() {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
|
|
|
|
public void setFragmentPanTranslationOffset(int offset) {
|
|
|
|
if (containerView != null) {
|
|
|
|
containerView.setFragmentPanTranslationOffset(offset);
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 23:48:16 +02:00
|
|
|
|
|
|
|
private View findScrollingChild(ViewGroup parent, float x, float y) {
|
|
|
|
int n = parent.getChildCount();
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
View child = parent.getChildAt(i);
|
|
|
|
if (child.getVisibility() != View.VISIBLE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
child.getHitRect(rect);
|
|
|
|
if (rect.contains((int) x, (int) y)) {
|
|
|
|
if (child.canScrollHorizontally(-1)) {
|
|
|
|
return child;
|
|
|
|
} else if (child instanceof ViewGroup) {
|
|
|
|
View v = findScrollingChild((ViewGroup) child, x - rect.left, y - rect.top);
|
|
|
|
if (v != null) {
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|