|
|||||||||||||||||
|
Bubble Level
DescriptionThis 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.
Features
1.0 - 25 October 2010 Future Plans The level needs to be more sensitive, adjust accordingly. Make the level more aesthetically pleasing. Instructions Place the phone on a flat object and adjust the object to center the bubble drawn on the device.
package tessier.jean.com; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; 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) { g.setColor(Color.GREEN); 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; } }
package tessier.jean.com; import android.R.color; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; 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) { super(context); g = new Paint(); g.setColor(Color.WHITE); g.setStyle(Paint.Style.FILL); bubble = new Bubble(10,50000,0); } /** * Draws the level to the screen. Then draws the bubble on top. */ private void drawBoard() { g.setColor(Color.BLACK); _canvas.drawRect(0,0,500,500,g); g.setColor(Color.WHITE); _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; } @Override 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; bubble.setR(r); bubble.setX(cX); drawBoard(); } @Override protected void onDraw(Canvas canvas) { drawBoard(); canvas.drawBitmap(_bitmap, 0, 0, g); invalidate(); } }
package tessier.jean.com; import org.openintents.sensorsimulator.hardware.SensorManagerSimulator; import android.app.Activity; 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. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); b=new Board(this); setContentView(b); CONTEXT = this; highAccel = 0; totalAccel = 0; mSensorManager = SensorManagerSimulator.getSystemService(this, SENSOR_SERVICE); mSensorManager.connectSimulator(); mSensorManager.registerListener(this, SensorManager.SENSOR_ACCELEROMETER | SensorManager.SENSOR_MAGNETIC_FIELD | SensorManager.SENSOR_ORIENTATION, SensorManager.SENSOR_DELAY_FASTEST); } public static Context getContext() { return CONTEXT; } public void onAccelerationChanged(float x, float y, float z) { ((TextView)findViewById(R.id.x)).setText("X: "+String.valueOf(x)); ((TextView)findViewById(R.id.y)).setText("Y: "+String.valueOf(y)); ((TextView)findViewById(R.id.z)).setText("Z: "+String.valueOf(z)); } @Override public void onSensorChanged(int sensor, float[] values) { if(sensor == SensorManager.SENSOR_ORIENTATION) { b.getBubble().setY(215+(int)(values[1]*1.194)); } } } Biography
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 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. |