Fix situations where the panel wouldn't descend.
Change-Id: I41c1d6a973b2693487062f3a5fbf922ff2025897
This commit is contained in:
@@ -19,6 +19,16 @@ public class PanelBar extends FrameLayout {
|
|||||||
private PanelHolder mPanelHolder;
|
private PanelHolder mPanelHolder;
|
||||||
private ArrayList<PanelView> mPanels = new ArrayList<PanelView>();
|
private ArrayList<PanelView> mPanels = new ArrayList<PanelView>();
|
||||||
protected PanelView mTouchingPanel;
|
protected PanelView mTouchingPanel;
|
||||||
|
private static final int STATE_CLOSED = 0;
|
||||||
|
private static final int STATE_TRANSITIONING = 1;
|
||||||
|
private static final int STATE_OPEN = 2;
|
||||||
|
private int mState = STATE_CLOSED;
|
||||||
|
private boolean mTracking;
|
||||||
|
|
||||||
|
private void go(int state) {
|
||||||
|
LOG("go state: %d -> %d", mState, state);
|
||||||
|
mState = state;
|
||||||
|
}
|
||||||
|
|
||||||
public PanelBar(Context context, AttributeSet attrs) {
|
public PanelBar(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -62,8 +72,11 @@ public class PanelBar extends FrameLayout {
|
|||||||
final int i = (int)(N * event.getX() / getMeasuredWidth());
|
final int i = (int)(N * event.getX() / getMeasuredWidth());
|
||||||
mTouchingPanel = mPanels.get(i);
|
mTouchingPanel = mPanels.get(i);
|
||||||
mPanelHolder.setSelectedPanel(mTouchingPanel);
|
mPanelHolder.setSelectedPanel(mTouchingPanel);
|
||||||
LOG("PanelBar.onTouch: ACTION_DOWN: panel %d", i);
|
LOG("PanelBar.onTouch: state=%d ACTION_DOWN: panel %d", mState, i);
|
||||||
onPanelPeeked();
|
if (mState == STATE_CLOSED || mState == STATE_OPEN) {
|
||||||
|
go(STATE_TRANSITIONING);
|
||||||
|
onPanelPeeked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final boolean result = mTouchingPanel.getHandle().dispatchTouchEvent(event);
|
final boolean result = mTouchingPanel.getHandle().dispatchTouchEvent(event);
|
||||||
return result;
|
return result;
|
||||||
@@ -72,11 +85,13 @@ public class PanelBar extends FrameLayout {
|
|||||||
public void panelExpansionChanged(PanelView panel, float frac) {
|
public void panelExpansionChanged(PanelView panel, float frac) {
|
||||||
boolean fullyClosed = true;
|
boolean fullyClosed = true;
|
||||||
PanelView fullyOpenedPanel = null;
|
PanelView fullyOpenedPanel = null;
|
||||||
|
LOG("panelExpansionChanged: start state=%d panel=%s", mState, panel.getName());
|
||||||
for (PanelView pv : mPanels) {
|
for (PanelView pv : mPanels) {
|
||||||
|
// adjust any other panels that may be partially visible
|
||||||
if (pv.getExpandedHeight() > 0f) {
|
if (pv.getExpandedHeight() > 0f) {
|
||||||
fullyClosed = false;
|
fullyClosed = false;
|
||||||
final float thisFrac = pv.getExpandedFraction();
|
final float thisFrac = pv.getExpandedFraction();
|
||||||
LOG("panel %s: f=%.1f", pv, thisFrac);
|
LOG("panelExpansionChanged: -> %s: f=%.1f", pv.getName(), thisFrac);
|
||||||
if (panel == pv) {
|
if (panel == pv) {
|
||||||
if (thisFrac == 1f) fullyOpenedPanel = panel;
|
if (thisFrac == 1f) fullyOpenedPanel = panel;
|
||||||
} else {
|
} else {
|
||||||
@@ -84,11 +99,15 @@ public class PanelBar extends FrameLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fullyOpenedPanel != null) onPanelFullyOpened(fullyOpenedPanel);
|
if (fullyOpenedPanel != null && !mTracking) {
|
||||||
if (fullyClosed) onAllPanelsCollapsed();
|
go(STATE_OPEN);
|
||||||
else onPanelPeeked();
|
onPanelFullyOpened(fullyOpenedPanel);
|
||||||
|
} else if (fullyClosed && !mTracking) {
|
||||||
|
go(STATE_CLOSED);
|
||||||
|
onAllPanelsCollapsed();
|
||||||
|
}
|
||||||
|
|
||||||
LOG("panelExpansionChanged: [%s%s ]",
|
LOG("panelExpansionChanged: end state=%d [%s%s ]", mState,
|
||||||
(fullyOpenedPanel!=null)?" fullyOpened":"", fullyClosed?" fullyClosed":"");
|
(fullyOpenedPanel!=null)?" fullyOpened":"", fullyClosed?" fullyClosed":"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,4 +132,17 @@ public class PanelBar extends FrameLayout {
|
|||||||
public void onPanelFullyOpened(PanelView openPanel) {
|
public void onPanelFullyOpened(PanelView openPanel) {
|
||||||
LOG("onPanelFullyOpened");
|
LOG("onPanelFullyOpened");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onTrackingStarted(PanelView panel) {
|
||||||
|
mTracking = true;
|
||||||
|
if (panel != mTouchingPanel) {
|
||||||
|
LOG("shouldn't happen: onTrackingStarted(%s) != mTouchingPanel(%s)",
|
||||||
|
panel, mTouchingPanel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onTrackingStopped(PanelView panel) {
|
||||||
|
mTracking = false;
|
||||||
|
panelExpansionChanged(panel, panel.getExpandedFraction());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import com.android.systemui.R;
|
|||||||
public class PanelView extends FrameLayout {
|
public class PanelView extends FrameLayout {
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
public static final String TAG = PanelView.class.getSimpleName();
|
public static final String TAG = PanelView.class.getSimpleName();
|
||||||
public static final void LOG(String fmt, Object... args) {
|
public final void LOG(String fmt, Object... args) {
|
||||||
if (!DEBUG) return;
|
if (!DEBUG) return;
|
||||||
Log.v(TAG, String.format(fmt, args));
|
Log.v(TAG, (mViewName != null ? (mViewName + ": ") : "") + String.format(fmt, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final boolean BRAKES = false;
|
public static final boolean BRAKES = false;
|
||||||
@@ -61,6 +61,7 @@ public class PanelView extends FrameLayout {
|
|||||||
|
|
||||||
private float mVel, mAccel;
|
private float mVel, mAccel;
|
||||||
private int mFullHeight = 0;
|
private int mFullHeight = 0;
|
||||||
|
private String mViewName;
|
||||||
|
|
||||||
private void animationTick(long dtms) {
|
private void animationTick(long dtms) {
|
||||||
if (!mTimeAnimator.isStarted()) {
|
if (!mTimeAnimator.isStarted()) {
|
||||||
@@ -69,7 +70,7 @@ public class PanelView extends FrameLayout {
|
|||||||
mTimeAnimator.setTimeListener(mAnimationCallback);
|
mTimeAnimator.setTimeListener(mAnimationCallback);
|
||||||
|
|
||||||
mTimeAnimator.start();
|
mTimeAnimator.start();
|
||||||
} else {
|
} else if (dtms > 0) {
|
||||||
final float dt = dtms * 0.001f; // ms -> s
|
final float dt = dtms * 0.001f; // ms -> s
|
||||||
LOG("tick: v=%.2fpx/s dt=%.4fs", mVel, dt);
|
LOG("tick: v=%.2fpx/s dt=%.4fs", mVel, dt);
|
||||||
LOG("tick: before: h=%d", (int) mExpandedHeight);
|
LOG("tick: before: h=%d", (int) mExpandedHeight);
|
||||||
@@ -170,13 +171,16 @@ public class PanelView extends FrameLayout {
|
|||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
final float y = event.getY();
|
final float y = event.getY();
|
||||||
final float rawY = event.getRawY();
|
final float rawY = event.getRawY();
|
||||||
LOG("handle.onTouch: y=%.1f rawY=%.1f off=%.1f", y, rawY, mTouchOffset);
|
LOG("handle.onTouch: a=%s y=%.1f rawY=%.1f off=%.1f",
|
||||||
|
MotionEvent.actionToString(event.getAction()),
|
||||||
|
y, rawY, mTouchOffset);
|
||||||
PanelView.this.getLocationOnScreen(mAbsPos);
|
PanelView.this.getLocationOnScreen(mAbsPos);
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
mVelocityTracker = VelocityTracker.obtain();
|
mVelocityTracker = VelocityTracker.obtain();
|
||||||
trackMovement(event);
|
trackMovement(event);
|
||||||
|
mBar.onTrackingStarted(PanelView.this);
|
||||||
mTouchOffset = (rawY - mAbsPos[1]) - PanelView.this.getExpandedHeight();
|
mTouchOffset = (rawY - mAbsPos[1]) - PanelView.this.getExpandedHeight();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -190,6 +194,7 @@ public class PanelView extends FrameLayout {
|
|||||||
|
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
mBar.onTrackingStopped(PanelView.this);
|
||||||
trackMovement(event);
|
trackMovement(event);
|
||||||
mVelocityTracker.computeCurrentVelocity(1000);
|
mVelocityTracker.computeCurrentVelocity(1000);
|
||||||
|
|
||||||
@@ -241,6 +246,11 @@ public class PanelView extends FrameLayout {
|
|||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
|
mViewName = getResources().getResourceName(getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return mViewName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -278,7 +288,7 @@ public class PanelView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG("setExpansion: height=%.1f fh=%.1f", h, fh);
|
LOG("setExpansion: height=%.1f fh=%.1f", h, fh);
|
||||||
|
|
||||||
if (h < 0) h = 0;
|
if (h < 0) h = 0;
|
||||||
else if (h > fh) h = fh;
|
else if (h > fh) h = fh;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user