Class: PMApplication
- Defined in:
- lib/project/pro_motion/pm_application.rb
Overview
RM-773 module ProMotion
Class Attribute Summary collapse
-
.current_application ⇒ Object
Returns the value of attribute current_application.
-
.home_screen_class ⇒ Object
Returns the value of attribute home_screen_class.
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#current_activity ⇒ Object
Returns the value of attribute current_activity.
Class Method Summary collapse
Instance Method Summary collapse
-
#after(delay, &block) ⇒ Object
Execute the given block after the given number of seconds.
- #alert(options = {}, &block) ⇒ Object
- #application_info ⇒ Object
- #async(options = {}, &block) ⇒ Object
- #content_resolver ⇒ Object
-
#current_screen ⇒ Object
Typically you don’t use this, use ‘find.screen` instead, TODO, probably should remove this.
- #data_dir ⇒ Object
-
#development? ⇒ Boolean
True if the app is running in the :development environment.
-
#environment ⇒ Symbol
Environment the app is running it.
- #guess_current_screen ⇒ Object
- #home_screen_class ⇒ Object
- #identifier ⇒ Object
-
#launch(command = {}) ⇒ Object
Launch native services via intent app.launch(sms: ‘5045558008’) app.launch(tel: ‘5045558008’) app.launch(web: ‘giphy.com’) app.launch(email: ‘[email protected]’) app.launch(email: ‘[email protected]’, subject: “Hey Chica”, message: “Howdy”) app.launch(chooser: ‘I hope you have a nice day!’).
- #name ⇒ Object
- #net ⇒ Object
- #onCreate ⇒ Object
- #package_manager ⇒ Object
- #package_name ⇒ Object
- #r ⇒ Object
-
#release? ⇒ Boolean
(also: #production?)
True if the app is running in the :release environment.
- #resource ⇒ Object
-
#sms(phone_number) ⇒ Object
Send user to native Texting app.sms(“555-555-5555”).
-
#test? ⇒ Boolean
True if the app is running in the :test environment.
- #toast(message, params = {}) ⇒ Object
- #window ⇒ Object
Class Attribute Details
.current_application ⇒ Object
Returns the value of attribute current_application.
182 183 184 |
# File 'lib/project/pro_motion/pm_application.rb', line 182 def current_application @current_application end |
.home_screen_class ⇒ Object
Returns the value of attribute home_screen_class.
182 183 184 |
# File 'lib/project/pro_motion/pm_application.rb', line 182 def home_screen_class @home_screen_class end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
4 5 6 |
# File 'lib/project/pro_motion/pm_application.rb', line 4 def context @context end |
#current_activity ⇒ Object
Returns the value of attribute current_activity.
4 5 6 |
# File 'lib/project/pro_motion/pm_application.rb', line 4 def current_activity @current_activity end |
Class Method Details
.home_screen(hclass) ⇒ Object
184 185 186 187 |
# File 'lib/project/pro_motion/pm_application.rb', line 184 def home_screen(hclass) mp "PMApplication home_screen", debugging_only: true @home_screen_class = hclass end |
Instance Method Details
#after(delay, &block) ⇒ Object
Execute the given block after the given number of seconds
app.after(10) do
p "This will print in 10 seconds"
end
177 178 179 |
# File 'lib/project/pro_motion/pm_application.rb', line 177 def after(delay, &block) DelayedExecution.after(delay, &block) end |
#alert(options = {}, &block) ⇒ Object
118 119 120 |
# File 'lib/project/pro_motion/pm_application.rb', line 118 def alert(={}, &block) AlertDialog.new(, &block) end |
#application_info ⇒ Object
24 25 26 |
# File 'lib/project/pro_motion/pm_application.rb', line 24 def application_info context.applicationInfo end |
#async(options = {}, &block) ⇒ Object
104 105 106 |
# File 'lib/project/pro_motion/pm_application.rb', line 104 def async(={}, &block) MotionAsync.async(, &block) end |
#content_resolver ⇒ Object
32 33 34 |
# File 'lib/project/pro_motion/pm_application.rb', line 32 def content_resolver context.contentResolver end |
#current_screen ⇒ Object
Typically you don’t use this, use ‘find.screen` instead, TODO, probably should remove this
59 60 61 62 63 |
# File 'lib/project/pro_motion/pm_application.rb', line 59 def current_screen if @current_activity && @current_activity.respond_to?(:fragment) @current_activity.fragment end end |
#data_dir ⇒ Object
48 49 50 |
# File 'lib/project/pro_motion/pm_application.rb', line 48 def data_dir application_info.dataDir end |
#development? ⇒ Boolean
88 89 90 |
# File 'lib/project/pro_motion/pm_application.rb', line 88 def development? environment == :development end |
#environment ⇒ Symbol
72 73 74 |
# File 'lib/project/pro_motion/pm_application.rb', line 72 def environment @_environment ||= RUBYMOTION_ENV.to_sym end |
#guess_current_screen ⇒ Object
65 66 67 68 69 |
# File 'lib/project/pro_motion/pm_application.rb', line 65 def guess_current_screen # TODO #ca.getFragmentManager.findFragmentById(Android::R::Id.fragment_container) #ca.getFragmentManager.frameTitle end |
#home_screen_class ⇒ Object
20 21 22 |
# File 'lib/project/pro_motion/pm_application.rb', line 20 def home_screen_class @home_screen_class end |
#identifier ⇒ Object
40 41 42 |
# File 'lib/project/pro_motion/pm_application.rb', line 40 def identifier application_info.packageName end |
#launch(command = {}) ⇒ Object
Launch native services via intent app.launch(sms: ‘5045558008’) app.launch(tel: ‘5045558008’) app.launch(web: ‘giphy.com’) app.launch(email: ‘[email protected]’) app.launch(email: ‘[email protected]’, subject: “Hey Chica”, message: “Howdy”) app.launch(chooser: ‘I hope you have a nice day!’)
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/project/pro_motion/pm_application.rb', line 136 def launch(command={}) action_view = "android.intent.action.VIEW" action_send = "android.intent.action.SEND" action_dial = "android.intent.action.DIAL" key_list = command.keys launch_intent = case when key_list.include?(:sms) sms_intent = Android::Content::Intent.new(action_view) sms_intent.setData(Android::Net::Uri.fromParts("sms", command[:sms].to_s, nil)) when key_list.include?(:email) email_intent = Android::Content::Intent.new(action_view) email_string = "mailto:#{command[:email]}" email_string += "?subject=#{command[:subject].to_s}" email_string += "&body=#{command[:message].to_s}" email_intent.setData(Android::Net::Uri.parse(email_string)) when key_list.include?(:web) web_intent = Android::Content::Intent.new(action_view) web_intent.setData(Android::Net::Uri.parse(command[:web])) when key_list.include?(:tel) tel_intent = Android::Content::Intent.new(action_dial) tel_intent.setData(Android::Net::Uri.fromParts("tel", command[:tel], nil)) when key_list.include?(:chooser) = Android::Content::Intent.new(action_send) .type = "text/plain" .putExtra("android.intent.extra.TEXT", command[:chooser].to_s) if command[:chooser] Android::Content::Intent.createChooser(, nil) else mp "[BP Warning] Launch type unknown - '#{command.keys.inspect}'" nil end find.activity.startActivity(launch_intent) if launch_intent end |
#name ⇒ Object
36 37 38 |
# File 'lib/project/pro_motion/pm_application.rb', line 36 def name application_info.loadLabel(package_manager) end |
#net ⇒ Object
100 101 102 |
# File 'lib/project/pro_motion/pm_application.rb', line 100 def net BluePotionNet end |
#onCreate ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/project/pro_motion/pm_application.rb', line 6 def onCreate mp "PMApplication onCreate", debugging_only: true # We can always get to the current application from PMApplication.current_application # but we set the child class's current_application too, in case someone uses that PMApplication.current_application = self self.class.current_application = self @context = self @home_screen_class = self.class.home_screen_class self.on_create if respond_to?(:on_create) end |
#package_manager ⇒ Object
28 29 30 |
# File 'lib/project/pro_motion/pm_application.rb', line 28 def package_manager context.getPackageManager end |
#package_name ⇒ Object
44 45 46 |
# File 'lib/project/pro_motion/pm_application.rb', line 44 def package_name @package_name ||= application_info.packageName end |
#r ⇒ Object
96 97 98 |
# File 'lib/project/pro_motion/pm_application.rb', line 96 def r RMQResource end |
#release? ⇒ Boolean Also known as: production?
77 78 79 |
# File 'lib/project/pro_motion/pm_application.rb', line 77 def release? environment == :release end |
#resource ⇒ Object
92 93 94 |
# File 'lib/project/pro_motion/pm_application.rb', line 92 def resource RMQResource end |
#sms(phone_number) ⇒ Object
Send user to native Texting app.sms(“555-555-5555”)
124 125 126 127 |
# File 'lib/project/pro_motion/pm_application.rb', line 124 def sms(phone_number) mp "[BP Deprecated] use app.launch(sms: #{phone_number}) over app.sms" launch(sms: phone_number) end |
#test? ⇒ Boolean
83 84 85 |
# File 'lib/project/pro_motion/pm_application.rb', line 83 def test? environment == :test end |
#toast(message, params = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/project/pro_motion/pm_application.rb', line 108 def toast(, params={}) = case params[:length] when :long Android::Widget::Toast::LENGTH_LONG else Android::Widget::Toast::LENGTH_SHORT end Android::Widget::Toast.makeText(rmq.activity, , ).show end |
#window ⇒ Object
52 53 54 55 56 |
# File 'lib/project/pro_motion/pm_application.rb', line 52 def window if @current_activity @window ||= @current_activity.getWindow end end |