Java Code Examples for android.support.v4.widget.ViewDragHelper#create()

The following examples show how to use android.support.v4.widget.ViewDragHelper#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlideFrameLayout.java    From AccountBook with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 构造方法
 */
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));
}
 
Example 2
Source File: DragLayout.java    From timecat with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: ZSwipeItem.java    From ZListVIew with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: RNBottomSheetBehavior.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
@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;
}
 
Example 5
Source File: BottomSheetBehaviorV2.java    From paper-launcher with MIT License 5 votes vote down vote up
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;
}
 
Example 6
Source File: DragLayout.java    From TestChat with Apache License 2.0 5 votes vote down vote up
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());
        }
 
Example 7
Source File: RNBottomSheetBehavior.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
@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;
}
 
Example 8
Source File: ResideLayout.java    From ResideLayout with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
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>();
}
 
Example 10
Source File: DragHelperGridView.java    From PlusDemo with Apache License 2.0 4 votes vote down vote up
public DragHelperGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
    dragHelper = ViewDragHelper.create(this, new DragCallback());
}
 
Example 11
Source File: DragUpDownLayout.java    From PlusDemo with Apache License 2.0 4 votes vote down vote up
public DragUpDownLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);

    dragHelper = ViewDragHelper.create(this, dragListener);
    viewConfiguration = ViewConfiguration.get(context);
}
 
Example 12
Source File: DragLayout.java    From FakeWeather with Apache License 2.0 4 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    mViewDragHelper = ViewDragHelper.create(this, 1f, new ViewDragCallback());
}
 
Example 13
Source File: SwipeBackLayout.java    From LLApp with Apache License 2.0 4 votes vote down vote up
public SwipeBackLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    viewDragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelperCallBack());
}
 
Example 14
Source File: SwipeListLayout.java    From SwipeListView with Apache License 2.0 4 votes vote down vote up
public SwipeListLayout(Context context, AttributeSet attrs) {
	super(context, attrs);
	mDragHelper = ViewDragHelper.create(this, callback);
}
 
Example 15
Source File: PullBackLayout.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
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();
}
 
Example 16
Source File: ClosableSlidingLayout.java    From MyBlogDemo with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 17
Source File: SlidingUpPanelLayout.java    From Sky31Radio with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: AnchorSheetBehavior.java    From AnchorSheetBehavior with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 19
Source File: SlideLayout.java    From SlideActivity with MIT License 3 votes vote down vote up
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);
}
 
Example 20
Source File: SwipeLayout.java    From RecyclerViewAdapter with Apache License 2.0 2 votes vote down vote up
public SwipeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    viewDragHelper = ViewDragHelper.create(this, new DragHelperCallback());


}