title: Android Espresso, How can I perform onLongClick and slideDown continued?
body: <p>I mean, I can perform the two actions sequentially but in the middle there is an <code>ACTION_UP</code> MotionEvent where I removed the OnTouchListener I'm using on the view</p>
  
  <p>In my case I need to avoid trigger that event. </p>
  
  <p>I have a sport field with players, one of the Use Cases is move a player after a longClick, the feature works well but I can’t reproduce the feature in the tests.</p>
  
  <p><a href="https://i.stack.imgur.com/c1u63.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c1u63.gif" alt="No TouchListener until onLongClick"></a></p>
  
  <p>Here is the code of the class I want to test, I tried to condensed all the relevant code associated to the question.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class FootballFieldLayout extends RelativeLayout implements View.OnTouchListener {
      [...]
      public void addPlayer(FieldPlayer player) {
          final FieldPlayerView fpv = new FieldPlayerView(getContext(), player);
          addView(fpv);
          fpv.setOnLongClickListener(new OnLongClickListener() {
              @Override
              public boolean onLongClick(View v) {
                  v.setOnTouchListener(FootballFieldLayout.this);
                      return true;
                  }
              });
      }
      [...]
      public float dX=NO_DELTA, dY=NO_DELTA;
  
      @Override
      public boolean onTouch(View view, MotionEvent event) {
          switch (event.getAction()) {
  
              case MotionEvent.ACTION_MOVE:
                  if(dX == NO_DELTA || dY == NO_DELTA){ setDelta(view, event); }
                  view.animate()
                      .x(event.getRawX() + dX)
                      .y(event.getRawY() + dY)
                      .setDuration(0)
                      .start();
                      break;
              case MotionEvent.ACTION_UP:
                  view.setOnTouchListener(null);
                  resetDelta();
                  break;
              default:
                  return false;
          }
          return true;
      }
  }
  </code></pre>
  
  <p>Here is the test</p>
  
  <pre class="lang-java prettyprint-override"><code>public class MoveOnLongClickActivityTest {
      [...]
      @Test
      public void playerCanBeMovedVerticallyAfterLongClick() throws InterruptedException {
          onView(withId(R.id.activity_field)).check(matches(isDisplayed()));
          View view = mActivityRule.getActivity().findViewById(R.id.test_player);
  
          float[] beginCoord = {view.getX(), view.getY()};
          onView(withId(R.id.test_player)).perform(longClick());
          onView(withId(R.id.test_player)).perform(swipeDown());
          float[] endCoord = {view.getX(), view.getY()};
  
          assertThat(beginCoord[1], not(equalTo(endCoord[1])));
      }
  }
  </code></pre>
  
  <p>I always use the ViewActions of the framework or use a recipe from another person changing some things but I never tried to build a complex ViewAction and I'm a bit lost.</p>