The Android Mobile Phone Platform
by Tom Thompson

Listing One

(a) Java ME

class DrawScreen extends Canvas implements CommandListener {
    private int width;
    private int height;
    DrawScreen()  {  // Constructor
        width = getWidth();
        height = get Height();
}


(b) Android

class SpaceView extends View {
public SpaceView(Context context, AttributeSet attrs, Map inflateParams) {
        super(context, attrs, inflateParams);
    } // constructor
// This method called at startup or when screen changes.
// w, h,-- current screen's width and height
// oldw, oldh -- previous screen's width and height
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mX = w;  // Get screen's width
        mY = h;  // Get screen's height
    } // onSizeChanged


1


