Question

I've made an easter egg on my application that needs a touch combination to work. It works fine, but I cannot do any other click on the screen. My class extends FragmentActivity, so I can't use onTouchEvent. If I remove the overridden method dispatchTouchEvent, I can click normally.

My code:

                public class LoginActivity extends FragmentActivity implements Window.Callback {
                  private ImageView animEaster;
                  private AnimationDrawable animDrawable;

                  @Override
                  protected void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                   ....
                  }
    @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            int action = event.getAction();
            switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_POINTER_DOWN:
                if (!isAtivado) {
                    easter = "";
                    isAtivado = true;
                    System.out.println("Ativou");
                }
                break;
            case MotionEvent.ACTION_POINTER_UP:
                int count = event.getPointerCount();
                easter += count;
                if (count <= 2) {
                    if (isAtivado) {
                        System.out.println("Desativou");
                        isAtivado = false;
                        if (easter.equals("5435432")) {
                            animEaster.setVisibility(View.VISIBLE);
                            lblProdDes.setVisibility(View.VISIBLE);
                            lblProdDes.setVisibility(View.VISIBLE);
                            if (Servidor.servidor.equals("???????")) {
                                lblProdDes.setText("DESENVOLVIMENTO");
                            } else {
                                lblProdDes.setText("PRODUÇÃO");
                            }
                            animDrawable.start();
                            new Handler().postDelayed(new Runnable() {
                                public void run() {
                                    animEaster.setVisibility(View.GONE);
                                    animEaster.setVisibility(View.GONE);
                                    lblProdDes.setVisibility(View.GONE);
                                    animDrawable.stop();
                                }
                            }, 5000);
                        }
                    }
                }
                break;
            }
            return true;
        }
....

My easter egg works, but the clicks doesn't.

Était-ce utile?

La solution

At some point, you need to call super.dispatchTouchEvent(). If you don't, events will never get dispatched to other views. Looks like instead of "return true;" at the end this should be "return super.dispatchTouchEvent(event);".

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top