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;
|
2014-11-11 23:16:17 +01:00
|
|
|
import android.widget.LinearLayout;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
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;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Components.CubicBezierInterpolator;
|
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
|
|
|
}
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
public class LinearLayoutContainer extends LinearLayout {
|
|
|
|
|
2016-04-25 21:26:41 +02:00
|
|
|
private Rect rect = new Rect();
|
|
|
|
private boolean isKeyboardVisible;
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
public LinearLayoutContainer(Context context) {
|
|
|
|
super(context);
|
|
|
|
setOrientation(VERTICAL);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
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();
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean result = super.drawChild(canvas, child, drawingTime);
|
|
|
|
if (actionBarHeight != 0 && headerShadowDrawable != null) {
|
|
|
|
headerShadowDrawable.setBounds(0, actionBarHeight, getMeasuredWidth(), actionBarHeight + headerShadowDrawable.getIntrinsicHeight());
|
|
|
|
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
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
super.onLayout(changed, l, t, r, b);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
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
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean inPreviewMode;
|
|
|
|
private ColorDrawable previewBackgroundDrawable;
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
private LinearLayoutContainer containerView;
|
|
|
|
private LinearLayoutContainer containerViewBack;
|
2014-11-07 11:23:17 +01:00
|
|
|
private DrawerLayoutContainer drawerLayoutContainer;
|
2014-11-11 23:16:17 +01:00
|
|
|
private ActionBar currentActionBar;
|
|
|
|
|
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;
|
|
|
|
private boolean beginTrackingSent;
|
|
|
|
private boolean transitionAnimationInProgress;
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean transitionAnimationPreviewMode;
|
2019-05-14 14:08:05 +02:00
|
|
|
private int[][] animateStartColors = new int[2][];
|
|
|
|
private int[][] animateEndColors = new int[2][];
|
2018-07-30 04:07:02 +02:00
|
|
|
private ThemeDescription[][] themeAnimatorDescriptions = new ThemeDescription[2][];
|
|
|
|
private ThemeDescription.ThemeDescriptionDelegate[] themeAnimatorDelegate = new ThemeDescription.ThemeDescriptionDelegate[2];
|
|
|
|
private AnimatorSet themeAnimatorSet;
|
|
|
|
private float themeAnimationValue;
|
|
|
|
private boolean animateThemeAfterAnimation;
|
|
|
|
private Theme.ThemeInfo animateSetThemeAfterAnimation;
|
2019-02-08 03:30:32 +01:00
|
|
|
private boolean animateSetThemeNightAfterAnimation;
|
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;
|
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;
|
2014-11-11 23:16:17 +01:00
|
|
|
containerViewBack = new LinearLayoutContainer(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);
|
|
|
|
|
|
|
|
containerView = new LinearLayoutContainer(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()) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
lastFragment.onConfigurationChanged(newConfig);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (lastFragment.visibleDialog instanceof BottomSheet) {
|
|
|
|
((BottomSheet) lastFragment.visibleDialog).onConfigurationChanged(newConfig);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public void drawHeaderShadow(Canvas canvas, int y) {
|
|
|
|
if (headerShadowDrawable != null) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
lastFragment.dismissCurrentDialig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
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) {
|
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) {
|
|
|
|
clipRight = translationX;
|
|
|
|
} 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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(ActionBarLayoutDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
lastFragment.onPause();
|
|
|
|
lastFragment.onFragmentDestroy();
|
2014-09-24 04:17:27 +02:00
|
|
|
lastFragment.setParentLayout(null);
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentsStack.remove(fragmentsStack.size() - 1);
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
LinearLayoutContainer temp = containerView;
|
2014-06-04 01:31:48 +02:00
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
2014-11-11 23:16:17 +01:00
|
|
|
bringChildToFront(containerView);
|
|
|
|
|
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();
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (fragmentsStack.size() >= 2) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
lastFragment.onPause();
|
|
|
|
if (lastFragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) lastFragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
lastFragment.onRemoveFromParent();
|
|
|
|
parent.removeView(lastFragment.fragmentView);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (lastFragment.actionBar != null && lastFragment.actionBar.getAddToContainer()) {
|
|
|
|
ViewGroup parent = (ViewGroup) lastFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(lastFragment.actionBar);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
containerViewBack.setVisibility(View.GONE);
|
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;
|
|
|
|
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);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (lastFragment.actionBar != null && lastFragment.actionBar.getAddToContainer()) {
|
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
|
|
|
}
|
|
|
|
containerViewBack.addView(fragmentView);
|
2018-07-30 04:07:02 +02:00
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.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
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
2014-06-07 01:35:21 +02:00
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (!currentFragment.swipeBackEnabled) {
|
|
|
|
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);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (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);
|
|
|
|
if (currentFragment.canBeginSlide()) {
|
|
|
|
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);
|
|
|
|
if (!inPreviewMode && !transitionAnimationPreviewMode && !startedTracking && currentFragment.swipeBackEnabled) {
|
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;
|
|
|
|
animatorSet.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(containerView, "translationX", containerView.getMeasuredWidth()),
|
|
|
|
ObjectAnimator.ofFloat(this, "innerTranslationX", (float) containerView.getMeasuredWidth())
|
2014-11-07 11:23:17 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
distToMove = x;
|
|
|
|
animatorSet.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(containerView, "translationX", 0),
|
|
|
|
ObjectAnimator.ofFloat(this, "innerTranslationX", 0.0f)
|
2014-11-07 11:23:17 +01:00
|
|
|
);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
|
|
|
|
animatorSet.setDuration(Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
|
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;
|
|
|
|
} else {
|
|
|
|
maybeStartTracking = false;
|
|
|
|
startedTracking = false;
|
|
|
|
}
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.recycle();
|
|
|
|
velocityTracker = null;
|
|
|
|
}
|
|
|
|
} else if (ev == null) {
|
2014-06-07 01:35:21 +02:00
|
|
|
maybeStartTracking = false;
|
|
|
|
startedTracking = false;
|
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;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (!currentActionBar.isActionModeShowed() && currentActionBar != null && 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;
|
|
|
|
}
|
|
|
|
|
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();
|
2014-06-04 01:31:48 +02:00
|
|
|
parent.removeView(fragment.fragmentView);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (fragment.actionBar != null && fragment.actionBar.getAddToContainer()) {
|
2014-11-11 23:16:17 +01:00
|
|
|
ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragment.actionBar);
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
containerViewBack.setVisibility(View.GONE);
|
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;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
previewBackgroundDrawable.setAlpha((int) (0x80 * interpolated));
|
|
|
|
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));
|
|
|
|
previewBackgroundDrawable.setAlpha((int) (0x80 * (1.0f - interpolated)));
|
|
|
|
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() {
|
|
|
|
if (delayedOpenAnimationRunnable == null) {
|
|
|
|
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) {
|
2014-09-28 15:37:26 +02:00
|
|
|
if (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);
|
2014-09-24 04:17:27 +02:00
|
|
|
if (parentActivity.getCurrentFocus() != null) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (fragment.actionBar != null && fragment.actionBar.getAddToContainer()) {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (removeActionBarExtraHeight) {
|
|
|
|
fragment.actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
2014-11-19 11:32:27 +01:00
|
|
|
ViewGroup parent = (ViewGroup) fragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragment.actionBar);
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
containerViewBack.addView(fragment.actionBar);
|
2019-01-23 18:03:33 +01:00
|
|
|
fragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, overlayAction);
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2014-11-21 11:59:05 +01:00
|
|
|
|
2014-06-13 20:26:05 +02:00
|
|
|
containerViewBack.addView(fragmentView);
|
2018-07-30 04:07:02 +02:00
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.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) {
|
|
|
|
layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(8);
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = AndroidUtilities.dp(46);
|
|
|
|
layoutParams.topMargin += AndroidUtilities.statusBarHeight;
|
|
|
|
} else {
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
|
|
|
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
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
LinearLayoutContainer 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) {
|
|
|
|
previewBackgroundDrawable = new ColorDrawable(0x80000000);
|
|
|
|
}
|
|
|
|
previewBackgroundDrawable.setAlpha(0);
|
|
|
|
Theme.moveUpDrawable.setAlpha(0);
|
|
|
|
}
|
2014-11-11 23:16:17 +01: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
|
|
|
}
|
|
|
|
|
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;
|
2018-08-27 10:33:11 +02:00
|
|
|
onOpenAnimationEndRunnable = () -> {
|
|
|
|
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<>();
|
|
|
|
animators.add(ObjectAnimator.ofFloat(this, "alpha", 0.0f, 1.0f));
|
2014-09-24 04:17:27 +02:00
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.setVisibility(VISIBLE);
|
2016-06-24 12:27:15 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(backgroundView, "alpha", 0.0f, 1.0f));
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
|
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;
|
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
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
fragment.onTransitionAnimationEnd(true, false);
|
|
|
|
fragment.onBecomeFullyVisible();
|
2014-09-24 04:17:27 +02:00
|
|
|
};
|
2015-10-29 18:10:07 +01:00
|
|
|
fragment.onTransitionAnimationStart(true, false);
|
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) {
|
|
|
|
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(true, true, preview);
|
2016-04-25 21:26:41 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
AndroidUtilities.runOnUIThread(waitingForKeyboardCloseRunnable, 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;
|
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 {
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setAlpha(1.0f);
|
|
|
|
containerView.setTranslationX(0.0f);
|
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);
|
|
|
|
}
|
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();
|
2016-10-11 13:57:01 +02:00
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
|
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);
|
2015-06-29 19:12:11 +02:00
|
|
|
containerViewBack.setVisibility(View.GONE);
|
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)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) fragment.fragmentView.getLayoutParams();
|
|
|
|
layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
|
|
|
|
fragment.fragmentView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
presentFragmentInternalRemoveOld(false, prevFragment);
|
|
|
|
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(fragment.fragmentView, "scaleX", 1.0f, 1.05f, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(fragment.fragmentView, "scaleY", 1.0f, 1.05f, 1.0f));
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.setInterpolator(new CubicBezierInterpolator(0.42, 0.0, 0.58, 1.0));
|
|
|
|
|
|
|
|
animatorSet.start();
|
|
|
|
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
|
|
|
|
|
|
|
fragment.setInPreviewMode(false);
|
|
|
|
}
|
|
|
|
if (currentTranslation != nextTranslation) {
|
|
|
|
containerView.setTranslationY(nextTranslation);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishPreviewFragment() {
|
|
|
|
if (!inPreviewMode && !transitionAnimationPreviewMode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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) {
|
2014-11-11 23:16:17 +01:00
|
|
|
LinearLayoutContainer 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);
|
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
|
|
|
|
if (removeActionBarExtraHeight) {
|
|
|
|
previousFragment.actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
|
|
|
ViewGroup parent = (ViewGroup) previousFragment.actionBar.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(previousFragment.actionBar);
|
|
|
|
}
|
|
|
|
containerView.addView(previousFragment.actionBar);
|
|
|
|
previousFragment.actionBar.setTitleOverlayText(titleOverlayText, titleOverlayTextId, overlayAction);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
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);
|
|
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.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);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
previousFragment.onTransitionAnimationStart(true, true);
|
|
|
|
currentFragment.onTransitionAnimationStart(false, false);
|
2014-09-24 04:17:27 +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-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;
|
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);
|
|
|
|
currentFragment.onTransitionAnimationEnd(false, false);
|
|
|
|
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;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
2015-10-29 18:10:07 +01:00
|
|
|
currentFragment.onTransitionAnimationEnd(false, false);
|
|
|
|
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;
|
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<>();
|
|
|
|
animators.add(ObjectAnimator.ofFloat(this, "alpha", 1.0f, 0.0f));
|
2014-11-11 23:16:17 +01:00
|
|
|
if (backgroundView != null) {
|
2016-06-24 12:27:15 +02:00
|
|
|
animators.add(ObjectAnimator.ofFloat(backgroundView, "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);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (previousFragment.actionBar != null && previousFragment.actionBar.getAddToContainer()) {
|
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
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
containerView.addView(fragmentView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
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 {
|
|
|
|
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;
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
if (themeAnimatorDescriptions[j] != null) {
|
|
|
|
int rE, gE, bE, aE, rS, gS, bS, aS, a, r, g, b;
|
|
|
|
for (int i = 0; i < themeAnimatorDescriptions[j].length; i++) {
|
|
|
|
rE = Color.red(animateEndColors[j][i]);
|
|
|
|
gE = Color.green(animateEndColors[j][i]);
|
|
|
|
bE = Color.blue(animateEndColors[j][i]);
|
|
|
|
aE = Color.alpha(animateEndColors[j][i]);
|
|
|
|
|
|
|
|
rS = Color.red(animateStartColors[j][i]);
|
|
|
|
gS = Color.green(animateStartColors[j][i]);
|
|
|
|
bS = Color.blue(animateStartColors[j][i]);
|
|
|
|
aS = Color.alpha(animateStartColors[j][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));
|
2019-06-04 12:14:50 +02:00
|
|
|
int color = Color.argb(a, r, g, b);
|
|
|
|
Theme.setAnimatedColor(themeAnimatorDescriptions[j][i].getCurrentKey(), color);
|
|
|
|
themeAnimatorDescriptions[j][i].setColor(color, false, false);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (themeAnimatorDelegate[j] != null) {
|
|
|
|
themeAnimatorDelegate[j].didSetColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Keep
|
|
|
|
public float getThemeAnimationValue() {
|
|
|
|
return themeAnimationValue;
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public void animateThemedValues(Theme.ThemeInfo theme, boolean nightTheme) {
|
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;
|
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
|
|
|
themeAnimatorDescriptions[i] = null;
|
|
|
|
animateStartColors[i] = null;
|
|
|
|
animateEndColors[i] = null;
|
|
|
|
themeAnimatorDelegate[i] = null;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
}
|
|
|
|
if (fragment != null) {
|
|
|
|
startAnimation = true;
|
|
|
|
themeAnimatorDescriptions[i] = fragment.getThemeDescriptions();
|
|
|
|
animateStartColors[i] = new int[themeAnimatorDescriptions[i].length];
|
|
|
|
for (int a = 0; a < themeAnimatorDescriptions[i].length; a++) {
|
|
|
|
animateStartColors[i][a] = themeAnimatorDescriptions[i][a].getSetColor();
|
|
|
|
ThemeDescription.ThemeDescriptionDelegate delegate = themeAnimatorDescriptions[i][a].setDelegateDisabled();
|
|
|
|
if (themeAnimatorDelegate[i] == null && delegate != null) {
|
|
|
|
themeAnimatorDelegate[i] = delegate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
2019-02-08 03:30:32 +01:00
|
|
|
Theme.applyTheme(theme, nightTheme);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
animateEndColors[i] = new int[themeAnimatorDescriptions[i].length];
|
|
|
|
for (int a = 0; a < themeAnimatorDescriptions[i].length; a++) {
|
|
|
|
animateEndColors[i][a] = themeAnimatorDescriptions[i][a].getSetColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startAnimation) {
|
|
|
|
themeAnimatorSet = new AnimatorSet();
|
|
|
|
themeAnimatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(themeAnimatorSet)) {
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
themeAnimatorDescriptions[a] = null;
|
|
|
|
animateStartColors[a] = null;
|
|
|
|
animateEndColors[a] = null;
|
|
|
|
themeAnimatorDelegate[a] = null;
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
Theme.setAnimatingColor(false);
|
2018-07-30 04:07:02 +02:00
|
|
|
themeAnimatorSet = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(themeAnimatorSet)) {
|
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
themeAnimatorDescriptions[a] = null;
|
|
|
|
animateStartColors[a] = null;
|
|
|
|
animateEndColors[a] = null;
|
|
|
|
themeAnimatorDelegate[a] = null;
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
Theme.setAnimatingColor(false);
|
2018-07-30 04:07:02 +02:00
|
|
|
themeAnimatorSet = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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);
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
Theme.setAnimatingColor(true);
|
|
|
|
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;
|
2018-07-30 04:07:02 +02:00
|
|
|
transitionAnimationPreviewMode = false;
|
2014-06-13 17:03:06 +02:00
|
|
|
transitionAnimationStartTime = 0;
|
2017-07-23 19:29:17 +02:00
|
|
|
onCloseAnimationEndRunnable.run();
|
|
|
|
onCloseAnimationEndRunnable = null;
|
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-02-08 03:30:32 +01:00
|
|
|
animateThemedValues(animateSetThemeAfterAnimation, animateSetThemeNightAfterAnimation);
|
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;
|
2018-07-30 04:07:02 +02:00
|
|
|
transitionAnimationPreviewMode = false;
|
2014-06-13 17:03:06 +02:00
|
|
|
transitionAnimationStartTime = 0;
|
2017-07-23 19:29:17 +02:00
|
|
|
onOpenAnimationEndRunnable.run();
|
|
|
|
onOpenAnimationEndRunnable = null;
|
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();
|
2014-06-14 10:36:01 +02:00
|
|
|
if (intent != null) {
|
2014-09-24 04:17:27 +02:00
|
|
|
parentActivity.startActivityForResult(intent, requestCode);
|
2014-06-14 10:36:01 +02:00
|
|
|
}
|
2014-06-13 17:03:06 +02:00
|
|
|
} else {
|
2014-06-14 10:36:01 +02:00
|
|
|
if (intent != null) {
|
2014-09-24 04:17:27 +02:00
|
|
|
parentActivity.startActivityForResult(intent, requestCode);
|
2014-06-14 10:36:01 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|