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


Java DragEvent.getX方法代码示例

本文整理汇总了Java中android.view.DragEvent.getX方法的典型用法代码示例。如果您正苦于以下问题:Java DragEvent.getX方法的具体用法?Java DragEvent.getX怎么用?Java DragEvent.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.DragEvent的用法示例。


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

示例1: getDragEventType

import android.view.DragEvent; //导入方法依赖的package包/类
/**
 * 获取拖拽触发的执行事件类型
 *
 * @param draggedViewPager 最外层 {@link com.bigfat.draggedviewpager.view.MDA_DraggedViewPager}
 * @param currentPageIndex 当前页索引
 * @param pageIndex        响应拖拽事件item所在页索引
 * @param view             响应拖拽事件的item
 * @param event            拖拽事件
 * @return 拖拽事件类型
 */
public static DragEventType getDragEventType(MDA_DraggedViewPager draggedViewPager, int currentPageIndex, int pageIndex,
    View view, DragEvent event) {
    if (currentPageIndex > 0//有上一页
        && (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting()
        .canBeSwiped(currentPageIndex - 1))//上一页可被交换
        //触摸至上一页//或至触摸至当前页左边界,则切换到上一页
        && (pageIndex < currentPageIndex || (pageIndex == currentPageIndex && event.getX() < view.getWidth() / 8))) {
        return DragEventType.SCROLL_PREVIOUS;
    } else if (currentPageIndex < (draggedViewPager.getContainer().getChildCount() - 1)//在有下一页的前提下
        && (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting()
        .canBeSwiped(currentPageIndex + 1))//下一页可被交换
        //触摸至下一页//或至触摸至当前页右边界,则切换到下一页
        && (pageIndex > currentPageIndex || (pageIndex == currentPageIndex && event.getX() > view.getWidth() / 8 * 7))) {
        return DragEventType.SCROLL_NEXT;
    }
    return DragEventType.DEFAULT;
}
 
开发者ID:yueban,项目名称:DraggedViewPager,代码行数:28,代码来源:DragUtils.java

示例2: findAppropriateDropHandle

import android.view.DragEvent; //导入方法依赖的package包/类
private boolean findAppropriateDropHandle(DragEvent event) {
    Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:"
            + mLocationOnScreen[1]);
    mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX());
    mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY());
    Log.i(TAG, "DLV Drag location relative, x: " + mDragLocationOnScreen[0]
            + " y: " + mDragLocationOnScreen[1]);

    if (mCurrentDropHandleView != null) {
        ((DropAcceptable) mCurrentDropHandleView).onDrop(event);
        mCurrentDropHandleView = null;
        return true;
    } else {
        return false;
    }
}
 
开发者ID:nichollyn,项目名称:amddviews,代码行数:17,代码来源:DropableListView.java

示例3: findAppropriateDropHandle

import android.view.DragEvent; //导入方法依赖的package包/类
private boolean findAppropriateDropHandle(DragEvent event) {
    Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:"
            + mLocationOnScreen[1]);
    mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX());
    mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY());
    Log.i(TAG, "DGV Drag location relative, x: " + mDragLocationOnScreen[0]
            + " y: " + mDragLocationOnScreen[1]);

    if (mCurrentDropHandleView != null) {
        ((DropAcceptable) mCurrentDropHandleView).onDrop(event);
        mCurrentDropHandleView = null;
        return true;
    } else {
        return false;
    }
}
 
开发者ID:nichollyn,项目名称:amddviews,代码行数:17,代码来源:DropableGridView.java

示例4: onDrag

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDrag(final View view, final DragEvent event) {
    //if (catView == null) return true;
    switch (event.getAction()) {
        case DragEvent.ACTION_DROP:
            final View dragView = (View)event.getLocalState();
            final int width = dragView.getWidth();
            final int height = dragView.getHeight();
            final int xPos = (int)(event.getX() - (width / 2));
            final int yPos = (int)(event.getY() - (height / 2));

            final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width, height);
            layoutParams.setMargins(xPos, yPos, 0, 0);
            dragView.setLayoutParams(layoutParams);
            dragView.setVisibility(View.VISIBLE);
            catView = null;
            break;
    }
    return true;
}
 
开发者ID:birbeck,项目名称:kitty-playground,代码行数:21,代码来源:MyActivity.java

示例5: onDragEvent

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDragEvent (DragEvent event) {
    final int action = event.getAction();

    switch (action) {
        case DragEvent.ACTION_DRAG_STARTED:
            mLastX = event.getX();
            mLastY = event.getY();
            return true;

        case DragEvent.ACTION_DRAG_ENTERED:
            return true;

        case DragEvent.ACTION_DRAG_LOCATION:
            mLastX = event.getX();
            mLastY = event.getY();
            mEventListener.onDriverDragMove(event.getX(), event.getY());
            return true;

        case DragEvent.ACTION_DROP:
            mLastX = event.getX();
            mLastY = event.getY();
            mEventListener.onDriverDragMove(event.getX(), event.getY());
            mEventListener.onDriverDragEnd(mLastX, mLastY);
            return true;
        case DragEvent.ACTION_DRAG_EXITED:
            mEventListener.onDriverDragExitWindow();
            return true;

        case DragEvent.ACTION_DRAG_ENDED:
            mEventListener.onDriverDragCancel();
            return true;

        default:
            return false;
    }
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:38,代码来源:DragDriver.java

示例6: hscrollOnDrag

import android.view.DragEvent; //导入方法依赖的package包/类
private void hscrollOnDrag(View view, DragEvent event, HorizontalScrollView scrollView) {
    float tx = view.getLeft() + event.getX();

    if (isAncestor(scrollView, view)) {

        int thresh = scrollView.getWidth() / 6;

        if (tx < scrollView.getScrollX() + thresh) {
            scrollView.smoothScrollBy(-10, 0);
        } else if (tx > scrollView.getScrollX() + scrollView.getWidth() - thresh) {
            scrollView.smoothScrollBy(10,0);
        }
    }
}
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:15,代码来源:MainActivity.java

示例7: handleSystemDragStart

import android.view.DragEvent; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.N)
private void handleSystemDragStart(DragEvent event) {
    if (!FeatureFlags.LAUNCHER3_USE_SYSTEM_DRAG_DRIVER || !Utilities.isNycOrAbove()) {
        return;
    }
    if (mLauncher.isWorkspaceLocked()) {
        return;
    }

    ClipDescription description = event.getClipDescription();
    if (!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
        return;
    }
    ShortcutInfo info = new ShortcutInfo();
    // Set a dummy intent until we get the final value
    info.intent = new Intent();

    // Since we are not going through the workspace for starting the drag, set drag related
    // information on the workspace before starting the drag.
    ExternalDragPreviewProvider previewProvider =
            new ExternalDragPreviewProvider(mLauncher, info);
    mLauncher.getWorkspace().prepareDragWithProvider(previewProvider);

    DragOptions options = new DragOptions();
    options.systemDndStartPoint = new Point((int) event.getX(), (int) event.getY());

    int halfPadding = previewProvider.previewPadding / 2;
    mDragController.startDrag(
            Bitmap.createBitmap(1, 1, Config.ARGB_8888),
            0, 0,
            new AnotherWindowDragSource(mLauncher), info,
            new Point(- halfPadding, halfPadding),
            previewProvider.getPreviewBounds(), 1f, options);
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:35,代码来源:DragLayer.java

示例8: onDrag

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDrag(View v, DragEvent event) {
    if (event.getAction() == DragEvent.ACTION_DROP) {
        View view = (View) event.getLocalState();

        int xLimit = (mWrapper.getWidth() / 2) - mImageOffset;
        int yLimit = (mWrapper.getHeight() / 2) - mImageOffset;

        float dropX = event.getX() - mImageOffset;
        float dropY = event.getY() - mImageOffset;

        view.setTranslationX(dropX);
        view.setTranslationY(dropY);
        view.setVisibility(View.VISIBLE);

        if (dropX < xLimit && dropY < yLimit) {
            // Top left corner
            view.animate().x(mCorner1.getX()).y(mCorner1.getY());
        } else if (dropX > xLimit && dropY < yLimit) {
            // Top right corner
            view.animate().x(mCorner2.getX()).y(mCorner2.getY());
        } else if (dropX < xLimit && dropY > yLimit) {
            // Bottom left corner
            view.animate().x(mCorner3.getX()).y(mCorner3.getY());
        } else if (dropX > xLimit && dropY > yLimit) {
            // Bottom right corner
            view.animate().x(mCorner4.getX()).y(mCorner4.getY());
        }
    }
    return true;
}
 
开发者ID:delizondo,项目名称:CursoAndroid,代码行数:32,代码来源:AnimationsActivity.java

示例9: setState

import android.view.DragEvent; //导入方法依赖的package包/类
private void setState(DragEvent event) {
    float translation = event.getY() - mStatePanelTrack.getTouchPoint().y;
    float alpha = 1.0f - (Math.abs(translation)
            / mStatePanelTrack.getCurrentView().getHeight());
    if (mStatePanelTrack.getOrientation() == LinearLayout.VERTICAL) {
        translation = event.getX() - mStatePanelTrack.getTouchPoint().x;
        alpha = 1.0f - (Math.abs(translation)
                / mStatePanelTrack.getCurrentView().getWidth());
        mStatePanelTrack.getCurrentView().setTranslationX(translation);
    } else {
        mStatePanelTrack.getCurrentView().setTranslationY(translation);
    }
    mStatePanelTrack.getCurrentView().setBackgroundAlpha(alpha);
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:15,代码来源:DragListener.java

示例10: onDrag

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDrag(View view, DragEvent event) {
    // Defines a variable to store the action type for the incoming event
    final int action = event.getAction();
    // Handles each of the expected events
    switch(action) {
        case DragEvent.ACTION_DRAG_STARTED:
            return true;
        case DragEvent.ACTION_DRAG_ENTERED:
            return true;
        case DragEvent.ACTION_DRAG_LOCATION:
            return true;
        case DragEvent.ACTION_DRAG_EXITED:
            return true;
        case DragEvent.ACTION_DROP:
            ClipData cd = event.getClipData();
            String tag = cd.getItemAt(0).getText().toString();
            int id = Integer.parseInt(tag);
            View marker = findViewWithTag(tag);
            //marker.setX(event.getX());
            float x = event.getX() - marker.getWidth()/2;
            float pos = mMarkerMediator.onPositionRequested(id, x);
            mMarkerMediator.onPositionChanged(id, pos);
            invalidate();
            return true;
        case DragEvent.ACTION_DRAG_ENDED:
            return true;
        // An unknown action type was received.
        default:
            Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
            break;
    }

    return false;
}
 
开发者ID:WycliffeAssociates,项目名称:translationRecorder,代码行数:36,代码来源:DraggableViewFrame.java

示例11: onDrag

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
        public boolean onDrag(View v, DragEvent event) {
            int dragEvent = event.getAction();

            switch (dragEvent) {
                case DragEvent.ACTION_DRAG_ENTERED:
                    Log.i("DragEvent", "Entered");
                    break;
                case DragEvent.ACTION_DRAG_ENDED:
                    Log.i("DragEvent", "Ended");
                    break;
                case DragEvent.ACTION_DRAG_STARTED:
                    GraphicUnitWidget draggedView = (GraphicUnitWidget) event.getLocalState();
                    Log.i("DragEvent", "Started at LAMP = " + draggedView.getX() + "/" + draggedView.getY() + "   EVENT = " + event.getX() + "/" + event.getY());
                    dragXDiff = event.getX() - draggedView.getX();
                    dragYDiff = event.getY() - draggedView.getY();
                    //stop displaying the view where it was before it was dragged
                    draggedView.setVisibility(View.INVISIBLE);
                    break;
                case DragEvent.ACTION_DROP:
                    GraphicUnitWidget droppedView = (GraphicUnitWidget) event.getLocalState();
                    Log.i("DragEvent", "Dropped at LAMP = " + Math.round(event.getX() + dragXDiff) + "/" + Math.round(event.getY() + dragYDiff) + "   EVENT = " + event.getX() + "/" + event.getY());
                    Log.i("DragEvent", "Drop target at TOP = " + v.getTop() + "   LEFT = " + v.getLeft());
//                    droppedView.setX(Math.round(event.getX() + dragXDiff + v.getLeft() - 70));
//                    droppedView.setY(Math.round(event.getY() + dragYDiff/* + v.getTop()*/ - 50));
                    //TODO - Fix this temporary hard coded adjustment
                    droppedView.setX(Math.round(event.getX())-30);
                    droppedView.setY(Math.round(event.getY())-30);

                    droppedView.setVisibility(View.VISIBLE);

                    setRoomRelativePositions(droppedView);

                    Log.d("Unit", "Dropped view pos X/Y = " + droppedView.getX() + "/" + droppedView.getY());
                    Log.d("UnitPos", "dropped REL: " + droppedView.getgUnit().getRoomRelativeX() + "/" + droppedView.getgUnit().getRoomRelativeY() + "   Calc: X=(" + mRoomView.getScaledBitmapWidth() + "/(" + droppedView.getX() + "-" + mRoomView.getScaledBitmapX() + ")  Y=(" + mRoomView.getScaledBitmapHeight() + "/(" + droppedView.getY() + "-" + mRoomView.getScaledBitmapY() + ")");
                    break;
            }
            return true;
        }
 
开发者ID:tonyalpskog,项目名称:OpenHAB_Room_Flipper,代码行数:40,代码来源:UnitPlacementFragment.java

示例12: onDragStart

import android.view.DragEvent; //导入方法依赖的package包/类
private boolean onDragStart(DragEvent event) {
    if (!mRequest.isValid()) {
        return false;
    }
    ClipDescription desc =  event.getClipDescription();
    if (desc == null || !desc.hasMimeType(getMimeType())) {
        return false;
    }

    final PendingAddItemInfo item;
    if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT) {
        item = new PendingAddShortcutInfo(
                new PinShortcutRequestActivityInfo(mRequest, mLauncher));
    } else {
        // mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET
        LauncherAppWidgetProviderInfo providerInfo =
                LauncherAppWidgetProviderInfo.fromProviderInfo(
                        mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher));
        final PinWidgetFlowHandler flowHandler =
                new PinWidgetFlowHandler(providerInfo, mRequest);
        item = new PendingAddWidgetInfo(providerInfo) {
            @Override
            public WidgetAddFlowHandler getHandler() {
                return flowHandler;
            }
        };
    }
    View view = new View(mLauncher);
    view.setTag(item);

    Point downPos = new Point((int) event.getX(), (int) event.getY());
    DragOptions options = new DragOptions();
    options.systemDndStartPoint = downPos;
    options.preDragCondition = this;

    // We use drag event position as the screenPos for the preview image. Since mPreviewRect
    // already includes the view position relative to the drag event on the source window,
    // and the absolute position (position relative to the screen) of drag event is same
    // across windows, using drag position here give a good estimate for relative position
    // to source window.
    PendingItemDragHelper dragHelper = new PendingItemDragHelper(view);
    if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET) {
        dragHelper.setPreview(getPreview(mRequest));
    }

    dragHelper.startDrag(new Rect(mPreviewRect),
            mPreviewBitmapWidth, mPreviewViewWidth, downPos,  this, options);
    mDragStartTime = SystemClock.uptimeMillis();
    return true;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:51,代码来源:PinItemDragListener.java

示例13: onDragEvent

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDragEvent (DragEvent event) {
    final int action = event.getAction();

    switch (action) {
        case DragEvent.ACTION_DRAG_STARTED:
            mLastX = event.getX();
            mLastY = event.getY();
            return true;

        case DragEvent.ACTION_DRAG_ENTERED:
            return true;

        case DragEvent.ACTION_DRAG_LOCATION:
            mLastX = event.getX();
            mLastY = event.getY();
            mEventListener.onDriverDragMove(event.getX(), event.getY());
            return true;

        case DragEvent.ACTION_DROP:
            mLastX = event.getX();
            mLastY = event.getY();
            mReceivedDropEvent =
                    updateInfoFromClipData(event.getClipData(), event.getClipDescription());
            return mReceivedDropEvent;

        case DragEvent.ACTION_DRAG_EXITED:
            mEventListener.onDriverDragExitWindow();
            return true;

        case DragEvent.ACTION_DRAG_ENDED:
            if (mReceivedDropEvent) {
                mEventListener.onDriverDragEnd(mLastX, mLastY, null);
            } else {
                mEventListener.onDriverDragCancel();
            }
            return true;

        default:
            return false;
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:43,代码来源:DragDriver.java

示例14: onDragEvent

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDragEvent(@NonNull DragEvent event) {
    PlenProgramAdapter adapter = mAdapter.orElseThrow(AssertionError::new);

    ClipDescription clipDescription = event.getClipDescription();
    if (clipDescription == null || !DRAG_DATA_LABEL.equals(clipDescription.getLabel())) {
        return false;
    }

    int x = (int) event.getX();
    int y = (int) event.getY();
    int position = pointToPosition(x, y);

    switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_ENTERED:
            if (adapter.positionOfBlankRow() == INVALID_POSITION) {
                adapter.moveBlankRowToLast();
            }
            break;

        case DragEvent.ACTION_DRAG_LOCATION:
            removeCallbacks(mRemoveBlankRowCallback);
            // ドロップ予定地に空白行
            if (position != INVALID_POSITION) {
                View view = getChildAt(position - getFirstVisiblePosition());
                double viewCenter = view.getY() + view.getHeight() / 2.;
                if (Math.abs(y - viewCenter) < view.getHeight() / 2.) {
                    adapter.moveBlankRow(position);
                }
            }
            // 端にドラッグすると自動スクロール
            View child = getChildAt(0);
            double scrollZone = child != null ? child.getHeight() : 0;
            final int firstPosition = getFirstVisiblePosition();
            final int lastPosition = getLastVisiblePosition();
            if (y < scrollZone) smoothScrollToPosition(firstPosition - 1);
            if (y > getHeight() - scrollZone) smoothScrollToPosition(lastPosition + 1);
            break;

        case DragEvent.ACTION_DROP:
            getDragData(event.getClipData()).ifPresent(adapter::dropToBlankRow);
            break;

        case DragEvent.ACTION_DRAG_ENDED:
        case DragEvent.ACTION_DRAG_EXITED:
            adapter.removeBlankRow();
            break;
    }
    return true;
}
 
开发者ID:plenprojectcompany,项目名称:plen-Scenography_Android,代码行数:51,代码来源:PlenProgramView.java

示例15: onDrag

import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDrag(View view, DragEvent event) {
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    if(event.getAction() == DragEvent.ACTION_DRAG_ENTERED && view
            .getId() == R.id.viewholder_card) {
        final RecyclerView rv = (RecyclerView) view.getParent();
        final CardAdapter ca = (CardAdapter) rv.getAdapter();
        final Rect r = new Rect();
        ((NestedScrollView) rv.getParent().getParent()).getHitRect(r);
        int first = -1;
        int last = -1;
        for(int i = 0; i < rv.getAdapter().getItemCount(); i++) {
            if(rv.getChildAt(i).getLocalVisibleRect(r)) {
                if(first == -1) {
                    first = i;
                } else if(i == rv.getAdapter().getItemCount() - 1) {
                    last = i;
                }
            } else if(first != -1) {
                last = i - 1;
                break;
            }
        }
        final int tp = ca.indexOf((int) view.getTag());
        final float relativePos = event.getY() - view.getY();
        final int[] pos = new int[2];
        if(tp == first) {
            rv.getChildAt(first).getLocationOnScreen(pos);
            if(pos[1] + relativePos < 0.1 * metrics.heightPixels) {
                dragUp();
            }

        } else if(tp == last) {
            rv.getChildAt(last).getLocationOnScreen(pos);
            if(pos[1] + relativePos > 0.9 * metrics.heightPixels) {
                dragDown();
            }

        }

    } else if(event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
        if(event.getX() / metrics.widthPixels > 0.85f && System
                .nanoTime() - mLastPageChange > 5E8) {
            dragRight();
            mLastPageChange = System.nanoTime();
        } else if(event.getX() / metrics.widthPixels < 0.15f && System
                .nanoTime() - mLastPageChange > 5E8) {
            dragLeft();
            mLastPageChange = System.nanoTime();
        }
    }
    return true;
}
 
开发者ID:tpb1908,项目名称:AndroidProjectsClient,代码行数:54,代码来源:ProjectActivity.java


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