bluepotion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +10 -0
  3. data/lib/bluepotion.rb +16 -0
  4. data/lib/project/ext/activity.rb +62 -0
  5. data/lib/project/ext/array_list.rb +25 -0
  6. data/lib/project/ext/fragment.rb +2 -0
  7. data/lib/project/ext/object.rb +105 -0
  8. data/lib/project/ext/string.rb +23 -0
  9. data/lib/project/ext/view.rb +81 -0
  10. data/lib/project/potion.rb +50 -0
  11. data/lib/project/pro_motion/pm_activity.rb +38 -0
  12. data/lib/project/pro_motion/pm_application.rb +71 -0
  13. data/lib/project/pro_motion/pm_home_activity.rb +14 -0
  14. data/lib/project/pro_motion/pm_screen.rb +67 -0
  15. data/lib/project/pro_motion/pm_screen_module.rb +165 -0
  16. data/lib/project/pro_motion/pm_single_fragment_activity.rb +31 -0
  17. data/lib/project/ruby_motion_query/rmq/actions.rb +48 -0
  18. data/lib/project/ruby_motion_query/rmq/base.rb +260 -0
  19. data/lib/project/ruby_motion_query/rmq/data.rb +64 -0
  20. data/lib/project/ruby_motion_query/rmq/debug.rb +9 -0
  21. data/lib/project/ruby_motion_query/rmq/enumerablish.rb +99 -0
  22. data/lib/project/ruby_motion_query/rmq/events.rb +28 -0
  23. data/lib/project/ruby_motion_query/rmq/factory.rb +47 -0
  24. data/lib/project/ruby_motion_query/rmq/position.rb +2 -0
  25. data/lib/project/ruby_motion_query/rmq/selectors.rb +72 -0
  26. data/lib/project/ruby_motion_query/rmq/styles.rb +108 -0
  27. data/lib/project/ruby_motion_query/rmq/subviews.rb +95 -0
  28. data/lib/project/ruby_motion_query/rmq/tags.rb +58 -0
  29. data/lib/project/ruby_motion_query/rmq/traverse.rb +287 -0
  30. data/lib/project/ruby_motion_query/rmq/utils.rb +36 -0
  31. data/lib/project/ruby_motion_query/rmq/version.rb +6 -0
  32. data/lib/project/ruby_motion_query/rmq_activity_data.rb +3 -0
  33. data/lib/project/ruby_motion_query/rmq_app.rb +9 -0
  34. data/lib/project/ruby_motion_query/rmq_color.rb +121 -0
  35. data/lib/project/ruby_motion_query/rmq_device.rb +47 -0
  36. data/lib/project/ruby_motion_query/rmq_event.rb +1 -0
  37. data/lib/project/ruby_motion_query/rmq_font.rb +61 -0
  38. data/lib/project/ruby_motion_query/rmq_image.rb +55 -0
  39. data/lib/project/ruby_motion_query/rmq_rect.rb +576 -0
  40. data/lib/project/ruby_motion_query/rmq_screen_data.rb +3 -0
  41. data/lib/project/ruby_motion_query/rmq_stylesheet.rb +39 -0
  42. data/lib/project/ruby_motion_query/rmq_view_data.rb +88 -0
  43. data/lib/project/ruby_motion_query/stylers/rmq_button_styler.rb +3 -0
  44. data/lib/project/ruby_motion_query/stylers/rmq_image_button_styler.rb +3 -0
  45. data/lib/project/ruby_motion_query/stylers/rmq_image_view_styler.rb +24 -0
  46. data/lib/project/ruby_motion_query/stylers/rmq_linear_layout_styler.rb +32 -0
  47. data/lib/project/ruby_motion_query/stylers/rmq_relative_layout_styler.rb +7 -0
  48. data/lib/project/ruby_motion_query/stylers/rmq_styler_helper.rb +3 -0
  49. data/lib/project/ruby_motion_query/stylers/rmq_text_view_styler.rb +50 -0
  50. data/lib/project/ruby_motion_query/stylers/rmq_view_styler.rb +201 -0
  51. data/lib/project/version.rb +3 -0
  52. data/templates/screen/app/screens/name_screen.rb +20 -0
  53. data/templates/screen/app/stylesheets/name_screen_stylesheet.rb +24 -0
  54. data/templates/screen/spec/screens/name_screen_spec.rb +8 -0
  55. metadata +119 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 843068c1c8ba6af4bd308d825109986b0361d4b1
4
+ data.tar.gz: a7733756b70dde4407a24f100e0513c9d31df1c3
5
+ SHA512:
6
+ metadata.gz: 550fd29b558508b3c1c963b49f62c96a2d15c2e1542de02f40a0df473159a6b37015321b9824a3a1f1d53578b1dccfd08a6a39bc8adde46632305cce013f33cf
7
+ data.tar.gz: 4bcb7d36b43f1c347d78400337a420dc298f90bd82ad3341fff6684918298f01c29c34a80a1e843bbc64223b8c8e91b1e05f0ada3daf29eb3151a28d7953f752
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ <p align="center"><img src="http://s3.amazonaws.com/ir_public/projects/redpotion/BluePotion_logo_500w.png" alt="logo" width="250px"></p>
2
+
3
+ <br />
4
+
5
+ BluePotion
6
+ -----------
7
+
8
+ Like [RedPotion](http://redpotion.org), but for RubyMotion Android.
9
+
10
+ ## BluePotion is pre-alpha right now!
data/lib/bluepotion.rb ADDED
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ require 'bluepotion'
8
+
9
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
10
+ Motion::Project::App.setup do |app|
11
+ insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
12
+
13
+ Dir.glob(File.join(lib_dir_path, "project/**/*.rb")).reverse.each do |file|
14
+ app.files.insert(insert_point, file)
15
+ end
16
+ end
@@ -0,0 +1,62 @@
1
+ class Android::App::Activity
2
+
3
+ def root_view
4
+ @_root_view ||= getWindow.getDecorView.findViewById(Android::R::Id::Content)
5
+ end
6
+
7
+ def rmq_data
8
+ @_rmq_data ||= RMQActivityData.new
9
+ end
10
+
11
+ def rmq(*working_selectors)
12
+ crmq = (rmq_data.cached_rmq ||= RMQ.create_with_selectors([], self))
13
+
14
+ if working_selectors.length == 0
15
+ crmq
16
+ else
17
+ RMQ.create_with_selectors(working_selectors, self, crmq)
18
+ end
19
+ end
20
+
21
+ def stylesheet
22
+ self.rmq.stylesheet
23
+ end
24
+
25
+ def stylesheet=(value)
26
+ self.rmq.stylesheet = value
27
+ end
28
+
29
+ def color(*params)
30
+ RMQ.color(*params)
31
+ end
32
+
33
+ def font
34
+ rmq.font
35
+ end
36
+
37
+ def image
38
+ rmq.image
39
+ end
40
+
41
+ def append_view(view_or_class, style=nil, opts={})
42
+ self.rmq.append_view(view_or_class, style, opts)
43
+ end
44
+
45
+ def append_view!(view_or_class, style=nil, opts={})
46
+ self.rmq.append_view(view_or_class, style, opts).get
47
+ end
48
+
49
+ class << self
50
+
51
+ def stylesheet(style_sheet_class)
52
+ @rmq_style_sheet_class = style_sheet_class
53
+ end
54
+
55
+ def rmq_style_sheet_class
56
+ @rmq_style_sheet_class
57
+ end
58
+
59
+ end
60
+
61
+
62
+ end
@@ -0,0 +1,25 @@
1
+ class Java::Util::ArrayList
2
+
3
+ # REMOVE when RubyMotion adds this
4
+ def uniq
5
+ if self.length <= 1
6
+ self
7
+ else
8
+ h = {}
9
+ self.each do |el|
10
+ h[el] = nil
11
+ end
12
+ h.keys
13
+ end
14
+ end
15
+
16
+ # REMOVE when RubyMotion adds this
17
+ def uniq!
18
+ # This was failing with an array of views, TODO, check
19
+ out = self.uniq
20
+ self.clear
21
+ self.addAll out
22
+ self
23
+ end
24
+
25
+ end
@@ -0,0 +1,2 @@
1
+ class Android::App::Fragment
2
+ end
@@ -0,0 +1,105 @@
1
+ class Object
2
+
3
+ # REMOVE when RubyMotion adds this
4
+ def object_id
5
+ Java::Lang::System.identityHashCode(self)
6
+ end
7
+
8
+ # REMOVE when RubyMotion adds this
9
+ def caller
10
+ out = "caller:"
11
+
12
+ stacktrace = Java::Lang::Thread.currentThread.getStackTrace
13
+ stacktrace.each_with_index do |trc, i|
14
+ klass_name = trc.className
15
+ method_name = trc.methodName
16
+
17
+ next if klass_name == "com.rubymotion.ReplTask"
18
+ next if method_name == "getStackTrace" || method_name == "getThreadStackTrace"
19
+
20
+ line_number = trc.getLineNumber
21
+ out << "\n "
22
+ #out << " " * i
23
+ if line_number < 0
24
+ out << " "
25
+ else
26
+ out << line_number.to_s.ljust(4)
27
+ end
28
+ out << " "
29
+ out << method_name.to_s.ljust(30)
30
+ out << " "
31
+ out << klass_name.to_s
32
+ end
33
+
34
+ out
35
+ end
36
+
37
+ def inspect
38
+ if self.respond_to?(:id)
39
+ "<#{short_class_name}|#{id}>"
40
+ else
41
+ "<#{short_class_name}|#{object_id}>"
42
+ end
43
+ end
44
+
45
+ def short_class_name
46
+ self.class.name.split('.').last
47
+ end
48
+
49
+
50
+ # RMQ stuff
51
+
52
+ def rmq(*working_selectors)
53
+ if (app = RMQ.app) && ((cvc = app.current_screen) || (cvc = app.current_activity))
54
+ cvc.rmq(working_selectors)
55
+ else
56
+ RMQ.create_with_array_and_selectors([], working_selectors, self)
57
+ end
58
+ end
59
+
60
+ def find(*args) # Do not alias this, strange bugs happen where classes don't have methods
61
+ rmq(*args)
62
+ end
63
+
64
+ def find!(*args) # Do not alias this, strange bugs happen where classes don't have methods
65
+ rmq(*args).get
66
+ end
67
+
68
+
69
+ # BluePotion stuff
70
+
71
+ # REMOVE when mp starts working
72
+ def mp(s, opts={})
73
+ if opts[:debugging_only]
74
+ return unless RMQ.debugging?
75
+ end
76
+
77
+ if s.nil?
78
+ s = "<nil>"
79
+ else
80
+ s = s.to_s
81
+ end
82
+ backspace = "\b\b " * (Android::App::Application.name.length + 13)
83
+ lines = s.split("\n")
84
+ lines.each do |line|
85
+ if RMQ.debugging?
86
+ out = backspace
87
+ out << "\e[1;#{36}m#{self.object_id}\e[0m #{self.short_class_name}".ljust(50)
88
+ out << " \e[1;#{34}m#{line}\e[0m"
89
+ puts out
90
+ else
91
+ puts "#{backspace} \e[1;#{34}m#{line}\e[0m"
92
+ end
93
+ end
94
+ end
95
+
96
+ def app
97
+ rmq.app
98
+ end
99
+
100
+ def device
101
+ rmq.device
102
+ end
103
+
104
+
105
+ end
@@ -0,0 +1,23 @@
1
+ class String
2
+ # REMOVE when RubyMotion adds this
3
+ def rjust(number_of_characters)
4
+ if self.length < number_of_characters
5
+ out = " " * (number_of_characters - self.length)
6
+ out << self
7
+ out
8
+ else
9
+ self
10
+ end
11
+ end
12
+
13
+ # REMOVE when RubyMotion adds this
14
+ def ljust(number_of_characters)
15
+ if self.length < number_of_characters
16
+ out = self
17
+ out << " " * (number_of_characters - self.length)
18
+ out
19
+ else
20
+ self
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,81 @@
1
+ class Android::View::View
2
+ def inspect
3
+ "<#{id} #{short_class_name}>"
4
+ end
5
+
6
+ def to_s
7
+ self.inspect
8
+ end
9
+
10
+ def rmq_data
11
+ @_rmq_data ||= RMQViewData.new
12
+ end
13
+
14
+ def rmq_created
15
+ end
16
+
17
+ # Override this to build your view and view's subviews
18
+ def rmq_build
19
+ on_load
20
+ end
21
+ def on_load
22
+ end
23
+
24
+ def rmq_appended
25
+ end
26
+
27
+ def rmq_style_applied
28
+ on_styled
29
+ end
30
+
31
+ def on_styled
32
+ end
33
+
34
+ def rmq(*working_selectors)
35
+ q = RMQ.create_with_selectors(working_selectors, self) #.tap do |o|
36
+ q
37
+ #if vc = self.rmq_data.view_controller
38
+ #o.weak_view_controller = vc
39
+ #end
40
+ #end
41
+ end
42
+
43
+ def color(*params)
44
+ RMQ.color(*params)
45
+ end
46
+
47
+ def font
48
+ rmq.font
49
+ end
50
+
51
+ def image
52
+ rmq.image
53
+ end
54
+
55
+ def append_view(view_or_class, style=nil, opts={})
56
+ self.rmq.append_view(view_or_class, style, opts)
57
+ end
58
+
59
+ def append_view!(view_or_class, style=nil, opts={})
60
+ self.rmq.append_view(view_or_class, style, opts).get
61
+ end
62
+
63
+ def subviews
64
+ out = []
65
+
66
+ if self.is_a?(Potion::ViewGroup)
67
+ (0...self.getChildCount).each_with_index do |i|
68
+ sbv = self.getChildAt(i)
69
+ out << sbv unless self == sbv
70
+ end
71
+ end
72
+
73
+ out
74
+ end
75
+
76
+ def superview
77
+ sv = self.getParent()
78
+ sv = nil unless sv.is_a?(Potion::ViewGroup)
79
+ sv
80
+ end
81
+ end
@@ -0,0 +1,50 @@
1
+ module Potion
2
+ Activity = Android::App::Activity
3
+ View = Android::View::View
4
+ ViewGroup = Android::View::ViewGroup
5
+
6
+ # layouts
7
+ LinearLayout = Android::Widget::LinearLayout
8
+ FrameLayout = Android::Widget::FrameLayout
9
+ RelativeLayout = Android::Widget::RelativeLayout
10
+ AbsoluteLayout = Android::Widget::AbsoluteLayout
11
+
12
+ # widgets
13
+ Label = Android::Widget::TextView
14
+ TextView = Android::Widget::TextView
15
+ ImageView = Android::Widget::ImageView
16
+ Button = Android::Widget::Button
17
+ Toast = Android::Widget::Toast
18
+
19
+ # graphics
20
+ Color = Android::Graphics::Color
21
+ Typeface = Android::Graphics::Typeface
22
+
23
+ ArrayList = Java::Util::ArrayList
24
+ end
25
+
26
+ #
27
+ # Android's generateViewId method was implemented in API leve 17 - for older devices we need to
28
+ # roll our own solution.
29
+ #
30
+ # This is apparently Android's implementation from View.java, according to:
31
+ # http://stackoverflow.com/questions/1714297/android-view-setidint-id-programmatically-how-to-avoid-id-conflicts
32
+ class Potion::ViewIdGenerator
33
+
34
+ @current_id = Java::Util::Concurrent::Atomic::AtomicInteger.new(1)
35
+
36
+ def self.generate
37
+ while true do
38
+ result = @current_id.get
39
+ # aapt-generated IDs have the high byte nonzero; clamp to the range under that.
40
+ new_value = result + 1
41
+ if new_value > 0x00FFFFFF
42
+ new_value = 1
43
+ end
44
+ if @current_id.compareAndSet(result, new_value)
45
+ return result
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,38 @@
1
+ #module ProMotion
2
+
3
+ class PMActivity < Android::App::Activity
4
+
5
+ def onCreate(saved_instance_state)
6
+ super
7
+
8
+ mp "PMActivity onCreate", debugging_only: true
9
+
10
+ on_create(saved_instance_state)
11
+ PMApplication.current_application.context
12
+ end
13
+
14
+ def on_create(saved_instance_state)
15
+ mp "PMActivity on_create", debugging_only: true
16
+ end
17
+
18
+ def onResume
19
+ super
20
+ PMApplication.current_application.current_activity = self
21
+ end
22
+
23
+ def onPause
24
+ clear_references
25
+ super
26
+ end
27
+
28
+ def onDestroy
29
+ clear_references
30
+ super
31
+ end
32
+
33
+ def clear_references
34
+ end
35
+
36
+ end
37
+
38
+ #end
@@ -0,0 +1,71 @@
1
+ # RM-773
2
+ #module ProMotion
3
+ class PMApplication < Android::App::Application
4
+ attr_accessor :home_screen_class, :context, :current_activity
5
+
6
+ def onCreate
7
+ mp "PMApplication onCreate", debugging_only: true
8
+
9
+ # We can always get to the current application from PMApplication.current_application
10
+ # but we set the child class's current_application too, in case someone uses that
11
+ PMApplication.current_application = self
12
+ self.class.current_application = self
13
+
14
+ @context = self
15
+
16
+ @home_screen_class = self.class.home_screen_class
17
+ self.on_create if respond_to?(:on_create)
18
+ end
19
+
20
+ def window
21
+ if @current_activity
22
+ @window ||= @current_activity.getWindow
23
+ end
24
+ end
25
+
26
+ def current_screen
27
+ if @current_activity && (ca = @current_activity)
28
+ if ca.is_a?(PMSingleFragmentActivity)
29
+ ca.fragment
30
+ end
31
+ end
32
+ end
33
+
34
+ def guess_current_screen
35
+ # TODO
36
+ #ca.getFragmentManager.findFragmentById(Android::R::Id.fragment_container)
37
+ #ca.getFragmentManager.frameTitle
38
+ end
39
+
40
+ # @return [Symbol] Environment the app is running it
41
+ def environment
42
+ @_environment ||= RUBYMOTION_ENV.to_sym
43
+ end
44
+
45
+ # @return [Boolean] true if the app is running in the :release environment
46
+ def release?
47
+ environment == :release
48
+ end
49
+ alias :production? :release?
50
+
51
+ # @return [Boolean] true if the app is running in the :test environment
52
+ def test?
53
+ environment == :test
54
+ end
55
+
56
+ # @return [Boolean] true if the app is running in the :development environment
57
+ def development?
58
+ environment == :development
59
+ end
60
+
61
+ class << self
62
+ attr_accessor :current_application, :home_screen_class
63
+
64
+ def home_screen(hclass)
65
+ mp "PMApplication home_screen", debugging_only: true
66
+ @home_screen_class = hclass
67
+ end
68
+
69
+ end
70
+ end
71
+ #end