class PMApplication

Attributes

current_application[RW]
home_screen_class[RW]
context[RW]
current_activity[RW]

Public Class Methods

home_screen(hclass) click to toggle source
# 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

after(delay, &block) click to toggle source

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
alert(options={}, &block) click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 118
def alert(options={}, &block)
  AlertDialog.new(options, &block)
end
application_info() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 24
def application_info
  context.applicationInfo
end
async(options={}, &block) click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 104
def async(options={}, &block)
  MotionAsync.async(options, &block)
end
content_resolver() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 32
def content_resolver
  context.contentResolver
end
current_screen() click to toggle source

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
data_dir() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 48
def data_dir
  application_info.dataDir
end
development?() click to toggle source

@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
environment() click to toggle source

@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
guess_current_screen() click to toggle source
# 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() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 20
def home_screen_class
  @home_screen_class
end
identifier() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 40
def identifier
  application_info.packageName
end
launch(command={}) click to toggle source

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
name() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 36
def name
  application_info.loadLabel(package_manager)
end
net() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 100
def net
  BluePotionNet
end
onCreate() click to toggle source
# 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() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 28
def package_manager
  context.getPackageManager
end
package_name() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 44
def package_name
  @package_name ||= application_info.packageName
end
production?()
Alias for: release?
r() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 96
def r
  RMQResource
end
release?() click to toggle source

@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
Also aliased as: production?
resource() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 92
def resource
  RMQResource
end
sms(phone_number) click to toggle source

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
test?() click to toggle source

@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
toast(message, params={}) click to toggle source
# 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
window() click to toggle source
# File lib/project/pro_motion/pm_application.rb, line 52
def window
  if @current_activity
    @window ||= @current_activity.getWindow
  end
end