Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
Duplicate branch in 'switch'. How to avoid the warning

I have a code for my MotionEvent in Android app. It has condition when I release the last finger (ACTION_UP), and the condition when I release the finger, but any other finger still on the screen (ACTION_POINTER_UP). So, this is two different conditions, and I need to run code in both cases. But compiler tell me, that I have exact the same code and offers to merge this two sections in one.

How can I avoid this warning?

There is a code:

switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN: // first touch
                // some code for a touch
                break;
            case MotionEvent.ACTION_POINTER_DOWN: // second and more touch
                // some code for a second touch
                break;
            case MotionEvent.ACTION_MOVE:
                // code when the finger moves
                break;
            case MotionEvent.ACTION_UP:

                // left side
                if (event.getPointerId(event.getActionIndex()) == fingerOnALeftSide) {
                    Log.d("tag", "Now we release the finger that was on a left side");
                    leftFingerInTouch = false;
                }

                // right side
                if (event.getPointerId(event.getActionIndex()) == fingerOnARightSide) {
                    Log.d("tag", "Now we release the finger that was on a right side");
                    myBluetooth.send(COMMAND_STOP_ENGINE);
                }
                break;
            case MotionEvent.ACTION_POINTER_UP:

                // left side
                if (event.getPointerId(event.getActionIndex()) == fingerOnALeftSide) {
                    Log.d("tag", "Now we release the finger that was on a left side");
                    leftFingerInTouch = false;
                }

                // right side
                if (event.getPointerId(event.getActionIndex()) == fingerOnARightSide) {
                    Log.d("tag", "Now we release the finger that was on a right side");
                    myBluetooth.send(COMMAND_STOP_ENGINE);
                }
                break;
            default:
                break;
        }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It looks like this and works.

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:

                // left side
                if (event.getPointerId(event.getActionIndex()) == fingerOnALeftSide) {
                    Log.d("tag", "Now we release the finger that was on a left side");
                    leftFingerInTouch = false;
                }

                // right side
                if (event.getPointerId(event.getActionIndex()) == fingerOnARightSide) {
                    Log.d("tag", "Now we release the finger that was on a right side");
                    myBluetooth.send(COMMAND_STOP_ENGINE);
                }
                break;
            default:
                break;
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda