aprsdroid/src/LogActivity.scala

91 wiersze
2.3 KiB
Scala

package org.aprsdroid.app
2009-12-31 16:50:01 +00:00
2010-01-30 21:37:54 +00:00
import _root_.android.app.AlertDialog
2010-01-05 17:04:13 +00:00
import _root_.android.content._
2010-02-08 00:35:33 +00:00
import _root_.android.content.pm.PackageInfo;
2011-04-12 22:21:42 +00:00
import _root_.android.database.Cursor
import _root_.android.location._
import _root_.android.os.{Bundle, Handler}
2010-01-06 16:37:16 +00:00
import _root_.android.preference.PreferenceManager
import _root_.java.text.SimpleDateFormat
import _root_.android.util.Log
import _root_.android.view.View
2011-05-20 23:21:41 +00:00
import _root_.android.widget.ListView
import _root_.android.widget.SimpleCursorAdapter
import _root_.android.widget.TextView
2010-01-06 16:37:16 +00:00
import _root_.android.widget.Toast
2010-01-09 02:25:52 +00:00
import _root_.java.util.Date
class LogActivity extends MainListActivity("log", R.id.log) {
2011-07-01 20:21:16 +00:00
val TAG = "APRSdroid.Log"
2010-01-01 12:49:39 +00:00
2010-06-13 23:43:49 +00:00
lazy val storage = StorageDatabase.open(this)
lazy val postcursor = storage.getPosts("300")
2010-01-06 16:37:16 +00:00
lazy val postlist = getListView()
2009-12-31 16:50:01 +00:00
2011-04-12 22:21:42 +00:00
lazy val locReceiver = new LocationReceiver2[Cursor](load_cursor, replace_cursor, cancel_cursor)
2011-05-20 23:29:15 +00:00
lazy val la = new PostListAdapter(this)
2010-01-06 16:25:09 +00:00
2009-12-31 16:50:01 +00:00
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
2010-01-01 12:49:39 +00:00
Log.d(TAG, "starting " + getString(R.string.build_version))
onContentViewLoaded()
onStartLoading()
2011-04-12 22:21:42 +00:00
la.setFilterQueryProvider(storage.getPostFilter("300"))
2011-04-12 22:21:42 +00:00
2010-06-13 23:43:49 +00:00
postlist.setAdapter(la)
2010-08-08 19:58:39 +00:00
postlist.setTextFilterEnabled(true)
2010-01-01 12:49:39 +00:00
}
2010-01-06 16:37:16 +00:00
override def onResume() {
super.onResume()
2011-04-10 14:00:11 +00:00
registerReceiver(locReceiver, new IntentFilter(AprsService.UPDATE))
2011-04-13 00:29:04 +00:00
locReceiver.startTask(null)
2011-04-10 14:00:11 +00:00
2011-05-28 22:03:32 +00:00
postlist.requestFocus()
2010-01-06 16:37:16 +00:00
}
2011-04-10 14:00:11 +00:00
override def onPause() {
super.onPause()
2010-01-06 16:25:09 +00:00
unregisterReceiver(locReceiver)
}
2011-04-12 23:07:18 +00:00
override def onDestroy() {
super.onDestroy()
la.changeCursor(null)
}
2011-05-20 23:21:41 +00:00
override def onListItemClick(l : ListView, v : View, position : Int, id : Long) {
import StorageDatabase.Post._
//super.onListItemClick(l, v, position, id)
val c = getListView().getItemAtPosition(position).asInstanceOf[Cursor]
val t = c.getInt(COLUMN_TYPE)
if (t != TYPE_POST && t != TYPE_INCMG)
return
val call = c.getString(COLUMN_MESSAGE).split(">")(0)
Log.d(TAG, "onListItemClick: %s".format(call))
2011-05-26 10:31:48 +00:00
openDetails(call)
2011-05-20 23:21:41 +00:00
}
2011-04-12 22:21:42 +00:00
def load_cursor(i : Intent) = {
val c = storage.getPosts("300")
2011-04-12 22:21:42 +00:00
c.getCount()
c
}
def replace_cursor(c : Cursor) {
2011-05-28 20:30:31 +00:00
if (!getListView().hasTextFilter())
la.changeCursor(c)
onStopLoading()
2011-04-12 22:21:42 +00:00
}
def cancel_cursor(c : Cursor) {
c.close()
}
2009-12-31 16:50:01 +00:00
}