Hi

I have a simple Activity that populates a list.  I simulated the fling
up action so that the list scrolls down using Android
TouchUtils.drag(InstrumentationTestCase test, float fromX, float toX,
float fromY, float toY, int stepCount) API.

The simulation works on a Froyo device.  I can see the list being
scrolled down when the test ran.  But the same test does not work on
Gingerbread device.  The app is launched, but the list is not being
scrolled down at all.   Do you know if it's an issue with Gingerbread
or I need to update my code?

The screen size of both phones are about the same.  So, I don't think
it's the X and Y coordinates that are incorrect.

The app code:
public class ListViewApp extends ListActivity {
        private static String[] items = { "item1", "item2", "item3", "item3",
                        "item4", "item5", "item6", "item7", "item8", "item9", 
"item10",
                        "item11", "item12", "item13", "item14", "item15" , 
"i16", "i17",
"i18", "i19"};
                public void onCreate(Bundle savedInstanceState) {

                        super.onCreate(savedInstanceState);
                        setListAdapter(new ArrayAdapter<String>(this,
                                R.layout.list_view_example, items));
                }
}

The test app:

public class ListViewTests extends
ActivityInstrumentationTestCase2<ListViewApp> {
        private ListViewApp activity;
        private Instrumentation instr;
        private Context context;
        private int screenWidth = 0;
        private int screenHeight = 0;
        private int[] xy = new int[2];

        public ListViewTests() {
                super("com.motorola.ui3dv2.test.auto", ListViewApp.class);
        }

        protected void setUp() throws Exception {
                super.setUp();

                Log.d(TestUtil.TAG, this.getClass().getName() + ".setUp()");

                /*
                 * prepare to send key events to the app under test by turning 
on
touch
                 * mode. Must be done before the first call to getActivity()
                 */

                setActivityInitialTouchMode(true);

                activity = getActivity();
                assertNotNull(activity);

                instr = getInstrumentation();
                assertNotNull("Instrumentation is null.", instr);

                context = instr.getContext();
                assertNotNull("Context is null", context);

                screenWidth = activity.getWindowManager().getDefaultDisplay()
                                .getWidth();
                screenHeight = activity.getWindowManager().getDefaultDisplay()
                                .getHeight();

                Log.d(TestUtil.TAG, "screenWidth: " + screenWidth + " 
screenHeight:
"
                                + screenHeight);
                // to safeguard against grip suppression, don't get too close 
to the
edge
                xy[0] = screenWidth/4;
                xy[1] = screenHeight/10;
                Log.d(TestUtil.TAG, "X coordinate: " + xy[0] + " Y coordinate: "
                                + xy[1]);

                instr.waitForIdleSync();

                // waiting for app to load
                try {
                        Thread.sleep(TestUtil.WAIT_LONG_MILLISEC);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

        @Override
        protected void tearDown() throws Exception {
                Log.d(TestUtil.TAG, this.getClass().getName() + ".tearDown()");

                super.tearDown();
        }

        /**
         * Launch the app and fling up to scroll down the list
         */
        public void testFlingUp() {

                int fromX, toX, fromY, toY = 0;

                fromX = xy[0];
                toX = fromX;
                fromY = (screenHeight - 60);
                toY = (screenHeight / 2);

                TouchUtils.drag(this, fromX, toX, fromY, toY, 1);
                try {
                        Thread.sleep(5000);
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to