Fork me on GitHub

Friday, August 14, 2015

Scaloid 4.0 is released

Today I release Scaloid 4.0, which includes lots of improvements.

Incompatible changes

Scaloid 4.0 is best with Android API Level 16, while still supports Level 10

Scaloid 4.0 distribution is compiled with Android API Level 16, still retaining compatibility with Level 10. Accessor methods and deprecation warning is based on API Level 16, so you have to carefully check the availability of API if you target lower version of Android. In our experience on building an App for Gingerbread, currently we found no obstruction that prevents building a Scaloid app for older devices.

To compile with Scaloid 4.0, you have to specify build time Android API in file as android-16 or higher.


Usual use case of LocalServiceConnection is:
val service = new LocalServiceConnection[MyService]
service {
  myService => // do something with myService
The implementation of apply() is changed to:
def apply[T](f: S => Unit): Unit = service.fold(onConnected(f))(f)
The block will be executed later if the service is not connected yet. Formally it was just did nothing when the service is not connected yet. This behavior now becomes ifAvailable. Then all the code using apply(...) should be changed to ifAvailable(...).


Constructor parameter of SArrayAdapter is now java.util.List.


spinnerDialog returns Future[ProgressDialog].

End of incompatible changes

More convenient press-and-hold action

We provided the press-and-hold action callback from the last release. The sample code below increases the number on the TextView in every 100 milliseconds:
val num = STextView("0")
SButton("Increase").onPressAndHold(100, num.text = (num.text.toString.toInt + 1).toString)
The press-and-holds has separate callback from that of clicks. Often the behavior for a click and press-and-hold are the same. In this case, we have to assign it individually:
val num = STextView("0")
SButton("Increase", num.text = (num.text.toString.toInt + 1).toString)
.onPressAndHold(100, num.text = (num.text.toString.toInt + 1).toString)
This kind of repetition is not looks good. From Scaloid 4.0, we introduce a shorter representation:
val num = STextView("0")
SButton("Increase", num.text = (num.text.toString.toInt + 1).toString, 100)

Cleaner and type-safe way to access SharedPreference

SharedPreference can be accessed in this way:
val executionCount = preferenceVar(0) // default value 0
val ec = executionCount() // read
executionCount() = ec + 1 // write
executionCount.remove() // remove
Refer to this post for more details:

`here` method

To attach a view widget to a layout, we have two major way to do it. One is using apply method of companion object of views:
new SLinearLayout {
  SButton("Hello") textColor Color.RED
The other is creating object with new keyword, and assign it to the layout using += method:
lazy val button = new SButton("Hello")

onCreate {
  contentView = new SLinearLayout {
    this += button
    button textColor Color.RED
In Scaloid 4.0, we have another choice:
lazy val button = new SButton("Hello")

onCreate {
  contentView = new SLinearLayout { textColor Color.RED
As you see, this += is abbreviated with .here. Because it returns SButton, method chaining is available.

Oftentimes, style is applied to widgets, and sometimes we want avoid it for some widget. We provide hereWithoutStyle method:
lazy val button = new SButton("Hello") textColor Color.RED
lazy val redBtn = new SButton("Hello") textColor Color.RED

contentView = new SLinearLayout {
  style {
    case b: Button => b textColor Color.BLUE
  } // blue
  redBtn.hereWithoutStyle // red
here method can also be applied to layouts:
contentView = new SVerticalLayout {
  new SLinearLayout {

1 comment:

  1. Just found your post by searching on the Google, I am Impressed and Learned Lot of new thing from your post.
    hotmail signup process