2014-06-04 01:31:48 +02:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.4.x.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013-2014.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Views.ActionBar;
|
|
|
|
|
|
|
|
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-06-04 01:31:48 +02:00
|
|
|
import android.os.Build;
|
2014-06-13 00:37:05 +02:00
|
|
|
import android.os.Handler;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.ActionMode;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.VelocityTracker;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.AnimationUtils;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2014-09-28 15:37:26 +02:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2014-06-04 01:31:48 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.R;
|
2014-11-06 22:34:47 +01:00
|
|
|
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
|
|
|
|
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
|
|
|
|
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
|
|
|
|
import org.telegram.ui.AnimationCompat.ViewProxy;
|
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
|
|
|
|
2014-06-13 20:26:05 +02:00
|
|
|
private class FrameLayoutAnimationListener extends FrameLayout {
|
|
|
|
public FrameLayoutAnimationListener(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAnimationEnd() {
|
|
|
|
super.onAnimationEnd();
|
2014-09-24 04:17:27 +02:00
|
|
|
ActionBarLayout.this.onAnimationEndCheck();
|
2014-06-13 20:26:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public static interface ActionBarLayoutDelegate {
|
|
|
|
public abstract boolean onPreIme();
|
|
|
|
public abstract void onOverlayShow(View view, BaseFragment fragment);
|
|
|
|
public abstract boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout);
|
|
|
|
public abstract boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout);
|
|
|
|
public abstract boolean needCloseLastFragment(ActionBarLayout layout);
|
|
|
|
public abstract void onRebuildAllFragments(ActionBarLayout layout);
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
protected ActionBar actionBar;
|
2014-06-13 20:26:05 +02:00
|
|
|
private FrameLayoutAnimationListener containerView;
|
|
|
|
private FrameLayoutAnimationListener containerViewBack;
|
2014-06-04 01:31:48 +02:00
|
|
|
private View shadowView;
|
2014-11-07 11:23:17 +01:00
|
|
|
private DrawerLayoutContainer drawerLayoutContainer;
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
private Animation openAnimation;
|
|
|
|
private Animation closeAnimation;
|
2014-09-24 04:17:27 +02:00
|
|
|
private Animation alphaOpenAnimation;
|
|
|
|
private Animation alphaOpenAnimation2;
|
|
|
|
private Animation alphaCloseAnimation;
|
|
|
|
private Animation alphaCloseAnimation2;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-06-04 20:57:11 +02:00
|
|
|
private boolean maybeStartTracking = false;
|
2014-06-07 01:35:21 +02:00
|
|
|
protected boolean startedTracking = false;
|
2014-06-04 01:31:48 +02:00
|
|
|
private int startedTrackingX;
|
2014-06-20 02:18:13 +02:00
|
|
|
private int startedTrackingY;
|
2014-06-07 01:35:21 +02:00
|
|
|
protected boolean animationInProgress = false;
|
2014-06-04 01:31:48 +02:00
|
|
|
private VelocityTracker velocityTracker = null;
|
|
|
|
private boolean beginTrackingSent = false;
|
|
|
|
private boolean transitionAnimationInProgress = false;
|
|
|
|
private long transitionAnimationStartTime;
|
|
|
|
private boolean inActionMode = false;
|
2014-06-07 01:35:21 +02:00
|
|
|
private int startedTrackingPointerId;
|
2014-06-13 17:03:06 +02:00
|
|
|
private Runnable onCloseAnimationEndRunnable = null;
|
|
|
|
private Runnable onOpenAnimationEndRunnable = null;
|
2014-09-24 04:17:27 +02:00
|
|
|
private boolean useAlphaAnimations = false;
|
|
|
|
private View backgroundView;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
private ActionBarLayoutDelegate delegate = null;
|
|
|
|
protected Activity parentActivity = null;
|
2014-06-04 20:57:11 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public ArrayList<BaseFragment> fragmentsStack = null;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public ActionBarLayout(Context context) {
|
|
|
|
super(context);
|
|
|
|
parentActivity = (Activity)context;
|
2014-06-04 01:31:48 +02:00
|
|
|
try {
|
2014-09-24 04:17:27 +02:00
|
|
|
openAnimation = AnimationUtils.loadAnimation(context, R.anim.scale_in);
|
|
|
|
closeAnimation = AnimationUtils.loadAnimation(context, R.anim.scale_out);
|
2014-06-04 01:31:48 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
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;
|
|
|
|
containerViewBack = new FrameLayoutAnimationListener(parentActivity);
|
|
|
|
addView(containerViewBack);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
containerView = new FrameLayoutAnimationListener(parentActivity);
|
|
|
|
addView(containerView);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
shadowView = new FrameLayout(parentActivity);
|
|
|
|
addView(shadowView);
|
2014-06-04 01:31:48 +02:00
|
|
|
shadowView.setBackgroundResource(R.drawable.shadow);
|
|
|
|
ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams();
|
2014-07-03 00:39:05 +02:00
|
|
|
layoutParams.width = AndroidUtilities.dp(2);
|
2014-06-04 01:31:48 +02:00
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
shadowView.setLayoutParams(layoutParams);
|
|
|
|
shadowView.setVisibility(View.INVISIBLE);
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
actionBar = new ActionBar(parentActivity);
|
|
|
|
addView(actionBar);
|
2014-06-04 01:31:48 +02:00
|
|
|
layoutParams = actionBar.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
actionBar.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
for (BaseFragment fragment : fragmentsStack) {
|
2014-09-24 04:17:27 +02:00
|
|
|
fragment.setParentLayout(this);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
needLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
|
|
|
if (!fragmentsStack.isEmpty()) {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
lastFragment.onConfigurationChanged(newConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void onResume() {
|
2014-06-04 01:31:48 +02:00
|
|
|
fixLayout();
|
2014-06-13 17:03:06 +02:00
|
|
|
if (transitionAnimationInProgress) {
|
|
|
|
if (onCloseAnimationEndRunnable != null) {
|
|
|
|
closeAnimation.cancel();
|
|
|
|
onCloseAnimationEnd(false);
|
|
|
|
} else if (onOpenAnimationEndRunnable != null) {
|
|
|
|
openAnimation.cancel();
|
|
|
|
onOpenAnimationEnd(false);
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
actionBar.setCurrentActionBarLayer(lastFragment.actionBarLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
return !(!animationInProgress && !checkTransitionAnimation()) || onTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
|
|
|
onTouchEvent(null);
|
|
|
|
super.requestDisallowInterceptTouchEvent(disallowIntercept);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
|
|
|
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
|
|
|
return delegate != null && delegate.onPreIme() || super.dispatchKeyEventPreIme(event);
|
|
|
|
}
|
|
|
|
return super.dispatchKeyEventPreIme(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAnimationEnd() {
|
|
|
|
super.onAnimationEnd();
|
|
|
|
onAnimationEndCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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-06-13 20:26:05 +02:00
|
|
|
FrameLayoutAnimationListener temp = containerView;
|
2014-06-04 01:31:48 +02:00
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
|
|
|
ViewGroup parent = (ViewGroup)containerView.getParent();
|
2014-11-06 22:34:47 +01:00
|
|
|
parent.bringChildToFront(containerView);
|
|
|
|
parent.bringChildToFront(shadowView);
|
|
|
|
parent.bringChildToFront(actionBar);
|
|
|
|
//parent.removeViewInLayout(containerView);
|
|
|
|
//parent.addView(containerView, 1);
|
2014-06-04 01:31:48 +02:00
|
|
|
lastFragment = fragmentsStack.get(fragmentsStack.size() - 1);
|
|
|
|
lastFragment.onResume();
|
|
|
|
} else {
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
lastFragment.onPause();
|
|
|
|
if (lastFragment.fragmentView != null) {
|
|
|
|
ViewGroup parent = (ViewGroup) lastFragment.fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(lastFragment.fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
containerViewBack.setVisibility(View.GONE);
|
2014-09-24 04:17:27 +02:00
|
|
|
AndroidUtilities.unlockOrientation(parentActivity);
|
2014-06-04 01:31:48 +02:00
|
|
|
startedTracking = false;
|
|
|
|
animationInProgress = false;
|
2014-11-06 22:34:47 +01:00
|
|
|
|
|
|
|
ViewProxy.setTranslationX(containerView, 0);
|
|
|
|
ViewProxy.setTranslationX(containerViewBack, 0);
|
|
|
|
actionBar.stopMoving(backAnimation);
|
|
|
|
shadowView.setVisibility(View.INVISIBLE);
|
|
|
|
ViewProxy.setTranslationX(shadowView, -AndroidUtilities.dp(2));
|
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();
|
|
|
|
shadowView.setVisibility(View.VISIBLE);
|
2014-11-06 22:34:47 +01:00
|
|
|
ViewProxy.setTranslationX(shadowView, -AndroidUtilities.dp(2));
|
2014-06-07 01:35:21 +02:00
|
|
|
containerViewBack.setVisibility(View.VISIBLE);
|
|
|
|
beginTrackingSent = false;
|
|
|
|
|
|
|
|
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
|
|
|
actionBar.prepareForMoving(lastFragment.actionBarLayer);
|
2014-09-24 04:17:27 +02:00
|
|
|
View fragmentView = lastFragment.createView(parentActivity.getLayoutInflater(), null);
|
2014-06-07 01:35:21 +02:00
|
|
|
ViewGroup parentView = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parentView != null) {
|
|
|
|
parentView.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
containerViewBack.addView(fragmentView);
|
|
|
|
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
|
|
|
if (fragmentView.getBackground() == null) {
|
|
|
|
fragmentView.setBackgroundColor(0xffffffff);
|
|
|
|
}
|
|
|
|
lastFragment.onResume();
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
AndroidUtilities.lockOrientation(parentActivity);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 20:57:11 +02:00
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
2014-11-07 11:23:17 +01:00
|
|
|
if(!checkTransitionAnimation() && !inActionMode && !animationInProgress) {
|
|
|
|
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);
|
|
|
|
if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.dp(10) && Math.abs(dx) / 3 > dy) {
|
2014-06-07 01:35:21 +02:00
|
|
|
prepareForMoving(ev);
|
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;
|
|
|
|
}
|
|
|
|
actionBar.moveActionBarByX(dx);
|
|
|
|
ViewProxy.setTranslationX(containerView, dx);
|
|
|
|
ViewProxy.setTranslationX(shadowView, dx - AndroidUtilities.dp(2));
|
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);
|
|
|
|
if (!startedTracking) {
|
|
|
|
float velX = velocityTracker.getXVelocity();
|
|
|
|
float velY = velocityTracker.getYVelocity();
|
|
|
|
if (velX >= 3500 && velX > velY) {
|
|
|
|
prepareForMoving(ev);
|
2014-11-07 21:10:12 +01:00
|
|
|
if (!beginTrackingSent) {
|
|
|
|
if (((Activity)getContext()).getCurrentFocus() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(((Activity)getContext()).getCurrentFocus());
|
|
|
|
}
|
|
|
|
beginTrackingSent = true;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-11-07 11:23:17 +01:00
|
|
|
}
|
|
|
|
if (startedTracking) {
|
|
|
|
float x = ViewProxy.getX(containerView);
|
|
|
|
AnimatorSetProxy animatorSet = new AnimatorSetProxy();
|
|
|
|
float velX = velocityTracker.getXVelocity();
|
|
|
|
float velY = velocityTracker.getYVelocity();
|
|
|
|
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
|
|
|
|
float distToMove = 0;
|
|
|
|
if (!backAnimation) {
|
|
|
|
distToMove = containerView.getMeasuredWidth() - x;
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "x", containerView.getMeasuredWidth()),
|
|
|
|
ObjectAnimatorProxy.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - AndroidUtilities.dp(2)),
|
|
|
|
ObjectAnimatorProxy.ofFloat(actionBar.currentLayer, "x", actionBar.getMeasuredWidth()),
|
|
|
|
ObjectAnimatorProxy.ofFloat(actionBar.shadowView, "x", actionBar.getMeasuredWidth() - AndroidUtilities.dp(2)),
|
|
|
|
ObjectAnimatorProxy.ofFloat(actionBar.previousLayer, "alphaEx", 1.0f)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
distToMove = x;
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "x", 0),
|
|
|
|
ObjectAnimatorProxy.ofFloat(shadowView, "x", -AndroidUtilities.dp(2)),
|
|
|
|
ObjectAnimatorProxy.ofFloat(actionBar.currentLayer, "x", 0),
|
|
|
|
ObjectAnimatorProxy.ofFloat(actionBar.shadowView, "x", -AndroidUtilities.dp(2)),
|
|
|
|
ObjectAnimatorProxy.ofFloat(actionBar.previousLayer, "alphaEx", 0)
|
|
|
|
);
|
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));
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animator) {
|
|
|
|
onSlideAnimationEnd(backAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Object animator) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public ActionBar getActionBar() {
|
|
|
|
return actionBar;
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public void onBackPressed() {
|
2014-06-04 18:00:42 +02:00
|
|
|
if (startedTracking || checkTransitionAnimation() || fragmentsStack.isEmpty()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (actionBar.currentLayer != null && actionBar.currentLayer.isSearchFieldVisible) {
|
|
|
|
actionBar.currentLayer.closeSearchField();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
private void onAnimationEndCheck() {
|
|
|
|
onCloseAnimationEnd(false);
|
|
|
|
onOpenAnimationEnd(false);
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public boolean checkTransitionAnimation() {
|
|
|
|
if (transitionAnimationInProgress && transitionAnimationStartTime < System.currentTimeMillis() - 400) {
|
|
|
|
transitionAnimationInProgress = false;
|
2014-09-24 04:17:27 +02:00
|
|
|
onAnimationEndCheck();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
return transitionAnimationInProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
2014-10-01 00:36:18 +02:00
|
|
|
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
2014-09-24 04:17:27 +02:00
|
|
|
@Override
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
needLayout();
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
|
|
|
getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
|
|
|
} else {
|
|
|
|
getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
});
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void needLayout() {
|
2014-09-24 04:17:27 +02:00
|
|
|
WindowManager manager = (WindowManager)parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
2014-06-04 01:31:48 +02:00
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
|
|
|
|
int height = 0;
|
|
|
|
if (actionBar.getVisibility() == View.VISIBLE) {
|
2014-11-06 22:34:47 +01:00
|
|
|
height = AndroidUtilities.getCurrentActionBarHeight();
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
if (containerView != null) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) containerView.getLayoutParams();
|
|
|
|
if (layoutParams.topMargin != height) {
|
|
|
|
layoutParams.setMargins(0, height, 0, 0);
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
containerView.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (containerViewBack != null) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) containerViewBack.getLayoutParams();
|
|
|
|
if (layoutParams.topMargin != height) {
|
|
|
|
layoutParams.setMargins(0, height, 0, 0);
|
|
|
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
containerViewBack.setLayoutParams(layoutParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBar getInternalActionBar() {
|
|
|
|
return actionBar;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
parent.removeView(fragment.fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
containerViewBack.setVisibility(View.GONE);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean presentFragment(BaseFragment fragment) {
|
2014-09-28 15:37:26 +02:00
|
|
|
return presentFragment(fragment, false, false, true);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean presentFragment(BaseFragment fragment, boolean removeLast) {
|
2014-09-28 15:37:26 +02:00
|
|
|
return presentFragment(fragment, removeLast, false, true);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 15:37:26 +02:00
|
|
|
public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation, boolean check) {
|
|
|
|
if (checkTransitionAnimation() || delegate != null && check && !delegate.needPresentFragment(fragment, removeLast, forceWithoutAnimation, this) || !fragment.onFragmentCreate()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
if (parentActivity.getCurrentFocus() != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
|
2014-09-28 15:37:26 +02:00
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.hideEmojiKeyboard);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
boolean needAnimation = openAnimation != null && !forceWithoutAnimation && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
|
|
|
|
if (useAlphaAnimations && fragmentsStack.size() == 0 && alphaOpenAnimation == null) {
|
|
|
|
needAnimation = false;
|
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);
|
|
|
|
View fragmentView = fragment.createView(parentActivity.getLayoutInflater(), null);
|
2014-06-13 20:26:05 +02:00
|
|
|
containerViewBack.addView(fragmentView);
|
2014-06-04 01:31:48 +02:00
|
|
|
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
|
|
|
fragmentsStack.add(fragment);
|
|
|
|
fragment.onResume();
|
|
|
|
actionBar.setCurrentActionBarLayer(fragment.actionBarLayer);
|
|
|
|
if (fragmentView.getBackground() == null) {
|
|
|
|
fragmentView.setBackgroundColor(0xffffffff);
|
|
|
|
}
|
2014-06-13 20:26:05 +02:00
|
|
|
|
|
|
|
FrameLayoutAnimationListener temp = containerView;
|
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
|
|
|
containerView.setVisibility(View.VISIBLE);
|
|
|
|
ViewGroup parent = (ViewGroup)containerView.getParent();
|
2014-11-06 22:34:47 +01:00
|
|
|
//parent.removeView(containerView);
|
|
|
|
//parent.addView(containerView, 1);
|
|
|
|
parent.bringChildToFront(containerView);
|
|
|
|
parent.bringChildToFront(shadowView);
|
|
|
|
parent.bringChildToFront(actionBar);
|
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
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
if (needAnimation) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (useAlphaAnimations && fragmentsStack.size() == 1) {
|
|
|
|
presentFragmentInternalRemoveOld(removeLast, currentFragment);
|
|
|
|
startAnimation(alphaOpenAnimation);
|
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.setVisibility(VISIBLE);
|
|
|
|
backgroundView.startAnimation(alphaOpenAnimation2);
|
2014-06-13 17:03:06 +02:00
|
|
|
}
|
2014-09-24 04:17:27 +02:00
|
|
|
} else {
|
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
transitionAnimationInProgress = true;
|
|
|
|
onOpenAnimationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
presentFragmentInternalRemoveOld(removeLast, currentFragment);
|
|
|
|
fragment.onOpenAnimationEnd();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
openAnimation.reset();
|
|
|
|
containerView.startAnimation(openAnimation);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
} else {
|
|
|
|
fragment.onOpenAnimationEnd();
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
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);
|
2014-06-13 20:26:05 +02:00
|
|
|
containerViewBack.setVisibility(View.GONE);
|
|
|
|
ViewGroup parent = (ViewGroup)containerView.getParent();
|
|
|
|
parent.removeView(containerViewBack);
|
|
|
|
parent.addView(containerViewBack, 0);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 17:03:06 +02:00
|
|
|
public void closeLastFragment(boolean animated) {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (delegate != null && !delegate.needCloseLastFragment(this) || checkTransitionAnimation()) {
|
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());
|
|
|
|
}
|
|
|
|
boolean needAnimation = animated && closeAnimation != null && parentActivity.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).getBoolean("view_animations", true);
|
|
|
|
if (useAlphaAnimations && fragmentsStack.size() == 1 && alphaCloseAnimation == null) {
|
|
|
|
needAnimation = false;
|
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) {
|
|
|
|
FrameLayoutAnimationListener temp = containerView;
|
|
|
|
containerView = containerViewBack;
|
|
|
|
containerViewBack = temp;
|
|
|
|
containerView.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
previousFragment.setParentLayout(this);
|
|
|
|
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater(), null);
|
|
|
|
containerView.addView(fragmentView);
|
|
|
|
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
|
|
|
previousFragment.onResume();
|
|
|
|
actionBar.setCurrentActionBarLayer(previousFragment.actionBarLayer);
|
|
|
|
if (fragmentView.getBackground() == null) {
|
|
|
|
fragmentView.setBackgroundColor(0xffffffff);
|
|
|
|
}
|
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;
|
|
|
|
closeAnimation.reset();
|
|
|
|
onCloseAnimationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
closeLastFragmentInternalRemoveOld(currentFragment);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
containerViewBack.startAnimation(closeAnimation);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (needAnimation && useAlphaAnimations) {
|
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
transitionAnimationInProgress = true;
|
|
|
|
alphaCloseAnimation.reset();
|
|
|
|
alphaCloseAnimation2.reset();
|
|
|
|
startAnimation(alphaCloseAnimation);
|
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.startAnimation(alphaCloseAnimation2);
|
|
|
|
}
|
|
|
|
onCloseAnimationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
removeFragmentFromStack(currentFragment);
|
|
|
|
setVisibility(GONE);
|
|
|
|
if (backgroundView != null) {
|
|
|
|
backgroundView.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
removeFragmentFromStack(currentFragment);
|
|
|
|
setVisibility(GONE);
|
|
|
|
if (backgroundView != null) {
|
|
|
|
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;
|
|
|
|
}
|
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);
|
|
|
|
View fragmentView = previousFragment.createView(parentActivity.getLayoutInflater(), null);
|
2014-06-04 01:31:48 +02:00
|
|
|
containerView.addView(fragmentView);
|
|
|
|
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
fragmentView.setLayoutParams(layoutParams);
|
|
|
|
previousFragment.onResume();
|
|
|
|
actionBar.setCurrentActionBarLayer(previousFragment.actionBarLayer);
|
|
|
|
if (fragmentView.getBackground() == null) {
|
|
|
|
fragmentView.setBackgroundColor(0xffffffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeFragmentFromStack(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);
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void removeAllFragments() {
|
|
|
|
for (int a = 0; a < fragmentsStack.size(); a++) {
|
|
|
|
removeFragmentFromStack(fragmentsStack.get(a));
|
|
|
|
a--;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
public void rebuildAllFragmentViews(boolean last) {
|
|
|
|
for (int a = 0; a < fragmentsStack.size() - (last ? 0 : 1); a++) {
|
|
|
|
fragmentsStack.get(a).setParentLayout(null);
|
|
|
|
fragmentsStack.get(a).setParentLayout(this);
|
|
|
|
}
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onRebuildAllFragments(this);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showActionBar() {
|
|
|
|
actionBar.setVisibility(View.VISIBLE);
|
|
|
|
needLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideActionBar() {
|
|
|
|
actionBar.setVisibility(View.GONE);
|
|
|
|
needLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && !checkTransitionAnimation() && !startedTracking) {
|
|
|
|
actionBar.onMenuButtonPressed();
|
|
|
|
}
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
2014-09-24 04:17:27 +02:00
|
|
|
protected void onOverlayShow(View view, BaseFragment fragment) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onOverlayShow(view, fragment);
|
|
|
|
}
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public void onActionModeStarted(ActionMode mode) {
|
|
|
|
hideActionBar();
|
|
|
|
inActionMode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onActionModeFinished(ActionMode mode) {
|
|
|
|
showActionBar();
|
|
|
|
inActionMode = false;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-13 17:03:06 +02:00
|
|
|
private void onCloseAnimationEnd(boolean post) {
|
|
|
|
if (transitionAnimationInProgress && onCloseAnimationEndRunnable != null) {
|
|
|
|
transitionAnimationInProgress = false;
|
|
|
|
transitionAnimationStartTime = 0;
|
|
|
|
if (post) {
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
onCloseAnimationEndRunnable.run();
|
|
|
|
onCloseAnimationEndRunnable = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
onCloseAnimationEndRunnable.run();
|
|
|
|
onCloseAnimationEndRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onOpenAnimationEnd(boolean post) {
|
|
|
|
if (transitionAnimationInProgress && onOpenAnimationEndRunnable != null) {
|
|
|
|
transitionAnimationInProgress = false;
|
|
|
|
transitionAnimationStartTime = 0;
|
|
|
|
if (post) {
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
onOpenAnimationEndRunnable.run();
|
|
|
|
onOpenAnimationEndRunnable = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
onOpenAnimationEndRunnable.run();
|
|
|
|
onOpenAnimationEndRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (onCloseAnimationEndRunnable != null) {
|
|
|
|
closeAnimation.cancel();
|
|
|
|
onCloseAnimationEnd(false);
|
|
|
|
} else if (onOpenAnimationEndRunnable != null) {
|
|
|
|
openAnimation.cancel();
|
|
|
|
onOpenAnimationEnd(false);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (useAlphaAnimations) {
|
|
|
|
alphaOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.icon_anim_fade_in);
|
|
|
|
alphaOpenAnimation2 = AnimationUtils.loadAnimation(getContext(), R.anim.icon_anim_fade_in);
|
|
|
|
alphaCloseAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.icon_anim_fade_out);
|
|
|
|
alphaCloseAnimation2 = AnimationUtils.loadAnimation(getContext(), R.anim.icon_anim_fade_out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-04 01:31:48 +02:00
|
|
|
}
|