View Single Post
 
Old April 7th, 2010, 07:13 PM
Omen_20 Omen_20 is offline
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 10: Compass

All works except the actual compass on the outside. When moving the phone around the two circles in the center react right. The outer compass however doesnt move to the correct position and instead just wiggles. It stays with North at the top and wiggles when the phone is moved. Extreme movements seem to get it to react more, but it always returns to its original position.

Is the placement of this code in the correct place, before the for loop?
Code:
protected void onDraw(Canvas canvas) {
    int px = getMeasuredWidth() / 2;
    int py = getMeasuredHeight() / 2 ;
    int radius = Math.min(px, py);
    
    // Draw the background
    canvas.drawCircle(px, py, radius, circlePaint);
    // Rotate our perspective so that the 'top' is
    // facing the current bearing.
    canvas.save();
    canvas.rotate(-bearing, px, py);
    int textWidth = (int)textPaint.measureText("W");
    int cardinalX = px-textWidth/2;
    int cardinalY = py-radius+textHeight;
        
    // Draw the marker every 15 degrees and a text every 45.
    for (int i = 0; i < 24; i++) {
Complete code