bluepotion 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/project/blue_potion_net.rb +105 -0
- data/lib/project/ext/object.rb +2 -0
- data/lib/project/potion.rb +19 -3
- data/lib/project/potion_dialog/potion_dialog.rb +46 -0
- data/lib/project/pro_motion/{pm_activity.rb → activities/pm_activity.rb} +18 -0
- data/lib/project/pro_motion/activities/pm_home_activity.rb +14 -0
- data/lib/project/pro_motion/activities/pm_navigation_activity.rb +83 -0
- data/lib/project/pro_motion/{pm_single_fragment_activity.rb → activities/pm_single_fragment_activity.rb} +14 -3
- data/lib/project/pro_motion/adapters/pm_base_adapter.rb +75 -0
- data/lib/project/pro_motion/adapters/pm_cursor_adapter.rb +44 -0
- data/lib/project/pro_motion/fragments/pm_list_screen.rb +191 -0
- data/lib/project/pro_motion/{pm_screen.rb → fragments/pm_screen.rb} +31 -6
- data/lib/project/pro_motion/{pm_screen_module.rb → fragments/pm_screen_module.rb} +72 -20
- data/lib/project/pro_motion/pm_application.rb +15 -4
- data/lib/project/pro_motion/{pm_hash_bundle.rb → support/pm_hash_bundle.rb} +4 -0
- data/lib/project/ruby_motion_query/rmq/base.rb +1 -1
- data/lib/project/ruby_motion_query/rmq/data.rb +2 -36
- data/lib/project/ruby_motion_query/rmq/subviews.rb +30 -0
- data/lib/project/ruby_motion_query/rmq_color.rb +1 -1
- data/lib/project/ruby_motion_query/rmq_resource.rb +26 -0
- data/lib/project/version.rb +1 -1
- data/lib/project/volley_wrap/http_result.rb +98 -0
- data/lib/project/volley_wrap/request.rb +98 -0
- data/lib/project/volley_wrap/response_listener.rb +49 -0
- data/lib/project/volley_wrap/session_client.rb +72 -0
- metadata +19 -8
- data/lib/project/pro_motion/pm_home_activity.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada06103d7e2b09d8f69878a072869d19f3c0188
|
4
|
+
data.tar.gz: 612d94fc6906fb6ad7d9a9d76376ff0f6203ab2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4f9d90c3edea2e837635765b801a6d73c21b8e1ab0125c25ffe72bb8293373b8db84418de2603d88f5db341c19c8e12085e99072aa03ea0dc50a939f6d2e3d2
|
7
|
+
data.tar.gz: a54a04e03c0d3ef01b52abd99585246de71bc3b4715789e328a6c94037f770f37a290a62c1450b2eda8e3ec45fc97d756b890c02a412cac13b362d78c82ec3df
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Nice wrapper around VolleyWrapper, to use in BluePotion.
|
2
|
+
#
|
3
|
+
# result that is returned has these attributes:
|
4
|
+
# response
|
5
|
+
# object
|
6
|
+
# body
|
7
|
+
# status_code
|
8
|
+
# headers
|
9
|
+
# not_modified?
|
10
|
+
# success?
|
11
|
+
# failure?
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # Create a session and do a single HTML get. It's better
|
15
|
+
# # to use the shared session below.
|
16
|
+
# app.net.get("http://google.com")do |response|
|
17
|
+
# mp response.object # <- HTML
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # To initialize the shared session, which is best to use
|
21
|
+
# # rather than the one-off above, do this. Once this
|
22
|
+
# # is done, all your gets, posts, puts, etc will use this
|
23
|
+
# # share session
|
24
|
+
# app.net.build_shared("http://baseurl.com") do |shared|
|
25
|
+
# # You can override the serializer per request
|
26
|
+
# # Leave blank for string
|
27
|
+
# shared.serializer = :json
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# # For shared, use relative paths
|
31
|
+
# app.net.get("foo.html") do |response|
|
32
|
+
# mp response.object # <- returns type you set in shared.serializer
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# # Post
|
36
|
+
# app.net.post("foo/bar", your_params_hash) do |response|
|
37
|
+
# mp response.object # <- returns type you set in shared.serializer
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# # If you have built a shared session, but want to use another
|
41
|
+
# # session, do this:
|
42
|
+
# app.net.get("foo.html", session: app.net.single_use_session) do |response|
|
43
|
+
# mp response.object # <- returns type you set in shared.serializer
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # Get json:
|
47
|
+
# url = "http://openweathermap.org/data/2.1/find/name?q=san%20francisco"
|
48
|
+
# app.net.get_json(url) do |request|
|
49
|
+
# # request.object is a hash, parsed from the json
|
50
|
+
# temp_kelvin = request.object["list"].first["main"]["temp"]
|
51
|
+
# end
|
52
|
+
class BluePotionNet
|
53
|
+
class << self
|
54
|
+
def session_client
|
55
|
+
@_session_client ||= VW::SessionClient
|
56
|
+
end
|
57
|
+
|
58
|
+
def session
|
59
|
+
session_client.shared ? session_client.shared : single_use_session
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_shared?
|
63
|
+
!session_client.shared.is_nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def single_use_session
|
67
|
+
session_client.new(PMApplication.current_application.context, "")
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_shared(url, &block)
|
71
|
+
session_client.build_shared(PMApplication.current_application.context, url, &block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get(url, opts={}, &block)
|
75
|
+
raise "[BluePotion error] You must provide a block when using app.net.get" unless block
|
76
|
+
ses = opts.delete(:session) || self.session
|
77
|
+
opts[:serializer] = :string unless opts[:serializer]
|
78
|
+
ses.get(url, opts, &block)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_json(url, opts={}, &block)
|
82
|
+
raise "[BluePotion error] You must provide a block when using app.net.get_json" unless block
|
83
|
+
opts[:serializer] = :json
|
84
|
+
get(url, opts, &block)
|
85
|
+
end
|
86
|
+
|
87
|
+
def post(url, params, opts={}, &block)
|
88
|
+
raise "[BluePotion error] You must provide a block when using app.net.post" unless block
|
89
|
+
ses = opts.delete(:session) || self.session
|
90
|
+
ses.post(url, params, opts, &block)
|
91
|
+
end
|
92
|
+
|
93
|
+
def put(url, params, opts={}, &block)
|
94
|
+
raise "[BluePotion error] You must provide a block when using app.net.put" unless block
|
95
|
+
ses = opts.delete(:session) || self.session
|
96
|
+
ses.put(url, params, opts, &block)
|
97
|
+
end
|
98
|
+
|
99
|
+
def delete(url, params, opts={}, &block)
|
100
|
+
raise "[BluePotion error] You must provide a block when using app.net.delete" unless block
|
101
|
+
ses = opts.delete(:session) || self.session
|
102
|
+
ses.delete(url, params, opts, &block)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/project/ext/object.rb
CHANGED
data/lib/project/potion.rb
CHANGED
@@ -1,28 +1,44 @@
|
|
1
1
|
module Potion
|
2
2
|
Activity = Android::App::Activity
|
3
|
+
Intent = Android::Content::Intent
|
3
4
|
View = Android::View::View
|
5
|
+
Window = Android::View::Window
|
4
6
|
ViewGroup = Android::View::ViewGroup
|
5
7
|
Integer = Java::Lang::Integer
|
6
8
|
ArrayList = Java::Util::ArrayList
|
7
9
|
Bundle = Android::Os::Bundle
|
10
|
+
Environment = Android::Os::Environment
|
11
|
+
Uri = Android::Net::Uri
|
12
|
+
ArrayAdapter = Android::Widget::ArrayAdapter
|
13
|
+
BaseAdapter = Android::Widget::BaseAdapter
|
14
|
+
Dialog = Android::App::Dialog
|
15
|
+
EditorInfo = Android::View::Inputmethod::EditorInfo
|
8
16
|
|
9
|
-
#
|
17
|
+
# Layouts
|
18
|
+
LayoutInflater = Android::View::LayoutInflater
|
10
19
|
LinearLayout = Android::Widget::LinearLayout
|
11
20
|
FrameLayout = Android::Widget::FrameLayout
|
12
21
|
RelativeLayout = Android::Widget::RelativeLayout
|
13
22
|
AbsoluteLayout = Android::Widget::AbsoluteLayout
|
14
23
|
|
15
|
-
#
|
24
|
+
# Widgets
|
16
25
|
Label = Android::Widget::TextView
|
17
26
|
TextView = Android::Widget::TextView
|
27
|
+
EditText = Android::Widget::EditText
|
18
28
|
ImageView = Android::Widget::ImageView
|
19
29
|
Button = Android::Widget::Button
|
20
30
|
CalendarView = Android::Widget::CalendarView
|
21
31
|
Toast = Android::Widget::Toast
|
32
|
+
ListView = Android::Widget::ListView
|
22
33
|
|
23
|
-
#
|
34
|
+
# Graphics
|
24
35
|
Color = Android::Graphics::Color
|
25
36
|
Typeface = Android::Graphics::Typeface
|
37
|
+
|
38
|
+
# Media
|
39
|
+
File = Java::Io::File
|
40
|
+
MediaStore = Android::Provider::MediaStore
|
41
|
+
Contacts = Android::Provider::ContactsContract::Contacts
|
26
42
|
end
|
27
43
|
|
28
44
|
#
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class PotionDialog
|
2
|
+
|
3
|
+
def initialize(options)
|
4
|
+
|
5
|
+
@width = options[:width] || options[:w]
|
6
|
+
@height = options[:height] || options[:h]
|
7
|
+
|
8
|
+
# err if missing required options
|
9
|
+
raise "[BluePotion ERROR] PotionDialog#initialize Requires an xml_layout" unless options[:xml_layout]
|
10
|
+
raise "[BluePotion ERROR] PotionDialog#initialize Cannot have width without height" if @width && !@height
|
11
|
+
raise "[BluePotion ERROR] PotionDialog#initialize Cannot have height without width" if @height && !@width
|
12
|
+
|
13
|
+
# Merging defaults
|
14
|
+
opts = {
|
15
|
+
title: false,
|
16
|
+
show: true
|
17
|
+
}.merge(options)
|
18
|
+
|
19
|
+
built_dialog = build_dialog(opts)
|
20
|
+
|
21
|
+
built_dialog.show if opts[:show]
|
22
|
+
|
23
|
+
built_dialog
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_dialog(options)
|
27
|
+
# create dialog
|
28
|
+
dialog = Potion::Dialog.new(find.activity)
|
29
|
+
|
30
|
+
# manage title
|
31
|
+
if options[:title]
|
32
|
+
dialog.title = options[:title]
|
33
|
+
else
|
34
|
+
dialog.requestWindowFeature(Potion::Window::FEATURE_NO_TITLE)
|
35
|
+
end
|
36
|
+
|
37
|
+
# set alert content
|
38
|
+
dialog.setContentView(options[:xml_layout])
|
39
|
+
|
40
|
+
# set width and height of Dialog Window
|
41
|
+
if @width && @height
|
42
|
+
dialog.window.setLayout(@width, @height)
|
43
|
+
end
|
44
|
+
dialog
|
45
|
+
end
|
46
|
+
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
class PMActivity < Android::App::Activity
|
4
4
|
|
5
|
+
EXTRA_FRAGMENT_CLASS = "fragment_class"
|
6
|
+
EXTRA_FRAGMENT_ARGUMENTS = "fragment_arguments"
|
7
|
+
|
5
8
|
def onCreate(saved_instance_state)
|
6
9
|
super
|
7
10
|
|
@@ -17,8 +20,10 @@
|
|
17
20
|
|
18
21
|
def onResume
|
19
22
|
super
|
23
|
+
on_resume
|
20
24
|
PMApplication.current_application.current_activity = self
|
21
25
|
end
|
26
|
+
def on_resume; end
|
22
27
|
|
23
28
|
def onPause
|
24
29
|
clear_references
|
@@ -38,6 +43,19 @@
|
|
38
43
|
end
|
39
44
|
def on_create_menu(_); end
|
40
45
|
|
46
|
+
def onOptionsItemSelected(item)
|
47
|
+
# Don't call super if method returns false
|
48
|
+
super unless on_options_item_selected(item) == false
|
49
|
+
end
|
50
|
+
|
51
|
+
def open(screen, options={})
|
52
|
+
find.screen.open screen, options
|
53
|
+
end
|
54
|
+
|
55
|
+
def close(options={})
|
56
|
+
find.screen.close options
|
57
|
+
end
|
58
|
+
|
41
59
|
end
|
42
60
|
|
43
61
|
#end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# RM-733
|
2
|
+
#module ProMotion
|
3
|
+
class PMHomeActivity < PMNavigationActivity
|
4
|
+
def on_create(saved_instance_state)
|
5
|
+
mp "PMHomeActivity on_create", debugging_only: true
|
6
|
+
@root_fragment ||= home_screen_class.new if home_screen_class
|
7
|
+
super # Opens @root_fragment
|
8
|
+
end
|
9
|
+
|
10
|
+
def home_screen_class
|
11
|
+
PMApplication.current_application.home_screen_class
|
12
|
+
end
|
13
|
+
end
|
14
|
+
#end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# An Activity designed to host a stack of fragments/screens.
|
2
|
+
# RM-733
|
3
|
+
#module ProMotion
|
4
|
+
class PMNavigationActivity < PMActivity
|
5
|
+
attr_accessor :fragment_container, :root_fragment, :menu
|
6
|
+
|
7
|
+
def on_create(saved_instance_state)
|
8
|
+
super
|
9
|
+
# mp "PMNavigationActivity on_create", debugging_only: true
|
10
|
+
activity_init
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_create_menu(menu)
|
14
|
+
@menu = menu
|
15
|
+
self.fragment.on_create_menu(menu) if self.fragment
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_options_item_selected(item)
|
19
|
+
self.fragment.on_options_item_selected(item) if self.fragment
|
20
|
+
end
|
21
|
+
|
22
|
+
def open_fragment(frag, options={})
|
23
|
+
mp frag
|
24
|
+
mgr = fragmentManager.beginTransaction
|
25
|
+
mgr.add(@fragment_container.getId, frag, "screen-#{fragmentManager.getBackStackEntryCount + 1}")
|
26
|
+
mgr.addToBackStack(nil)
|
27
|
+
mgr.commit
|
28
|
+
frag
|
29
|
+
end
|
30
|
+
|
31
|
+
def close_fragment
|
32
|
+
getFragmentManager.popBackStackImmediate
|
33
|
+
end
|
34
|
+
|
35
|
+
def fragment
|
36
|
+
# self.fragments.last
|
37
|
+
getFragmentManager.findFragmentByTag("screen-#{fragmentManager.getBackStackEntryCount}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_fragment_attached(frag)
|
41
|
+
# No-op for now.
|
42
|
+
end
|
43
|
+
|
44
|
+
def on_fragment_detached(frag)
|
45
|
+
if new_frag = self.fragment
|
46
|
+
new_frag.set_title if new_frag.respond_to?(:set_title)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def activity_init
|
53
|
+
setup_root_fragment_container
|
54
|
+
@root_fragment ||= intent_fragment_class && Kernel.const_get(intent_fragment_class.to_s).new
|
55
|
+
return unless @root_fragment
|
56
|
+
setup_root_fragment @root_fragment
|
57
|
+
open_fragment @root_fragment
|
58
|
+
@root_fragment = nil # Don't hang onto this reference.
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_root_fragment(frag)
|
62
|
+
return unless intent_fragment_arguments
|
63
|
+
PMHashBundle.from_bundle(intent_fragment_arguments).to_h.each do |key, value|
|
64
|
+
frag.send "#{key}=", value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def intent_fragment_arguments
|
69
|
+
intent.getBundleExtra(EXTRA_FRAGMENT_ARGUMENTS)
|
70
|
+
end
|
71
|
+
|
72
|
+
def intent_fragment_class
|
73
|
+
intent.getStringExtra(EXTRA_FRAGMENT_CLASS)
|
74
|
+
end
|
75
|
+
|
76
|
+
def setup_root_fragment_container
|
77
|
+
@fragment_container = Potion::FrameLayout.new(self)
|
78
|
+
@fragment_container.setId Potion::ViewIdGenerator.generate
|
79
|
+
self.contentView = @fragment_container
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
#end
|
@@ -4,14 +4,21 @@
|
|
4
4
|
class PMSingleFragmentActivity < PMActivity
|
5
5
|
attr_accessor :fragment_container, :fragment, :menu
|
6
6
|
|
7
|
-
EXTRA_FRAGMENT_CLASS = "fragment_class"
|
8
|
-
EXTRA_FRAGMENT_ARGUMENTS = "fragment_arguments"
|
9
|
-
|
10
7
|
def on_create(saved_instance_state)
|
11
8
|
super
|
12
9
|
|
13
10
|
mp "PMSingleFragmentActivity on_create", debugging_only: true
|
14
11
|
|
12
|
+
setup_fragment
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_resume
|
16
|
+
mp "PMSingleFragmentActivity on_resume", debugging_only: true
|
17
|
+
|
18
|
+
setup_fragment unless @fragment_container
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup_fragment
|
15
22
|
@fragment_container = Potion::FrameLayout.new(self)
|
16
23
|
@fragment_container.setId Potion::ViewIdGenerator.generate
|
17
24
|
self.contentView = @fragment_container
|
@@ -43,5 +50,9 @@
|
|
43
50
|
self.fragment.on_create_menu(menu) if self.fragment
|
44
51
|
end
|
45
52
|
|
53
|
+
def on_options_item_selected(item)
|
54
|
+
self.fragment.on_options_item_selected(item) if self.fragment
|
55
|
+
end
|
56
|
+
|
46
57
|
end
|
47
58
|
#end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class PMBaseAdapter < Android::Widget::BaseAdapter
|
2
|
+
attr_accessor :data
|
3
|
+
|
4
|
+
def initialize(opts={})
|
5
|
+
super()
|
6
|
+
@data = opts.fetch(:data, [])
|
7
|
+
end
|
8
|
+
|
9
|
+
def screen
|
10
|
+
@screen ||= rmq.screen
|
11
|
+
end
|
12
|
+
def screen=(value)
|
13
|
+
@screen
|
14
|
+
end
|
15
|
+
|
16
|
+
def areAllItemsEnabled(); are_all_items_enabled?; end
|
17
|
+
def are_all_items_enabled?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def isEnabled(position); is_enabled?(position); end
|
22
|
+
def is_enabled?(position)
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def isEmpty(); is_empty?; end
|
27
|
+
def is_empty?
|
28
|
+
data.blank?
|
29
|
+
end
|
30
|
+
|
31
|
+
def hasStableIds(); has_stable_ids?; end
|
32
|
+
def has_stable_ids?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def getViewTypeCount(); view_type_count; end
|
37
|
+
def view_type_count()
|
38
|
+
1
|
39
|
+
end
|
40
|
+
|
41
|
+
def getItemViewType(position); item_view_type_id(position); end
|
42
|
+
def item_view_type_id(position)
|
43
|
+
0
|
44
|
+
end
|
45
|
+
|
46
|
+
def getCount(); count(); end
|
47
|
+
def count()
|
48
|
+
data.length
|
49
|
+
end
|
50
|
+
|
51
|
+
def getItem(position); item(position); end
|
52
|
+
def item(position)
|
53
|
+
data[position]
|
54
|
+
end
|
55
|
+
|
56
|
+
def getItemId(position); item_id(position); end
|
57
|
+
def item_id(position)
|
58
|
+
position
|
59
|
+
end
|
60
|
+
|
61
|
+
def getView(position, convert_view, parent); view(position, convert_view, parent); end
|
62
|
+
def view(position, convert_view, parent)
|
63
|
+
data = item(position)
|
64
|
+
out = convert_view || rmq.create!(data[:cell_class] || Potion::TextView)
|
65
|
+
update_view(out, data[:title])
|
66
|
+
if data[:action]
|
67
|
+
find(out).on(:tap) { find.screen.send(data[:action], data[:arguments], position) }
|
68
|
+
end
|
69
|
+
out
|
70
|
+
end
|
71
|
+
|
72
|
+
def update_view(view, data)
|
73
|
+
out.text = data
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class PMCursorAdapter < PMBaseAdapter
|
2
|
+
attr_accessor :cursor
|
3
|
+
attr_accessor :cell_options
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
super()
|
7
|
+
@cursor = opts.fetch(:cursor)
|
8
|
+
@cell_options = opts.fetch(:cell, 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def count
|
12
|
+
cursor.count
|
13
|
+
end
|
14
|
+
|
15
|
+
def item(position)
|
16
|
+
cursor.moveToPosition(position)
|
17
|
+
cursor
|
18
|
+
end
|
19
|
+
|
20
|
+
def view(position, convert_view, parent)
|
21
|
+
data = item(position)
|
22
|
+
out = convert_view || rmq.create!(cell_options[:cell_class] || Potion::TextView)
|
23
|
+
update_view(out, data)
|
24
|
+
if cell_options[:action]
|
25
|
+
find(out).on(:tap) { find.screen.send(cell_options[:action], data, position) }
|
26
|
+
end
|
27
|
+
out
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_view(out, data)
|
31
|
+
out.text = data.getString(cell_options[:title_column])
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
__END__
|
37
|
+
|
38
|
+
def table_data
|
39
|
+
{
|
40
|
+
cursor: my_cursor,
|
41
|
+
title_column: 0,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# http://hipbyte.myjetbrains.com/youtrack/issue/RM-773 - can't put this in a module yet :(
|
2
|
+
#module ProMotion
|
3
|
+
|
4
|
+
class PMListScreen < Android::App::ListFragment
|
5
|
+
include PMScreenModule
|
6
|
+
|
7
|
+
attr_accessor :view
|
8
|
+
|
9
|
+
def table_data
|
10
|
+
mp "Implement a table_data method in #{self.inspect}."
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_view
|
15
|
+
# Potion::LinearLayout.new(self.activity)
|
16
|
+
self.view = create!(Potion::ListView, :list)
|
17
|
+
# find(self.view).style do |st|
|
18
|
+
# st.layout_width = :match_parent
|
19
|
+
# st.layout_height = :match_parent
|
20
|
+
# st.layout_weight = 1
|
21
|
+
# st.view.drawSelectorOnTop = false
|
22
|
+
# end
|
23
|
+
# self.view
|
24
|
+
end
|
25
|
+
|
26
|
+
def screen_setup
|
27
|
+
add_table_view
|
28
|
+
add_empty_view
|
29
|
+
add_adapter
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_table_view
|
33
|
+
# create(Potion::ListView, :list).style do |st|
|
34
|
+
# st.layout_width = :match_parent
|
35
|
+
# st.layout_height = :match_parent
|
36
|
+
# st.layout_weight = 1
|
37
|
+
# st.view.drawSelectorOnTop = false
|
38
|
+
# end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_empty_view
|
42
|
+
# append(Potion::TextView, :empty).style do |st|
|
43
|
+
# st.layout_width = :match_parent
|
44
|
+
# st.layout_height = :match_parent
|
45
|
+
# st.background = "#FFFFFF"
|
46
|
+
# st.text = "No data"
|
47
|
+
# end
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_adapter
|
51
|
+
self.view.setAdapter(adapter)
|
52
|
+
end
|
53
|
+
|
54
|
+
def adapter
|
55
|
+
@adapter ||= begin
|
56
|
+
td = table_data
|
57
|
+
if td.is_a?(Array)
|
58
|
+
PMBaseAdapter.new(data: td)
|
59
|
+
elsif td.is_a?(Hash)
|
60
|
+
mp "Please supply a cursor in #{self.inspect}#table_data." unless td[:cursor]
|
61
|
+
PMCursorAdapter.new(td)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
### Boilerplate from PMScreen ###
|
67
|
+
|
68
|
+
def onAttach(activity)
|
69
|
+
super
|
70
|
+
activity.on_fragment_attached(self) if activity.respond_to?(:on_fragment_attached)
|
71
|
+
on_attach(activity)
|
72
|
+
end
|
73
|
+
def on_attach(activity); end
|
74
|
+
|
75
|
+
def onCreate(bundle); super; on_create(bundle); end
|
76
|
+
def on_create(bundle); end
|
77
|
+
|
78
|
+
def onCreateView(inflater, parent, saved_instance_state)
|
79
|
+
super
|
80
|
+
|
81
|
+
if @xml_resource = self.class.xml_resource
|
82
|
+
@view = inflater.inflate(r(:layout, @xml_resource), parent, false)
|
83
|
+
else
|
84
|
+
v = load_view
|
85
|
+
@view ||= v
|
86
|
+
@view.setId Potion::ViewIdGenerator.generate
|
87
|
+
end
|
88
|
+
|
89
|
+
action_bar.hide if hide_action_bar?
|
90
|
+
|
91
|
+
on_create_view(inflater, parent, saved_instance_state)
|
92
|
+
|
93
|
+
@view
|
94
|
+
end
|
95
|
+
def on_create_view(inflater, parent, saved_instance_state); end
|
96
|
+
|
97
|
+
# def load_view
|
98
|
+
# Potion::FrameLayout.new(self.activity)
|
99
|
+
# end
|
100
|
+
|
101
|
+
def onActivityCreated(saved_instance_state)
|
102
|
+
mp "PMScreen onActivityCreated" if RMQ.debugging?
|
103
|
+
|
104
|
+
super
|
105
|
+
|
106
|
+
@view.rmq_data.is_screen_root_view = true
|
107
|
+
|
108
|
+
self.rmq.build(@view)
|
109
|
+
|
110
|
+
screen_setup
|
111
|
+
|
112
|
+
if self.class.rmq_style_sheet_class
|
113
|
+
self.rmq.stylesheet = self.class.rmq_style_sheet_class
|
114
|
+
@view.rmq.apply_style(:root_view) #if @view.rmq.stylesheet.respond_to?(:root_view)
|
115
|
+
end
|
116
|
+
|
117
|
+
build_and_tag_xml_views
|
118
|
+
|
119
|
+
set_title
|
120
|
+
on_load
|
121
|
+
on_activity_created
|
122
|
+
end
|
123
|
+
def on_load; end
|
124
|
+
def on_activity_created; end
|
125
|
+
|
126
|
+
def onStart; super; on_start; end
|
127
|
+
def on_start; end
|
128
|
+
alias :on_appear :on_start
|
129
|
+
|
130
|
+
def onResume; super; on_resume; end
|
131
|
+
def on_resume; end
|
132
|
+
|
133
|
+
def on_create_menu(menu); end
|
134
|
+
|
135
|
+
def onPause; super; on_pause; end
|
136
|
+
def on_pause; end
|
137
|
+
|
138
|
+
def onStop; super; on_stop; end
|
139
|
+
def on_stop; end
|
140
|
+
|
141
|
+
def onDestroyView; super; on_destroy_view; end
|
142
|
+
def on_destroy_view; end
|
143
|
+
|
144
|
+
def onDestroy; super; on_destroy; end
|
145
|
+
def on_destroy; end
|
146
|
+
|
147
|
+
def onDetach
|
148
|
+
super
|
149
|
+
on_detach
|
150
|
+
self.activity.on_fragment_detached(self) if self.activity.respond_to?(:on_fragment_detached)
|
151
|
+
end
|
152
|
+
def on_detach; end
|
153
|
+
|
154
|
+
def set_title
|
155
|
+
self.title = self.class.bars_title
|
156
|
+
end
|
157
|
+
|
158
|
+
def title
|
159
|
+
@title
|
160
|
+
end
|
161
|
+
def title=(value)
|
162
|
+
@title = value
|
163
|
+
|
164
|
+
if a = self.activity
|
165
|
+
if a_bar = self.action_bar
|
166
|
+
a_bar.title = value
|
167
|
+
end
|
168
|
+
a.title = value
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
def build_and_tag_xml_views
|
175
|
+
return unless @xml_resource
|
176
|
+
|
177
|
+
self.rmq.all.each do |view|
|
178
|
+
if ren = view.resource_entry_name
|
179
|
+
self.rmq.build(view).tag(ren.to_sym)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def hide_action_bar?
|
185
|
+
# RM-???: comparing nil to false causes ART crash
|
186
|
+
!self.class.show_action_bar.nil? && self.class.show_action_bar == false
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
#end
|