Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7740985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:54:48+00:00 2026-06-01T08:54:48+00:00

Currently I am struggling a little with the Unit test framework… what I am

  • 0

Currently I am struggling a little with the Unit test framework…

what I am trying to do

  • I need to simulate 2 clicks on the screen (100,100) and (400,400) at a small duration difference.
  • I need to simulate a longPressClick on the screen Let’s say ( 200, 200 )
  • Upon User click the native code runs and performs pixel manipulation on Bitmap.
  • This test is going to run for multiple pair-sets of points, for analysing the runtime performance of the system

Here’s where I am stuck

  • I am using activityInstrumentationTestCase2 and touchUtils for the user click events.
  • TouchUtils.longClickView(InstrumentationTestCase test, View v) works fine ; I’m able to detect the long pressing event propely , But test-case finishes even before the calculation / rendering is complete in my UI thread ; how do I stop the test from exiting in this case ?
  • How do i simulate 2 / 3 user clicks @ particular location on screen ? cause TouchUtils.clickView(InstrumentationTestCase test, View v) would only simulate the user click in the center of the screen … How to do it properly ?

These are the things I have tried and seems I’m missing out something:

  • TouchUtils.longClickView(InstrumentationTestCase test, View v) works fine…for creating longClickView .. Even I was able to create longClickView() at particular screen location by introducing the timedelay between ACTION_DOWN and ACTION_UP event.. please refer to the code attached
  • I was able to achieve the user clicking event at particular screen location , But I faced a strange issue .. When I am displatching the MotionEvent(100,100) from the test-case.. The framework would always add “-76” in the Y event .. not sure why there was this deviation … I worked around the issue by adding 76 to my input data (100,176) for time being .. did anyone face a similar issue ?
  • Even seems with this approach timing is very critical .. as If i place more delay between ACTION_DOWN and ACTION_UP , the event is detected as longClickPress … and if I put a little less … the “second” single click events ( ACTION_DOWN + ACTION_UP ) gets detected as DoubleTapEvent ..

What should be the right timing combination for ACTION_UP and ACTION_DOWN .. for a single user click event simulation .. ????????

    @Test
    public void testClick(){
    List<Points> pointSequence = new ArrayList<Points>();
    Log.d(TAG, "FirClick Start Timing : " + SystemClock.uptimeMillis());

    pointSequence.add(new Points(100f,176f));
    pointSequence.add(new Points(100f,176f));       
    singleClickSimulation(pointSequence,false);
    }       

    private void singleClickSimulation(List<Points> pointSequence, Boolean addDelay) {

    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    // NOTE : If I do not place this then the event is detected as doubleTap.
    eventTime += 100;
    Instrumentation inst = getInstrumentation();

    MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, pointSequence.get(0).getX(), pointSequence.get(0).getY(), 0);
    inst.sendPointerSync(event);                
    //eventTime = SystemClock.uptimeMillis();
    pointSequence.remove(0);        

    //This delay I have added just to test; whether there is enough time for pixel manipulation or not, actually it would be used only at the end of the run of all the test cases for single user click
    if(addDelay){
    eventTime = SystemClock.uptimeMillis() + 3000;
    }
    eventTime += 25;
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, pointSequence.get(0).getX(), pointSequence.get(0).getY(), 0);
    inst.sendPointerSync(event);
    pointSequence.remove(0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:54:49+00:00Added an answer on June 1, 2026 at 8:54 am

    Partial Answer :

    still to find what’s causing the 76px deviation when creating the user click events.

    I have been able to simuate the single user click event with 50ms difference propely.
    And I had to space 2 clicks by atleast 300ms ; so that “SingleTapConfirmed” can fire on its own for the GeastureDetector class..

    private void singleClickSimulation(List<Points> pointSequence,boolean addDelay) {
    
        long downTime = SystemClock.uptimeMillis();
        // event time MUST be retrieved only by this way!
        long eventTime = SystemClock.uptimeMillis();
    
                // This additional time was added between 2 successive clicks 
                // to make sure that "singleTapConfirmed" event can get fired for "GeastureDetector" class.
        eventTime +=400;
        downTime +=400;
        Instrumentation inst = getInstrumentation();
    
        MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, pointSequence.get(0).getX(), pointSequence.get(0).getY(), 0);
        inst.sendPointerSync(event);                
        //eventTime = SystemClock.uptimeMillis();
        pointSequence.remove(0);        
    
    
                //50 ms timedelay between ACTION_DOWN and ACTION_UP works well      
        eventTime += 50;
        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, pointSequence.get(0).getX(), pointSequence.get(0).getY(), 0);
        inst.sendPointerSync(event);
        pointSequence.remove(0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently struggling to use UI elements in Interface Builder. I keep trying to
Erlang version: R13B01 Currently I'm struggling trying to make Erlang work with SSL. The
I'm currently struggling with one of the bindings I'm trying to add to my
Because I'm currently struggling to learn IBM Rational ClearCase, I'd like to hear your
I am currently struggling with HTTP Session replication on tomcat with complex objects. Some
I'm currently struggling with this Collection was modified; enumeration operation may not execute issue.
I'm currently struggling with different resolutions when building my gallery-application . I've realized the
I'm currently struggling with the development of a todo list (mostly unimportant) within which
My math classes are far behind, and I'm currently struggling to find a decent
I'm pretty new to cocoa for Mac development. I'm currently struggling with getting a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.