本文整理匯總了Java中android.view.DragEvent.getY方法的典型用法代碼示例。如果您正苦於以下問題:Java DragEvent.getY方法的具體用法?Java DragEvent.getY怎麽用?Java DragEvent.getY使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.DragEvent
的用法示例。
在下文中一共展示了DragEvent.getY方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
示例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, "DGV Drag location relative, x: " + mDragLocationOnScreen[0]
+ " y: " + mDragLocationOnScreen[1]);
if (mCurrentDropHandleView != null) {
((DropAcceptable) mCurrentDropHandleView).onDrop(event);
mCurrentDropHandleView = null;
return true;
} else {
return false;
}
}
示例3: 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;
}
示例4: 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;
}
}
示例5: scrollOnDrag
import android.view.DragEvent; //導入方法依賴的package包/類
private void scrollOnDrag(View view, DragEvent event, ScrollView scrollView) {
float ty = view.getTop() + event.getY();
if (isAncestor(scrollView, view)) {
int thresh = scrollView.getHeight() / 6;
if (ty < scrollView.getScrollY() + thresh) {
scrollView.smoothScrollBy(0, -10);
} else if (ty > scrollView.getScrollY() + scrollView.getHeight() - thresh) {
scrollView.smoothScrollBy(0, 10);
}
}
}
示例6: 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);
}
示例7: 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;
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
}
示例12: 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;
}
示例13: 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;
}
示例14: onDrag
import android.view.DragEvent; //導入方法依賴的package包/類
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
mStart = new double[]{event.getX(), event.getY()};
Log.i(TAG, "ACTION_DRAG_STARTED");
// do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
Log.i(TAG, "ACTION_DRAG_ENTERED");
v.setBackgroundResource(enterShape);
break;
case DragEvent.ACTION_DRAG_EXITED:
Log.i(TAG, "ACTION_DRAG_EXITED");
v.setBackgroundResource(normalShape);
break;
case DragEvent.ACTION_DROP:
Log.i(TAG, "ACTION_DROP");
// Dropped, reassign View to ViewGroup
View view = (View) event.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
TileView container = (TileView) v;
mFinal = new double[]{event.getX(), event.getY()};
double[] newPos = coordinatesAfterDragging(container.getScale(), (String) view.getTag());
mTileView.addMarker(view, newPos[0], newPos[1]);
view.setTag(newPos[0]+":"+newPos[1]);
view.setVisibility(View.VISIBLE);
mFinal=null;
mStart=null;
break;
case DragEvent.ACTION_DRAG_ENDED:
Log.i(TAG, "ACTION_DRAG_ENDED");
v.setBackgroundResource(normalShape);
default:
break;
}
return true;
}
示例15: onDrag
import android.view.DragEvent; //導入方法依賴的package包/類
@Override
public boolean onDrag(View v, DragEvent event) {
View view = (View) event.getLocalState();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
if(!(v instanceof FrameLayout)){
view.setVisibility(View.VISIBLE);
return false;
}
if(!(((FrameLayout) v).getChildAt(0) instanceof MapView)){
view.setVisibility(View.VISIBLE);
return false;
}
MapView mapView = (MapView) ((FrameLayout) v).getChildAt(0);
int x = (int) event.getX();
int y = (int) event.getY();
Point point = new Point(x,y);
LatLng latLng = mapView.getMap().getProjection().fromScreenLocation(point);
Resource resource;
ClipData clipData = event.getClipData();
ClipData.Item item = clipData.getItemAt(0);
Bundle extras = item.getIntent().getExtras();
if (extras!=null){
resource = (Resource) extras.getSerializable("resource");
int position = extras.getInt("position");
if (!ResourceCategory.dragabledata.equals(resource.getResourceCategory())){
firstFragment.getResourceList().remove(resource);
firstFragment.getIconBitmapResourceList().remove(position);
firstFragment.getResourceImageAdapter().notifyDataSetChanged();
}
else{
resource.setIdRes(-1);
}
updateResourceOnDrop(resource, latLng, State.planned);
}
break;
case DragEvent.ACTION_DRAG_ENDED:
view.setVisibility(View.VISIBLE);
break;
default:
v.setVisibility(View.VISIBLE);
break;
}
return true;
}