本文整理汇总了Java中android.test.TouchUtils.drag方法的典型用法代码示例。如果您正苦于以下问题:Java TouchUtils.drag方法的具体用法?Java TouchUtils.drag怎么用?Java TouchUtils.drag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.test.TouchUtils
的用法示例。
在下文中一共展示了TouchUtils.drag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: swipeHorizontally
import android.test.TouchUtils; //导入方法依赖的package包/类
public static void swipeHorizontally(InstrumentationTestCase test, View v, Direction direction) {
int[] xy = new int[2];
v.getLocationOnScreen(xy);
final int viewWidth = v.getWidth();
final int viewHeight = v.getHeight();
float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
v.getResources().getDisplayMetrics());
float xStart = xy[0] + ((direction == Direction.LEFT) ? (viewWidth - distanceFromEdge) : distanceFromEdge);
float xEnd = xy[0] + ((direction == Direction.LEFT) ? distanceFromEdge : (viewWidth - distanceFromEdge));
float y = xy[1] + (viewHeight / 2.0f);
TouchUtils.drag(test, xStart, xEnd, y, y, DRAG_STEP_COUNT);
}
示例2: swipeVertically
import android.test.TouchUtils; //导入方法依赖的package包/类
public static void swipeVertically(InstrumentationTestCase test, View v, Direction direction) {
int[] xy = new int[2];
v.getLocationOnScreen(xy);
final int viewWidth = v.getWidth();
final int viewHeight = v.getHeight();
float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
v.getResources().getDisplayMetrics());
float x = xy[0] + (viewWidth / 2.0f);
float yStart = xy[1] + ((direction == Direction.UP) ? (viewHeight - distanceFromEdge) : distanceFromEdge);
float yEnd = xy[1] + ((direction == Direction.UP) ? distanceFromEdge : (viewHeight - distanceFromEdge));
TouchUtils.drag(test, x, x, yStart, yEnd, DRAG_STEP_COUNT);
}
示例3: swipeToRight
import android.test.TouchUtils; //导入方法依赖的package包/类
public void swipeToRight(ActivityInstrumentationTestCase2 aitc2){
DisplayMetrics dm = new DisplayMetrics();
testActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
TouchUtils.drag(aitc2, width - 30, 30, height / 2, height / 2, 5);
}
示例4: dragViewToX
import android.test.TouchUtils; //导入方法依赖的package包/类
public static int dragViewToX(InstrumentationTestCase test, View v, int gravity, int toX) {
if (gravity != Gravity.CENTER) {
throw new IllegalArgumentException("Can only handle Gravity.CENTER.");
}
Point point = getCenterOfViewOnScreen(test, v);
final int fromX = point.x;
final int fromY = point.y;
int deltaX = Math.abs(fromX - toX);
TouchUtils.drag(test, fromX, toX, fromY, fromY, deltaX);
return deltaX;
}