Fixed a bug where notifications could stay expanded
am: b2236108ae
Change-Id: I9c776321f0865f6971692008256cd80adbab5469
This commit is contained in:
@@ -326,7 +326,8 @@ public class ExpandHelper implements Gefingerpoken {
|
|||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
if (DEBUG) Log.d(TAG, "up/cancel");
|
if (DEBUG) Log.d(TAG, "up/cancel");
|
||||||
finishExpanding(false, getCurrentVelocity());
|
finishExpanding(ev.getActionMasked() == MotionEvent.ACTION_CANCEL /* forceAbort */,
|
||||||
|
getCurrentVelocity());
|
||||||
clearView();
|
clearView();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -390,7 +391,8 @@ public class ExpandHelper implements Gefingerpoken {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent ev) {
|
public boolean onTouchEvent(MotionEvent ev) {
|
||||||
if (!isEnabled()) {
|
if (!isEnabled() && !mExpanding) {
|
||||||
|
// In case we're expanding we still want to finish the current motion.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
trackVelocity(ev);
|
trackVelocity(ev);
|
||||||
@@ -485,7 +487,8 @@ public class ExpandHelper implements Gefingerpoken {
|
|||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
if (DEBUG) Log.d(TAG, "up/cancel");
|
if (DEBUG) Log.d(TAG, "up/cancel");
|
||||||
finishExpanding(false, getCurrentVelocity());
|
finishExpanding(!isEnabled() || ev.getActionMasked() == MotionEvent.ACTION_CANCEL,
|
||||||
|
getCurrentVelocity());
|
||||||
clearView();
|
clearView();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -526,28 +529,37 @@ public class ExpandHelper implements Gefingerpoken {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishExpanding(boolean force, float velocity) {
|
/**
|
||||||
|
* Finish the current expand motion
|
||||||
|
* @param forceAbort whether the expansion should be forcefully aborted and returned to the old
|
||||||
|
* state
|
||||||
|
* @param velocity the velocity this was expanded/ collapsed with
|
||||||
|
*/
|
||||||
|
private void finishExpanding(boolean forceAbort, float velocity) {
|
||||||
if (!mExpanding) return;
|
if (!mExpanding) return;
|
||||||
|
|
||||||
if (DEBUG) Log.d(TAG, "scale in finishing on view: " + mResizedView);
|
if (DEBUG) Log.d(TAG, "scale in finishing on view: " + mResizedView);
|
||||||
|
|
||||||
float currentHeight = mScaler.getHeight();
|
float currentHeight = mScaler.getHeight();
|
||||||
float h = mScaler.getHeight();
|
|
||||||
final boolean wasClosed = (mOldHeight == mSmallSize);
|
final boolean wasClosed = (mOldHeight == mSmallSize);
|
||||||
boolean nowExpanded;
|
boolean nowExpanded;
|
||||||
int naturalHeight = mScaler.getNaturalHeight();
|
if (!forceAbort) {
|
||||||
if (wasClosed) {
|
if (wasClosed) {
|
||||||
nowExpanded = (force || currentHeight > mOldHeight && velocity >= 0);
|
nowExpanded = currentHeight > mOldHeight && velocity >= 0;
|
||||||
|
} else {
|
||||||
|
nowExpanded = currentHeight >= mOldHeight || velocity > 0;
|
||||||
|
}
|
||||||
|
nowExpanded |= mNaturalHeight == mSmallSize;
|
||||||
} else {
|
} else {
|
||||||
nowExpanded = !force && (currentHeight >= mOldHeight || velocity > 0);
|
nowExpanded = !wasClosed;
|
||||||
}
|
}
|
||||||
nowExpanded |= mNaturalHeight == mSmallSize;
|
|
||||||
if (mScaleAnimation.isRunning()) {
|
if (mScaleAnimation.isRunning()) {
|
||||||
mScaleAnimation.cancel();
|
mScaleAnimation.cancel();
|
||||||
}
|
}
|
||||||
mCallback.expansionStateChanged(false);
|
mCallback.expansionStateChanged(false);
|
||||||
|
int naturalHeight = mScaler.getNaturalHeight();
|
||||||
float targetHeight = nowExpanded ? naturalHeight : mSmallSize;
|
float targetHeight = nowExpanded ? naturalHeight : mSmallSize;
|
||||||
if (targetHeight != currentHeight) {
|
if (targetHeight != currentHeight && mEnabled) {
|
||||||
mScaleAnimation.setFloatValues(targetHeight);
|
mScaleAnimation.setFloatValues(targetHeight);
|
||||||
mScaleAnimation.setupStartValues();
|
mScaleAnimation.setupStartValues();
|
||||||
final View scaledView = mResizedView;
|
final View scaledView = mResizedView;
|
||||||
@@ -575,6 +587,9 @@ public class ExpandHelper implements Gefingerpoken {
|
|||||||
mFlingAnimationUtils.apply(mScaleAnimation, currentHeight, targetHeight, velocity);
|
mFlingAnimationUtils.apply(mScaleAnimation, currentHeight, targetHeight, velocity);
|
||||||
mScaleAnimation.start();
|
mScaleAnimation.start();
|
||||||
} else {
|
} else {
|
||||||
|
if (targetHeight != currentHeight) {
|
||||||
|
mScaler.setHeight(targetHeight);
|
||||||
|
}
|
||||||
mCallback.setUserExpandedChild(mResizedView, nowExpanded);
|
mCallback.setUserExpandedChild(mResizedView, nowExpanded);
|
||||||
mCallback.setUserLockedChild(mResizedView, false);
|
mCallback.setUserLockedChild(mResizedView, false);
|
||||||
}
|
}
|
||||||
@@ -597,7 +612,7 @@ public class ExpandHelper implements Gefingerpoken {
|
|||||||
* Use this to abort any pending expansions in progress.
|
* Use this to abort any pending expansions in progress.
|
||||||
*/
|
*/
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
finishExpanding(true, 0f /* velocity */);
|
finishExpanding(true /* forceAbort */, 0f /* velocity */);
|
||||||
clearView();
|
clearView();
|
||||||
|
|
||||||
// reset the gesture detector
|
// reset the gesture detector
|
||||||
|
|||||||
@@ -1022,6 +1022,19 @@ public class NotificationStackScrollLayout extends ViewGroup
|
|||||||
public void setUserExpandedChild(View v, boolean userExpanded) {
|
public void setUserExpandedChild(View v, boolean userExpanded) {
|
||||||
if (v instanceof ExpandableNotificationRow) {
|
if (v instanceof ExpandableNotificationRow) {
|
||||||
ExpandableNotificationRow row = (ExpandableNotificationRow) v;
|
ExpandableNotificationRow row = (ExpandableNotificationRow) v;
|
||||||
|
if (userExpanded && onKeyguard()) {
|
||||||
|
// Due to a race when locking the screen while touching, a notification may be
|
||||||
|
// expanded even after we went back to keyguard. An example of this happens if
|
||||||
|
// you click in the empty space while expanding a group.
|
||||||
|
|
||||||
|
// We also need to un-user lock it here, since otherwise the content height
|
||||||
|
// calculated might be wrong. We also can't invert the two calls since
|
||||||
|
// un-userlocking it will trigger a layout switch in the content view.
|
||||||
|
row.setUserLocked(false);
|
||||||
|
updateContentHeight();
|
||||||
|
notifyHeightChangeListener(row);
|
||||||
|
return;
|
||||||
|
}
|
||||||
row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */);
|
row.setUserExpanded(userExpanded, true /* allowChildrenExpansion */);
|
||||||
row.onExpandedByGesture(userExpanded);
|
row.onExpandedByGesture(userExpanded);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user