How to move image/object with sensor manager?
<p>I'm currently using this project as a template:
<a href="http://www.droidnova.com/playing-with-graphics-in-android-part-vii,220.html" rel="nofollow">http://www.droidnova.com/playing-with-graphics-in-android-part-vii,220.html</a></p>

<p>I have my background and airplane loaded on the screen. I added a sensor manager on my main page.</p>

<pre><code>private SensorManager sensorManager;

/**
 * Method called on application start.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(new Panel(this));

    sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
    // add listener. The listener will be HelloAndroid (this) class
    sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); 
}

public void onAccuracyChanged(Sensor sensor,int accuracy){ 

}

public void onSensorChanged(SensorEvent event){

    // check sensor type
    if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){ 
        // assign directions
        float x=event.values[0];
        float y=event.values[1];
        float z=event.values[2]; 
        //Draw my plane here..........
    }
}
</code></pre>

<p>what I want to do is move my airplane around with the new coordidates, x and y. Do I need to place the sensor manager inside the panel class or can I do it from my main class? Here's my panel class:</p>

<pre><code>public class Panel extends SurfaceView implements SurfaceHolder.Callback {

private ObitBlastThread _thread;    
private ArrayList&lt;Graphic&gt; _graphics = new ArrayList&lt;Graphic&gt;();   
private Graphic _currentGraphic;
private SoundPool _soundPool;  
private Map&lt;Integer, Bitmap&gt; _bitmapCache = new HashMap&lt;Integer, Bitmap&gt;();    

public Panel(Context context) {
    super(context);
    fillBitmapCache();
    _soundPool = new SoundPool(16, AudioManager.STREAM_MUSIC, 100);
    //_playbackFile = _soundPool.load(getContext(), R.raw.explosion, 0);
    getHolder().addCallback(this);
    _thread = new ObitBlastThread(this);
    setFocusable(true);   
}    

private void fillBitmapCache() {
    _bitmapCache.put(R.drawable.background, BitmapFactory.decodeResource(getResources(), R.drawable.background));
    _bitmapCache.put(R.drawable.mainairplane, BitmapFactory.decodeResource(getResources(), R.drawable.mainairplane));
}

@Override
public void onDraw(Canvas canvas) {
    // draw the background
    canvas.drawBitmap(_bitmapCache.get(R.drawable.background), 0, 0, null);
    canvas.drawBitmap(_bitmapCache.get(R.drawable.mainairplane), 100, 225, null);
    Bitmap bitmap;
    Graphic.Coordinates coords;

    // draw the normal items
    for (Graphic graphic : _graphics) {
        bitmap = graphic.getBitmap();
        coords = graphic.getCoordinates();
        canvas.drawBitmap(bitmap, coords.getX(), coords.getY(), null);
    }                

    // draw current graphic at last...
    if (_currentGraphic != null) {
        bitmap = _currentGraphic.getBitmap();
        coords = _currentGraphic.getCoordinates();
        canvas.drawBitmap(bitmap, coords.getX(), coords.getY(), null);
    }
}    

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (!_thread.isAlive()) {
        _thread = new ObitBlastThread(this);
    }
    _thread.setRunning(true);
    _thread.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    boolean retry = true;
    _thread.setRunning(false);
    while (retry) {
        try {
            _thread.join();
            retry = false;
        } catch (InterruptedException e) {
            // we will try it again and again...
        }
    }
    Log.i("thread", "Thread terminated...");
}
</code></pre>

<p>}</p>
