aprsdroid/src/StationActivity.scala

101 wiersze
3.2 KiB
Scala
Czysty Zwykły widok Historia

2011-02-05 13:54:32 +00:00
package org.aprsdroid.app
2011-03-21 18:12:35 +00:00
import _root_.android.app.ListActivity
import _root_.android.content._
2011-03-22 20:59:09 +00:00
import _root_.android.database.Cursor
2011-03-26 23:52:56 +00:00
import _root_.android.net.Uri
2011-02-05 13:54:32 +00:00
import _root_.android.os.{Bundle, Handler}
2011-03-22 20:59:09 +00:00
import _root_.android.util.Log
2011-04-08 22:27:07 +00:00
import _root_.android.view.{Menu, MenuItem, View, Window}
2011-03-26 23:52:56 +00:00
import _root_.android.view.View.OnClickListener
import _root_.android.widget.{ListView,SimpleCursorAdapter}
2011-02-05 13:54:32 +00:00
2011-03-26 23:52:56 +00:00
class StationActivity extends ListActivity with OnClickListener {
2011-03-22 20:59:09 +00:00
lazy val prefs = new PrefsWrapper(this)
2011-03-26 23:52:56 +00:00
lazy val uihelper = new UIHelper(this, -1, prefs)
2011-03-22 20:59:09 +00:00
2011-03-26 23:52:56 +00:00
lazy val targetcall = getIntent().getStringExtra("call")
2011-03-22 20:59:09 +00:00
2011-03-26 23:52:56 +00:00
lazy val storage = StorageDatabase.open(this)
lazy val postcursor = storage.getStaPosts(targetcall, "100")
lazy val postlist = findViewById(R.id.postlist).asInstanceOf[ListView]
lazy val mycall = prefs.getCallSsid()
2011-04-13 00:30:58 +00:00
lazy val pla = new PositionListAdapter(this, prefs, mycall, targetcall, PositionListAdapter.SSIDS)
2011-03-22 20:59:09 +00:00
2011-02-05 13:54:32 +00:00
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
2011-04-08 22:27:07 +00:00
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)
2011-02-05 13:54:32 +00:00
setContentView(R.layout.stationactivity)
2011-04-08 22:27:07 +00:00
setProgressBarIndeterminateVisibility(true)
2011-02-05 13:54:32 +00:00
2011-03-22 20:59:09 +00:00
getListView().setOnCreateContextMenuListener(this);
setListAdapter(pla)
2011-03-26 23:52:56 +00:00
startManagingCursor(postcursor)
val la = new SimpleCursorAdapter(this, R.layout.listitem,
postcursor,
Array("TSS", StorageDatabase.Post.STATUS, StorageDatabase.Post.MESSAGE),
Array(R.id.listts, R.id.liststatus, R.id.listmessage))
la.setViewBinder(new PostViewBinder())
postlist.setAdapter(la)
Array(R.id.mapbutton, R.id.qrzcombutton, R.id.aprsfibutton).foreach((id) => {
findViewById(id).setOnClickListener(this)
})
2011-04-13 22:16:38 +00:00
setTitle(getString(R.string.app_sta) + ": " + targetcall)
2011-03-22 20:59:09 +00:00
}
override def onDestroy() {
super.onDestroy()
pla.onDestroy()
}
override def onCreateOptionsMenu(menu : Menu) : Boolean = {
2011-04-12 23:21:05 +00:00
getMenuInflater().inflate(R.menu.options, menu);
true
}
override def onPrepareOptionsMenu(menu : Menu) = uihelper.onPrepareOptionsMenu(menu)
override def onOptionsItemSelected(mi : MenuItem) : Boolean = {
uihelper.optionsItemAction(mi)
}
2011-03-22 20:59:09 +00:00
override def onListItemClick(l : ListView, v : View, position : Int, id : Long) {
//super.onListItemClick(l, v, position, id)
val c = getListView().getItemAtPosition(position).asInstanceOf[Cursor]
val call = c.getString(StorageDatabase.Position.COLUMN_CALL)
Log.d("StationActivity", "onListItemClick: %s".format(call))
if (targetcall == call) {
// click on own callssid
2011-04-08 19:49:56 +00:00
uihelper.trackOnMap(call)
2011-03-26 23:52:56 +00:00
} else {
2011-03-22 20:59:09 +00:00
startActivity(new Intent(this, classOf[StationActivity]).putExtra("call", call));
2011-03-26 23:52:56 +00:00
finish()
}
}
2011-03-22 20:59:09 +00:00
2011-03-26 23:52:56 +00:00
// button actions
override def onClick(view : View) {
view.getId match {
case R.id.mapbutton =>
2011-04-08 19:49:56 +00:00
uihelper.trackOnMap(targetcall)
2011-03-26 23:52:56 +00:00
case R.id.aprsfibutton =>
val url = "http://aprs.fi/?call=%s".format(targetcall)
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(url)))
case R.id.qrzcombutton =>
val url = "http://qrz.com/db/%s".format(targetcall.split("[- ]+")(0))
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(url)))
case _ =>
//status.setText(view.asInstanceOf[Button].getText)
}
2011-03-21 18:12:35 +00:00
}
2011-02-05 13:54:32 +00:00
}