Baitha is a library designed to make Scala development on Android easier and more fun. It leverages some of Scala’s features such as mix-ins and implicit conversions to make Android development with Scala a bit more idiomatic.
Baitha is still under heavy development. Some of its current features include:
- AlertDialogBuilder
-
An wrapper around Android’s
AlertDialog.Builder
class that provides some implicit conversions and a mini-DSL. - BuildMode
-
A trait that makes converting between debug/production code easier.
- EnhancedViews
-
Provides some implicit conversions to make adding listeners as functions.
- Logger
-
A replacement logging interface inspired by RoboGuice.
- SdkVersions
-
Offers conditional execution depending on the runtime version of the Android platform.
- TypedColumn and TypedCursorWrapper
-
An easier way to get data out of a cursor.
Baitha is designed to be used as an Android library project. This means that instead of including a compiled JAR file in your Android project, your project will directly make use of the source files provided by the library.
As of the time of this writing the latest release of the Android plugin for SBT (0.5.1) does not support Android libraries. However, the master branch has already integrated this support. You can build a local version of the plugin using the following steps:
% git clone git://github.com/jberkel/android-plugin.git % cd android-plugin % sbt update publish-local
The above steps should create a local version of the plugin with the necessary
library project support. To use the library, you will need to modify your
project/plugins/plugins.scala
file to have the following line:
val android = "org.scala-tools.sbt" % "sbt-android-plugin" % "0.5.2-SNAPSHOT"
One approach is to add the Baitha library as a Git submodule in a subdirectory of your project. Otherwise, you can check it out into its own directory:
% git clone git://github.com/sattvik/baitha.git
In order to actually use the library, you will need to make a reference to it
in your SBT project definition. To accomplish this, you will need to make some
modifications to your project/build/project.scala
:
import sbt._ trait Defaults { def androidPlatformName = "android-9" // (1) } class Parent(info: ProjectInfo) extends ParentProject(info) { override def shouldCheckOutputDirectories = false override def updateAction = task { None } lazy val baitha = project(Path.fromFile("../baitha"), "baitha", new BaithaProject(_)) // (2) lazy val main = project(".", "My Android Project", new MainProject(_), baitha) // (3) lazy val tests = project("tests", "tests", new TestProject(_), main) class MainProject(info: ProjectInfo) extends AndroidProject(info) with Defaults with MarketPublish with TypedResources { val keyalias = "change-me" val scalatest = "org.scalatest" % "scalatest" % "1.3" % "test" } class TestProject(info: ProjectInfo) extends AndroidTestProject(info) with Defaults class BaithaProject(info: ProjectInfo) extends AndroidLibraryProject(info) with Defaults { // (4) val scalatest = "org.scalatest" % "scalatest" % "1.3" % "test" val mockito = "org.mockito" % "mockito-core" % "1.8.5" % "test" } }
-
To compile, Baitha currently requires API level 9 or higher. However, the runtime works with API level 7 and higher.
-
Creates the project. Note that the
Path.fromFile("…")
is only necessary if accessing Baitha outside of your project’s directory structure. If you go for the git submodule approach, you can just use the directory name as a string. -
Declares the library as a dependency of the main project.
-
Defines the library project along with test dependencies.
Once you have made the above changes, reloading and updated your SBT project should make the library available for you.
As this project is very new, there is no process yet for contributing to the code. For now, your best bet is to open an issue or submit a pull request.
Copyright © 2011 Sattvik Software & Technology Resources, Ltd. Co. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.