Simple Level App

by joshbeck » Tue, 04 Nov 2008 15:53:59 GMT


Sponsored Links
 k, so I wrote an app tonight that reads the 'Roll' data from the
compass and levels a line
on the screen. (It's on marketplace. It's also here:
http://www.imakmud.com/level.apk
) --Source Code Below:

Here's how it works:
-Basically every time the compass data changes, the canvas is
rotated and redrawn. It's very fast I think.

Problems I'm experiencing:

What I've got there is a single view with a single canvas. I'd like to
incorporate some
static elements like a pointers that don't rotate with the rest of the
canvas.
I experimented with drawables, but I'm just not sure that's the
answer.

So, I'm looking to have multiple graphics on the screen. One rotates,
the others don't.
Any direction is appreciated. --God this device is awesome!

Here is the Simple Level Code with comments as I understand the
program to be working:
(Please correct me where I am wrong.) I hope it helps other, and I
hope other developers are
able to chime in.

-----Look for the //LOOK HERE comment.-----


--ALL IMPORTS CORRECT--

public class level extends Activity {

private static final String TAG = "Compass";
private Bitmap mBitmap;
private SensorManager mSensorManager;
private SampleView mView;
private float[] mValues;

//SensorListener is called by the SensorManager object returned in
OnCreate

private final SensorListener mListener = new SensorListener() {

public void onSensorChanged(int sensor, float[] values) {
if (Config.LOGD) Log.d(TAG, "sensorChanged (" + values[0]
+ ", " + values[1] + ", " + values[2] + ")");
//mValues contains direction, yaw, and roll.
mValues = values;
if (mView != null) {
mView.invalidate();
}
}

public void onAccuracyChanged(int sensor, int accuracy) {
// TODO Auto-generated method stub

}
};

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mSensorManager =
(SensorManager)getSystemService(Context.SENSOR_SERVICE);
mView = new SampleView(this);

//SampleView(); is called here. So is onDraw?
//Question: if a view is defined here through an xml file, is
onDraw still called by default?
// Is that even right to assume onDraw is called here?

setContentView(mView);
}

@Override
protected void onResume()
{
if (Config.LOGD) Log.d(TAG, "onResume");
super.onResume();
mSensorManager.registerListener(mListener,
SensorManager.SENSOR_ORIENTATION,
SensorManager.SENSOR_DELAY_GAME);
}

@Override
protected void onStop()
{
if (Config.LOGD) Log.d(TAG, "onStop");
mSensorManager.unregisterListener(mListener);
super.onStop();
}

private class SampleView extends View {
private Paint mPaint = new Paint();
private Path mPath = new Path();
private boolean mAnimate;
private long mNextTime;


public SampleView(Context context) {
super(context);
//Maybe onDraw is called at this point?

}

//Because mView.invalidate is called in SensorListener, we can count
on onDraw everytime
//there is a change of state.
@Override protected void onDraw(Ca



Simple Level App

by Steve Oldmeadow » Tue, 04 Nov 2008 16:26:51 GMT


 All you have to do is reverse the rotation e.g rotate by -rotateMe
after you have drawn the rotated image and then all subsequent draws
will be non rotated.



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. change button name when clicked

Hi to all..


         Can anyone tell me how can i change the button name when
click on that button...? button.setText("click") ; is not working...

Thank You
N V
--~--~---------~--~----~------------~-------~--~----~

2. Voice Recognition in Sample API not working

Not sure what I am missing (using emulator not phone). I was trying to
get the speech api working, however it gives me the error: No Activity
found to handle Intent
{ action=android.speech.action.RECOGNIZE_SPEECH (has extras).

So then I tried running the 1.5 r1 sample code (api) and tried the
speech sample there, but it also isn't running.  Indicating I was
missing an app or component.  So what is the missing link?  It seems
as if the actual emulator doesn't come with some default apps which
make the voice recognition possible.

--~--~---------~--~----~------------~-------~--~----~

3. Catch "LED stop" event - Possible?

4. OpenCORE :: Using individual nodes from the application

5. Alert Text box value read error

6. About recording Audio

7. Ho to deteck key press on soft keyboard