Top Level Namespace

Defined Under Namespace

Modules: Droiuby, JavaExtends, JavaMethodHelper, MissingHandler, MockObjects Classes: Accelerometer, Activity, Animator, AnimatorListenerWrapper, Array, AssetHandler, AsyncWrapper, BigDecimal, BitmapDrawableWrapper, ButtonWrapper, CanvasWrapper, CompoundButtonWrapper, DroiubyApp, DroiubyFramework, EditTextWrapper, FalseClass, Fixnum, Hash, ImageButtonWrapper, IntentWrapper, Java, LinearLayoutWrapper, ListAdapterWrapper, ListViewWrapper, MockEnvironment, MockTemplateParser, MotionEventsWrapper, NilClass, Numeric, Object, Paint, PayloadWrapper, Preferences, Project, Rect, RunnableWrapper, String, SurfaceHolderWrapper, SurfaceViewWrapper, Symbol, TextViewWrapper, Thread, ThreadPoolWrapper, TrueClass, ViewArray, ViewGroupWrapper, ViewWrapper, WebViewWrapper

Instance Method Summary collapse

Methods included from JavaMethodHelper::ClassMethods

#java_native_method, #java_native_method_on, #java_native_singleton, #java_native_singleton_on

Instance Method Details

#_active_bundlesObject



55
56
57
# File 'lib/droiuby/bootstrap.rb', line 55

def _active_bundles
  Java::com.droiuby.client.core.ExecutionBundleFactory.listActiveBundles.collect { |i| i.to_s }
end

#_activity_builderObject



43
44
45
# File 'lib/droiuby/bootstrap.rb', line 43

def _activity_builder
  PayloadWrapper.java_getActivityBuilder
end

#_add_error(error_message) ⇒ Object



63
64
65
66
# File 'lib/droiuby/bootstrap.rb', line 63

def _add_error(error_message)
  _execution_bundle.addError(error_message)
  error_message
end

#_container_payloadObject



15
16
17
# File 'lib/droiuby/bootstrap.rb', line 15

def _container_payload
  $container_payload
end

#_current_activityObject



39
40
41
# File 'lib/droiuby/bootstrap.rb', line 39

def _current_activity
  PayloadWrapper.java_getCurrentActivity
end

#_current_appObject



31
32
33
# File 'lib/droiuby/bootstrap.rb', line 31

def _current_app
  PayloadWrapper.java_getActiveApp
end

#_current_pageObject



19
20
21
# File 'lib/droiuby/bootstrap.rb', line 19

def _current_page
  PayloadWrapper.java_getCurrentPage
end

#_current_page_urlObject



47
48
49
# File 'lib/droiuby/bootstrap.rb', line 47

def _current_page_url
  _execution_bundle.getCurrentUrl
end

#_errorsObject



59
60
61
# File 'lib/droiuby/bootstrap.rb', line 59

def _errors
  _execution_bundle.getScriptErrors.collect { |e| e.to_s }
end

#_execution_bundleObject



35
36
37
# File 'lib/droiuby/bootstrap.rb', line 35

def _execution_bundle
  PayloadWrapper.java_getExecutionBundle
end

#_gcObject



149
150
151
# File 'lib/droiuby/bootstrap.rb', line 149

def _gc
  Droiuby::SystemWrapper.java_gc
end

#_namespaceObject



83
84
85
# File 'lib/droiuby/bootstrap.rb', line 83

def _namespace
  _execution_bundle.getName
end

#_nano_timeObject



153
154
155
# File 'lib/droiuby/bootstrap.rb', line 153

def _nano_time
  Droiuby::SystemWrapper.java_nanoTime
end

#_PObject



255
256
257
# File 'lib/droiuby/bootstrap.rb', line 255

def _P
  Preferences.new(Java::com.droiuby.client.core.utils.Utils.getCurrentPreferences(_current_app, _current_activity))
end

#_pool(&block) ⇒ Object



169
170
171
172
173
# File 'lib/droiuby/bootstrap.rb', line 169

def _pool(&block)
  thread_pool = ThreadPoolWrapper.new
  block.call(thread_pool)
  thread_pool.start
end

#_R(attr) ⇒ Object



68
69
70
# File 'lib/droiuby/bootstrap.rb', line 68

def _R(attr)
  Java::com.droiuby.client.core.builder.ActivityBuilder.resolveResource(_current_activity, attr)
end

#_rect(left = 0, top = 0, right = 0, bottom = 0) ⇒ Object



29
30
31
# File 'lib/droiuby/wrappers/canvas_wrapper.rb', line 29

def _rect(left = 0, top = 0, right = 0, bottom = 0)
  Rect.new(nil, left, top, right, bottom)
end

#_runtimeObject



27
28
29
# File 'lib/droiuby/bootstrap.rb', line 27

def _runtime
   _scripting_container.getProvider.getRuntime
end

#_scripting_containerObject



23
24
25
# File 'lib/droiuby/bootstrap.rb', line 23

def _scripting_container
  PayloadWrapper.java_getContainer
end

#_sleep(delay = 0) ⇒ Object



161
162
163
# File 'lib/droiuby/bootstrap.rb', line 161

def _sleep(delay = 0)
  Droiuby::SystemWrapper.java_sleep(delay)
end

#_switch(bundle) ⇒ Object



72
73
74
75
76
# File 'lib/droiuby/bootstrap.rb', line 72

def _switch(bundle)
  bundle = Java::com.droiuby.client.core.ExecutionBundleFactory.getBundle(bundle)
  $container_payload = bundle.getPayload
  true
end

#_thread(&block) ⇒ Object



165
166
167
# File 'lib/droiuby/bootstrap.rb', line 165

def _thread(&block)
  Java::com.droiuby.client.core.wrappers.ThreadWrapper.new(block, _execution_bundle)
end

#_timeObject



157
158
159
# File 'lib/droiuby/bootstrap.rb', line 157

def _time
  Droiuby::SystemWrapper.java_currentTimeMillis
end

#after_partial_setup(view_group) ⇒ Object



24
25
26
27
28
29
# File 'lib/droiuby/preload.rb', line 24

def after_partial_setup(view_group)
  $droiuby_plugins.each do |plugin|
    puts "plugin attach #{plugin.class.to_s}"
    plugin.after_partial_setup(view_group)
  end unless $droiuby_plugins.blank?
end

#after_view_setupObject



17
18
19
20
21
22
# File 'lib/droiuby/preload.rb', line 17

def after_view_setup
  $droiuby_plugins.each do |plugin|
    puts "plugin attach #{plugin.class.to_s}"
    plugin.after_view_setup
  end unless $droiuby_plugins.blank? 
end

#AndroidObject



228
229
230
# File 'lib/droiuby/bootstrap.rb', line 228

def Android
  Droiuby::Android
end

#asyncObject



259
260
261
# File 'lib/droiuby/bootstrap.rb', line 259

def async
  AsyncWrapper.new
end

#async_get(url, params = {}, options = {}, &block) ⇒ Object



263
264
265
266
267
268
269
# File 'lib/droiuby/bootstrap.rb', line 263

def async_get(url, params = {}, options ={}, &block)
  async.perform {
    http_get(url, params, options)
  }.done { |result|
    block.call result
  }
end

#canvas(&block) ⇒ Object



223
224
225
226
# File 'lib/droiuby/bootstrap.rb', line 223

def canvas(&block)
  auto_wrap_block = Proc.new { |v| block.call(Canvas.new(v))}
  wrap_native_view(Java::com.droiuby.client.core.wrappers.ViewWrapper.new(auto_wrap_block, _execution_bundle))
end

#http_get(url, params = {}, options = {}) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/droiuby/bootstrap.rb', line 271

def http_get(url, params = {}, options = {})

  encoded_params = []

  params.each do |k,v|
    encoded_params << "#{k.to_s}=#{CGI::escape(v.to_s)}"
  end

  url_string = url

  if encoded_params.size > 0
    url_string = "#{url}?#{encoded_params.join('&')}"
  end

  Java::com.droiuby.client.core.utils.Utils.load(_current_activity, url_string, _execution_bundle);
end

#launch(url) ⇒ Object



87
88
89
# File 'lib/droiuby/bootstrap.rb', line 87

def launch(url)
  Java::com.droiuby.client.core.DroiubyLauncher.launch(_current_activity, url)
end

#log_debug(message = '', tag = 'ruby') ⇒ Object



131
132
133
134
# File 'lib/droiuby/bootstrap.rb', line 131

def log_debug(message = '', tag = 'ruby')
  Droiuby::SystemWrapper.java_d(tag.to_s, message.to_s)
  nil
end

#on_ui_thread(&block) ⇒ Object



78
79
80
81
# File 'lib/droiuby/bootstrap.rb', line 78

def on_ui_thread(&block)
  _current_activity.runOnUiThread(RunnableWrapper.new(block).to_native);
  nil
end

#render(url, params = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/droiuby/bootstrap.rb', line 109

def render(url, params = {})
  http_method = Java::com.droiuby.client.core.utils.Utils::HTTP_GET
  if params[:method] && (params[:method] == :post)
    http_method = Java::com.droiuby.client.core.utils.Utils::HTTP_POST
  end

  new_activity = params[:activity] ? true : false;

  async.perform {
    Java::com.droiuby.client.core.DroiubyLauncher.loadPage(_current_activity, _execution_bundle, url, http_method)
  }.done { |result|
    if new_activity
      Java::com.droiuby.client.core.DroiubyLauncher.startNewActivity(_current_activity, result)
    else
      Java::com.droiuby.client.core.DroiubyLauncher.runController(_current_activity, _execution_bundle, page)
      #execute plugins
      after_view_setup
    end
  }

end

#reverse_resolve(view_id) ⇒ Object



51
52
53
# File 'lib/droiuby/bootstrap.rb', line 51

def reverse_resolve(view_id)
  _activity_builder.reverseLookupId(view_id)
end

#set_content_view(view = nil) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/droiuby/bootstrap.rb', line 91

def set_content_view(view = nil)
  if view.nil?
    Java::com.droiuby.client.core.DroiubyLauncher.setPage(_current_activity, _execution_bundle, _current_page)
  elsif view.kind_of? Integer
    _current_activity.setContentView(view)
  elsif view.kind_of? String
    _current_activity.setContentView( V(view) )
  end
end

#set_mock_environment(environment = nil) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/droiuby/spec/helper.rb', line 93

def set_mock_environment(environment = nil)
  puts "new environment"
  if environment.nil?
  doc = Nokogiri.XML(File.read('config.droiuby'))

    title = ''
    params = {}
    doc.css('app_descriptor').tap do |e|
      %w[name description base_url main framework].each do |attr|
        params[attr.to_sym] = e.css(attr).first.content
      end
    end

    $mock_environment = MockEnvironment.new(params)
  else
    $mock_environment = environment
  end
  $mock_environment
end

#start_droiuby_pluginsObject

trigger pre load



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/droiuby/preload.rb', line 2

def start_droiuby_plugins
  puts "starting plugins"
  $droiuby_plugins = []
  puts "loading plugins"
  Droiuby::Plugins.descendants.each { |klass|
    puts "plugin -> #{klass.to_s}"
    $droiuby_plugins << klass.new
  }

  $droiuby_plugins.each do |plugin|
    puts "plugin attach #{plugin.class.to_s}"
    plugin.after_bootstrap
  end unless $droiuby_plugins.blank?
end

#surface(&block) ⇒ Object



217
218
219
220
221
# File 'lib/droiuby/bootstrap.rb', line 217

def surface(&block)
  s = SurfaceViewWrapper.new
  block.call(s)
  s
end

#template(url) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/droiuby/bootstrap.rb', line 101

def template(url)
  async.perform {

  }.done { |result|

  }
end

#toast(text = '', duration = :short) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/droiuby/bootstrap.rb', line 136

def toast(text = '', duration = :short)
  j_duration = Java::android.widget.Toast::LENGTH_SHORT

  j_duration = case(duration)
  when :short
    Java::android.widget.Toast::LENGTH_SHORT
  when :long
    Java::android.widget.Toast::LENGTH_LONG
  end

  Java::android.widget.Toast.makeText(_current_activity, text, j_duration).show();
end

#V(selector = nil) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/droiuby/bootstrap.rb', line 232

def V(selectors = nil)

  return _R(selectors) if _activity_builder.nil?

  if selectors.nil? # Get root node if nil
    view = _activity_builder.getRootView
  elsif (selectors == 'top')
    view = _activity_builder.getTopView
  else
    view = _activity_builder.findViewByName(selectors)
  end

  if (view.kind_of? Java::java.util.ArrayList)
    wrapped_views = view.toArray.to_a.collect do |element|
      wrap_native_view(element)
    end
    ViewArray.new(wrapped_views)
  else
    wrap_native_view(view) if view
  end

end

#wrap_native(object) ⇒ Object



211
212
213
214
215
# File 'lib/droiuby/bootstrap.rb', line 211

def wrap_native(object)
  if (object.class == Java::android.content.Intent)
    return IntentWrapper.new(object)
  end
end

#wrap_native_view(view) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/droiuby/bootstrap.rb', line 175

def wrap_native_view(view)
  return nil unless view

  wrapped = if (view.class < Java::android.view.View)
    if (view.class == Java::android.widget.Button)
      ButtonWrapper.new(view)
    elsif (view.class == Java::android.widget.TextView)
      TextViewWrapper.new(view)
    elsif (view.class == Java::android.widget.EditText)
      EditTextWrapper.new(view)
    elsif (view.class == Java::android.widget.LinearLayout)
      LinearLayoutWrapper.new(view)
    elsif (view.class == Java::android.webkit.WebView)
      WebViewWrapper.new(view)
    elsif (view.class == Java::android.widget.ListView)
      ListViewWrapper.new(view)
    elsif (view.class < Java::android.view.ViewGroup)
      ViewGroupWrapper.new(view)
    elsif (view.class < Java::android.widget.CompoundButton)
      CompoundButtonWrapper.new(view)
    elsif (view.class < Java::com.droiuby.client.core.wrappers.SurfaceViewWrapper)
      SurfaceViewWrapper.new(view)
    elsif (view.class < Java::android.view.View)
      ViewWrapper.new(view)
    else
      view
    end
  elsif (view.class == Java::android.view.MotionEvent)
    MotionEventsWrapper.new(view)
  else
    view
  end

  wrapped
end