本文整理汇总了Java中org.oscim.event.MotionEvent.getX方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getX方法的具体用法?Java MotionEvent.getX怎么用?Java MotionEvent.getX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.oscim.event.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getX方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInputEvent
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
@Override
public void onInputEvent(Event e, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (action == MotionEvent.ACTION_DOWN) {
downX = motionEvent.getX() - mMap.getWidth() / 2;
downY = motionEvent.getY() - mMap.getHeight() / 2;
}
if (mActiveMarker == null)
return;
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
// Update corresponding waypoint
Waypoint waypoint = (Waypoint) mActiveMarker.getUid();
waypoint.setCoordinates(mActiveMarker.getPoint());
onWaypointSave(waypoint);
mActiveMarker = null;
// Unshift map to its original position
mMap.animator().animateTo(MAP_POSITION_ANIMATION_DURATION / 2, mMap.viewport().fromScreenPoint(mMap.getWidth() / 2, mMap.getHeight() / 2 - mFingerTipSize), 1, true);
mMap.getEventLayer().enableMove(true);
} else if (action == MotionEvent.ACTION_MOVE) {
float eventX = motionEvent.getX() - deltaX;
float eventY = motionEvent.getY() - deltaY - 3 * mFingerTipSize;
mActiveMarker.setPoint(mMap.viewport().fromScreenPoint(eventX, eventY));
mMarkerLayer.updateItems();
mMap.updateMap(true);
}
}
示例2: onInputEvent
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
@Override
public void onInputEvent(Event event, MotionEvent motionEvent) {
if ((motionEvent.getAction() == MotionEvent.ACTION_CANCEL || motionEvent.getAction() == MotionEvent.ACTION_UP) && currentlyDraggedItem != null) {
currentlyDraggedItem.onDragStop();
currentlyDraggedItem = null;
}
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
dragLastX = motionEvent.getX();
dragLastY = motionEvent.getY();
}
if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && currentlyDraggedItem != null) {
Point out = new Point();
mapView.map().viewport().toScreenPoint(GmsMapsTypeHelper.fromLatLng(currentlyDraggedItem.getPosition()), out);
out.x += mapView.getWidth() / 2;
out.y += mapView.getHeight() / 2;
float mx = motionEvent.getX() - dragLastX;
float my = motionEvent.getY() - dragLastY;
currentlyDraggedItem.setPosition(GmsMapsTypeHelper.toLatLng(mapView.map().viewport().fromScreenPoint((float) out.getX() + mx, (float) out.getY() + my)));
currentlyDraggedItem.onDragProgress();
dragLastX += mx;
dragLastY += my;
}
}
示例3: updateMulti
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
private void updateMulti(MotionEvent e) {
int cnt = e.getPointerCount();
mPrevX1 = e.getX(0);
mPrevY1 = e.getY(0);
if (cnt == 2) {
mDoScale = false;
mDoRotate = false;
mDoTilt = false;
mCanScale = mEnableScale;
mCanRotate = mEnableRotate;
mCanTilt = mEnableTilt;
mPrevX2 = e.getX(1);
mPrevY2 = e.getY(1);
double dx = mPrevX1 - mPrevX2;
double dy = mPrevY1 - mPrevY2;
mAngle = Math.atan2(dy, dx);
mPrevPinchWidth = Math.sqrt(dx * dx + dy * dy);
}
}
示例4: activateSelectedItems
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
/**
* When a content sensitive action is performed the content item needs to be
* identified. This method does that and then performs the assigned task on
* that item.
*
* @return true if event is handled false otherwise
*/
protected boolean activateSelectedItems(MotionEvent event, ActiveItem task) {
int size = mItemList.size();
if (size == 0)
return false;
int eventX = (int) event.getX() - mMap.getWidth() / 2;
int eventY = (int) event.getY() - mMap.getHeight() / 2;
Viewport mapPosition = mMap.viewport();
Box box = mapPosition.getBBox(null, 128);
box.map2mercator();
box.scale(1E6);
int nearest = -1;
int inside = -1;
double insideY = -Double.MAX_VALUE;
/* squared dist: 50*50 pixel ~ 2mm on 400dpi */
double dist = 2500;
for (int i = 0; i < size; i++) {
Item item = mItemList.get(i);
if (!box.contains(item.getPoint().longitudeE6,
item.getPoint().latitudeE6))
continue;
mapPosition.toScreenPoint(item.getPoint(), mTmpPoint);
float dx = (float) (mTmpPoint.x - eventX);
float dy = (float) (mTmpPoint.y - eventY);
MarkerSymbol it = item.getMarker();
if (it == null)
it = mMarkerRenderer.mDefaultMarker;
if (it.isInside(dx, dy)) {
if (mTmpPoint.y > insideY) {
insideY = mTmpPoint.y;
inside = i;
}
}
if (inside >= 0)
continue;
double d = dx * dx + dy * dy;
if (d > dist)
continue;
dist = d;
nearest = i;
}
if (inside >= 0)
nearest = inside;
if (nearest >= 0 && task.run(nearest)) {
mMarkerRenderer.update();
mMap.render();
return true;
}
return false;
}
示例5: onTouchEvent
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
public boolean onTouchEvent(MotionEvent e) {
int action = getAction(e);
if (action == MotionEvent.ACTION_DOWN) {
mMap.animator().cancel();
mStartMove = -1;
mDoubleTap = false;
mDragZoom = false;
mPrevX1 = e.getX(0);
mPrevY1 = e.getY(0);
mDown = true;
return true;
}
if (!(mDown || mDoubleTap)) {
/* no down event received */
return false;
}
if (action == MotionEvent.ACTION_MOVE) {
onActionMove(e);
return true;
}
if (action == MotionEvent.ACTION_UP) {
mDown = false;
if (mDoubleTap && !mDragZoom) {
float pivotX = 0, pivotY = 0;
if (!mFixOnCenter) {
pivotX = mPrevX1 - mMap.getWidth() / 2;
pivotY = mPrevY1 - mMap.getHeight() / 2;
}
/* handle double tap zoom */
mMap.animator().animateZoom(300, 2, pivotX, pivotY);
} else if (mStartMove > 0) {
/* handle fling gesture */
mTracker.update(e.getX(), e.getY(), e.getTime());
float vx = mTracker.getVelocityX();
float vy = mTracker.getVelocityY();
/* reduce velocity for short moves */
float t = e.getTime() - mStartMove;
if (t < FLING_MIN_THREHSHOLD) {
t = t / FLING_MIN_THREHSHOLD;
vy *= t * t;
vx *= t * t;
}
doFling(vx, vy);
}
return true;
}
if (action == MotionEvent.ACTION_CANCEL) {
return false;
}
if (action == MotionEvent.ACTION_POINTER_DOWN) {
mStartMove = -1;
updateMulti(e);
return true;
}
if (action == MotionEvent.ACTION_POINTER_UP) {
updateMulti(e);
return true;
}
return false;
}
示例6: activateSelectedItems
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
/**
* When a content sensitive action is performed the content item needs to be
* identified. This method does that and then performs the assigned task on
* that item.
*
* @return true if event is handled false otherwise
*/
protected boolean activateSelectedItems(MotionEvent event, ActiveItem task) {
int size = mItemList.size();
if (size == 0)
return false;
int eventX = (int) event.getX() - mMap.getWidth() / 2;
int eventY = (int) event.getY() - mMap.getHeight() / 2;
Viewport mapPosition = mMap.viewport();
BoundingBox bbox = mapPosition.getBBox(128);
int nearest = -1;
int inside = -1;
double insideY = -Double.MAX_VALUE;
/* squared dist: 50*50 pixel ~ 2mm on 400dpi */
double dist = 2500;
for (int i = 0; i < size; i++) {
Item item = mItemList.get(i);
if (!bbox.contains(item.geoPoint))
continue;
mapPosition.toScreenPoint(item.getPoint(), mTmpPoint);
float dx = (float) (mTmpPoint.x - eventX);
float dy = (float) (mTmpPoint.y - eventY);
MarkerSymbol it = item.getMarker();
if (it == null)
it = mMarkerRenderer.mDefaultMarker;
if (it.isInside(dx, dy)) {
if (mTmpPoint.y > insideY) {
insideY = mTmpPoint.y;
inside = i;
}
}
if (inside >= 0)
continue;
double d = dx * dx + dy * dy;
if (d > dist)
continue;
dist = d;
nearest = i;
}
if (inside >= 0)
nearest = inside;
if (nearest >= 0 && task.run(nearest)) {
mMarkerRenderer.update();
mMap.render();
return true;
}
return false;
}
示例7: onInputEvent
import org.oscim.event.MotionEvent; //导入方法依赖的package包/类
@Override
public void onInputEvent(Event event, MotionEvent e) {
int action = e.getAction() & MotionEvent.ACTION_MASK;
if ((action == MotionEvent.ACTION_CANCEL)) {
cancel();
return;
}
if (mLongpressTimer != null) {
// any pointer up while long press detection
// cancels timer
if (action == MotionEvent.ACTION_POINTER_UP
|| action == MotionEvent.ACTION_UP) {
cancel();
return;
}
// two fingers must still be down, tested
// one above.
if (action == MotionEvent.ACTION_MOVE) {
// update pointer positions
// int idx1 = e.findPointerIndex(mPointer1);
// int idx2 = e.findPointerIndex(mPointer2);
mCurX1 = e.getX(0);
mCurY1 = e.getY(0);
mCurX2 = e.getX(1);
mCurY2 = e.getY(1);
// cancel if moved one finger more than 50 pixel
float maxSq = 10 * 10;
float d = (mCurX1 - mPrevX1) * (mCurX1 - mPrevX1)
+ (mCurY1 - mPrevY1) * (mCurY1 - mPrevY1);
if (d > maxSq) {
cancel();
return;
}
d = (mCurX2 - mPrevX2) * (mCurX2 - mPrevX2)
+ (mCurY2 - mPrevY2) * (mCurY2 - mPrevY2);
if (d > maxSq) {
cancel();
return;
}
}
}
if ((action == MotionEvent.ACTION_POINTER_DOWN)
&& (e.getPointerCount() == 2)) {
// App.log.debug("down");
// keep track of pointer ids, only
// use these for gesture, ignoring
// more than two pointer
// mPointer1 = e.getPointerId(0);
// mPointer2 = e.getPointerId(1);
if (mLongpressTimer == null) {
// start timer, keep initial down position
mCurX1 = mPrevX1 = e.getX(0);
mCurY1 = mPrevY1 = e.getY(0);
mCurX2 = mPrevX2 = e.getX(1);
mCurY2 = mPrevY2 = e.getY(1);
runLongpressTimer();
}
}
}