class PMApplication
Attributes
Public Class Methods
# 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
Public Instance Methods
Execute the given block after the given number of seconds
@example app.after(10) do
p "This will print in 10 seconds"
end
# File lib/project/pro_motion/pm_application.rb, line 177 def after(delay, &block) DelayedExecution.after(delay, &block) end
# File lib/project/pro_motion/pm_application.rb, line 118 def alert(options={}, &block) AlertDialog.new(options, &block) end
# File lib/project/pro_motion/pm_application.rb, line 24 def application_info context.applicationInfo end
# File lib/project/pro_motion/pm_application.rb, line 104 def async(options={}, &block) MotionAsync.async(options, &block) end
# File lib/project/pro_motion/pm_application.rb, line 32 def content_resolver context.contentResolver end
Typically you don’t use this, use ‘find.screen` instead, TODO, probably should remove this
# 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
# File lib/project/pro_motion/pm_application.rb, line 48 def data_dir application_info.dataDir end
@return [Boolean] true if the app is running in the :development environment
# File lib/project/pro_motion/pm_application.rb, line 88 def development? environment == :development end
@return [Symbol] Environment the app is running it
# File lib/project/pro_motion/pm_application.rb, line 72 def environment @_environment ||= RUBYMOTION_ENV.to_sym end
# 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
# File lib/project/pro_motion/pm_application.rb, line 20 def home_screen_class @home_screen_class end
# File lib/project/pro_motion/pm_application.rb, line 40 def identifier application_info.packageName end
Launch native services via intent app.launch(sms: ‘5045558008’) app.launch(tel: ‘5045558008’) app.launch(web: ‘giphy.com’) app.launch(email: ‘your@mom.com’) app.launch(email: ‘your@mom.com’, subject: “Hey Chica”, message: “Howdy”) app.launch(chooser: ‘I hope you have a nice day!’)
# 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) message_intent = Android::Content::Intent.new(action_send) message_intent.type = "text/plain" message_intent.putExtra("android.intent.extra.TEXT", command[:chooser].to_s) if command[:chooser] Android::Content::Intent.createChooser(message_intent, nil) else mp "[BP Warning] Launch type unknown - '#{command.keys.inspect}'" nil end find.activity.startActivity(launch_intent) if launch_intent end
# File lib/project/pro_motion/pm_application.rb, line 36 def name application_info.loadLabel(package_manager) end
# File lib/project/pro_motion/pm_application.rb, line 100 def net BluePotionNet end
# 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
# File lib/project/pro_motion/pm_application.rb, line 28 def package_manager context.getPackageManager end
# File lib/project/pro_motion/pm_application.rb, line 44 def package_name @package_name ||= application_info.packageName end
# File lib/project/pro_motion/pm_application.rb, line 96 def r RMQResource end
@return [Boolean] true if the app is running in the :release environment
# File lib/project/pro_motion/pm_application.rb, line 77 def release? environment == :release end
# File lib/project/pro_motion/pm_application.rb, line 92 def resource RMQResource end
Send user to native Texting app.sms(“555-555-5555”)
# 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
@return [Boolean] true if the app is running in the :test environment
# File lib/project/pro_motion/pm_application.rb, line 83 def test? environment == :test end
# File lib/project/pro_motion/pm_application.rb, line 108 def toast(message, params={}) message_length = case params[:length] when :long Android::Widget::Toast::LENGTH_LONG else Android::Widget::Toast::LENGTH_SHORT end Android::Widget::Toast.makeText(rmq.activity, message, message_length).show end
# File lib/project/pro_motion/pm_application.rb, line 52 def window if @current_activity @window ||= @current_activity.getWindow end end