Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:20:43+00:00 2026-05-29T04:20:43+00:00

I have a compass application which is using orientation sensor and every time the

  • 0

I have a compass application which is using orientation sensor and every time the sensor changes my compass view is being invalidated in order to rotate towards north. My compass is a 444px x 444px bitmap. The problem I’m facing is that whenever the sensor changes and you see the compass rotating it’s lagging, basically poor fps. I’ve tried to use a surface view instead and to change the SENSOR_DELAY, without any change. Would love if someone could help me figure out the answer to this problem.

Registering sensor

    orientation = sm.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    sm.registerListener(this, orientation, SensorManager.SENSOR_DELAY_UI);

Whenever sensor changes

public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub
    if (compass != null) {
        float[] v = event.values;
        north = v[0];
        compass.setNorth(-north);
    }
} 

Methods in the compass view

public void setNorth(float n) {
    north_changed = true;
    north = n;
    invalidate();
}

private void drawBackground(Canvas canvas) {
    canvas.save();
    if (north_changed == true) {
        canvas.rotate(north);
    }
    float maxwidth = (float) (backgroundTexture.getWidth() * Math.sqrt(2));
    float maxheight = (float) (backgroundTexture.getHeight() * Math.sqrt(2));
    float ratio = Math.min(w / maxwidth, h / maxheight);
    int width = (int) (backgroundTexture.getWidth() * ratio);
    int height = (int) (backgroundTexture.getHeight() * ratio);
    canvas.drawBitmap(
            backgroundTexture,
            new Rect(0, 0, backgroundTexture.getWidth(), backgroundTexture
                    .getHeight()), new RectF(-width / 1.5f, -height / 1.5f,
                    width / 1.5f, height / 1.5f), facePaint);
    canvas.restore();
}

onDraw

protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    if (showCompass) {
        w = getWidth();
        h = getHeight();
        cx = w / 2;
        cy = h / 2;
        canvas.translate(cx, cy);
        loadImages();
        drawBackground(canvas);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:20:45+00:00Added an answer on May 29, 2026 at 4:20 am

    You can try this

    replace:

    sm.registerListener(this, orientation, SensorManager.SENSOR_DELAY_UI);

    with this:

    sm.registerListener(this, orientation, SensorManager.SENSOR_DELAY_FASTEST);

    And if you want some extra smoothness

    replace:

    if (compass != null) {
        float[] v = event.values;
        north = v[0];
        compass.setNorth(-north);
    }
    

    with this:

    if (compass != null) {
        float[] v = event.values;
        north =north*0.1f + v[0]*0.9f;
        compass.setNorth(-north);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing an application in which i have to record compass reading. which
Have just started using Visual Studio Professional's built-in unit testing features, which as I
As I am using Ruby on Rails to build an application, which only runs
I am trying to filter out the noise from the orientation/compass sensor in my
I am using blueprint via Compass but have no scroll bars on longer pages,
I have a application where I am guiding a vehicle on compass headings and
I have a problem using compass-style remotley over ssh and my favorite text-editor textmate.
I have an android application with a listview which .. blablabla .. presents a
I have a new-ish rails 3.1.1 app using sass/compass with compass taking care of
Have just started using Google Chrome , and noticed in parts of our site,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.