FileDocCategorySizeDatePackage
Balls.javaAPI DocAndroid 5.1 API3560Thu Mar 12 22:22:54 GMT 2015com.example.android.rs.balls

Balls

public class Balls extends android.app.Activity implements android.hardware.SensorEventListener

Fields Summary
private static final String
LOG_TAG
private static final boolean
DEBUG
private static final boolean
LOG_ENABLED
private BallsView
mView
private android.hardware.SensorManager
mSensorManager
Constructors Summary
Methods Summary
static voidlog(java.lang.String message)

        if (LOG_ENABLED) {
            Log.v(LOG_TAG, message);
        }
    
public voidonAccuracyChanged(android.hardware.Sensor sensor, int accuracy)

    
public voidonCreate(android.os.Bundle icicle)

        super.onCreate(icicle);

        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

        // Create our Preview view and set it as the content of our
        // Activity
        mView = new BallsView(this);
        setContentView(mView);
    
protected voidonPause()

        super.onPause();
        mView.pause();
        onStop();
    
protected voidonResume()

        mSensorManager.registerListener(this,
                                        mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                                        SensorManager.SENSOR_DELAY_FASTEST);

        // Ideally a game should implement onResume() and onPause()
        // to take appropriate action when the activity looses focus
        super.onResume();
        mView.resume();
    
public voidonSensorChanged(android.hardware.SensorEvent event)


    // get the current looper (from your Activity UI thread for instance


        
        //android.util.Log.d("rs", "sensor: " + event.sensor + ", x: " + event.values[0] + ", y: " + event.values[1] + ", z: " + event.values[2]);
        synchronized (this) {
            if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
                if(mView != null) {
                    mView.setAccel(event.values[0], event.values[1], event.values[2]);
                }
            }
        }
    
protected voidonStop()

        mSensorManager.unregisterListener(this);
        super.onStop();