mirror of
https://github.com/Tencent/QMUI_Android.git
synced 2026-10-17 04:31:16 +08:00
add method setEnableScrollBarFadeInOut for QMUIContinuousNestedScrollLayout
This commit is contained in:
+28
-1
@@ -51,6 +51,7 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
};
|
||||
private boolean mKeepBottomAreaStableWhenCheckLayout = false;
|
||||
private QMUIDraggableScrollBar mDraggableScrollBar;
|
||||
private boolean mEnableScrollBarFadeInOut = true;
|
||||
private boolean mIsDraggableScrollBarEnabled = false;
|
||||
private int mCurrentScrollState = IQMUIContinuousNestedScrollCommon.SCROLL_STATE_IDLE;
|
||||
private boolean mIsDismissDownEvent = false;
|
||||
@@ -72,6 +73,7 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
private void ensureScrollBar() {
|
||||
if (mDraggableScrollBar == null) {
|
||||
mDraggableScrollBar = createScrollBar(getContext());
|
||||
mDraggableScrollBar.setEnableFadeInAndOut(mEnableScrollBarFadeInOut);
|
||||
mDraggableScrollBar.setCallback(this);
|
||||
CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
@@ -81,7 +83,32 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
}
|
||||
|
||||
public void setDraggableScrollBarEnabled(boolean draggableScrollBarEnabled) {
|
||||
mIsDraggableScrollBarEnabled = draggableScrollBarEnabled;
|
||||
if(mIsDraggableScrollBarEnabled != draggableScrollBarEnabled){
|
||||
mIsDraggableScrollBarEnabled = draggableScrollBarEnabled;
|
||||
if(mIsDraggableScrollBarEnabled && !mEnableScrollBarFadeInOut){
|
||||
ensureScrollBar();
|
||||
mDraggableScrollBar.setPercent(getCurrentScrollPercent());
|
||||
mDraggableScrollBar.awakenScrollBar();
|
||||
}
|
||||
if(mDraggableScrollBar != null){
|
||||
mDraggableScrollBar.setVisibility(draggableScrollBarEnabled ? View.VISIBLE: View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnableScrollBarFadeInOut(boolean enableScrollBarFadeInOut) {
|
||||
if(mEnableScrollBarFadeInOut != enableScrollBarFadeInOut){
|
||||
mEnableScrollBarFadeInOut = enableScrollBarFadeInOut;
|
||||
if(mIsDraggableScrollBarEnabled && !mEnableScrollBarFadeInOut){
|
||||
ensureScrollBar();
|
||||
mDraggableScrollBar.setPercent(getCurrentScrollPercent());
|
||||
mDraggableScrollBar.awakenScrollBar();
|
||||
}
|
||||
if(mDraggableScrollBar != null){
|
||||
mDraggableScrollBar.setEnableFadeInAndOut(enableScrollBarFadeInOut);
|
||||
mDraggableScrollBar.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected QMUIDraggableScrollBar createScrollBar(Context context) {
|
||||
|
||||
@@ -49,6 +49,9 @@ import com.qmuiteam.qmui.util.QMUILangHelper;
|
||||
|
||||
public class QMUIDraggableScrollBar extends View {
|
||||
|
||||
private int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed};
|
||||
private int[] STATE_NORMAL = new int[]{};
|
||||
|
||||
private Drawable mDragDrawable;
|
||||
private int mKeepShownTime = 800;
|
||||
private int mTransitionDuration = 100;
|
||||
@@ -67,6 +70,7 @@ public class QMUIDraggableScrollBar extends View {
|
||||
private float mDragInnerTop = 0;
|
||||
private int mAdjustDistanceProtection = QMUIDisplayHelper.dp2px(getContext(), 20);
|
||||
private int mAdjustMaxDistanceOnce = QMUIDisplayHelper.dp2px(getContext(), 4);
|
||||
private boolean enableFadeInAndOut = true;
|
||||
|
||||
public QMUIDraggableScrollBar(Context context) {
|
||||
this(context, (AttributeSet) null);
|
||||
@@ -93,6 +97,14 @@ public class QMUIDraggableScrollBar extends View {
|
||||
mTransitionDuration = transitionDuration;
|
||||
}
|
||||
|
||||
public void setEnableFadeInAndOut(boolean enableFadeInAndOut) {
|
||||
this.enableFadeInAndOut = enableFadeInAndOut;
|
||||
}
|
||||
|
||||
public boolean isEnableFadeInAndOut() {
|
||||
return enableFadeInAndOut;
|
||||
}
|
||||
|
||||
public void setDragDrawable(Drawable dragDrawable) {
|
||||
mDragDrawable = dragDrawable.mutate();
|
||||
invalidate();
|
||||
@@ -138,6 +150,7 @@ public class QMUIDraggableScrollBar extends View {
|
||||
mIsInDragging = true;
|
||||
if(mCallback != null){
|
||||
mCallback.onDragStarted();
|
||||
mDragDrawable.setState(STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
} else if (action == MotionEvent.ACTION_MOVE) {
|
||||
@@ -151,6 +164,7 @@ public class QMUIDraggableScrollBar extends View {
|
||||
onDragging(drawable, y);
|
||||
if(mCallback != null){
|
||||
mCallback.onDragEnd();
|
||||
mDragDrawable.setState(STATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,29 +203,35 @@ public class QMUIDraggableScrollBar extends View {
|
||||
if (drawableWidth <= 0 || drawableHeight <= 0) {
|
||||
return;
|
||||
}
|
||||
long timeAfterStartShow = System.currentTimeMillis() - mStartTransitionTime;
|
||||
long timeAfterEndShow;
|
||||
|
||||
int needInvalidate = -1;
|
||||
if (timeAfterStartShow < mTransitionDuration) {
|
||||
// in show animation
|
||||
mCurrentAlpha = timeAfterStartShow * 1f / mTransitionDuration;
|
||||
needInvalidate = 0;
|
||||
} else if (timeAfterStartShow - mTransitionDuration < mKeepShownTime) {
|
||||
// keep show
|
||||
if(enableFadeInAndOut){
|
||||
long timeAfterStartShow = System.currentTimeMillis() - mStartTransitionTime;
|
||||
long timeAfterEndShow;
|
||||
if (timeAfterStartShow < mTransitionDuration) {
|
||||
// in show animation
|
||||
mCurrentAlpha = timeAfterStartShow * 1f / mTransitionDuration;
|
||||
needInvalidate = 0;
|
||||
} else if (timeAfterStartShow - mTransitionDuration < mKeepShownTime) {
|
||||
// keep show
|
||||
mCurrentAlpha = 1f;
|
||||
needInvalidate = (int) (mKeepShownTime - (timeAfterStartShow - mTransitionDuration));
|
||||
} else if ((timeAfterEndShow = timeAfterStartShow - mTransitionDuration - mKeepShownTime)
|
||||
< mTransitionDuration) {
|
||||
// in hide animation
|
||||
mCurrentAlpha = 1 - timeAfterEndShow * 1f / mTransitionDuration;
|
||||
needInvalidate = 0;
|
||||
} else {
|
||||
mCurrentAlpha = 0f;
|
||||
}
|
||||
if (mCurrentAlpha <= 0f) {
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
mCurrentAlpha = 1f;
|
||||
needInvalidate = (int) (mKeepShownTime - (timeAfterStartShow - mTransitionDuration));
|
||||
} else if ((timeAfterEndShow = timeAfterStartShow - mTransitionDuration - mKeepShownTime)
|
||||
< mTransitionDuration) {
|
||||
// in hide animation
|
||||
mCurrentAlpha = 1 - timeAfterEndShow * 1f / mTransitionDuration;
|
||||
needInvalidate = 0;
|
||||
} else {
|
||||
mCurrentAlpha = 0f;
|
||||
}
|
||||
if (mCurrentAlpha <= 0f) {
|
||||
return;
|
||||
}
|
||||
drawable.setAlpha((int) (mCurrentAlpha * 255));
|
||||
|
||||
int totalHeight = getHeight() - getScrollBarTopMargin() - getScrollBarBottomMargin();
|
||||
int totalWidth = getWidth();
|
||||
int top = getScrollBarTopMargin() + (int) ((totalHeight - drawableHeight) * mPercent);
|
||||
|
||||
Reference in New Issue
Block a user