kopia lustrzana https://github.com/ge0rg/aprsdroid
map: load all positions
rodzic
f3d1fd7dd6
commit
ea4a9e8b5b
|
@ -7,6 +7,8 @@ import _root_.android.os.{Bundle, Handler}
|
||||||
import _root_.android.util.Log
|
import _root_.android.util.Log
|
||||||
import _root_.android.view.{Menu, MenuItem, View}
|
import _root_.android.view.{Menu, MenuItem, View}
|
||||||
import _root_.com.google.android.maps._
|
import _root_.com.google.android.maps._
|
||||||
|
import _root_.scala.collection.mutable.ArrayBuffer
|
||||||
|
import _root_.java.util.ArrayList
|
||||||
|
|
||||||
// to make scala-style iterating over arraylist possible
|
// to make scala-style iterating over arraylist possible
|
||||||
import scala.collection.JavaConversions._
|
import scala.collection.JavaConversions._
|
||||||
|
@ -92,13 +94,13 @@ class MapAct extends MapActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Station(val point : GeoPoint, val call : String, val message : String, val symbol : String)
|
class Station(val movelog : ArrayBuffer[GeoPoint], val point : GeoPoint,
|
||||||
|
val call : String, val message : String, val symbol : String)
|
||||||
extends OverlayItem(point, call, message) {
|
extends OverlayItem(point, call, message) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StationOverlay(icons : Drawable, context : Context, db : StorageDatabase) extends ItemizedOverlay[Station](icons) {
|
class StationOverlay(icons : Drawable, context : MapAct, db : StorageDatabase) extends ItemizedOverlay[Station](icons) {
|
||||||
val TAG = "StationOverlay"
|
val TAG = "StationOverlay"
|
||||||
|
|
||||||
//lazy val calls = new scala.collection.mutable.HashMap[String, Boolean]()
|
//lazy val calls = new scala.collection.mutable.HashMap[String, Boolean]()
|
||||||
|
@ -120,7 +122,7 @@ class StationOverlay(icons : Drawable, context : Context, db : StorageDatabase)
|
||||||
(symbol(0) != '/' && symbol(0) != '\\')
|
(symbol(0) != '/' && symbol(0) != '\\')
|
||||||
}
|
}
|
||||||
|
|
||||||
def drawTrace(c : Canvas, m : MapView, call : String) : Unit = {
|
def drawTrace(c : Canvas, m : MapView, s : Station) : Unit = {
|
||||||
//Log.d(TAG, "drawing trace of %s".format(call))
|
//Log.d(TAG, "drawing trace of %s".format(call))
|
||||||
|
|
||||||
val tracePaint = new Paint()
|
val tracePaint = new Paint()
|
||||||
|
@ -135,25 +137,18 @@ class StationOverlay(icons : Drawable, context : Context, db : StorageDatabase)
|
||||||
val path = new Path()
|
val path = new Path()
|
||||||
val point = new Point()
|
val point = new Point()
|
||||||
|
|
||||||
val cur = db.getStaPositions(call, "%d".format(System.currentTimeMillis() - 30*3600*1000))
|
if (s.movelog.size() < 2) {
|
||||||
if (cur.getCount() < 2) {
|
|
||||||
cur.close()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cur.moveToFirst()
|
|
||||||
var first = true
|
var first = true
|
||||||
while (!cur.isAfterLast()) {
|
for (p <- s.movelog) {
|
||||||
val lat = cur.getInt(cur.getColumnIndexOrThrow(StorageDatabase.Position.LAT))
|
m.getProjection().toPixels(p, point)
|
||||||
val lon = cur.getInt(cur.getColumnIndexOrThrow(StorageDatabase.Position.LON))
|
|
||||||
m.getProjection().toPixels(new GeoPoint(lat, lon), point)
|
|
||||||
if (first) {
|
if (first) {
|
||||||
path.moveTo(point.x, point.y)
|
path.moveTo(point.x, point.y)
|
||||||
first = false
|
first = false
|
||||||
} else
|
} else
|
||||||
path.lineTo(point.x, point.y)
|
path.lineTo(point.x, point.y)
|
||||||
cur.moveToNext()
|
|
||||||
}
|
}
|
||||||
cur.close()
|
|
||||||
c.drawPath(path, tracePaint)
|
c.drawPath(path, tracePaint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,9 +190,7 @@ class StationOverlay(icons : Drawable, context : Context, db : StorageDatabase)
|
||||||
val destRect = new Rect(p.x-ss, p.y-ss, p.x+ss, p.y+ss)
|
val destRect = new Rect(p.x-ss, p.y-ss, p.x+ss, p.y+ss)
|
||||||
// first draw callsign and trace
|
// first draw callsign and trace
|
||||||
if (zoom >= 10) {
|
if (zoom >= 10) {
|
||||||
Benchmark("drawTrace") {
|
drawTrace(c, m, s)
|
||||||
drawTrace(c, m, s.call)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.drawText(s.call, p.x, p.y+ss+fontSize, strokePaint)
|
c.drawText(s.call, p.x, p.y+ss+fontSize, strokePaint)
|
||||||
c.drawText(s.call, p.x, p.y+ss+fontSize, textPaint)
|
c.drawText(s.call, p.x, p.y+ss+fontSize, textPaint)
|
||||||
|
@ -219,19 +212,32 @@ class StationOverlay(icons : Drawable, context : Context, db : StorageDatabase)
|
||||||
val filter = if (showObjects) null else "ORIGIN IS NULL"
|
val filter = if (showObjects) null else "ORIGIN IS NULL"
|
||||||
val c = db.getPositions(filter, null, null)
|
val c = db.getPositions(filter, null, null)
|
||||||
c.moveToFirst()
|
c.moveToFirst()
|
||||||
|
var m = new ArrayBuffer[GeoPoint]()
|
||||||
while (!c.isAfterLast()) {
|
while (!c.isAfterLast()) {
|
||||||
val call = c.getString(StorageDatabase.Position.COLUMN_CALL)
|
val call = c.getString(StorageDatabase.Position.COLUMN_CALL)
|
||||||
val symbol = c.getString(StorageDatabase.Position.COLUMN_SYMBOL)
|
|
||||||
val comment = c.getString(StorageDatabase.Position.COLUMN_COMMENT)
|
|
||||||
val lat = c.getInt(StorageDatabase.Position.COLUMN_LAT)
|
val lat = c.getInt(StorageDatabase.Position.COLUMN_LAT)
|
||||||
val lon = c.getInt(StorageDatabase.Position.COLUMN_LON)
|
val lon = c.getInt(StorageDatabase.Position.COLUMN_LON)
|
||||||
addStation(new Station(new GeoPoint(lat, lon), call, comment, symbol))
|
val symbol = c.getString(StorageDatabase.Position.COLUMN_SYMBOL)
|
||||||
|
val comment = c.getString(StorageDatabase.Position.COLUMN_COMMENT)
|
||||||
|
val p = new GeoPoint(lat, lon)
|
||||||
|
m.add(p)
|
||||||
|
// peek at the next row
|
||||||
|
c.moveToNext()
|
||||||
|
val next_call = if (!c.isAfterLast()) c.getString(StorageDatabase.Position.COLUMN_CALL) else null
|
||||||
|
c.moveToPrevious()
|
||||||
|
if (next_call != call) {
|
||||||
|
//Log.d(TAG, "end of call: " + call + " " + next_call + " " + m.size())
|
||||||
|
addStation(new Station(m, p, call, comment, symbol))
|
||||||
|
m = new ArrayBuffer[GeoPoint]()
|
||||||
|
}
|
||||||
c.moveToNext()
|
c.moveToNext()
|
||||||
}
|
}
|
||||||
c.close()
|
c.close()
|
||||||
setLastFocusedIndex(-1)
|
|
||||||
populate()
|
|
||||||
Log.d(TAG, "total %d items".format(size()))
|
Log.d(TAG, "total %d items".format(size()))
|
||||||
|
setLastFocusedIndex(-1)
|
||||||
|
Benchmark("populate") { populate() }
|
||||||
|
context.mapview.invalidate()
|
||||||
|
context.animateToCall()
|
||||||
}
|
}
|
||||||
|
|
||||||
def addStation(sta : Station) {
|
def addStation(sta : Station) {
|
||||||
|
|
|
@ -177,7 +177,7 @@ class StorageDatabase(context : Context) extends
|
||||||
def getPositions(sel : String, selArgs : Array[String], limit : String) : Cursor = Benchmark("getPositions") {
|
def getPositions(sel : String, selArgs : Array[String], limit : String) : Cursor = Benchmark("getPositions") {
|
||||||
getReadableDatabase().query(Position.TABLE, Position.COLUMNS,
|
getReadableDatabase().query(Position.TABLE, Position.COLUMNS,
|
||||||
sel, selArgs,
|
sel, selArgs,
|
||||||
Position.CALL, null, "_ID DESC", limit)
|
null, null, "CALL, _ID DESC", limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getRectPositions(lat1 : Int, lon1 : Int, lat2 : Int, lon2 : Int, limit : String) : Cursor = {
|
def getRectPositions(lat1 : Int, lon1 : Int, lat2 : Int, lon2 : Int, limit : String) : Cursor = {
|
||||||
|
|
Ładowanie…
Reference in New Issue