本文整理匯總了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;
}
示例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;
}
示例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 ========================
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
};
}
示例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");
}
}
示例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;
}
示例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);
}