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. Asynchronous takePicture()!?

After getting unexpected results from takePicture() and subsequent
image processing, I discovered that takePicture() is asynchronous.
Although the documentation indeed states that takePicture() (just?)
registers a callback,

http://code.google.com/android/reference/android/hardware/Camera.html

thereby suggestive of some other method to take the actual snapshot
(but such a method does not exist), takePicture() also doubles as a
trigger to actually take the snapshot, *but* asynchronously with the
code in which takePicture() is called. To me this seems highly
confusing at best, if not plain ugly. I could not find any
documentation about a Listener for completion of snapshot-taking, so
to fix things I now had to add my own semaphores and a while-sleep to
make sure my snapshot is taken and processed before I reuse the bitmap
in which I store the onPictureTaken() data.

Regards

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

2. New to the group and VoteReport app

Hi there. I am new to this group, and proud to say I just built my
first Android app in about 10 hours... including uploading it for
release in the Market! Fortunately, it is a fairly simple application
and I am not crazy, just working against the deadline of November 4th.
More on this...

I am part of a group working something called TwitterVoteReport.com
(also known as http://VoteReport.us) Twitter Vote Report is an all-
volunteer network of software developers, designers, and other
collaborators have teamed up with the award-winning blog techPresident
to launch this effort. The only resources contributed to this project
are the participantstime and expertise! Using Twitter Vote Report,
voters will be able to share their experiences and resources with one
another to solve problems quickly (e.g. on come now, the line is
too long. These messages will then be aggregated and mapped so that
we can eevoting problems around the country in real-time.

Since there was an effort to create an iPhone application underway, I
decided to "port" that work to Android. I've been involved in mobile
software and Java for a long time, and thought this seemed like a
fantastic application that made a lot of sense. After a full day of
hacking yesterday, and a few hours of testing (I promise), the first
release of the app was done. I hate calling things 1.0, so I didn -
VoteReport for Android 0.9.4 is released and available in the Android
Market. If you have a T-Mobile G1, just open the Market application
and search for otereportor simply browse under the Productivity
category. You can also download it direct at: 
http://openideals.com/android/VoteReport.apk.
Code will be up soon (this is an open source effort).

This is very simple app with a powerful concept, but it does do some
more complicated things under the cover (location lookup, web
integration, REST calls, etc). I am working on a GeoRSS parser (for
http://votereport.us/reports.atom) to generate a MapView overlay, but
that might take a few more hours.

Read on if you'd like at: 
http://openideals.com/2008/10/30/votereport-for-android-094/
Otherwise, if you are in the US, please check out the entire project:
http://twittervotereport.com

Best,
  Nathan

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

3. The same activity run in different process?

4. No Moto-Droids 'till next Christmas

5. Android Halloween Costume

6. Wikitude testers needed

7. Does Android 1.0 support progressive download of music and video files?