Module: PMScreenModule
- Included in:
- PMListScreen, PMScreen
- Defined in:
- lib/project/pro_motion/fragments/pm_screen_module.rb
Overview
hipbyte.myjetbrains.com/youtrack/issue/RM-773 - can’t put this in a module yet :( module ProMotion
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #action_bar ⇒ Object
-
#add_action_bar_button(options = {}) ⇒ Object
Example: add_action_bar_button(title: “My text”, show: :if_room).
- #append(view_or_class, style = nil, opts = {}, dummy = nil) ⇒ Object
- #append!(view_or_class, style = nil, opts = {}) ⇒ Object
- #build(view_or_class, style = nil, opts = {}) ⇒ Object
- #build!(view_or_class, style = nil, opts = {}) ⇒ Object
- #build_and_tag_xml_views ⇒ Object
- #cleanup ⇒ Object
- #close(options = {}) ⇒ Object
- #color(*params) ⇒ Object
- #create(view_or_class, style = nil, opts = {}) ⇒ Object
- #create!(view_or_class, style = nil, opts = {}) ⇒ Object
- #dummy_workaround_for_kind_of ⇒ Object
-
#find(*working_selectors) ⇒ Object
I do not call rmq below for performance reasons.
- #font ⇒ Object
- #hide_keyboard ⇒ Object
- #image ⇒ Object
- #log_tree ⇒ Object
- #menu ⇒ Object
-
#on_load ⇒ Object
abstract methods.
- #on_options_item_selected(item) ⇒ Object
- #on_return(opts = {}) ⇒ Object
- #onDestroy ⇒ Object
- #open(screen_class, options = {}) ⇒ Object
- #open_modal(screen_class, options) ⇒ Object
-
#r(resource_type, resource_name) ⇒ Object
temporary stand-in for Java’s R class, TODO remove this.
- #rmq(*working_selectors) ⇒ Object
- #rmq_data ⇒ Object
- #root_view ⇒ Object
- #set_title ⇒ Object
- #set_up_action_bar(options = {}) ⇒ Object
- #show_keyboard ⇒ Object
-
#show_toast(message) ⇒ Object
TODO, remove this, use app.toast.
- #soft_input_mode(mode) ⇒ Object
- #start_activity(activity_class) ⇒ Object
- #stylesheet ⇒ Object
- #stylesheet=(value) ⇒ Object
- #title ⇒ Object
- #title=(value) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#action_bar ⇒ Object
255 256 257 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 255 def activity && activity.getActionBar end |
#add_action_bar_button(options = {}) ⇒ Object
Example: add_action_bar_button(title: “My text”, show: :if_room)
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 276 def (={}) ||= { button_actions: {} } unless mp "#{self.inspect}#add_action_bar_button: No menu set up yet." return end [:show] ||= :always # Should be something like Android::MenuItem::SHOW_AS_ACTION_IF_ROOM show_as_action = 0 if [:show] == :never show_as_action = 1 if [:show] == :if_room show_as_action = 2 if [:show] == :always show_as_action = 4 if [:show] == :with_text show_as_action = 8 if [:show] == :collapse btn = self.activity..add(.fetch(:group, 0), .fetch(:item_id, [:current_id] || 0), .fetch(:order, 0), .fetch(:title, "")) btn.setShowAsAction(show_as_action) if show_as_action btn.setIcon(image.resource([:icon].to_s)) if [:icon] [:button_actions][btn.getItemId] = [:action] if [:action] [:current_id] = btn.getItemId + 1 btn end |
#append(view_or_class, style = nil, opts = {}, dummy = nil) ⇒ Object
125 126 127 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 125 def append(view_or_class, style=nil, opts={}, dummy=nil) self.rmq.append(view_or_class, style, opts) end |
#append!(view_or_class, style = nil, opts = {}) ⇒ Object
129 130 131 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 129 def append!(view_or_class, style=nil, opts={}) self.rmq.append(view_or_class, style, opts).get end |
#build(view_or_class, style = nil, opts = {}) ⇒ Object
141 142 143 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 141 def build(view_or_class, style=nil, opts={}) self.rmq.build(view_or_class, style, opts) end |
#build!(view_or_class, style = nil, opts = {}) ⇒ Object
145 146 147 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 145 def build!(view_or_class, style=nil, opts={}) self.rmq.build(view_or_class, style, opts).get end |
#build_and_tag_xml_views ⇒ Object
311 312 313 314 315 316 317 318 319 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 311 def build_and_tag_xml_views return unless @xml_resource self.rmq.all.each do |view| if ren = view.resource_entry_name self.rmq.build(view).tag(ren.to_sym) end end end |
#cleanup ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 68 def cleanup find.all.cleanup find.children.remove if @_rmq_data @_rmq_data.cleanup @_rmq_data = nil end end |
#close(options = {}) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 203 def close(={}) # Hang onto an activity reference, since we lose the activity act = self.activity if [:activity] && [:to_screen] # Closing to particular activity open [:to_screen], activity: [:activity], close: true elsif [:to_screen] # Closing to particular fragment while act.fragment && !act.fragment.is_a?([:to_screen]) act.close_fragment act.finish unless act.fragment end else # Closing current screen or activity if no screens left act.close_fragment if act.fragment end if act.fragment act.fragment. act.fragment.on_return() else act.finish unless act.fragment end end |
#color(*params) ⇒ Object
113 114 115 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 113 def color(*params) RMQ.color(*params) end |
#create(view_or_class, style = nil, opts = {}) ⇒ Object
133 134 135 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 133 def create(view_or_class, style=nil, opts={}) self.rmq.create(view_or_class, style, opts) end |
#create!(view_or_class, style = nil, opts = {}) ⇒ Object
137 138 139 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 137 def create!(view_or_class, style=nil, opts={}) self.rmq.create(view_or_class, style, opts).get end |
#dummy_workaround_for_kind_of ⇒ Object
58 59 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 58 def dummy_workaround_for_kind_of end |
#find(*working_selectors) ⇒ Object
I do not call rmq below for performance reasons
85 86 87 88 89 90 91 92 93 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 85 def find(*working_selectors) # I do not call rmq below for performance reasons crmq = (rmq_data.cached_rmq ||= RMQ.create_with_selectors([], self)) if working_selectors.length == 0 crmq else RMQ.create_with_selectors(working_selectors, self, crmq) end end |
#font ⇒ Object
117 118 119 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 117 def font rmq.font end |
#hide_keyboard ⇒ Object
244 245 246 247 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 244 def hide_keyboard input_manager = activity.getSystemService(Android::Content::Context::INPUT_METHOD_SERVICE) input_manager.hideSoftInputFromWindow(view.getWindowToken(), 0) end |
#image ⇒ Object
121 122 123 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 121 def image rmq.image end |
#log_tree ⇒ Object
149 150 151 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 149 def log_tree rmq.log_tree end |
#menu ⇒ Object
259 260 261 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 259 def activity. end |
#on_load ⇒ Object
abstract methods
110 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 110 def on_load; end |
#on_options_item_selected(item) ⇒ Object
300 301 302 303 304 305 306 307 308 309 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 300 def (item) return unless return unless method_name = [:button_actions][item.getItemId] if respond_to?(method_name) send(method_name) else mp "#{self.inspect} No method #{method_name.inspect} implemented for this screen." true end end |
#on_return(opts = {}) ⇒ Object
111 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 111 def on_return(opts={}); end |
#onDestroy ⇒ Object
61 62 63 64 65 66 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 61 def onDestroy #return super # disable rmq cleaning while debugging, but still super mp "onDestroy screen: #{self.class}", debugging_only: true self.cleanup super end |
#open(screen_class, options = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 163 def open(screen_class, ={}) mp "ScreenModule open", debugging_only: true if ![:activity] && self.activity.respond_to?(:open_fragment) if screen_class.respond_to?(:new) screen = screen_class.new else screen = screen_class end self.activity.open_fragment screen, else open_modal(screen_class, ) end end |
#open_modal(screen_class, options) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 178 def open_modal(screen_class, ) activity_class = .delete(:activity) || activity_class = if activity_class == :nav activity_class = PMSingleFragmentActivity if activity_class == :single intent = Potion::Intent.new(self.activity, activity_class) intent.putExtra PMActivity::EXTRA_FRAGMENT_CLASS, screen_class.to_s intent.setFlags(Potion::Intent::FLAG_ACTIVITY_CLEAR_TOP) if .delete(:close) if extras = .delete(:extras) extras.keys.each do |key, value| # TODO, cahnge to bundle and do like below intent.putExtra key.to_s, value.toString end end unless .blank? # The rest of the options are screen accessors, we use fragment arguments for this hash_bundle = PMHashBundle.from_hash() intent.putExtra PMActivity::EXTRA_FRAGMENT_ARGUMENTS, hash_bundle.to_bundle end self.activity.startActivity intent end |
#r(resource_type, resource_name) ⇒ Object
temporary stand-in for Java’s R class, TODO remove this
154 155 156 157 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 154 def r(resource_type, resource_name) resources.getIdentifier(resource_name.to_s, resource_type.to_s, activity.getApplicationInfo.packageName) end |
#rmq(*working_selectors) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 95 def rmq(*working_selectors) crmq = (rmq_data.cached_rmq ||= RMQ.create_with_selectors([], self)) if working_selectors.length == 0 crmq else RMQ.create_with_selectors(working_selectors, self, crmq) end end |
#rmq_data ⇒ Object
54 55 56 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 54 def rmq_data @_rmq_data ||= RMQScreenData.new end |
#root_view ⇒ Object
105 106 107 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 105 def root_view self.getView end |
#set_title ⇒ Object
321 322 323 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 321 def set_title self.title = self.class. end |
#set_up_action_bar(options = {}) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 263 def (={}) if [:show] .show .setDisplayHomeAsUpEnabled(!![:back]) .setDisplayShowHomeEnabled(!![:icon]) .setIcon(image.resource([:custom_icon].to_s)) if [:custom_icon] .setHomeAsUpIndicator(image.resource([:custom_back].to_s)) if [:custom_back] else .hide end end |
#show_keyboard ⇒ Object
249 250 251 252 253 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 249 def show_keyboard field = activity.getCurrentFocus() input_manager = activity.getSystemService(Android::Content::Context::INPUT_METHOD_SERVICE) input_manager.showSoftInput(field, Android::View::InputMethod::InputMethodManager::SHOW_FORCED) end |
#show_toast(message) ⇒ Object
TODO, remove this, use app.toast
159 160 161 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 159 def show_toast() # TODO, remove this, use app.toast Android::Widget::Toast.makeText(activity, , Android::Widget::Toast::LENGTH_SHORT).show end |
#soft_input_mode(mode) ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 235 def soft_input_mode(mode) mode_const = case mode when :adjust_resize Android::View::WindowManager::LayoutParams::SOFT_INPUT_ADJUST_RESIZE end activity.getWindow().setSoftInputMode(mode_const) end |
#start_activity(activity_class) ⇒ Object
229 230 231 232 233 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 229 def start_activity(activity_class) intent = Potion::Intent.new(self.activity, activity_class) #intent.putExtra("key", value); # Optional parameters self.activity.startActivity(intent) end |
#stylesheet ⇒ Object
77 78 79 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 77 def stylesheet self.rmq.stylesheet end |
#stylesheet=(value) ⇒ Object
81 82 83 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 81 def stylesheet=(value) self.rmq.stylesheet = value end |
#title ⇒ Object
325 326 327 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 325 def title @title end |
#title=(value) ⇒ Object
328 329 330 331 332 333 334 335 336 337 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 328 def title=(value) @title = value if a = self.activity if = self. .title = value end a.title = value end end |