Beispiel #1
0
  @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);
  }
Beispiel #2
0
  @Override
  protected void onPause() {
    super.onPause();

    SquashView.getInstance().onPause();

    // destroy shaders so that new ones will be created
    Shader.destroyShaders();
  }
Beispiel #3
0
  @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");
  }
Beispiel #4
0
  @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;
  }
Beispiel #5
0
  @Override
  protected void onResume() {
    super.onResume();

    SquashView.getInstance().onResume();
  }