I tried this, but it did not work
Here is my code, can some one help me with this


package com.rohit.test;

import android.content.Context;
import android.graphics.Canvas;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Config;
import android.util.Log;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class Compass extends MapActivity {

        private static final String TAG = "Compass";

        private SensorManager mSensorManager;
        private float[] mValues = null;
        private SampleView mView;

        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] + ")");
                        if (mView != null) {
                                mValues = values;
                                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,"<<my key>>");
                mView.setClickable(true);

                setContentView(mView);
                if (Config.LOGD)
                        Log.d(TAG, "onCreate");
        }

        @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();
        }

        public class SampleView extends MapView {

                public SampleView(Context context,String apiKey) {
                        super(context,apiKey);

                }
                @Override
                protected void dispatchDraw(Canvas canvas) {

                        if (mValues != null) {
                                int py=canvas.getClipBounds().bottom/2;
                                int px=canvas.getClipBounds().right/2;
                                canvas.rotate(-mValues[0],px,py);
                        }
                        super.dispatchDraw(canvas);
                }

        }

        @Override
        protected boolean isRouteDisplayed() {
                // TODO Auto-generated method stub
                return false;
        }

}

On Dec 17 2008, 3:20 am, David C <[email protected]> wrote:
> I just received this response:
>
> "Override a ViewGroup and apply the rotation indispatchDraw()."
>
> Thanks Romain!
>
> On Dec 8, 12:43 pm, David C <[email protected]> wrote:
>
> > "Bump"....  can anyone provide insight here?
>
> > Did theMapViewonDraw() API change to "final" at some point? If the
> > recommended method to rotate aMapViewis canvas.rotate() how can that
> > be achieved if not via onDraw()?
>
> > Personally I'd prefer to see theMapViewAPI extended to support
> > "setBearing()" or something similar, but nothing like that exists.
> > <sigh>
>
> > On Dec 7, 11:23 am, David C <[email protected]> wrote:
>
> > > A few threads have discussed using canvas.rotate() as a means to
> > > rotate aMapView. However, onDraw() is declared "final" forMapView
> > > and so can't be over-ridden. Is there an alternative way to manipulate
> > > theMapViewcanvas than from onDraw()?
>
> > > Thanks,
> > > David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to