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
- #close(options = {}) ⇒ Object
- #color(*params) ⇒ Object
- #create(view_or_class, style = nil, opts = {}) ⇒ Object
- #create!(view_or_class, style = nil, opts = {}) ⇒ Object
- #font ⇒ Object
- #hide_keyboard ⇒ Object
- #image ⇒ Object
- #menu ⇒ Object
- #on_load ⇒ Object
- #on_options_item_selected(item) ⇒ 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.
- #rmq(*working_selectors) ⇒ Object
- #rmq_data ⇒ Object
- #root_view ⇒ Object
- #show_toast(message) ⇒ Object
- #soft_input_mode(mode) ⇒ Object
- #start_activity(activity_class) ⇒ Object
- #stylesheet ⇒ Object
- #stylesheet=(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
202 203 204 205 206 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 202 def if a = activity a.getActionBar end end |
#add_action_bar_button(options = {}) ⇒ Object
Example: add_action_bar_button(title: “My text”, show: :if_room)
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 213 def (={}) @action_bar ||= { 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, @action_bar[: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] @action_bar[:button_actions][btn.getItemId] = [:action] if [:action] @action_bar[:current_id] = btn.getItemId + 1 btn end |
#append(view_or_class, style = nil, opts = {}, dummy = nil) ⇒ Object
88 89 90 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 88 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
92 93 94 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 92 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
104 105 106 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 104 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
108 109 110 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 108 def build!(view_or_class, style=nil, opts={}) self.rmq.build(view_or_class, style, opts).get end |
#close(options = {}) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 162 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 act.finish unless act.fragment end end |
#color(*params) ⇒ Object
76 77 78 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 76 def color(*params) RMQ.color(*params) end |
#create(view_or_class, style = nil, opts = {}) ⇒ Object
96 97 98 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 96 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
100 101 102 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 100 def create!(view_or_class, style=nil, opts={}) self.rmq.create(view_or_class, style, opts).get end |
#font ⇒ Object
80 81 82 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 80 def font rmq.font end |
#hide_keyboard ⇒ Object
197 198 199 200 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 197 def hide_keyboard input_manager = activity.getSystemService(Android::Content::Context::INPUT_METHOD_SERVICE) input_manager.hideSoftInputFromWindow(view.getWindowToken(), 0); end |
#image ⇒ Object
84 85 86 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 84 def image rmq.image end |
#menu ⇒ Object
208 209 210 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 208 def activity. end |
#on_load ⇒ Object
72 73 74 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 72 def on_load # abstract end |
#on_options_item_selected(item) ⇒ Object
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 237 def (item) return unless @action_bar return unless method_name = @action_bar[: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 |
#open(screen_class, options = {}) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 122 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
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 137 def open_modal(screen_class, ) activity_class = .delete(:activity) || PMNavigationActivity activity_class = PMNavigationActivity 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
113 114 115 116 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 113 def r(resource_type, resource_name) resources.getIdentifier(resource_name.to_s, resource_type.to_s, activity.getApplicationInfo.packageName) end |
#rmq(*working_selectors) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 58 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
46 47 48 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 46 def rmq_data @_rmq_data ||= RMQScreenData.new end |
#root_view ⇒ Object
68 69 70 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 68 def root_view self.getView end |
#show_toast(message) ⇒ Object
118 119 120 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 118 def show_toast() Android::Widget::Toast.makeText(activity, , Android::Widget::Toast::LENGTH_SHORT).show end |
#soft_input_mode(mode) ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 188 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
182 183 184 185 186 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 182 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
50 51 52 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 50 def stylesheet self.rmq.stylesheet end |
#stylesheet=(value) ⇒ Object
54 55 56 |
# File 'lib/project/pro_motion/fragments/pm_screen_module.rb', line 54 def stylesheet=(value) self.rmq.stylesheet = value end |