@Override public boolean onTouchEvent(MotionEvent event) { final float x = event.getX(); final float y = event.getY(); final float left = SquashView.getInstance().getLeft(); final float right = SquashView.getInstance().getRight(); final float top = SquashView.getInstance().getTop(); final float bottom = SquashView.getInstance().getBottom(); // if the squashview is full screen, dont ignore anything if (!mShowingUi) { mIgnoringEvent = false; } else if (event.getAction() == MotionEvent.ACTION_DOWN) { mIgnoringEvent = x >= left && x <= right && y >= top && y <= bottom ? false : true; } if (!mIgnoringEvent) { this.mDetector.onTouchEvent(event); } else { Log.w(TAG, "ignoring event " + event.getAction()); } // Be sure to call the superclass implementation return super.onTouchEvent(event); }
@Override protected void onPause() { super.onPause(); SquashView.getInstance().onPause(); // destroy shaders so that new ones will be created Shader.destroyShaders(); }
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInstance = this; // ensure that if nothing would be drawn, some default objects are // drawn instead if (Settings.getVisibleObjectCollections().size() == 0) { final Set<String> ss = new HashSet<String>(); ss.add(Integer.toString(SquashRenderer.OBJECT_COURT)); ss.add(Integer.toString(SquashRenderer.OBJECT_BALL)); ss.add(Integer.toString(SquashRenderer.OBJECT_FORCE)); ss.add(Integer.toString(SquashRenderer.OBJECT_ARENA)); ss.add(Integer.toString(SquashRenderer.OBJECT_CHAIRS)); Settings.setVisibleObjectCollections(ss); } // inflate layout setContentView(R.layout.layout_main); // register views SquashView.getInstance() .registerViews( (TextView) findViewById(R.id.txtHudFps), (TextView) findViewById(R.id.txtHudBall)); if (Settings.isHudVisible()) { SquashView.getInstance().showHud(); } else { SquashView.getInstance().hideHud(); } // retrieve reference to layout mLayout = (RelativeLayout) findViewById(R.id.layout); // initialize gesture detection mDetector = new GestureDetectorCompat(this, this); mDetector.setOnDoubleTapListener(this); // hide the ui initially // toggleUi(); Log.i(TAG, "SquashActivity created"); }
@Override public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) { final float dx = event2.getX() - event1.getX(); final float dy = event2.getY() - event1.getY(); if (Math.abs(dy) > 0.2f * SquashView.getInstance().getHeight()) { Log.d(TAG, "SwipeUp/Down"); SquashActivity.getInstance().toggleUi(); } Log.d(TAG, "onFling: dx=" + dx + ", dy=" + dy); // + // event1.toString()+event2.toString()); return true; }
@Override protected void onResume() { super.onResume(); SquashView.getInstance().onResume(); }