Advertisement
Guest User

"Red on Android" demo source code

a guest
Jun 24th, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REBOL 1.50 KB | None | 0 0
  1. Red [
  2.     Title:   "Red Android bridge demo"
  3.     Author:  "Nenad Rakocevic"
  4.     File:    %droid.red
  5.     Type:    'library
  6.     Tabs:    4
  7.     Rights:  "Copyright (C) 2013 Nenad Rakocevic. All rights reserved."
  8.     License: {
  9.         Distributed under the Boost Software License, Version 1.0.
  10.         See https://github.com/dockimbel/Red/blob/master/BSL-License.txt
  11.     }
  12. ]
  13.  
  14. #include %android.red
  15.  
  16.  
  17. on-java-event: function [face [integer!] event [integer!]][
  18.     switch/default event [
  19.         1 [
  20.             seq: java-do [input/getText]
  21.             if code: java-do [seq/toString][       
  22.                 set/any 'result do code
  23.                 unless unset? :result [
  24.                     result: form reduce ["==" mold result lf]
  25.                     java-do [output/append result]
  26.                 ]
  27.             ]
  28.         ]
  29.     ][
  30.         print ["java event:" event]
  31.     ]
  32. ]
  33.  
  34. HORIZONTAL: 0
  35. VERTICAL:   1
  36. BOTTOM:     80
  37.  
  38. main: function [this [integer!] /extern [input output]][
  39.     this: to-java-object this
  40.  
  41.     lay: java-new [android.widget.LinearLayout this]
  42.     java-do [lay/setOrientation VERTICAL]
  43.  
  44.     input: java-new [android.widget.EditText this]
  45.     java-do [input/setText "1 + 3"]
  46.     java-do [input/setId 100]
  47.     java-do [lay/addView input]
  48.    
  49.     btn: java-new [android.widget.Button this]
  50.     java-do [btn/setText "Do"]
  51.     java-do [btn/setId 101]
  52.     btn-click: java-new [com.example.hello.ClickEvent]
  53.     java-do [btn/setOnClickListener btn-click]
  54.     java-do [lay/addView btn]
  55.        
  56.     output: java-new [android.widget.TextView this]
  57.     java-do [output/setHeight 600]
  58.     java-do [output/setGravity BOTTOM]
  59.     java-do [lay/addView output]
  60.    
  61.     java-do [this/setContentView lay]
  62. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement