Mr. Rogers' IB Computer Science -- Android SmartPhone Programming Project
Help boost K-12 science, math, and computer education. Donate your obsolete Android phone to us (see below)! We promise to put it to good use in a classroom.

Mr Rogers Android Project Menu




   3D Compass

   3D Accelerometer

   Friction Tester


   Spherical Game



Greenville, SC
Bubble Level
This Android application is used for testing how level an object is, mimicking the appearance of an actual bubble level. This application is useful for avoiding carrying an actual bubble level around, and having a multi-purpose device for testing how level an object is and having other tools all-in-one.
This is a screen capture of the Android application in action. The green oval represents what would be the bubble in an actual bubble level. When in use, the green bubble will appear to "float" away from the center, and as the object the device is laying on is rotated, the green bubble moves closer or further from the center.
This is another screen capture of the program. This time, the device has been rotated the opposite direction of the first screen capture.

  • Visually aids in making a surface level.
  • Mimics the appearance of an actual bubble level.
1.0 - 25 October 2010

Future Plans
The level needs to be more sensitive, adjust accordingly.
Make the level more aesthetically pleasing.

Place the phone on a flat object and adjust the object to center the bubble drawn on the device.


Source Code
Bubble Class


public class Bubble {
        private int x, y, radius;

        public Bubble(int xP, int yP, int r)
                x = xP;
                y = yP;
                radius = r;

        public void draw(Canvas c, Paint g)
                c.drawCircle(x, y, radius, g);

        public void setY(int newY)
                y = newY;

        public void setX(int newX)
                x = newX;

        public void setR(int newR)
                radius = newR;
Board Class

import android.R.color;
import android.content.Context;
import android.view.View;

public class Board extends View
        int _height, _width;
        int cX, cY1, cY2, r;

        Bubble bubble;

        Bitmap _bitmap;
        Canvas _canvas;
        Paint g;

        public Board(Context context)
                g = new Paint();

                bubble = new Bubble(10,50000,0);
	 * Draws the level to the screen. Then draws the bubble on top.
        private void drawBoard()
                _canvas.drawRect(cX-r, cY1, cX+r, cY2, g);//left, top, right, bottom, paint
                _canvas.drawCircle(cX, cY1, r, g); //centerX, centerY, radius, paint
                _canvas.drawCircle(cX, cY2, r, g);
                bubble.draw(_canvas, g);

        public Bubble getBubble()
                return bubble;

        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
                _height = View.MeasureSpec.getSize(heightMeasureSpec);
                _width = View.MeasureSpec.getSize(widthMeasureSpec);

                setMeasuredDimension(_width, _height);

                _bitmap = Bitmap.createBitmap(_width, _height, Bitmap.Config.ARGB_8888);
                _canvas = new Canvas(_bitmap);

                cX = _width/2;
                cY1 = _height/4;
                cY2 = (_height*3)/4;
                r = _width/10;
        protected void onDraw(Canvas canvas) {
                canvas.drawBitmap(_bitmap, 0, 0, g);
SensorProgram Class

import org.openintents.sensorsimulator.hardware.SensorManagerSimulator;

import android.content.Context;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

public class SensorProgram extends Activity implements SensorListener
        private double highAccel, totalAccel;
        private SensorManagerSimulator mSensorManager;
        private static Context CONTEXT;
        private Board b;

        /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        b=new Board(this);
        CONTEXT = this;
        highAccel = 0;
        totalAccel = 0;
        mSensorManager = SensorManagerSimulator.getSystemService(this, SENSOR_SERVICE);

        mSensorManager.registerListener(this, SensorManager.SENSOR_ACCELEROMETER
                                | SensorManager.SENSOR_MAGNETIC_FIELD
                                | SensorManager.SENSOR_ORIENTATION,

    public static Context getContext()
        return CONTEXT;

        public void onAccelerationChanged(float x, float y, float z) {
                ((TextView)findViewById("X: "+String.valueOf(x));
                ((TextView)findViewById("Y: "+String.valueOf(y));
                ((TextView)findViewById("Z: "+String.valueOf(z));


        public void onSensorChanged(int sensor, float[] values) {
                if(sensor == SensorManager.SENSOR_ORIENTATION)


Jean Tessier is a senior at Southside High School. He enjoys reading
about psychology and learning new programming languages.


SAM Team--Southside High School's STEM and Computer Science extra-curricular club (Mr. Rogers Sponsor)

Android Developer Site

Mr. Rogers' Twitter Site

Mr. Rogers Teacher's Blog

Mr. Rogers T-shirts

Check out other web sites created by Mr. R:

Want to learn more about movie physics in Star Trek and find out :
  • what makes Star Trek unique
  • how Star Trek compares to Star Wars
  • why the star ship Enterprise needs to remain in space
  • what should and shouldn't be done in space battles
  • what it takes to blast off and travel the galaxy
  • the basics of orbiting
Insultingly Stupid Movie Physics is one of the most humorous, entertaining, and readable physics books available, yet is filled with all kinds of useful content and clear explanations for high school, 1st semester college physics students, and film buffs.

It explains all 3 of Newton's laws, the 1st and 2nd laws of thermodynamics, momentum, energy, gravity, circular motion and a host of other topics all through the lens of Hollywood movies using Star Trek and numerous other films.

If you want to learn how to think physics and have a lot of fun in the process, this is the book for you!


First the web site,

now the book!

Mr. Rogers Home | Common Sylabus | AP Comp Sci I | AP Comp Sci II | AP Physics Mech | AP Physics E&M | AP Statistics | IB Design Tech | Southside

[ Intuitor Home | Physics | Movie Physics | Chess | Forchess | Hex | Intuitor Store |

Copyright 1996-2010 T. K. Rogers, all rights reserved. Forchess is a registered trademark of T. K. Rogers.
No part of this website may be reproduced in any form, electronic or otherwise, without express written approval.