implement tap on multiple overlapping stations

javaax25
Georg Lukas 2012-07-11 23:40:59 +02:00
rodzic 40353fa407
commit e3560ba623
3 zmienionych plików z 53 dodań i 2 usunięć

Wyświetl plik

@ -23,6 +23,7 @@
<!-- Maps activity -->
<string name="sta_lastreport">%s Last Report</string>
<string name="map_track_call">Tracking %s...</string>
<string name="map_select">Select station</string>
<string name="map_loading">Loading...</string>

Wyświetl plik

@ -1,12 +1,15 @@
package org.aprsdroid.app
import _root_.android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import _root_.android.app.AlertDialog
import _root_.android.content.{BroadcastReceiver, Context, DialogInterface, Intent, IntentFilter}
import _root_.android.database.Cursor
import _root_.android.graphics.drawable.{Drawable, BitmapDrawable}
import _root_.android.graphics.{Canvas, Paint, Path, Point, Rect, Typeface}
import _root_.android.os.{Bundle, Handler}
import _root_.android.util.Log
import _root_.android.view.{Menu, MenuItem, View}
import _root_.android.widget.SimpleCursorAdapter
import _root_.android.widget.Spinner
import _root_.android.widget.TextView
import _root_.com.google.android.maps._
import _root_.scala.collection.mutable.ArrayBuffer
@ -122,6 +125,14 @@ class Station(val movelog : ArrayBuffer[GeoPoint], val pt : GeoPoint,
val call : String, val origin : String, val symbol : String)
extends OverlayItem(pt, call, origin) {
def inArea(bl : GeoPoint, tr : GeoPoint) = {
val lat_ok = (bl.latitudeE6 <= pt.latitudeE6 && pt.latitudeE6 <= tr.latitudeE6)
val lon_ok = if (bl.longitudeE6 <= tr.longitudeE6)
(bl.longitudeE6 <= pt.longitudeE6 && pt.longitudeE6 <= tr.longitudeE6)
else
(bl.longitudeE6 <= pt.longitudeE6 || pt.longitudeE6 <= tr.longitudeE6)
lat_ok && lon_ok
}
}
class StationOverlay(icons : Drawable, context : MapAct, db : StorageDatabase) extends ItemizedOverlay[Station](icons) {
@ -246,6 +257,42 @@ class StationOverlay(icons : Drawable, context : MapAct, db : StorageDatabase) e
stations.add(sta)
}
override def onTap(gp : GeoPoint, mv : MapView) : Boolean = {
//Log.d(TAG, "user tapped " + gp)
//Log.d(TAG, "icon bounds: " + icons.getBounds())
// convert geopoint to pixels
val proj = mv.getProjection()
val p = proj.toPixels(gp, null)
// ... to pixel area ... to geo area
//Log.d(TAG, "coords: " + p)
val botleft = proj.fromPixels(p.x - 16, p.y + 16)
val topright = proj.fromPixels(p.x + 16, p.y - 16)
Log.d(TAG, "from " + botleft + " to " + topright)
// fetch stations in the tap
val list = stations.filter(_.inArea(botleft, topright)).map(_.call)
Log.d(TAG, "found " + list.size() + " stations")
val result = if (list.size() == 0)
false // nothing found, do not revert to superclass
else if (list.size() == 1) {
// found one entry
val call = list.get(0)
Log.d(TAG, "user clicked on " + call)
context.openDetails(call)
true
} else {
// TODO: replace simple adapter with StationListAdapter for better UI
new AlertDialog.Builder(context).setTitle(R.string.map_select)
.setItems(list.toArray.asInstanceOf[Array[CharSequence]], new DialogInterface.OnClickListener() {
override def onClick(di : DialogInterface, item : Int) {
context.openDetails(list.get(item))
}})
.setNegativeButton(android.R.string.cancel, null)
.show()
true
}
result
}
override def onTap(index : Int) : Boolean = {
val s = stations(index)
val target = if (s.origin != null && s.origin != "") s.origin

Wyświetl plik

@ -277,7 +277,10 @@ class StorageDatabase(context : Context) extends
def getRectStations(lat1 : Int, lon1 : Int, lat2 : Int, lon2 : Int, limit : String) : Cursor = {
Log.d(TAG, "StorageDatabase.getRectStations: %d,%d - %d,%d".format(lat1, lon1, lat2, lon2))
getStations("LAT >= ? AND LAT <= ? AND LON >= ? AND LON <= ?",
// check for areas overflowing between +180 and -180 degrees
val QUERY = if (lon1 <= lon2) "LAT >= ? AND LAT <= ? AND LON >= ? AND LON <= ?"
else "LAT >= ? AND LAT <= ? AND (LON <= ? OR LON >= ?)"
getStations(QUERY,
Array(lat1, lat2, lon1, lon2).map(_.toString), limit)
}