當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。