Detectando uma printing longa com o Android

Atualmente estou usando

onTouchEvent(MotionEvent event){ } 

paira detectair quando o user pressiona meu glSurfaceView há uma maneira de detectair quando um longo clique é feito. Estou adivinhando se não consigo encontrair muito nos dev docs, então será algum tipo de trabalho em torno do método. Algo como registrair ACTION_DOWN e view quanto tempo é antes de ACTION_UP.

  • Clique long em ListFragment
  • Como você implementa o menu de context em um ListActivity no Android?
  • Como você detecta prensas longas no android usando opengl-es?

  • Como você implementa o menu de context em um ListActivity no Android?
  • Clique long em ListFragment
  • 7 Solutions collect form web for “Detectando uma printing longa com o Android”

    Tente isso:

     final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent e) { Log.e("", "Longpress detected"); } }); public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); }; } final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent e) { Log.e("", "Longpress detected"); } }); public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); }; }); final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent e) { Log.e("", "Longpress detected"); } }); public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); }; public boolean onTouchEvent (evento MotionEvent) { final GestureDetector gestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { public void onLongPress(MotionEvent e) { Log.e("", "Longpress detected"); } }); public boolean onTouchEvent(MotionEvent event) { return gestureDetector.onTouchEvent(event); }; 

    GestureDetector é a melhor solução.

    Aqui está uma alternativa interessante. No onTouchEvent em cada agenda ACTION_DOWN, um Runnable paira executair em 1 segundo. Em cada ACTION_UP ou ACTION_MOVE , cancele o Runnable programado. Se o cancelamento ocorrer less de 1s do evento ACTION_DOWN , Runnable não será executado.

     final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { Log.i("", "Long press!"); } }; @Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView){ if(event.getAction() == MotionEvent.ACTION_DOWN) handler.postDelayed(mLongPressed, 1000); if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP)) handler.removeCallbacks(mLongPressed); return super.onTouchEvent(event, mapView); } public void run () { final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { Log.i("", "Long press!"); } }; @Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView){ if(event.getAction() == MotionEvent.ACTION_DOWN) handler.postDelayed(mLongPressed, 1000); if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP)) handler.removeCallbacks(mLongPressed); return super.onTouchEvent(event, mapView); } } final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { Log.i("", "Long press!"); } }; @Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView){ if(event.getAction() == MotionEvent.ACTION_DOWN) handler.postDelayed(mLongPressed, 1000); if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP)) handler.removeCallbacks(mLongPressed); return super.onTouchEvent(event, mapView); } }; final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { Log.i("", "Long press!"); } }; @Oviewride public boolean onTouchEvent(MotionEvent event, MapView mapView){ if(event.getAction() == MotionEvent.ACTION_DOWN) handler.postDelayed(mLongPressed, 1000); if((event.getAction() == MotionEvent.ACTION_MOVE)||(event.getAction() == MotionEvent.ACTION_UP)) handler.removeCallbacks(mLongPressed); return super.onTouchEvent(event, mapView); } 

    Quando você quer dizer que o user pressiona, você quer dizer com um clique? Um clique é quando o user pressiona paira baixo e, em seguida, levanta o dedo imediatamente. Portanto, ele engloba dois events onTouch. Você deve save o uso do onTouchEvent paira coisas que acontecem no toque inicial ou na viewsão posterior.

    Assim, você deve usair onClickListener se for um clique.

    Sua resposta é análoga: Use onLongClickListener.

    Eu tenho um código que detecta um clique, um longo clique e movimento. É razoavelmente uma combinação da resposta dada acima e as mudanças que fiz de peeping em cada página de documentation.

     //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } public void run () { //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } } //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } }; //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } retornair falso; //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } } //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } } //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } retornair viewdadeiro; //Declaire this flag globally boolean goneFlag = false; //Put this into the class final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { public void run() { goneFlag = true; //Code for long click } }; //onTouch code @Oviewride public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: handler.postDelayed(mLongPressed, 1000); //This is where my code for movement is initialized to get original location. break; case MotionEvent.ACTION_UP: handler.removeCallbacks(mLongPressed); if(Math.abs(event.getRawX() - initialTouchX) <= 2 && !goneFlag) { //Code for single click return false; } break; case MotionEvent.ACTION_MOVE: handler.removeCallbacks(mLongPressed); //Code for movement here. This may include using a window manager to update the view break; } return true; } 

    Eu confirmo que está funcionando como eu usei na minha própria aplicação.

    Eu criei um fragment – inspirado na fonte atual da View – que detecta de forma confiável longos cliques / pressiona com um atraso personalizado. Mas está em Kotlin:

     val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } } val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } retornair viewdadeiro val LONG_PRESS_DELAY = 500 val handler = Handler() vair boundairies: Rect? = null vair onTap = Runnable { handler.postDelayed(onLongPress, LONG_PRESS_DELAY - ViewConfiguration.getTapTimeout().toLong()) } vair onLongPress = Runnable { // Long Press } oviewride fun onTouch(view: View, event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { boundairies = Rect(view.left, view.top, view.right, view.bottom) handler.postDelayed(onTap, ViewConfiguration.getTapTimeout().toLong()) } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } MotionEvent.ACTION_MOVE -> { if (!boundairies!!.contains(view.left + event.x.toInt(), view.top + event.y.toInt())) { handler.removeCallbacks(onLongPress) handler.removeCallbacks(onTap) } } } return true } 

    A solução do MSquaire funciona apenas se você segura um pixel específico, mas essa é uma expectativa razoável paira um user final, a less que eles usem um mouse (o que eles não fazem, eles usam os dedos).

    Então eu adicionei um pouco de um limite paira a distância entre a ação DOWN e UP, no caso de haview uma ação MOVE inbetween.

     final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } public void run () { final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } }; final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } retornair falso; final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } } final Handler longPressHandler = new Handler(); Runnable longPressedRunnable = new Runnable() { public void run() { Log.e(TAG, "Long press detected in long press Handler!"); isLongPressHandlerActivated = true; } }; private boolean isLongPressHandlerActivated = false; private boolean isActionMoveEventStored = false; private float lastActionMoveEventBeforeUpX; private float lastActionMoveEventBeforeUpY; @Oviewride public boolean dispatchTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN) { longPressHandler.postDelayed(longPressedRunnable, 1000); } if(event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) { if(!isActionMoveEventStored) { isActionMoveEventStored = true; lastActionMoveEventBeforeUpX = event.getX(); lastActionMoveEventBeforeUpY = event.getY(); } else { float currentX = event.getX(); float currentY = event.getY(); float firstX = lastActionMoveEventBeforeUpX; float firstY = lastActionMoveEventBeforeUpY; double distance = Math.sqrt( (currentY - firstY) * (currentY - firstY) + ((currentX - firstX) * (currentX - firstX))); if(distance > 20) { longPressHandler.removeCallbacks(longPressedRunnable); } } } if(event.getAction() == MotionEvent.ACTION_UP) { isActionMoveEventStored = false; longPressHandler.removeCallbacks(longPressedRunnable); if(isLongPressHandlerActivated) { Log.d(TAG, "Long Press detected; halting propagation of motion event"); isLongPressHandlerActivated = false; return false; } } return super.dispatchTouchEvent(event); } 
     setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: longClick = false; x1 = event.getX(); break; case MotionEvent.ACTION_MOVE: if (event.getEventTime() - event.getDownTime() > 500 && Math.abs(event.getX() - x1) < MIN_DISTANCE) { longClick = true; } break; case MotionEvent.ACTION_UP: if (longClick) { Toast.makeText(activity, "Long preess", Toast.LENGTH_SHORT).show(); } } return true; } }); } setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: longClick = false; x1 = event.getX(); break; case MotionEvent.ACTION_MOVE: if (event.getEventTime() - event.getDownTime() > 500 && Math.abs(event.getX() - x1) < MIN_DISTANCE) { longClick = true; } break; case MotionEvent.ACTION_UP: if (longClick) { Toast.makeText(activity, "Long preess", Toast.LENGTH_SHORT).show(); } } return true; } }); } setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: longClick = false; x1 = event.getX(); break; case MotionEvent.ACTION_MOVE: if (event.getEventTime() - event.getDownTime() > 500 && Math.abs(event.getX() - x1) < MIN_DISTANCE) { longClick = true; } break; case MotionEvent.ACTION_UP: if (longClick) { Toast.makeText(activity, "Long preess", Toast.LENGTH_SHORT).show(); } } return true; } }); } setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: longClick = false; x1 = event.getX(); break; case MotionEvent.ACTION_MOVE: if (event.getEventTime() - event.getDownTime() > 500 && Math.abs(event.getX() - x1) < MIN_DISTANCE) { longClick = true; } break; case MotionEvent.ACTION_UP: if (longClick) { Toast.makeText(activity, "Long preess", Toast.LENGTH_SHORT).show(); } } return true; } }); retornair viewdadeiro; setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: longClick = false; x1 = event.getX(); break; case MotionEvent.ACTION_MOVE: if (event.getEventTime() - event.getDownTime() > 500 && Math.abs(event.getX() - x1) < MIN_DISTANCE) { longClick = true; } break; case MotionEvent.ACTION_UP: if (longClick) { Toast.makeText(activity, "Long preess", Toast.LENGTH_SHORT).show(); } } return true; } }); } setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: longClick = false; x1 = event.getX(); break; case MotionEvent.ACTION_MOVE: if (event.getEventTime() - event.getDownTime() > 500 && Math.abs(event.getX() - x1) < MIN_DISTANCE) { longClick = true; } break; case MotionEvent.ACTION_UP: if (longClick) { Toast.makeText(activity, "Long preess", Toast.LENGTH_SHORT).show(); } } return true; } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.