Android Open Source - spotthestation My Compass View






From Project

Back to project page spotthestation.

License

The source code is released under:

Apache License

If you think the Android project spotthestation listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Written by Eleanor Da Fonseca, Weixiong Cen, Harrison Black & Boris Feron
 *//*from ww w. j  a  v a  2 s . c om*/

package nasa.android.spotthestation;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.View;

public class MyCompassView extends View
{
    private Paint paint;
    private float azimuth = 0;
    private float issAzimuth = 0;

    public MyCompassView(Context context)
    {
  super(context);
  init();
    }

    private void init()
    {
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setStrokeWidth(2);
  paint.setTextSize(25);
  paint.setStyle(Paint.Style.STROKE);
  paint.setColor(Color.WHITE);
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
  int xCentre = getMeasuredWidth() / 2;
  int yCentre = getMeasuredHeight() / 2;
  float radius = (float) (Math.max(xCentre, yCentre) * 0.45);
  paint.setColor(Color.WHITE);
  canvas.drawCircle(xCentre, yCentre, radius, paint);
  paint.setColor(Color.RED);
  float xNorth = (float) (xCentre + radius * Math.sin((double)Math.toRadians(-azimuth)));
  float yNorth = (float) (yCentre - radius * Math.cos((double)Math.toRadians(-azimuth)));
  canvas.drawLine(xCentre, yCentre, xNorth, yNorth, paint);
  canvas.drawText("N", xNorth, yNorth, paint);
  paint.setColor(Color.BLUE);

  float xISS = (float) (xCentre + radius * Math.sin((double)Math.toRadians(-(azimuth - issAzimuth))));
  float yISS = (float) (yCentre - radius * Math.cos((double)Math.toRadians(-(azimuth - issAzimuth))));
  canvas.drawLine(xCentre, yCentre, xISS, yISS, paint);
  canvas.drawText("ISS", xISS, yISS, paint);
  paint.setColor(Color.GREEN);
  canvas.drawLine(xCentre, yCentre, xCentre, yCentre - radius, paint);
  canvas.drawText("User", xCentre, yCentre - radius, paint);
    }

    public void updateData(float azimuthUpdated, float issAzimuth)
    {
  this.azimuth = (azimuthUpdated + 90) % 360; // The compass of our phone is offset by 90 degrees
                // of our screen orientation and hence we must add 90.
                // We take the value modulo 360 to ensure we have no
                // angle greater than this number.
  this.issAzimuth = (float)-Math.toDegrees(issAzimuth);
  invalidate();
    }
}




Java Source Code List

Entities.NASAImageCommentTable.java
Entities.NASAImageCommentTable_.java
Entities.NASAImageTable.java
Entities.NASAImageTable_.java
Entities.NASARegistrationTable.java
Entities.NASARegistrationTable_.java
.ISSPollingApp.java
.NotificationMDB.java
Servlets.ImageDownloadServlet.java
Servlets.ImageUploadServlet.java
Servlets.MarkerDownloadServlet.java
Servlets.RegistrationServlet.java
Threads.HttpPollingThread.java
Utilities.ZoneCalculator.java
Utilities.ZoneCalculator.java
WebServices.NotificationService.java
nasa.android.spotthestation.CameraActivity.java
nasa.android.spotthestation.CameraPlusActivity.java
nasa.android.spotthestation.GCMIntentService.java
nasa.android.spotthestation.HelpActivity.java
nasa.android.spotthestation.ImageViewActivity.java
nasa.android.spotthestation.MapActivity.java
nasa.android.spotthestation.MyCompassView.java
nasa.android.spotthestation.TwitterActivity.java
nasa.android.spotthestation.TwitterWebviewActivity.java
nasa.android.spotthestation.UploadToNasaServerActivity.java
org.netbeans.rest.application.config.ApplicationConfig.java