# scaloid **Repository Path**: scalalibs/scaloid ## Basic Information - **Project Name**: scaloid - **Description**: Scaloid is a library that simplifies your Android code. It makes your code easy to understand and maintain by leveraging Scala language. - **Primary Language**: Scala - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2015-11-17 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: android-modules **Tags**: None ## README

# Simpler Android Scaloid is a library that simplifies your Android code. It makes your code easy to understand and maintain by [leveraging Scala language](https://github.com/pocorall/scaloid/wiki/Appendix#wiki-faqs-about-scaloid). For example, the code block shown below: ```scala val button = new Button(context) button.setText("Greet") button.setOnClickListener(new OnClickListener() { def onClick(v: View) { Toast.makeText(context, "Hello!", Toast.LENGTH_SHORT).show() } }) layout.addView(button) ``` is reduced to: ```scala SButton("Greet", toast("Hello!")) ``` ### Benefits * **Write elegant Android software**
Simplicity is number one principle, keeps programmability and type-safety. * **Easy to use**
Check the [quick start guide](https://github.com/pocorall/scaloid/wiki/Installation#wiki-quick-start) * **Compatible with your legacy code**
You can [use both Scaloid and plain-old Java Android API](https://github.com/pocorall/scaloid/wiki/Appendix#wiki-i-cant-use-scaloid-because-it-does-not-provide-a-functionality-x). You can gradually improve your legacy code. * **Production quality**
Not a toy project. The creator of Scaloid uses it to build [a millionth downloaded app](https://play.google.com/store/apps/details?id=com.soundcorset.client.android). ### Demos Fork one of this to start a new project: * [Hello world of Scaloid for sbt](https://github.com/pocorall/hello-scaloid-sbt) (recommended, it builds faster) * [Hello world of Scaloid for maven](https://github.com/pocorall/hello-scaloid-maven) * [Hello world of Scaloid for gradle](https://github.com/pocorall/hello-scaloid-gradle) Learn how Scaloid can be used in action: * [Scaloid port of apidemos app](https://github.com/pocorall/scaloid-apidemos) * [List of projects using Scaloid](https://github.com/pocorall/scaloid/wiki/Appendix#wiki-list-of-projects-using-scaloid) * [Tutorial by Gaston Hillar](http://www.drdobbs.com/mobile/developing-android-apps-with-scala-and-s/240161584) - [part 1](http://www.drdobbs.com/mobile/developing-android-apps-with-scala-and-s/240161584) and [part 2](http://www.drdobbs.com/mobile/developing-android-apps-with-scala-and-s/240162204) ## Contents * [Core design principle](#core-design-principle) * [UI Layout without XML](#ui-layout-without-xml) * [Layout context](#layout-context) * [Styles for programmers](#styles-for-programmers) * [Automatic layout converter](#automatic-layout-converter) * [Lifecycle management](#lifecycle-management) * [Asynchronous task processing](https://github.com/pocorall/scaloid/wiki/Basics#wiki-asynchronous-task-processing) * [Implicit conversions](https://github.com/pocorall/scaloid/wiki/Basics#wiki-implicit-conversions) * [Shorter listeners](https://github.com/pocorall/scaloid/wiki/Basics#wiki-enriched-implicit-classes) * [Database cursor](http://blog.scaloid.org/2014/02/simple-enhancements-on-accessing.html) * [Traits](https://github.com/pocorall/scaloid/wiki/Basics#wiki-traits) * [Smarter logging](https://github.com/pocorall/scaloid/wiki/Basics#wiki-logging) * [Improved getters/setters](#scala-getters-and-setters) * [Classes](#classes) * [Concise dialog builder](#class-alertdialogbuilder) * [Beauty ArrayAdapter](#class-sarrayadapter) * [Dynamically Preferences](#class-preferences) [`Read in blog`](http://blog.scaloid.org/2013/03/dynamicly-accessing-sharedpreferences.html) * [Binding services concisely](#class-localservice) [`Read in blog`](http://blog.scaloid.org/2013/03/introducing-localservice.html) ## Other links * [Quick start guide](https://github.com/pocorall/scaloid/wiki/Installation#wiki-quick-start) * [API doc](http://docs.scaloid.org/) * [Blog](http://blog.scaloid.org/) * [Twitter](https://twitter.com/scaloid/) * [FAQs](https://github.com/pocorall/scaloid/wiki/Appendix#wiki-faqs-about-scaloid) * [FAQs about Scala on Android](https://github.com/pocorall/scaloid/wiki/Appendix#wiki-faqs-about-scala-on-android) * [Inside Scaloid](https://github.com/pocorall/scaloid/wiki/Inside-Scaloid) * [We are hiring!](#we-are-hiring) ## Core design principle "Being practically simple" is number one principle of Scaloid. Most frequently used things should be written shorter, like [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding). To do this, I first observed Android programs I wrote, and thought that which part of the code is more fundamental than others. For example, what is the most essential part of buttons? Buttons should have some visible things on it, such as title or image, so the buttons are created like this: `SButton("Hello")`. The second essential part is doing something when it is pressed: `SImageButton(R.drawable.hello, toast("World!"))`. What should be the third one? The answer might not the same for every people, but I think that repetition frequency of press-and-hold action is nice: `SButton("Add", n += 1, 500)` increases `n` for every 500 milliseconds when the user holds the button. ## UI Layout without XML

Android SDK leverages XML to build UI layouts. However, XML is considered still a bit verbose, and lacks programmability. Scaloid composes UI layout in Scala DSL style, therefore achieve both clarity and programmability. For example, suppose a legacy XML layout as shown below: ```xml