Dismiss SnackBar when detached
SnackBarManager state is not cleared when SnackBar is detached from a
window without dismiss(). After then it is remained as dismissing state
forever.
Test: 1) Long-press a conversation and click archive action.
2) Press back key before the snackbar is dismissed.
3) Repeat 1) and check the snackbar is shown or not.
Change-Id: Icf2cdcd30aea42685db68e5ac36436a34c9c94ae
Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
This commit is contained in:
@@ -25,6 +25,7 @@ import android.view.Gravity;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.MeasureSpec;
|
import android.view.View.MeasureSpec;
|
||||||
|
import android.view.View.OnAttachStateChangeListener;
|
||||||
import android.view.View.OnTouchListener;
|
import android.view.View.OnTouchListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
@@ -86,6 +87,23 @@ public class SnackBarManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final OnAttachStateChangeListener mAttachStateChangeListener =
|
||||||
|
new OnAttachStateChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onViewDetachedFromWindow(View v) {
|
||||||
|
// Dismiss the PopupWindow and clear SnackBarManager state.
|
||||||
|
mHideHandler.removeCallbacks(mDismissRunnable);
|
||||||
|
mPopupWindow.dismiss();
|
||||||
|
|
||||||
|
mCurrentSnackBar = null;
|
||||||
|
mNextSnackBar = null;
|
||||||
|
mIsCurrentlyDismissing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewAttachedToWindow(View v) {}
|
||||||
|
};
|
||||||
|
|
||||||
private final int mTranslationDurationMs;
|
private final int mTranslationDurationMs;
|
||||||
private final Handler mHideHandler;
|
private final Handler mHideHandler;
|
||||||
|
|
||||||
@@ -181,6 +199,7 @@ public class SnackBarManager {
|
|||||||
mPopupWindow.showAsDropDown(anchorView, 0, getRelativeOffset(snackBar));
|
mPopupWindow.showAsDropDown(anchorView, 0, getRelativeOffset(snackBar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snackBar.getParentView().addOnAttachStateChangeListener(mAttachStateChangeListener);
|
||||||
|
|
||||||
// Animate the toast bar into view.
|
// Animate the toast bar into view.
|
||||||
placeSnackBarOffScreen(snackBar);
|
placeSnackBarOffScreen(snackBar);
|
||||||
@@ -238,6 +257,8 @@ public class SnackBarManager {
|
|||||||
// PopupWindow.dismiss() will fire an IllegalArgumentException if the activity
|
// PopupWindow.dismiss() will fire an IllegalArgumentException if the activity
|
||||||
// has already ended while we were animating
|
// has already ended while we were animating
|
||||||
}
|
}
|
||||||
|
snackBar.getParentView()
|
||||||
|
.removeOnAttachStateChangeListener(mAttachStateChangeListener);
|
||||||
|
|
||||||
mCurrentSnackBar = null;
|
mCurrentSnackBar = null;
|
||||||
mIsCurrentlyDismissing = false;
|
mIsCurrentlyDismissing = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user