resolve merge conflicts of c252b661e6 to master
Change-Id: Ia3fbedc5b0f90988ef319720a9e668ccc9e297f4
This commit is contained in:
@@ -23,6 +23,7 @@ import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.TypedArray;
|
||||
@@ -33,7 +34,6 @@ import android.view.VelocityTracker;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
@@ -44,7 +44,6 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
private static final String TAG = "SwipeDismissLayout";
|
||||
|
||||
private static final float DISMISS_MIN_DRAG_WIDTH_RATIO = .33f;
|
||||
private boolean mUseDynamicTranslucency = true;
|
||||
|
||||
public interface OnDismissedListener {
|
||||
void onDismissed(SwipeDismissLayout layout);
|
||||
@@ -64,6 +63,8 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
void onSwipeCancelled(SwipeDismissLayout layout);
|
||||
}
|
||||
|
||||
private boolean mIsWindowNativelyTranslucent;
|
||||
|
||||
// Cached ViewConfiguration and system-wide constant values
|
||||
private int mSlop;
|
||||
private int mMinFlingVelocity;
|
||||
@@ -78,24 +79,12 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
private VelocityTracker mVelocityTracker;
|
||||
private float mTranslationX;
|
||||
private boolean mBlockGesture = false;
|
||||
private boolean mActivityTranslucencyConverted = false;
|
||||
|
||||
private final DismissAnimator mDismissAnimator = new DismissAnimator();
|
||||
|
||||
private OnDismissedListener mDismissedListener;
|
||||
private OnSwipeProgressChangedListener mProgressListener;
|
||||
private ViewTreeObserver.OnEnterAnimationCompleteListener mOnEnterAnimationCompleteListener =
|
||||
new ViewTreeObserver.OnEnterAnimationCompleteListener() {
|
||||
@Override
|
||||
public void onEnterAnimationComplete() {
|
||||
// SwipeDismissLayout assumes that the host Activity is translucent
|
||||
// and temporarily disables translucency when it is fully visible.
|
||||
// As soon as the user starts swiping, we will re-enable
|
||||
// translucency.
|
||||
if (mUseDynamicTranslucency && getContext() instanceof Activity) {
|
||||
((Activity) getContext()).convertFromTranslucent();
|
||||
}
|
||||
}
|
||||
};
|
||||
private BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
|
||||
private Runnable mRunnable = new Runnable() {
|
||||
@Override
|
||||
@@ -141,8 +130,8 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(
|
||||
com.android.internal.R.styleable.Theme);
|
||||
mUseDynamicTranslucency = !a.hasValue(
|
||||
com.android.internal.R.styleable.Window_windowIsTranslucent);
|
||||
mIsWindowNativelyTranslucent = a.getBoolean(
|
||||
com.android.internal.R.styleable.Window_windowIsTranslucent, false);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@@ -157,20 +146,12 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if (getContext() instanceof Activity) {
|
||||
getViewTreeObserver().addOnEnterAnimationCompleteListener(
|
||||
mOnEnterAnimationCompleteListener);
|
||||
}
|
||||
getContext().registerReceiver(mScreenOffReceiver, mScreenOffFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
getContext().unregisterReceiver(mScreenOffReceiver);
|
||||
if (getContext() instanceof Activity) {
|
||||
getViewTreeObserver().removeOnEnterAnimationCompleteListener(
|
||||
mOnEnterAnimationCompleteListener);
|
||||
}
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@@ -273,9 +254,6 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
mLastX = ev.getRawX();
|
||||
updateSwiping(ev);
|
||||
if (mSwiping) {
|
||||
if (mUseDynamicTranslucency && getContext() instanceof Activity) {
|
||||
((Activity) getContext()).convertToTranslucent(null, null);
|
||||
}
|
||||
setProgress(ev.getRawX() - mDownX);
|
||||
break;
|
||||
}
|
||||
@@ -298,8 +276,12 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
protected void cancel() {
|
||||
if (mUseDynamicTranslucency && getContext() instanceof Activity) {
|
||||
((Activity) getContext()).convertFromTranslucent();
|
||||
if (!mIsWindowNativelyTranslucent) {
|
||||
Activity activity = findActivity();
|
||||
if (activity != null && mActivityTranslucencyConverted) {
|
||||
activity.convertFromTranslucent();
|
||||
mActivityTranslucencyConverted = false;
|
||||
}
|
||||
}
|
||||
if (mProgressListener != null) {
|
||||
mProgressListener.onSwipeCancelled(this);
|
||||
@@ -323,6 +305,7 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
private void updateSwiping(MotionEvent ev) {
|
||||
boolean oldSwiping = mSwiping;
|
||||
if (!mSwiping) {
|
||||
float deltaX = ev.getRawX() - mDownX;
|
||||
float deltaY = ev.getRawY() - mDownY;
|
||||
@@ -332,6 +315,16 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
mSwiping = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mSwiping && !oldSwiping) {
|
||||
// Swiping has started
|
||||
if (!mIsWindowNativelyTranslucent) {
|
||||
Activity activity = findActivity();
|
||||
if (activity != null) {
|
||||
mActivityTranslucencyConverted = activity.convertToTranslucent(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDismiss(MotionEvent ev) {
|
||||
@@ -404,6 +397,17 @@ public class SwipeDismissLayout extends FrameLayout {
|
||||
return 1 - progress * progress * progress;
|
||||
}
|
||||
|
||||
private Activity findActivity() {
|
||||
Context context = getContext();
|
||||
while (context instanceof ContextWrapper) {
|
||||
if (context instanceof Activity) {
|
||||
return (Activity) context;
|
||||
}
|
||||
context = ((ContextWrapper) context).getBaseContext();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class DismissAnimator implements AnimatorUpdateListener, Animator.AnimatorListener {
|
||||
private final TimeInterpolator DISMISS_INTERPOLATOR = new DecelerateInterpolator(1.5f);
|
||||
private final long DISMISS_DURATION = 250;
|
||||
|
||||
Reference in New Issue
Block a user