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