Java Code Examples for androidx.customview.widget.ViewDragHelper#create()
The following examples show how to use
androidx.customview.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: DragLayout.java From NewFastFrame with Apache License 2.0 | 6 votes |
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 2
Source File: BottomSheetBehaviorGoogleMapsLike.java From CustomBottomSheetBehavior with Apache License 2.0 | 5 votes |
@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 (parent.getFitsSystemWindows() && !child.getFitsSystemWindows()) { child.setFitsSystemWindows(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; }
Example 3
Source File: QuickAttachmentDrawer.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
public QuickAttachmentDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); dragHelper = ViewDragHelper.create(this, 1.f, new ViewDragHelperCallback()); initializeView(); updateHalfExpandedAnchorPoint(); onConfigurationChanged(); }
Example 4
Source File: SwipeDismissBehavior.java From material-components-android with Apache License 2.0 | 5 votes |
private void ensureViewDragHelper(ViewGroup parent) { if (viewDragHelper == null) { viewDragHelper = sensitivitySet ? ViewDragHelper.create(parent, sensitivity, dragCallback) : ViewDragHelper.create(parent, dragCallback); } }
Example 5
Source File: NowPlayingView.java From odyssey with GNU General Public License v3.0 | 5 votes |
public NowPlayingView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDragHelper = ViewDragHelper.create(this, 1f, new BottomDragCallbackHelper()); mPlaybackServiceState = PlaybackService.PLAYSTATE.STOPPED; mLastTrack = new TrackModel(); mServiceConnection = new PlaybackServiceConnection(getContext().getApplicationContext()); mServiceConnection.setNotifier(new ServiceConnectionListener()); }
Example 6
Source File: SwipeBackLayout.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
public SwipeBackLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false); mDragHelper = ViewDragHelper.create(this, 1f, new DragHelperCallback()); mTouchSlop = mDragHelper.getTouchSlop(); setSwipeBackListener(defaultSwipeBackListener); init(context, attrs); }
Example 7
Source File: BottomSheetBehaviorGoogleMapsLike.java From CustomBottomSheetBehavior with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent( CoordinatorLayout parent, V child, MotionEvent event ) { if ( ! child.isShown() ) { return false; } int action = event.getActionMasked(); if ( mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN ) { return true; } // Detect scroll direction for ignoring collapsible if(mLastStableState == STATE_ANCHOR_POINT && action==MotionEvent.ACTION_MOVE) { if(event.getY()>mInitialY && !mCollapsible) { reset(); return false; } } 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 8
Source File: PullDismissLayout.java From StoryView with MIT License | 5 votes |
private void init(@NonNull Context context) { if (!isInEditMode()) { ViewConfiguration vc = ViewConfiguration.get(context); minFlingVelocity = (float) vc.getScaledMinimumFlingVelocity(); dragHelper = ViewDragHelper.create(this, new PullDismissLayout.ViewDragCallback(this)); } }
Example 9
Source File: DuoDrawerLayout.java From duo-navigation-drawer with Apache License 2.0 | 5 votes |
private void initialize() { mLayoutInflater = LayoutInflater.from(getContext()); mViewDragCallback = new ViewDragCallback(); mViewDragHelper = ViewDragHelper.create(this, 1.0f, mViewDragCallback); mViewDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); this.setFocusableInTouchMode(true); this.setClipChildren(false); this.requestFocus(); }
Example 10
Source File: MainDragLayout.java From NewFastFrame with Apache License 2.0 | 5 votes |
public MainDragLayout(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 11
Source File: DragLayout.java From UIWidget with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public DragLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDragHelper = ViewDragHelper.create(this, 0.8f, new ViewDragCallback()); mDensity = getResources().getDisplayMetrics().density * 400; }
Example 12
Source File: BottomSheetBehavior.java From bottomsheetrecycler with Apache License 2.0 | 4 votes |
@Override public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) { if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { child.setFitsSystemWindows(true); } // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (shapeThemingEnabled && materialShapeDrawable != null) { ViewCompat.setBackground(child, materialShapeDrawable); } // Set elevation on MaterialShapeDrawable if (materialShapeDrawable != null) { // Use elevation attr if set on bottomsheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); } if (viewRef == null) { // First layout with this behavior. peekHeightMin = parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min); viewRef = new WeakReference<>(child); } if (viewDragHelper == null) { viewDragHelper = ViewDragHelper.create(parent, dragCallback); } int savedTop = child.getTop(); // First let the parent lay it out parent.onLayoutChild(child, layoutDirection); // Offset the bottom sheet parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); fitToContentsOffset = Math.max(0, parentHeight - child.getHeight()); calculateHalfExpandedOffset(); calculateCollapsedOffset(); if (state == STATE_EXPANDED) { ViewCompat.offsetTopAndBottom(child, getExpandedOffset()); } else if (state == STATE_HALF_EXPANDED) { ViewCompat.offsetTopAndBottom(child, halfExpandedOffset); } else if (hideable && state == STATE_HIDDEN) { ViewCompat.offsetTopAndBottom(child, parentHeight); } else if (state == STATE_COLLAPSED) { ViewCompat.offsetTopAndBottom(child, collapsedOffset); } else if (state == STATE_DRAGGING || state == STATE_SETTLING) { ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop()); } //nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child)); return true; }
Example 13
Source File: SwipeItemView.java From GetApk with MIT License | 4 votes |
private void init(Context context){ viewDragHelper = ViewDragHelper.create(this, new DragHelperCallback()); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); }
Example 14
Source File: PullRefreshLayout.java From FriendCircle with GNU General Public License v3.0 | 4 votes |
private void init() { mDragHelper = ViewDragHelper.create(this, 1.0f, mDrageCallback); mState = new State(); mLayoutState = new LayoutState(); }
Example 15
Source File: SlideInContactsLayout.java From toktok-android with GNU General Public License v3.0 | 4 votes |
public SlideInContactsLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDragHelper = ViewDragHelper.create(this, 1f, new DragHelperCallback()); }
Example 16
Source File: DraggableCoordinatorLayout.java From material-components-android with Apache License 2.0 | 4 votes |
public DraggableCoordinatorLayout(Context context, AttributeSet attrs) { super(context, attrs); viewDragHelper = ViewDragHelper.create(this, dragCallback); }
Example 17
Source File: BottomSheetBehavior.java From material-components-android with Apache License 2.0 | 4 votes |
@Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull V child, int layoutDirection) { if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { child.setFitsSystemWindows(true); } if (viewRef == null) { // First layout with this behavior. peekHeightMin = parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min); setSystemGestureInsets(parent); viewRef = new WeakReference<>(child); // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (shapeThemingEnabled && materialShapeDrawable != null) { ViewCompat.setBackground(child, materialShapeDrawable); } // Set elevation on MaterialShapeDrawable if (materialShapeDrawable != null) { // Use elevation attr if set on bottomsheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); // Update the material shape based on initial state. isShapeExpanded = state == STATE_EXPANDED; materialShapeDrawable.setInterpolation(isShapeExpanded ? 0f : 1f); } updateAccessibilityActions(); if (ViewCompat.getImportantForAccessibility(child) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } } if (viewDragHelper == null) { viewDragHelper = ViewDragHelper.create(parent, dragCallback); } int savedTop = child.getTop(); // First let the parent lay it out parent.onLayoutChild(child, layoutDirection); // Offset the bottom sheet parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); fitToContentsOffset = Math.max(0, parentHeight - child.getHeight()); calculateHalfExpandedOffset(); calculateCollapsedOffset(); if (state == STATE_EXPANDED) { ViewCompat.offsetTopAndBottom(child, getExpandedOffset()); } else if (state == STATE_HALF_EXPANDED) { ViewCompat.offsetTopAndBottom(child, halfExpandedOffset); } else if (hideable && state == STATE_HIDDEN) { ViewCompat.offsetTopAndBottom(child, parentHeight); } else if (state == STATE_COLLAPSED) { ViewCompat.offsetTopAndBottom(child, collapsedOffset); } else if (state == STATE_DRAGGING || state == STATE_SETTLING) { ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop()); } nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child)); return true; }
Example 18
Source File: ViewDragFrame.java From zone-sdk with MIT License | 4 votes |
public ViewDragFrame(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mViewDragHelper = ViewDragHelper.create(this, mCallback); mViewDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); }
Example 19
Source File: ViewDragStudyFrame.java From zone-sdk with MIT License | 4 votes |
public ViewDragStudyFrame(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mViewDragHelper=ViewDragHelper.create(this,mCallback); mViewDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); }
Example 20
Source File: SwipeBackLayout.java From pandora with Apache License 2.0 | 4 votes |
private void init() { mHelper = ViewDragHelper.create(this, new ViewDragCallback()); mShadow = getResources().getDrawable(R.drawable.pd_shadow_left); mHelper.setEdgeTrackingEnabled(EDGE_LEFT); }