2
votes

I am seasoned developer and I have just returned to Android after being off work ill for 2 years (6 full strokes and near death but rebuilt everything!). Anyway I'm playing around with a custom subclassed ImageView. I've got the onTouch and onDraw working perfectly. I've added a listener for the accelerometer in the main activity so I can also move my sprite with this.

Tilting left makes my sprite move left as intended, as does up. If I tilt right though it still moves left. Likewise if I tilt down it still moves up.

I'm sure I can't see something as I've been staring at it too long so I'd appreciate a new pair of eyes!

Thanks

Leigh

package com.tilleytech.wubl.view;

/**
 * Created by Leigh on 09/03/2015.
 */

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

import com.tilleytech.wubl.R;
import com.tilleytech.wubl.WUBLApplication;
import com.tilleytech.wubl.object.Point;
import com.tilleytech.wubl.util.Util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DrawView extends ImageView implements OnTouchListener {

    public static enum DIRECTION {LEFT, RIGHT, UP, DOWN};
    private static final String TAG = "DrawView";
    private Bitmap player = null;
    private Bitmap saucer = null;
    private Bitmap saucer2 = null;
    private Bitmap saucer3 = null;
    private int saucerLeft=1100;
    private int saucer2Left=1400;
    private int saucer3Left=1250;


    //boundary of our view
    private static final int XMIN = 0;
    private  static final int XBOUNDARY=1080;
    private static final int YMIN=0;
    private static final int YBOUNDARY=1920;

    List<Point> points = new ArrayList<Point>();
    Paint paint = new Paint();


    public DrawView(Context context) {
        super(context);
        init(context);
    }

    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        setFocusable(true);
        setFocusableInTouchMode(true);

        this.setOnTouchListener(this);

/*        paint.setColor(Color.WHITE);
        paint.setAntiAlias(true);*/

        player = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.player, 80, 93);
        saucer = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.saucer, 100, 73);
        saucer2 = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.saucer2, 100, 73);
        saucer3 = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.saucer3, 100, 73);

        setWillNotDraw(false);
    }

    @Override
    public void onDraw(Canvas canvas) {

        //test out some UFOs in here for now
         if(saucer2Left<-150) {
            saucerLeft=1100;
            saucer2Left= 1400;
            saucer3Left=1250;
        }
        canvas.drawBitmap(saucer, saucerLeft--, 10, null);
        canvas.drawBitmap(saucer2, saucer2Left--, 10, null);
        canvas.drawBitmap(saucer3, saucer3Left--, 125, null);

        //We have 20 points which will create a trail effect
        WUBLApplication.logMessage("Whiz through our points drawing to canvas.", TAG, WUBLApplication.LogLevel.Debug);
        synchronized (points) {
            for (Point point : points) { //set in onTouch

                canvas.drawBitmap(player, point.getX(), point.getY(), null);

            }
        }
    }

    public boolean onTouch(View view, MotionEvent event) {

        int eventAction = event.getAction();
        switch (eventAction) {
            case MotionEvent.ACTION_DOWN:
                // finger touches the screen
                break;

            case MotionEvent.ACTION_MOVE:
                // finger moves on the screen
                Point point = new Point(event.getX(), event.getY());

                addPoint(point);
                synchronized (points) {
                    if (points.size() > 20) {
                        points.remove(0);
                    }
              }
              break;

            case MotionEvent.ACTION_UP:
                // finger leaves the screen
              cleanUpPoints();
              break;
        }
        //Force a repaint
        invalidate();

        return true;
    }

    public void cleanUpPoints() {
        synchronized (points) {
            int counter = 1;
            int max = points.size()-1;
            Iterator<Point> it = points.iterator();
            while (it.hasNext() & counter <= max) {
                it.next();
                it.remove();
                counter++;
            }
        }
    }


    public void addPoint(Point point) {
        //WUBLApplication.logMessage("addPoint: " + point.toString(), TAG, WUBLApplication.LogLevel.Debug);
        synchronized (points){
            points.add(point);
        }
    }

    public Point getPoint(int index) {
        Point point=null;
        if(index>-1) {
            synchronized (points) {
                if (!points.isEmpty()) {
                    point = points.get(index);
                }
            }
        }
        return point;
    }

    public Point getLastPoint() {
        Point point=null;
        //WUBLApplication.logMessage("getLastPoint before synch block", TAG, WUBLApplication.LogLevel.Debug);
        synchronized (points) {
            //WUBLApplication.logMessage("Points isEmpty: " + points.isEmpty(), TAG, WUBLApplication.LogLevel.Debug);
            if (!points.isEmpty()) {
                point = points.get(points.size() - 1);
            }
        }
        return point;
    }

    public void clearPoints() {
        synchronized (points){
            points.clear();
        }
    }

    public int getPointsSize(){
        int result=0;
        synchronized (points){
            result=points.size();
        }
        return result;
    }

    public void moveSprite(DIRECTION direction, float change) {

        //Called from accelerometer listener in activity using this view

        WUBLApplication.logMessage("moveSprite with direction: " + direction.toString(), TAG, WUBLApplication.LogLevel.Debug);
        //Get the last point and shift from here
        Point lastKnownPoint = getLastPoint();
        switch (direction) {
            case LEFT: {
                WUBLApplication.logMessage("moveSprite inside LEFT", TAG, WUBLApplication.LogLevel.Debug);
                if (lastKnownPoint != null) {
                    float lastX = lastKnownPoint.getX();
                    float lastY = lastKnownPoint.getY();
                    if (lastX - change > XMIN && lastX - change < XBOUNDARY) {
                        WUBLApplication.logMessage("LEFT: subtract from x", TAG, WUBLApplication.LogLevel.Debug);
                        lastX -= change;
                        addPoint(new Point(lastX, lastY));
                    }
                }
                break;
            }
            case RIGHT: {
                WUBLApplication.logMessage("moveSprite inside RIGHT", TAG, WUBLApplication.LogLevel.Debug);
                if (lastKnownPoint != null) {
                    float lastX = lastKnownPoint.getX();
                    float lastY = lastKnownPoint.getY();
                    if (lastX + change > XMIN && lastX + change < XBOUNDARY) {
                        WUBLApplication.logMessage("RIGHT: add to x", TAG, WUBLApplication.LogLevel.Debug);
                        lastX += change;
                        addPoint(new Point(lastX, lastY));
                    }
                }
                break;
            }
            case UP: {
                WUBLApplication.logMessage("moveSprite inside UP", TAG, WUBLApplication.LogLevel.Debug);
                if (lastKnownPoint != null) {
                    float lastX = lastKnownPoint.getX();
                    float lastY = lastKnownPoint.getY();
                    WUBLApplication.logMessage("UP: Add to y", TAG, WUBLApplication.LogLevel.Debug);
                    if (lastY + change > YMIN && lastY + change < YBOUNDARY) {
                        lastY += change;
                        addPoint(new Point(lastX, lastY));
                    }
                }
                break;
            }
            case DOWN: {
                WUBLApplication.logMessage("moveSprite inside DOWN", TAG, WUBLApplication.LogLevel.Debug);
                if (lastKnownPoint != null) {
                    float lastX = lastKnownPoint.getX();
                    float lastY = lastKnownPoint.getY();
                    if (lastY - change > YMIN && lastY - change < YBOUNDARY) {
                        WUBLApplication.logMessage("DOWN: subtract from y", TAG, WUBLApplication.LogLevel.Debug);
                        lastY -= change;
                        addPoint(new Point(lastX, lastY));
                    }
                }
                break;
            }
        }

        invalidate();
    }
}

and the activity class:

package com.tilleytech.wubl.activity;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.tilleytech.wubl.R;
import com.tilleytech.wubl.WUBLApplication;
import com.tilleytech.wubl.view.DrawView;


/**
 * Created by Leigh on 09/03/2015.
 */
public class DrawingViewActivity extends Activity implements SensorEventListener {

    DrawView drawView;
    private SensorManager sensorManager;
    private Sensor accelerometer;
    private final static String TAG = DrawingViewActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set full screen view
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_drawingview);
        drawView = (DrawView)findViewById(R.id.drawingview);
        listenAccelerometer();
        drawView.requestFocus();
    }

    protected void listenAccelerometer() {
        WUBLApplication.logMessage("Request sensor service", TAG, WUBLApplication.LogLevel.Debug);
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
            // success! we have an accelerometer
            WUBLApplication.logMessage("Link to accelerometer", TAG, WUBLApplication.LogLevel.Debug);
            accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
            sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
        } else {
            // fai! we dont have an accelerometer!
            WUBLApplication.logMessage("No accelerometer found!", TAG, WUBLApplication.LogLevel.Debug);
        }


    }

    //onResume() register the accelerometer for listening the events
    protected void onResume() {
        super.onResume();
        sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    }

    //onPause() unregister the accelerometer for stop listening the events
    protected void onPause() {
        super.onPause();
        sensorManager.unregisterListener(this);
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }


    @Override
    public void onSensorChanged(SensorEvent event) {
        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];

        int speed = 6;
        if (Math.abs(x) > Math.abs(y)) {
            if (x < 0) {
                //right
                WUBLApplication.logMessage("accelerometer right", TAG, WUBLApplication.LogLevel.Debug);
                float xChange = speed * x;
                drawView.moveSprite(DrawView.DIRECTION.RIGHT, xChange);
            }
            if (x > 0) {
                //left
                WUBLApplication.logMessage("accelerometer left", TAG, WUBLApplication.LogLevel.Debug);
                float xChange = speed * x;
                drawView.moveSprite(DrawView.DIRECTION.LEFT, xChange);
            }
        } else {
            if (y < 0) {
                //up
                WUBLApplication.logMessage("accelerometer up", TAG, WUBLApplication.LogLevel.Debug);
                float yChange = speed * y;
                drawView.moveSprite(DrawView.DIRECTION.UP, yChange);
            }
            if (y > 0) {
                //down
                WUBLApplication.logMessage("accelerometer down", TAG, WUBLApplication.LogLevel.Debug);
                float yChange = speed * y;
                drawView.moveSprite(DrawView.DIRECTION.DOWN, yChange);
            }
        }
        if (x > (-2) && x < (2) && y > (-2) && y < (2)) {
            //centre
            drawView.cleanUpPoints();
            //nothing, hold
        }
    }
    @Override
    protected void onStop()
    {
        // Unregister the listener
        sensorManager.unregisterListener(this);
        super.onStop();
    }
}
1

1 Answers

1
votes

So I just returned to the Android stuff recently and I cannot believe that I posted this back in 2015!

Anyway I looked at it today and I have solved it. Essentially you need to realise that you need to account for how the z,y and z axis work and what you're trying to achieve.

Here is a nice pic of how the x, y and z planes work relative to the accelerometer:x,y and z for accelerometer

What I was doing wrong was passing in the real value of x and y (not concerned with z in this example/problem) into my custom ImageView and then decrementing or incrementing for left/right or up/down.

So my accelerometer code was working (logcat for left/right/up/down) but my image movement was not.

I logged the actual values and it was then that I realised that if x or y are less than 0 you need to take the Math.abs value to pass to a function that is already deciding on the decrementing or incrementing depending on a prticular direction (I detect LEFT/RIGHT/UP/DOWN in the onChanged event implementation for the SensorEventListener. In this case my custom sub-classed ImageView, DrawView, is deciding on decrementing or incrementing.

This is a rough prototype so these two classes are quite tightly coupled really but I still think that some may find this code useful.

It is also worth noting that values below 2 are just noise; if and when you try out sensors you'll notice, from logging, that they are extremely sensitive and firing all of the time!

package com.tilleytech.wubl.activity;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.tilleytech.wubl.R;
import com.tilleytech.wubl.WUBLApplication;
import com.tilleytech.wubl.view.DrawView;


/**
 * Created by Leigh on 09/03/2015.
* Updated 19/06/2017
 */
public class DrawingViewActivity extends Activity implements SensorEventListener {

    DrawView drawView;
    private SensorManager sensorManager;
    private Sensor accelerometer;
    private final static String TAG = DrawingViewActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set full screen view
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_drawingview);
        drawView = (DrawView)findViewById(R.id.drawingview);
        listenAccelerometer();
        drawView.requestFocus();
    }

    protected void listenAccelerometer() {
        WUBLApplication.logMessage("Request sensor service", TAG, WUBLApplication.LogLevel.Debug);
        sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        if (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) {
            // success! we have an accelerometer
            WUBLApplication.logMessage("Link to accelerometer", TAG, WUBLApplication.LogLevel.Debug);
            accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
            sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
        } else {
            // fai! we dont have an accelerometer!
            WUBLApplication.logMessage("No accelerometer found!", TAG, WUBLApplication.LogLevel.Debug);
        }
    }

    //onResume() register the accelerometer for listening the events
    protected void onResume() {
        super.onResume();
        sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
    }

    //onPause() unregister the accelerometer for stop listening the events
    protected void onPause() {
        super.onPause();
        sensorManager.unregisterListener(this);
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {

    }


    @Override
    public void onSensorChanged(SensorEvent event) {

        float x = event.values[0]; //HORIZONTAL
        float y = event.values[1]; //VERTICAL
        float z = event.values[2]; //INTO SCREEN


        //Just noise
        if (x > (-2) && x < (2) && y > (-2) && y < (2)) {
            //centre
            drawView.cleanUpPoints();
            //nothing, hold
        }
        else {
            int speed = 6;
            if (Math.abs(x) > Math.abs(y)) {
                //HORIZONTAL PLANE
                if (x < 0) {
                    //right
                    WUBLApplication.logMessage("accelerometer RIGHT x: " + x + " y: " + y, TAG, WUBLApplication.LogLevel.Debug);
                    //As we have the actual value we need to abs it so that it doesn't subtract!
                    float xChange = speed * Math.abs(x);
                    drawView.moveSprite(DrawView.DIRECTION.RIGHT, xChange);
                } else if (x > 0) {
                    //left
                    WUBLApplication.logMessage("accelerometer LEFT  x: " + x + " y: " + y, TAG, WUBLApplication.LogLevel.Debug);
                    float xChange = speed * x;
                    drawView.moveSprite(DrawView.DIRECTION.LEFT, xChange);
                }
            } else {
                //VERTICAL PLANE
                if (y > 0) {
                    //up
                    WUBLApplication.logMessage("accelerometer UP  x: " + x + " y: " + y, TAG, WUBLApplication.LogLevel.Debug);
                    float yChange = speed * y;
                    drawView.moveSprite(DrawView.DIRECTION.UP, yChange);
                } else if (y < 0) {
                    //down
                    WUBLApplication.logMessage("accelerometer DOWN  x: " + x + " y: " + y, TAG, WUBLApplication.LogLevel.Debug);

                    //As we have the actual value we need to abs it so that it doesn't subtract!
                    float yChange = speed * Math.abs(y);
                    drawView.moveSprite(DrawView.DIRECTION.DOWN, yChange);
                }
            }
        }

        //Clean trail
        drawView.cleanUpPoints();
    }

    @Override
    protected void onStop()
    {
        // Unregister the listener
        sensorManager.unregisterListener(this);
        super.onStop();
    }
}

And the other class, the sub-classed ImageView, DrawView:

package com.tilleytech.wubl.view;

/**
 * Created by Leigh on 09/03/2015.
 * Updated 19/06/2017
 */

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.support.v7.widget.AppCompatImageView;

import com.tilleytech.wubl.R;
import com.tilleytech.wubl.WUBLApplication;
import com.tilleytech.wubl.object.Point;
import com.tilleytech.wubl.util.Util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DrawView extends AppCompatImageView implements OnTouchListener {

    public static enum DIRECTION {LEFT, RIGHT, UP, DOWN};
    private final static String TAG = DrawView.class.getSimpleName();
    private Bitmap player = null;
    private Bitmap saucer = null;
    private Bitmap saucer2 = null;
    private Bitmap saucer3 = null;

    //boundary of our view
    private static final int XMIN = 0;
    private  static final int XBOUNDARY=1080;
    private static final int YMIN=0;
    private static final int YBOUNDARY=1920;

    List<Point> points = new ArrayList<Point>();
    Paint paint = new Paint();

    private int saucerLeft=1100;
    private int saucer2Left=1400;
    private int saucer3Left=1250;

    public DrawView(Context context) {
        super(context);
        init(context);
    }

    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public DrawView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        setFocusable(true);
        setFocusableInTouchMode(true);

        this.setOnTouchListener(this);

/*        paint.setColor(Color.WHITE);
        paint.setAntiAlias(true);*/

        player = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.player, 80, 93);
        saucer = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.saucer, 100, 73);
        saucer2 = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.saucer2, 100, 73);
        saucer3 = Util.decodeSampledBitmapFromResource(getResources(), R.drawable.saucer3, 100, 73);

        setWillNotDraw(false);
    }

    @Override
    public void onDraw(Canvas canvas) {

        //test out some UFOs in here for now
         if(saucer2Left<-150) {
            saucerLeft=1100;
            saucer2Left= 1400;
            saucer3Left=1250;
        }
        canvas.drawBitmap(saucer, saucerLeft--, 10, null);
        canvas.drawBitmap(saucer2, saucer2Left--, 10, null);
        canvas.drawBitmap(saucer3, saucer3Left--, 125, null);

        //We have 20 points which will create a trail effect
        WUBLApplication.logMessage("Whiz through our points drawing to canvas.", TAG, WUBLApplication.LogLevel.Debug);
        synchronized (points) {
            for (Point point : points) { //set in onTouch

                canvas.drawBitmap(player, point.getX(), point.getY(), null);

            }
        }
    }

    public boolean onTouch(View view, MotionEvent event) {

        int eventAction = event.getAction();
        switch (eventAction) {
            case MotionEvent.ACTION_DOWN:
                // finger touches the screen
                break;

            case MotionEvent.ACTION_MOVE:
                // finger moves on the screen
                Point point = new Point(event.getX(), event.getY());

                addPoint(point);
                synchronized (points) {
                    if (points.size() > 20) {
                        points.remove(0);
                    }
              }
              break;

            case MotionEvent.ACTION_UP:
                // finger leaves the screen
              cleanUpPoints();
              break;
        }
        //Force a repaint
        invalidate();

        return true;
    }

    public void cleanUpPoints() {
        synchronized (points) {
            int counter = 1;
            int max = points.size()-1;
            Iterator<Point> it = points.iterator();
            while (it.hasNext() & counter <= max) {
                it.next();
                it.remove();
                counter++;
            }
        }
    }


    public void addPoint(Point point) {
        //WUBLApplication.logMessage("addPoint: " + point.toString(), TAG, WUBLApplication.LogLevel.Debug);
        synchronized (points){
            points.add(point);
        }
    }

    public Point getPoint(int index) {
        Point point=null;
        if(index>-1) {
            synchronized (points) {
                if (!points.isEmpty()) {
                    point = points.get(index);
                }
            }
        }
        return point;
    }

    public Point getLastPoint() {
        Point point=null;
        //WUBLApplication.logMessage("getLastPoint before synch block", TAG, WUBLApplication.LogLevel.Debug);
        synchronized (points) {
            //WUBLApplication.logMessage("Points isEmpty: " + points.isEmpty(), TAG, WUBLApplication.LogLevel.Debug);
            if (!points.isEmpty()) {
                point = points.get(points.size() - 1);
            }
        }
        return point;
    }

    public void clearPoints() {
        synchronized (points){
            points.clear();
        }
    }

    public int getPointsSize(){
        int result=0;
        synchronized (points){
            result=points.size();
        }
        return result;
    }

    public void moveSprite(DIRECTION direction, float change) {

        //Called from accelerometer listener in activity using this view

        WUBLApplication.logMessage("moveSprite with direction: " + direction.toString(), TAG, WUBLApplication.LogLevel.Debug);
        //Get the last point and shift from here
        Point lastKnownPoint = getLastPoint();
        if (lastKnownPoint != null) {

            float lastX = lastKnownPoint.getX();
            float lastY = lastKnownPoint.getY();

            switch (direction) {
                case LEFT: {
                    WUBLApplication.logMessage("moveSprite inside LEFT", TAG, WUBLApplication.LogLevel.Debug);

                    //if (lastX - change > XMIN && lastX - change < XBOUNDARY) {
                        WUBLApplication.logMessage("LEFT: subtract from x", TAG, WUBLApplication.LogLevel.Debug);
                        lastX -= change;
                        addPoint(new Point(lastX, lastY));
                    //}
                }
                break;

            case RIGHT: {
                WUBLApplication.logMessage("moveSprite inside RIGHT", TAG, WUBLApplication.LogLevel.Debug);
                //if (lastX + change > XMIN && lastX + change < XBOUNDARY) {
                    WUBLApplication.logMessage("RIGHT: add to x", TAG, WUBLApplication.LogLevel.Debug);
                    lastX += change;
                    addPoint(new Point(lastX, lastY));
                //}
            }
            break;

            case UP: {
                WUBLApplication.logMessage("moveSprite inside UP", TAG, WUBLApplication.LogLevel.Debug);
                //if (lastY - change > YMIN && lastY - change < YBOUNDARY) {
                    WUBLApplication.logMessage("UP: add to y", TAG, WUBLApplication.LogLevel.Debug);
                    lastY += change;
                    addPoint(new Point(lastX, lastY));
                //}
            }
            break;

            case DOWN: {
                WUBLApplication.logMessage("moveSprite inside DOWN", TAG, WUBLApplication.LogLevel.Debug);
                //if (lastY + change > YMIN && lastY + change < YBOUNDARY) {
                    WUBLApplication.logMessage("DOWN: subtract from y", TAG, WUBLApplication.LogLevel.Debug);
                    lastY -= change;
                    addPoint(new Point(lastX, lastY));
                //}
            }
            break;

        }//switch
       invalidate();
    }
    }


}

I hope that this helps people when trying out the accelerometer.

I'll post back updates as and when I feel it is appropriate.

Thanks for your time.

Leigh