A joint talk with @javielinux about #Scala as an alternative for better #Android Development where some common android development pitfalls are shown and how they can be solved with Scala.
val title = TypedResource[TextView](R.id.title) object layout { val abc_screen_toolbar = TypedLayout[ActionBarOverlayLayout](R.layout.abc_screen_toolbar) } } class MyActivity extends AppCompatActivity with TypedActivity { val titleTextView = findView(title) //titleTextView inferred as TextView, no casting needed } (Scala on Android) 㱺 Painless Android Development with Scala 6
Fast (incremental compilation and proguard caching) — Proguard + MultiDexApplication integration (Circumvents 65K method limit) — Supports AAR, JAR and APK artifact types (Scala on Android) 㱺 Painless Android Development with Scala 8
person.job map (_.name) OR val jobName : Option[String] = for { job <- person.job } yield job.name OR Option, Try, Either, \/, Validation (Scala on Android) 㱺 Painless Android Development with Scala 10
{ public void bar() { FooUtils.get(getContext(), R.string.name); } } public class FooUtils { static String get(Context c, int res) { return c.getString(res); } } (Scala on Android) 㱺 Painless Android Development with Scala 11
{ ... switch (action) { case MotionEvent.ACTION_DOWN: ... break; case MotionEvent.ACTION_MOVE: ... break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: ... break; } } (Scala on Android) 㱺 Painless Android Development with Scala 22
import MotionEvent._ action match { case ACTION_DOWN => ??? case ACTION_MOVE => ??? case ACTION_UP | ACTION_CANCEL => ??? } } (Scala on Android) 㱺 Painless Android Development with Scala 23
Person(_, lastName) if lastName == “Pacheco” => println(“Guapetón”) case Person(name, _) if name == “Raúl” => println(“Resultón”) case _ => println(“Programadores Java”) } (Scala on Android) 㱺 Painless Android Development with Scala 24
def eggs : Eggs } class PlatyPus extends Mammal with EggsSupport PlatyPus().eggs <- Success!!! (Scala on Android) 㱺 Painless Android Development with Scala 28