Java 类android.support.v4.widget.ViewDragHelper 实例源码
项目:RLibrary
文件:SwipeBackLayout.java
@Override
public boolean tryCaptureView(View child, int pointerId) {
isCaptureAbort = false;
if (!enableSwipeBack) {
return false;
}
if (child == null || child.getLeft() != 0 || child.getTranslationX() != 0f ||
mViewDragState != ViewDragHelper.STATE_IDLE) {
return false;
}
mIsLeftEdge = mDragHelper.isEdgeTouched(ViewDragHelper.EDGE_LEFT, pointerId);
mTargetView = child;
if (mIsLeftEdge || isForceIntercept()) {
return canTryCaptureView(child);
}
return false;
}
项目:GitHub
文件:SwipeBackLayout.java
@Override
public boolean tryCaptureView(View child, int pointerId) {
boolean edgeTouched = mDragHelper.isEdgeTouched(mEdgeFlag, pointerId);
if (edgeTouched) {
if (mDragHelper.isEdgeTouched(EDGE_LEFT, pointerId)) {
mTrackingEdge = EDGE_LEFT;
} else if (mDragHelper.isEdgeTouched(EDGE_RIGHT, pointerId)) {
mTrackingEdge = EDGE_RIGHT;
} else if (mDragHelper.isEdgeTouched(EDGE_BOTTOM, pointerId)) {
mTrackingEdge = EDGE_BOTTOM;
}
}
boolean directionCheck = false;
if (mEdgeFlag == EDGE_LEFT || mEdgeFlag == EDGE_RIGHT) {
// 左右边缘则检测竖直方向的滑动
directionCheck = !mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_VERTICAL, pointerId);
} else if (mEdgeFlag == EDGE_BOTTOM) {
// 下边缘则检测水平方向的滑动
directionCheck = !mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_HORIZONTAL, pointerId);
} else if (mEdgeFlag == EDGE_ALL) {
directionCheck = true;
}
return edgeTouched && directionCheck;
}
项目:GitHub
文件:DragLayout.java
public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.app, 0, 0);
bottomDragVisibleHeight = (int) a.getDimension(R.styleable.app_bottomDragVisibleHeight, 0);
bototmExtraIndicatorHeight = (int) a.getDimension(R.styleable.app_bototmExtraIndicatorHeight, 0);
a.recycle();
mDragHelper = ViewDragHelper
.create(this, 10f, new DragHelperCallback());
mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP);
moveDetector = new GestureDetectorCompat(context, new MoveDetector());
moveDetector.setIsLongpressEnabled(false); // 不处理长按事件
// 滑动的距离阈值由系统提供
ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
}
项目:WechatChatroomHelper
文件:BGASwipeBackLayout2.java
@Override
public void onViewDragStateChanged(int state) {
if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
if (mSlideOffset == 0) {
updateObscuredViewsVisibility(mSlideableView);
dispatchOnPanelClosed(mSlideableView);
mPreservedOpenState = false;
} else {
dispatchOnPanelOpened(mSlideableView);
mPreservedOpenState = true;
}
// ======================== 新加的 START ========================
// }
mIsSliding = false;
} else {
mIsSliding = true;
}
// ======================== 新加的 END ========================
}
项目:WechatChatroomHelper
文件:BGASwipeBackLayout2.java
public BGASwipeBackLayout2(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final float density = context.getResources().getDisplayMetrics().density;
// ======================== 新加的 START ========================
// mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);
mOverhangSize = 0;
// ======================== 新加的 END ========================
final ViewConfiguration viewConfig = ViewConfiguration.get(context);
setWillNotDraw(false);
ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}
项目:android-SpringAnimator
文件:TranslationPreviewFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_square, container, false);
mCardView = (CardView) view.findViewById(R.id.card_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mCardZ = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2.f, getResources().getDisplayMetrics());
mCardView.setZ(mCardZ);
}
final ViewDragHelper viewDragHelper = ViewDragHelper.create(view, mViewDragHelperCallback);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
viewDragHelper.processTouchEvent(event);
return false;
}
});
recordOriginalLocation(mCardView);
return view;
}
项目:Pocket-Plays-for-Twitch
文件:Service.java
/**
* Method for increasing a Navigation Drawer's edge size.
*/
public static void increaseNavigationDrawerEdge(DrawerLayout aDrawerLayout, Context context) {
// Increase the area from which you can open the navigation drawer.
try {
Field mDragger = aDrawerLayout.getClass().getDeclaredField("mLeftDragger");
mDragger.setAccessible(true);
ViewDragHelper draggerObj = (ViewDragHelper) mDragger.get(aDrawerLayout);
Field mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize");
mEdgeSize.setAccessible(true);
int edgeSize = mEdgeSize.getInt(draggerObj) * 3;
mEdgeSize.setInt(draggerObj, edgeSize); //optimal value as for me, you may set any constant in dp
} catch(Exception e) {
e.printStackTrace();
}
}
项目:drag-to-close
文件:DragHelperCallback.java
/**
* Checks dragging states and notifies them.
*/
@Override
public void onViewDragStateChanged(int state) {
// If no state change, don't do anything
if (state == lastDraggingState) {
return;
}
// If last state was dragging or settling and current state is idle,
// the view has stopped moving. If the top border of the container is
// equal to the vertical draggable range, the view has being dragged out,
// so close activity is called
if ((lastDraggingState == ViewDragHelper.STATE_DRAGGING
|| lastDraggingState == ViewDragHelper.STATE_SETTLING)
&& state == ViewDragHelper.STATE_IDLE
&& topBorderDraggableContainer == dragToClose.getDraggableRange()) {
dragToClose.closeActivity();
}
// If the view has just started being dragged, notify event
if (state == ViewDragHelper.STATE_DRAGGING) {
dragToClose.onStartDraggingView();
}
// Save current state
lastDraggingState = state;
}
项目:Widgets
文件:SlideLayout.java
private void init(Context context, AttributeSet attrs) {
//获取相关属性设置
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlideLayout);
mAlphaColor = ta.getColor(R.styleable.SlideLayout_sl_anim_alpha_color, DEF_ANIM_ALPHA_COLOR);
mEdgeEnable = ta.getBoolean(R.styleable.SlideLayout_sl_edge_enable, DEF_EDGE_ENABLE);
mMainAlphaEnable = ta.getBoolean(R.styleable.SlideLayout_sl_main_alpha_enable, DEF_MAIN_ALPHA_ENABLE);
ta.recycle();
//初始化ViewDragHelper相关
mCallback = new DragCallback();
mDragHelper = ViewDragHelper.create(this, DEF_SENSITIVITY, mCallback);
if (mEdgeEnable) {
//设置边缘滑动检测
mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
//设置最小滑动速度
mDragHelper.setMinVelocity(DEF_SENSITIVITY * DEF_MIN_FLING_VELOCITY);
}
//初始化屏幕触控处理相关
mGestureListener = new GestureListener();
mGestureDetector = new GestureDetectorCompat(context, mGestureListener);
//设置初始状态为关闭
mStatus = Status.CLOSED;
}
项目:Multi-SwipeBackLayout
文件:SwipeBackLayout.java
/**
* \
* 通过xml布局 自定义属性调用
*
* @param context 上下文
* @param attrs xml属性
*/
public SwipeBackLayout(Context context, AttributeSet attrs) {
super(context, attrs);
//①获取ViewDragHelper的实例
mViewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallback());
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout);
mDragDirectionMask = ta.getInt(R.styleable.SwipeBackLayout_dragDirection, NONE);
mShadowColor = ta.getColor(R.styleable.SwipeBackLayout_shadowColor, mShadowColor);
int contentLayoutId = ta.getResourceId(R.styleable.SwipeBackLayout_contentView,View.NO_ID);
ta.recycle();
addShadowView(context);
if (View.NO_ID != contentLayoutId){
mContentView = LayoutInflater.from(context).inflate(contentLayoutId, this, false);
addView(mContentView);
}
enableSwipeBack = true;
}
项目:pulltorefresh
文件:FPullToRefreshView.java
private int getTopLayoutHeaderView()
{
// 初始值
int top = getTopHeaderViewReset();
if (getDirection() == Direction.FROM_HEADER)
{
if (mViewDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE)
{
switch (mState)
{
case REFRESHING:
case REFRESH_SUCCESS:
case REFRESH_FAILURE:
top += mHeaderView.getRefreshHeight();
break;
}
} else
{
top = mHeaderView.getTop();
}
}
return top;
}
项目:pulltorefresh
文件:FPullToRefreshView.java
private int getTopLayoutFooterView()
{
// 初始值
int top = getTopFooterViewReset();
if (getDirection() == Direction.FROM_FOOTER)
{
if (mViewDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE)
{
switch (mState)
{
case REFRESHING:
case REFRESH_SUCCESS:
case REFRESH_FAILURE:
top -= mFooterView.getRefreshHeight();
break;
}
} else
{
top = mFooterView.getTop();
}
}
return top;
}
项目:Tribe
文件:DraggableSquareView.java
public DraggableSquareView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mDragHelper = ViewDragHelper
.create(this, 10f, new DragHelperCallback());
moveDetector = new GestureDetectorCompat(context,
new MoveDetector());
moveDetector.setIsLongpressEnabled(false); // 不能处理长按事件,否则违背最初设计的初衷
spaceInterval = (int) getResources().getDimension(R.dimen.drag_square_interval); // 小方块之间的间隔
// 滑动的距离阈值由系统提供
ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
anchorHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (draggingView != null) {
// 开始移动重心的动画
draggingView.startAnchorAnimation();
}
}
};
}
项目:GCSApp
文件:ShoppingCartAdapter.java
private void setDrawerLeftEdgeSize (Context context, DrawerLayout drawerLayout, float displayWidthPercentage) {
if (context == null || drawerLayout == null) return;
try {
// 找到 ViewDragHelper 并设置 Accessible 为true
Field leftDraggerField =
drawerLayout.getClass().getDeclaredField("mRightDragger");//Right
leftDraggerField.setAccessible(true);
ViewDragHelper leftDragger = (ViewDragHelper) leftDraggerField.get(drawerLayout);
// 找到 edgeSizeField 并设置 Accessible 为true
Field edgeSizeField = leftDragger.getClass().getDeclaredField("mEdgeSize");
edgeSizeField.setAccessible(true);
int edgeSize = edgeSizeField.getInt(leftDragger);
// 设置新的边缘大小
int screenWidth = PixelUtil.getWidth(context);
edgeSizeField.setInt(leftDragger, Math.max(edgeSize, (int) (screenWidth * displayWidthPercentage)));
} catch (Exception e) {
Log.e("aaa", "setDrawerLeftEdgeSize wrong");
}
}
项目:boohee_v5.6
文件:BottomSheetBehavior.java
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
if (!(this.mState == 1 || this.mState == 2)) {
parent.onLayoutChild(child, layoutDirection);
}
this.mParentHeight = parent.getHeight();
this.mMinOffset = Math.max(0, this.mParentHeight - child.getHeight());
this.mMaxOffset = Math.max(this.mParentHeight - this.mPeekHeight, this.mMinOffset);
if (this.mState == 3) {
ViewCompat.offsetTopAndBottom(child, this.mMinOffset);
} else if (this.mHideable && this.mState == 5) {
ViewCompat.offsetTopAndBottom(child, this.mParentHeight);
} else if (this.mState == 4) {
ViewCompat.offsetTopAndBottom(child, this.mMaxOffset);
}
if (this.mViewDragHelper == null) {
this.mViewDragHelper = ViewDragHelper.create(parent, this.mDragCallback);
}
this.mViewRef = new WeakReference(child);
this.mNestedScrollingChildRef = new WeakReference(findScrollingChild(child));
return true;
}
项目:Glitchy
文件:SideMenu.java
public SideMenu(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
final float density = context.getResources().getDisplayMetrics().density;
mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);
final ViewConfiguration viewConfig = ViewConfiguration.get(context);
setWillNotDraw(false);
ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
setPanelSlideListener(new SimpleMenuPanelSlideListener());
setSliderFadeColor(ContextCompat.getColor(context, android.R.color.transparent));
setParallaxDistance(PARALLAX_DISTANCE);
}
项目:AppFirCloud
文件:ResideLayout.java
@Override
public void onViewDragStateChanged(int state) {
if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
if (mSlideOffset == 0) {
updateObscuredViewsVisibility(mSlideableView);
dispatchOnPanelClosed(mSlideableView);
mPreservedOpenState = false;
} else {
dispatchOnPanelOpened(mSlideableView);
mPreservedOpenState = true;
}
}
}
项目:rebase-android
文件:SwipeBackLayout.java
@Override
public void onViewDragStateChanged(int state) {
if (state == draggingState) return;
if ((draggingState == ViewDragHelper.STATE_DRAGGING ||
draggingState == ViewDragHelper.STATE_SETTLING) &&
state == ViewDragHelper.STATE_IDLE) {
// the view stopped from moving.
if (draggingOffset == getDragRange()) {
finish();
}
}
draggingState = state;
}
项目:GitHub
文件:SwipeBackLayout.java
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
super.onViewReleased(releasedChild, xvel, yvel);
if (mCurEdgeFlag == ViewDragHelper.EDGE_LEFT) {
if (mCurrentX > getWidth() / 2) {
mViewDragHelper.settleCapturedViewAt(getWidth(), 0);
} else {
mViewDragHelper.settleCapturedViewAt(0, 0);
mCurrentX = 0;
}
invalidate();
}
}
项目:GitHub
文件:SwipeBackLayout.java
@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
super.onViewPositionChanged(changedView, left, top, dx, dy);
if (mCurEdgeFlag == ViewDragHelper.EDGE_LEFT) {
if (mOnScrollListener != null)
mOnScrollListener.complete((float) (Math.abs(left) * 1.00 / getWidth()));
if (left >= getWidth()) finish();
}
}
项目:QMUI_Android
文件:SwipeBackLayout.java
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
final boolean drawContent = child == mContentView;
boolean ret = super.drawChild(canvas, child, drawingTime);
if (mScrimOpacity > 0 && drawContent
&& mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) {
drawShadow(canvas, child);
drawScrim(canvas, child);
}
return ret;
}
项目:GitHub
文件:SwipeBackLayout.java
@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
if (state == ViewDragHelper.STATE_IDLE) {
mTrackingEdge = EDGE_INVALID;
}
}
项目:conductor-attacher
文件:SwipeBackLayout.java
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
final boolean drawContent = child == mContentView;
final boolean ret = super.drawChild(canvas, child, drawingTime);
if (mScrimOpacity > 0 && drawContent
&& mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) {
drawScrim(canvas, child);
}
return ret;
}
项目:GitHub
文件:SwipeBackLayout.java
@Override
public void onViewDragStateChanged(int state) {
if (state == draggingState) return;
if ((draggingState == ViewDragHelper.STATE_DRAGGING || draggingState == ViewDragHelper.STATE_SETTLING) &&
state == ViewDragHelper.STATE_IDLE) {
// the view stopped from moving.
if (draggingOffset == getDragRange()) {
finish();
}
}
draggingState = state;
}
项目:Multi-SwipeToRefreshLayout
文件:SwipeToRefreshLayout.java
public SwipeToRefreshLayout(@NonNull Context context, @NonNull View contentView, int directionMask) {
super(context);
mViewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallback());
mContentView = contentView;
mDirectionMask = directionMask;
enableSwipe = true;
}
项目:Nibo
文件:BottomSheetBehaviorGoogleMapsLike.java
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
// First let the parent lay it out
if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
if (ViewCompat.getFitsSystemWindows(parent) &&
!ViewCompat.getFitsSystemWindows(child)) {
ViewCompat.setFitsSystemWindows(child, true);
}
parent.onLayoutChild(child, layoutDirection);
}
// Offset the bottom sheet
mParentHeight = parent.getHeight();
mMinOffset = Math.max(0, mParentHeight - child.getHeight());
mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);
/**
* New behavior
*/
if (mState == STATE_ANCHOR_POINT) {
ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
} else if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
} else if (mHideable && mState == STATE_HIDDEN) {
ViewCompat.offsetTopAndBottom(child, mParentHeight);
} else if (mState == STATE_COLLAPSED) {
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
}
if (mViewDragHelper == null) {
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
}
mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
return true;
}
项目:RLibrary
文件:SwipeBackLayout.java
@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
if (mListener != null) mListener.onStateChanged(state);
SwipeBackLayout.this.onViewDragStateChanged(state);
switch (state) {
case ViewDragHelper.STATE_IDLE:
onStateIdle();
if (isCaptureAbort) {
onRequestOpened();
} else {
//滚动结束
if (mTargetView.getLeft() < getMinCloseWidth()) {
// State Open
onRequestOpened();
if (mListener != null) mListener.onRequestOpened();
} else {
// State Closed
onRequestClose();
if (mListener != null) mListener.onRequestClose();
}
mTargetView = null;
}
isCaptureAbort = false;
break;
case ViewDragHelper.STATE_DRAGGING:
//开始滚动
onStateDragging();
break;
case ViewDragHelper.STATE_SETTLING:
//滑行中...
break;
}
}
项目:Multi-SwipeToRefreshLayout
文件:SwipeDrawerLayout.java
public SwipeDrawerLayout(@NonNull Context context, @NonNull View contentView, int directionMask) {
super(context);
mViewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallback());
mContentView = contentView;
mDirectionMask = directionMask;
enableSwipe = true;
}
项目:Cable-Android
文件:QuickAttachmentDrawer.java
public QuickAttachmentDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
dragHelper = ViewDragHelper.create(this, 1.f, new ViewDragHelperCallback());
initializeView();
updateHalfExpandedAnchorPoint();
onConfigurationChanged();
}
项目:Multi-SwipeToRefreshLayout
文件:OverScrollLayout.java
public OverScrollLayout(@NonNull Context context, @NonNull View contentView, int directionMask) {
super(context);
mViewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallback());
mContentView = contentView;
mDirectionMask = directionMask;
enableSwipe = true;
}
项目:Multi-SwipeToRefreshLayout
文件:OverScrollLayout.java
@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
if (mLastDragState == ViewDragHelper.STATE_SETTLING && state == ViewDragHelper.STATE_DRAGGING) {
if (mViewDragHelper.smoothSlideViewTo(mContentView, mOriginX, mOriginY)) {
ViewCompat.postInvalidateOnAnimation(OverScrollLayout.this);
}
}
if (state == ViewDragHelper.STATE_IDLE) {
mCurrentDirection = NONE;
}
Log.e("zhou","==============onViewDragStateChanged=================="+state);
mLastDragState = state;
}
项目:switchbutton
文件:FSwitchButton.java
/**
* 根据状态改变view
*
* @param anim
*/
private void updateViewByState(boolean anim)
{
int left = mIsChecked ? getLeftChecked() : getLeftNormal();
if (mViewThumb.getLeft() != left)
{
if (mIsDebug)
{
Log.i(TAG, "updateViewByState anim:" + anim);
}
if (anim)
{
mViewDragHelper.smoothSlideViewTo(mViewThumb, left, mViewThumb.getTop());
} else
{
mViewThumb.layout(left, mViewThumb.getTop(), left + mViewThumb.getMeasuredWidth(), mViewThumb.getBottom());
}
invalidate();
}
if (mViewDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING)
{
//触发滚动成功,不需要立即更新view的可见状态,动画结束后更新
mIsScrollerStarted = true;
} else
{
// 立即更新view的可见状态
updateViewVisibilityByState();
}
mViewThumb.setSelected(mIsChecked);
if (mOnViewPositionChangedCallback != null)
{
mOnViewPositionChangedCallback.onViewPositionChanged(FSwitchButton.this);
}
}
项目:FriendBook
文件:BaseActivity.java
protected void onSlideStateChanged(int state) {
if(getWindowIsTranslucent()){
return;
}
if (state == ViewDragHelper.STATE_DRAGGING) {
Drawable windowBackground = getWindowBackground();
if (windowBackground != null) {
getWindow().setBackgroundDrawable(windowBackground);
} else {
getWindow().setBackgroundDrawable(getDefaultWindowBackground());
}
}
}
项目:PeSanKita-android
文件:QuickAttachmentDrawer.java
@Override
public void onViewDragStateChanged(int state) {
if (dragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
setDrawerState(drawerState);
slideOffset = getTargetSlideOffset();
requestLayout();
}
}
项目:FabulousFilter
文件:ViewPagerBottomSheetBehavior.java
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
ViewCompat.setFitsSystemWindows(child, true);
}
int savedTop = child.getTop();
// First let the parent lay it out
parent.onLayoutChild(child, layoutDirection);
// Offset the bottom sheet
mParentHeight = parent.getHeight();
int peekHeight;
if (mPeekHeightAuto) {
if (mPeekHeightMin == 0) {
mPeekHeightMin = parent.getResources().getDimensionPixelSize(
R.dimen.design_bottom_sheet_peek_height_min);
}
peekHeight = Math.max(mPeekHeightMin, mParentHeight - parent.getWidth() * 9 / 16);
} else {
peekHeight = mPeekHeight;
}
mMinOffset = Math.max(0, mParentHeight - child.getHeight());
mMaxOffset = Math.max(mParentHeight - peekHeight, mMinOffset);
if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
} else if (mHideable && mState == STATE_HIDDEN) {
ViewCompat.offsetTopAndBottom(child, mParentHeight);
} else if (mState == STATE_COLLAPSED) {
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
} else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
}
if (mViewDragHelper == null) {
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
}
mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
return true;
}
项目:FabulousFilter
文件:ViewPagerBottomSheetBehavior.java
private void reset() {
mActivePointerId = ViewDragHelper.INVALID_POINTER;
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
}
项目:Cable-Android
文件:QuickAttachmentDrawer.java
@Override
public void onViewDragStateChanged(int state) {
if (dragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
setDrawerState(drawerState);
slideOffset = getTargetSlideOffset();
requestLayout();
}
}
项目:Discover
文件:SnakeButtonLayout.java
public SnakeButtonLayout(Context context, AttributeSet attrs) {
super(context, attrs);
marginRight = PUtils.getInstance().getMarginRight();
marginBottom = PUtils.getInstance().getMarginBottom();
isVisible = PUtils.getInstance().getVisible();
mDragHelper = ViewDragHelper.create(this, 10f, new MyViewDragCallBack());
controller = ViewController.getInstance();
}
项目:TestChat
文件:DragLayout.java
public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// 如果水平方向的偏移量大于竖直方向的偏移量,就消化该事件,
return Math.abs(distanceX) > Math.abs(distanceY) || super.onScroll(e1, e2, distanceX, distanceY);
}
});
// 永远要记得,该工具实现的拖拉是基于控件位置的改变来实现的
mViewDragHelper = ViewDragHelper.create(this, new DragViewCallBack());
}
项目:TestChat
文件:DragLayout.java
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// 如果符合条件直接截获事件由自己在onTouchEvent方法中处理
// 如果在释放自动滑动的过程中点击,会导致停止动画
boolean result = mViewDragHelper.shouldInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
// 这里是为了防止在滑动的过程中,突然点击,导致被点击的页面停止滑动的的情况发生
if (!result && mViewDragHelper.getViewDragState() == ViewDragHelper.STATE_DRAGGING && ev.getAction() == MotionEvent.ACTION_UP) {
if (getChildAt(2).getLeft() < range / 2) {
closeMenu();
} else {
openMenu();
}
}
return result;
}