From 7e540160af7e001b4b5be076e01cae746ab1ba65 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Mon, 13 Dec 2010 21:04:00 +0100 Subject: [PATCH] add drawing of paths --- src/MapAct.scala | 39 ++++++++++++++++++++++++++++++++++++++- src/StorageDatabase.scala | 6 ++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/MapAct.scala b/src/MapAct.scala index ddd0906..1485bbb 100644 --- a/src/MapAct.scala +++ b/src/MapAct.scala @@ -2,7 +2,7 @@ package de.duenndns.aprsdroid import _root_.android.content.{BroadcastReceiver, Context, Intent, IntentFilter} import _root_.android.graphics.drawable.{Drawable, BitmapDrawable} -import _root_.android.graphics.{Canvas, Paint, Point, Rect, Typeface} +import _root_.android.graphics.{Canvas, Paint, Path, Point, Rect, Typeface} import _root_.android.os.Bundle import _root_.android.util.Log import _root_.com.google.android.maps._ @@ -74,6 +74,43 @@ class StationOverlay(icons : Drawable, db : StorageDatabase) extends ItemizedOve (symbol(0) != '/' && symbol(0) != '\\') } + def drawTrace(c : Canvas, m : MapView, call : String) : Unit = { + //Log.d(TAG, "drawing trace of %s".format(call)) + + val tracePaint = new Paint() + tracePaint.setARGB(200, 255, 128, 128) + tracePaint.setStyle(Paint.Style.STROKE) + tracePaint.setStrokeJoin(Paint.Join.ROUND) + tracePaint.setStrokeCap(Paint.Cap.ROUND) + tracePaint.setStrokeWidth(2) + tracePaint.setAntiAlias(true) + + + val path = new Path() + val point = new Point() + + val cur = db.getStaPositions(call, "%d".format(System.currentTimeMillis() - 30*3600*1000)) + if (cur.getCount() < 2) { + cur.close() + return + } + cur.moveToFirst() + var first = true + while (!cur.isAfterLast()) { + val lat = cur.getInt(cur.getColumnIndexOrThrow(StorageDatabase.Position.LAT)) + val lon = cur.getInt(cur.getColumnIndexOrThrow(StorageDatabase.Position.LON)) + m.getProjection().toPixels(new GeoPoint(lat, lon), point) + if (first) { + path.moveTo(point.x, point.y) + first = false + } else + path.lineTo(point.x, point.y) + cur.moveToNext() + } + cur.close() + c.drawPath(path, tracePaint) + } + override def draw(c : Canvas, m : MapView, shadow : Boolean) : Unit = { if (shadow) return; diff --git a/src/StorageDatabase.scala b/src/StorageDatabase.scala index c211a50..22bf92a 100644 --- a/src/StorageDatabase.scala +++ b/src/StorageDatabase.scala @@ -125,6 +125,12 @@ class StorageDatabase(context : Context) extends Position.CALL, null, "_ID DESC", limit) } + def getStaPositions(call : String, limit : String) : Cursor = { + getReadableDatabase().query(Position.TABLE, Position.COLUMNS, + "call LIKE ? AND TS > ?", Array(call, limit), + null, null, "_ID DESC", null) + } + def addPost(ts : Long, posttype : Int, status : String, message : String) { val cv = new ContentValues() cv.put(Post.TS, ts.asInstanceOf[java.lang.Long])