android.support.v4.widget.ViewDragHelper#create ( )源码实例Demo

下面列出了android.support.v4.widget.ViewDragHelper#create ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ZListVIew   文件: ZSwipeItem.java
public ZSwipeItem(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	mDragHelper = ViewDragHelper.create(this, mDragHelperCallback);

	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.ZSwipeItem);
	// 默认是右边缘检测
	int ordinal = a.getInt(R.styleable.ZSwipeItem_drag_edge,
			DragEdge.Right.ordinal());
	mDragEdge = DragEdge.values()[ordinal];
	// 默认模式是拉出
	ordinal = a.getInt(R.styleable.ZSwipeItem_show_mode,
			ShowMode.PullOut.ordinal());
	mShowMode = ShowMode.values()[ordinal];

	mHorizontalSwipeOffset = a.getDimension(
			R.styleable.ZSwipeItem_horizontalSwipeOffset, 0);
	mVerticalSwipeOffset = a.getDimension(
			R.styleable.ZSwipeItem_verticalSwipeOffset, 0);

	a.recycle();
}
 
源代码2 项目: timecat   文件: DragLayout.java
public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, dragLayout, 0, 0);
    bottomDragVisibleHeight = (int) typedArray.getDimension(R.styleable.dragLayout_bottomDragVisibleHeight, 0);
    bottomExtraIndicatorHeight = (int) typedArray.getDimension(R.styleable.dragLayout_bottomExtraIndicatorHeight, 0);
    typedArray.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();
}
 
源代码3 项目: AccountBook   文件: SlideFrameLayout.java
/**
 * 构造方法
 */
public SlideFrameLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    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(dip2px(MIN_FLING_VELOCITY));
    setEdgeSize(dip2px(20));

    mPreviousSnapshotView = new PreviewView(context);
    addView(mPreviousSnapshotView, new LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.MATCH_PARENT));
}
 
@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 (mAnchorEnabled && mState == STATE_ANCHOR_POINT) {
    toggleHeaderColor(true);
    ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
  } else if (mState == STATE_EXPANDED) {
    toggleHeaderColor(true);
    ViewCompat.offsetTopAndBottom(child, mMinOffset);
  } else if (mHideable && mState == STATE_HIDDEN) {
    ViewCompat.offsetTopAndBottom(child, mParentHeight);
  } else if (mState == STATE_COLLAPSED) {
    toggleHeaderColor(false);
    ViewCompat.offsetTopAndBottom(child, mMaxOffset);
  }
  if ( mViewDragHelper == null ) {
    mViewDragHelper = ViewDragHelper.create( parent, mDragCallback );
  }
  mViewRef = new WeakReference<>(child);
  mNestedScrollingChildRef = new WeakReference<>( findScrollingChild( child ) );
  return true;
}
 
public TranslucentDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    final float density = getResources().getDisplayMetrics().density;
    mMinDrawerMargin = (int) (MIN_DRAWER_MARGIN * density + 0.5f);
    final float minVel = MIN_FLING_VELOCITY * density;

    mLeftCallback = new ViewDragCallback(Gravity.LEFT);
    mRightCallback = new ViewDragCallback(Gravity.RIGHT);

    mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback);
    mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT);
    mLeftDragger.setMinVelocity(minVel);
    mLeftCallback.setDragger(mLeftDragger);

    mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback);
    mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT);
    mRightDragger.setMinVelocity(minVel);
    mRightCallback.setDragger(mRightDragger);

    // So that we can catch the back button
    setFocusableInTouchMode(true);

    ViewCompat.setImportantForAccessibility(this,
            ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewGroupCompat.setMotionEventSplittingEnabled(this, false);
    if (ViewCompat.getFitsSystemWindows(this)) {
        IMPL.configureApplyInsets(this);
        mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context);
    }

    mDrawerElevation = DRAWER_ELEVATION * density;

    mNonDrawerViews = new ArrayList<View>();
}
 
源代码6 项目: ResideLayout   文件: ResideLayout.java
public ResideLayout(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);

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}
 
@Override
public boolean onTouchEvent( CoordinatorLayout parent, V child, MotionEvent event ) {
  if ( ! child.isShown() ) {
    return false;
  }

  int action = MotionEventCompat.getActionMasked( event );
  if ( mState == STATE_DRAGGING  &&  action == MotionEvent.ACTION_DOWN ) {
    toggleHeaderColor(true);
    return true;
  }

  if (mViewDragHelper == null) {
    mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
  }

  mViewDragHelper.processTouchEvent( event );

  if ( action == MotionEvent.ACTION_DOWN ) {
    reset();
  }

  // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
  // to capture the bottom sheet in case it is not captured and the touch slop is passed.
  if ( action == MotionEvent.ACTION_MOVE  &&  ! mIgnoreEvents ) {
    if ( Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop() ) {
      mViewDragHelper.captureChildView( child, event.getPointerId(event.getActionIndex()) );
    }
  }
  return ! mIgnoreEvents;
}
 
源代码8 项目: 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());
        }
 
源代码9 项目: paper-launcher   文件: BottomSheetBehaviorV2.java
public boolean onLayoutChildFixed(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(
                    android.support.design.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;
}
 
源代码10 项目: LLApp   文件: SwipeBackLayout.java
public SwipeBackLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    viewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallBack());
}
 
源代码11 项目: PlusDemo   文件: DragHelperGridView.java
public DragHelperGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
    dragHelper = ViewDragHelper.create(this, new DragCallback());
}
 
源代码12 项目: PlusDemo   文件: DragUpDownLayout.java
public DragUpDownLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);

    dragHelper = ViewDragHelper.create(this, dragListener);
    viewConfiguration = ViewConfiguration.get(context);
}
 
源代码13 项目: FakeWeather   文件: DragLayout.java
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mViewDragHelper = ViewDragHelper.create(this, 1f, new ViewDragCallback());
}
 
源代码14 项目: SwipeListView   文件: SwipeListLayout.java
public SwipeListLayout(Context context, AttributeSet attrs) {
	super(context, attrs);
	mDragHelper = ViewDragHelper.create(this, callback);
}
 
源代码15 项目: ForPDA   文件: PullBackLayout.java
public PullBackLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    dragger = ViewDragHelper.create(this, 1f / 8f, new ViewDragCallback());
    minimumFlingVelocity = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();
}
 
源代码16 项目: MyBlogDemo   文件: ClosableSlidingLayout.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public ClosableSlidingLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDragHelper = ViewDragHelper.create(this, 0.8f, new ViewDragCallback());
    MINVEL = getResources().getDisplayMetrics().density * 400;
}
 
源代码17 项目: Sky31Radio   文件: SlidingUpPanelLayout.java
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if(isInEditMode()) {
        mShadowDrawable = null;
        mDragHelper = null;
        return;
    }

    if (attrs != null) {
        TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS);

        if (defAttrs != null) {
            int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY);
            if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {
                throw new IllegalArgumentException("gravity must be set to either top or bottom");
            }
            mIsSlidingUp = gravity == Gravity.BOTTOM;
        }

        defAttrs.recycle();

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout);

        if (ta != null) {
            mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_panelHeight, -1);
            mSlidePanelOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_slidePanelOffset, DEFAULT_SLIDE_PANEL_OFFSET);
            mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1);
            mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_paralaxOffset, -1);
            mDirectOffset = ta.getBoolean(R.styleable.SlidingUpPanelLayout_directOffset,DEFAULT_DIRECT_OFFSET_FLAG);

            mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY);
            mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR);

            mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1);
            mDragViewClickable = ta.getBoolean(R.styleable.SlidingUpPanelLayout_dragViewClickable, DEFAULT_DRAG_VIEW_CLICKABLE);

            mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_overlay,DEFAULT_OVERLAY_FLAG);

            mAnchorPoint = ta.getFloat(R.styleable.SlidingUpPanelLayout_anchorPoint, DEFAULT_ANCHOR_POINT);

            mSlideState = SlideState.values()[ta.getInt(R.styleable.SlidingUpPanelLayout_initialState, DEFAULT_SLIDE_STATE.ordinal())];
        }

        ta.recycle();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    if (mPanelHeight == -1) {
        mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f);
    }
    if (mShadowHeight == -1) {
        mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f);
    }
    if (mParallaxOffset == -1) {
        mParallaxOffset = (int) (DEFAULT_PARALAX_OFFSET * density);
    }
    // If the shadow height is zero, don't show the shadow
    if (mShadowHeight > 0) {
        if (mIsSlidingUp) {
            mShadowDrawable = getResources().getDrawable(R.drawable.above_shadow);
        } else {
            mShadowDrawable = getResources().getDrawable(R.drawable.below_shadow);
        }

    } else {
        mShadowDrawable = null;
    }

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(mMinFlingVelocity * density);

    mIsSlidingEnabled = true;
}
 
源代码18 项目: AnchorSheetBehavior   文件: AnchorSheetBehavior.java
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
    if (getFitsSystemWindows(parent) && !getFitsSystemWindows(child)) {
        child.setFitsSystemWindows(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(
                    android.support.design.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);
    mAnchorOffset = (int) Math.max(mParentHeight * mAnchorThreshold, mMinOffset);
    if (mState == STATE_EXPANDED) {
        offsetTopAndBottom(child, mMinOffset);
    } else if (mState == STATE_ANCHOR) {
        offsetTopAndBottom(child, mAnchorOffset);
    } else if ((mHideable && mState == STATE_HIDDEN) || mState == STATE_FORCE_HIDDEN) {
        offsetTopAndBottom(child, mParentHeight);
    } else if (mState == STATE_COLLAPSED) {
        offsetTopAndBottom(child, mMaxOffset);
    } else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
        offsetTopAndBottom(child, savedTop - child.getTop());
    }
    if (mViewDragHelper == null) {
        mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
    }
    mViewRef = new WeakReference<>(child);
    mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
    return true;
}
 
源代码19 项目: SlideActivity   文件: SlideLayout.java
public SlideLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = context.getResources().getDisplayMetrics().density;

    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);
}
 
源代码20 项目: RecyclerViewAdapter   文件: SwipeLayout.java
public SwipeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    viewDragHelper = ViewDragHelper.create(this, new DragHelperCallback());


}