Class: PMApplication

Inherits:
Android::App::Application
  • Object
show all
Defined in:
lib/project/pro_motion/pm_application.rb

Overview

RM-773 module ProMotion

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.current_applicationObject

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_classObject

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

#contextObject

Returns the value of attribute context.



4
5
6
# File 'lib/project/pro_motion/pm_application.rb', line 4

def context
  @context
end

#current_activityObject

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(options={}, &block)
  AlertDialog.new(options, &block)
end

#application_infoObject



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(options={}, &block)
  MotionAsync.async(options, &block)
end

#content_resolverObject



32
33
34
# File 'lib/project/pro_motion/pm_application.rb', line 32

def content_resolver
  context.contentResolver
end

#current_screenObject

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_dirObject



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

#environmentSymbol



72
73
74
# File 'lib/project/pro_motion/pm_application.rb', line 72

def environment
  @_environment ||= RUBYMOTION_ENV.to_sym
end

#guess_current_screenObject



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_classObject



20
21
22
# File 'lib/project/pro_motion/pm_application.rb', line 20

def home_screen_class
  @home_screen_class
end

#identifierObject



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)
    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

#nameObject



36
37
38
# File 'lib/project/pro_motion/pm_application.rb', line 36

def name
  application_info.loadLabel(package_manager)
end

#netObject



100
101
102
# File 'lib/project/pro_motion/pm_application.rb', line 100

def net
  BluePotionNet
end

#onCreateObject



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_managerObject



28
29
30
# File 'lib/project/pro_motion/pm_application.rb', line 28

def package_manager
  context.getPackageManager
end

#package_nameObject



44
45
46
# File 'lib/project/pro_motion/pm_application.rb', line 44

def package_name
  @package_name ||= application_info.packageName
end

#rObject



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

#resourceObject



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(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

#windowObject



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