First, Target Activity Code:
layout file is main.xml ....
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Create View...
setContentView(R.layout.main);Add touch event...only view logcat. I check Logcat to touch by tester.
@Override public boolean onTouchEvent(MotionEvent me) { Log.d("surface", "x=" + me.getX() + " y=" + me.getY()); return false; }Second, Tester Activity Code is... It is extends ActivityInstrumentationTestCase2.
This is setUp(). Must need getActivity().
public void setUp() throws Exception { super.setUp(); mActivity = getActivity(); mInstrumentation = getInstrumentation(); }This is surface touch test.
long downtime = SystemClock.uptimeMillis(); long eventtime = SystemClock.uptimeMillis(); MotionEvent event = MotionEvent.obtain(downtime, eventtime, MotionEvent.ACTION_DOWN, 100, 100, 0); mInstrumentation.sendPointerSync(event); eventtime = SystemClock.uptimeMillis() + 1000; event = MotionEvent.obtain(downtime, eventtime, MotionEvent.ACTION_UP, 100, 100, 0); mInstrumentation.sendPointerSync(event);Next, JUnit start then Logcat view follow:
D/surface(1469): x=100.0 y=100.0 D/surface(1469): x=100.0 y=100.0
Target source code is here.
Tester source code is here.
0 件のコメント:
コメントを投稿