Android Open Source - QuestCompass Location Overlay






From Project

Back to project page QuestCompass.

License

The source code is released under:

Apache License

If you think the Android project QuestCompass 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

package de.renard.radar.map;
/*w  ww  .j  av  a2 s . c om*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.google.android.gms.maps.model.CameraPosition;

public class LocationOverlay extends View {

  private final float[] mLinePts = new float[8];
  private final Rect mTextBounds = new Rect();
  private final Paint mRecticlePaint = new Paint() {
    {
      setColor(Color.BLACK);
      setStrokeWidth(2);
      setStyle(Paint.Style.STROKE);
      setAntiAlias(true);
    }
  };
  private final Paint mTextPaint = new Paint() {
    {
      setColor(Color.BLACK);
      setTextSize(20f);
      setAntiAlias(true);
      setTextAlign(Align.LEFT);
    }
  };
  private CameraPosition position;

  public LocationOverlay(Context context) {
    super(context);
  }

  public LocationOverlay(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (position != null) {
      final int centerY = (getBottom() - getTop()) / 2;
      final int centerX = (getRight() - getLeft()) / 2;
      mLinePts[0] = 0;
      mLinePts[1] = centerY;
      mLinePts[2] = getRight();
      mLinePts[3] = centerY;
      mLinePts[4] = centerX;
      mLinePts[5] = getTop();
      mLinePts[6] = centerX;
      mLinePts[7] = getBottom();
      canvas.drawLines(mLinePts, mRecticlePaint);
      float radius = getWidth() * 0.1f;
      radius = Math.min(10f, radius);
      canvas.drawCircle(centerX, centerY, radius, mRecticlePaint);
      final String lat = String.format("%.6f", position.target.latitude);
      final String lon = String.format("%.6f", position.target.longitude);
      mTextPaint.getTextBounds("0.0000000", 0, 9, mTextBounds);
      canvas.drawText(lat, centerX - mTextBounds.width() - 10, centerY,
          mTextPaint);
      canvas.drawText(lon, centerX + 10, centerY, mTextPaint);
    }
  }

  public void updateCameraPostion(CameraPosition position) {
    this.position = position;
    this.invalidate();
  }
}




Java Source Code List

de.renard.radar.CompassFilter.java
de.renard.radar.CompassSensorListener.java
de.renard.radar.LocationAdapter.java
de.renard.radar.LocationDescriptionDialog.java
de.renard.radar.LocationListDaoGenerator.java
de.renard.radar.LocationListDialog.java
de.renard.radar.RadarActivity.java
de.renard.radar.ScreenOrienationEventListener.java
de.renard.radar.SensorDataController.java
de.renard.radar.Util.java
de.renard.radar.map.LocationOverlay.java
de.renard.radar.map.LocationPickActivity.java
de.renard.radar.views.LocationDeleteInterface.java
de.renard.radar.views.RadarView.java
de.renard.radar.views.RotateView.java