当前位置: 首页>>代码示例>>Java>>正文


Java ViewDragHelper类代码示例

本文整理汇总了Java中android.support.v4.widget.ViewDragHelper的典型用法代码示例。如果您正苦于以下问题:Java ViewDragHelper类的具体用法?Java ViewDragHelper怎么用?Java ViewDragHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ViewDragHelper类属于android.support.v4.widget包,在下文中一共展示了ViewDragHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryCaptureView

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
@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;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:18,代码来源:SwipeBackLayout.java

示例2: tryCaptureView

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
@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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:SwipeBackLayout.java

示例3: onViewDragStateChanged

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
@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 ========================
        }
 
开发者ID:zhudongya123,项目名称:WechatChatroomHelper,代码行数:20,代码来源:BGASwipeBackLayout2.java

示例4: BGASwipeBackLayout2

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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);
    }
 
开发者ID:zhudongya123,项目名称:WechatChatroomHelper,代码行数:21,代码来源:BGASwipeBackLayout2.java

示例5: onCreateView

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
@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;
}
 
开发者ID:unixzii,项目名称:android-SpringAnimator,代码行数:24,代码来源:TranslationPreviewFragment.java

示例6: increaseNavigationDrawerEdge

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
/**
 * 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();
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:20,代码来源:Service.java

示例7: onViewDragStateChanged

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:davidmigloz,项目名称:drag-to-close,代码行数:28,代码来源:DragHelperCallback.java

示例8: init

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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;
}
 
开发者ID:yhyzgn,项目名称:Widgets,代码行数:27,代码来源:SlideLayout.java

示例9: SwipeBackLayout

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
/**
 * \
 * 通过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;
}
 
开发者ID:zhouphenix,项目名称:Multi-SwipeBackLayout,代码行数:25,代码来源:SwipeBackLayout.java

示例10: getTopLayoutHeaderView

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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;
}
 
开发者ID:zj565061763,项目名称:pulltorefresh,代码行数:25,代码来源:FPullToRefreshView.java

示例11: getTopLayoutFooterView

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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;
}
 
开发者ID:zj565061763,项目名称:pulltorefresh,代码行数:25,代码来源:FPullToRefreshView.java

示例12: DraggableSquareView

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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();
            }
        }
    };
}
 
开发者ID:funnyzhaov,项目名称:Tribe,代码行数:24,代码来源:DraggableSquareView.java

示例13: setDrawerLeftEdgeSize

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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");
    }
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:22,代码来源:ShoppingCartAdapter.java

示例14: onLayoutChild

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:22,代码来源:BottomSheetBehavior.java

示例15: SideMenu

import android.support.v4.widget.ViewDragHelper; //导入依赖的package包/类
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);
}
 
开发者ID:chemickypes,项目名称:Glitchy,代码行数:21,代码来源:SideMenu.java


注:本文中的android.support.v4.widget.ViewDragHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。