Skip to content

Instantly share code, notes, and snippets.

@luisbebop
Last active December 25, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisbebop/6904316 to your computer and use it in GitHub Desktop.
Save luisbebop/6904316 to your computer and use it in GitHub Desktop.
package org.scaloid.hello
import org.scaloid.common._
import android.graphics.Color
import org.jamruby.core.Jamruby;
import org.jamruby.mruby.MRuby;
import org.jamruby.mruby.ParserState;
import org.jamruby.mruby.Value;
object TestScalaObject {
val TEST_SYMBOL = "*"
var ctx :SVerticalLayout = _;
def SetContext(c : SVerticalLayout) = {
ctx = c
}
def GetContext() : SVerticalLayout = {
ctx
}
def testMethod() : String = {
"LOL"
}
}
class HelloScaloid extends SActivity {
onCreate {
contentView = new SVerticalLayout {
style {
case b: SButton => b.textColor(Color.RED).onClick(loading())
case t: STextView => t textSize 10.dip
case v => v.backgroundColor(Color.YELLOW)
}
TestScalaObject.SetContext(this)
val code = """c = JAVA.find_class("org/scaloid/hello/TestScalaObject")
sm = c.get_static_method("testMethod","()Ljava/lang/String;")
o = c.call_static(sm)
"""
// val code = """c = JAVA.find_class("org/scaloid/hello/TestScalaObject")
// sm = c.get_static_method("GetContext","()Lorg/scaloid/common/SVerticalLayout;")
// o = c.call_static(sm)
// """
var jamRuby: Jamruby = new Jamruby()
var ps: ParserState = jamRuby.parse(code)
var ret: Value = jamRuby.run(ps)
STextView(ret.toString(jamRuby.state()))
STextView("Me too")
STextView("I am taller than you") textSize 15.dip // overriding
SEditText("Yellow input field")
SButton(R.string.red)
} padding 20.dip
}
def getInstance():String = {
"LOL"
}
def coolToast(s:String):String= {
toast(s)
"lol"
}
def loading() = {
toast("Bang!")
//spinnerDialog("Dialog", "working ....")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment