AccelHandler.java :  » UnTagged » mobilebombsquad » edu » wpi » cs525h » mobilebombsquad » ayeg » accel » Android Open Source

Android Open Source » UnTagged » mobilebombsquad 
mobilebombsquad » edu » wpi » cs525h » mobilebombsquad » ayeg » accel » AccelHandler.java
package edu.wpi.cs525h.mobilebombsquad.ayeg.accel;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Vibrator;

public class AccelHandler {

  Context context;
  PlayableSurfaceView view;
  
  MediaPlayer mp;
  Vibrator vibrator;
  
  boolean conditionMet = false;
  
  public AccelHandler(Context context, PlayableSurfaceView view) {
    this.context = context;
    this.view = view;
    
    mp = MediaPlayer.create(context, R.raw.notify);
    vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    
  }
  
  void updateBubble(float x, float y, float z) {
    int height = view.getHeight();
    int width = view.getWidth();
    
    double xProportion = x / (Math.PI / 2);
    double yProportion = y / (Math.PI / 2);
    
    int newX = (int) (width/2.0 + xProportion*(width/2.0));
    int newY = (int) (height/2.0 + yProportion*(height/2.0));
    
    view.bubble.updatePosition(newX, newY);
    view.invalidate();
    
    if (checkCondition()) {
      if (!conditionMet) {
        //vibrator.vibrate(75);
        mp.start();
        conditionMet = true;
      }
    } else {
      conditionMet = false;
    }
  }
  
  boolean checkCondition() {
    return view.checkBubbleCircle();
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.