ProMotion 1.2.1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -10
- data/lib/ProMotion.rb +11 -2
- data/lib/ProMotion/cocoatouch/ns_string.rb +5 -0
- data/lib/ProMotion/cocoatouch/ns_url.rb +5 -0
- data/lib/ProMotion/cocoatouch/tab_bar_controller.rb +5 -7
- data/lib/ProMotion/cocoatouch/table_view_cell.rb +0 -16
- data/lib/ProMotion/cocoatouch/table_view_controller.rb +2 -3
- data/lib/ProMotion/cocoatouch/view_controller.rb +3 -6
- data/lib/ProMotion/delegate/delegate.rb +0 -3
- data/lib/ProMotion/delegate/delegate_module.rb +24 -20
- data/lib/ProMotion/{containers → ipad}/split_screen.rb +30 -32
- data/lib/ProMotion/{logger.rb → logger/logger.rb} +6 -5
- data/lib/ProMotion/screen/nav_bar_module.rb +126 -0
- data/lib/ProMotion/screen/screen.rb +0 -3
- data/lib/ProMotion/screen/screen_module.rb +54 -177
- data/lib/ProMotion/screen/screen_navigation.rb +29 -40
- data/lib/ProMotion/{view → styling}/styling.rb +17 -47
- data/lib/ProMotion/table/cell/table_view_cell_module.rb +76 -123
- data/lib/ProMotion/table/data/table_data.rb +1 -1
- data/lib/ProMotion/table/extensions/longpressable.rb +24 -0
- data/lib/ProMotion/table/extensions/refreshable.rb +1 -0
- data/lib/ProMotion/table/grouped_table_screen.rb +0 -5
- data/lib/ProMotion/table/table.rb +63 -83
- data/lib/ProMotion/table/table_screen.rb +0 -4
- data/lib/ProMotion/{containers → tabs}/tabs.rb +20 -21
- data/lib/ProMotion/version.rb +1 -1
- data/lib/ProMotion/web/web_screen.rb +0 -4
- data/lib/ProMotion/web/web_screen_module.rb +8 -5
- data/spec/functional/func_screen_spec.rb +14 -18
- data/spec/functional/func_split_screen_spec.rb +2 -2
- data/spec/functional/func_table_screen_spec.rb +54 -40
- data/spec/functional/func_web_screen_spec.rb +12 -17
- data/spec/helpers/test_helper.rb +27 -0
- data/spec/unit/delegate_spec.rb +4 -67
- data/spec/unit/image_title_screen.rb +9 -0
- data/spec/unit/image_view_title_screen.rb +9 -0
- data/spec/unit/load_view_spec.rb +27 -0
- data/spec/unit/main_spec.rb +0 -6
- data/spec/unit/screen_helpers_spec.rb +23 -17
- data/spec/unit/screen_spec.rb +21 -17
- data/spec/unit/searchable_table_spec.rb +55 -0
- data/spec/unit/split_screen_in_tab_bar_spec.rb +5 -5
- data/spec/unit/split_screen_spec.rb +4 -4
- data/spec/unit/tab_bar_spec.rb +79 -0
- data/spec/unit/tab_spec.rb +11 -5
- data/spec/unit/tables/table_module_spec.rb +22 -8
- data/spec/unit/tables/table_screen_spec.rb +1 -1
- data/spec/unit/tables/table_view_cell_spec.rb +16 -16
- data/spec/unit/view_helper_spec.rb +6 -81
- data/spec/unit/view_title_screen.rb +10 -0
- data/spec/unit/web_spec.rb +31 -37
- metadata +37 -111
- data/.gitignore +0 -33
- data/.travis.yml +0 -4
- data/CONTRIBUTING.md +0 -20
- data/Gemfile +0 -5
- data/LICENSE +0 -22
- data/ProMotion.gemspec +0 -30
- data/Rakefile +0 -66
- data/app/app_delegate.rb +0 -7
- data/app/screens/basic_screen.rb +0 -15
- data/lib/ProMotion/delegate/delegate_notifications.rb +0 -70
- data/lib/ProMotion/extensions/conversions.rb +0 -20
- data/lib/ProMotion/map/map_screen.rb +0 -10
- data/lib/ProMotion/map/map_screen_annotation.rb +0 -65
- data/lib/ProMotion/map/map_screen_module.rb +0 -212
- data/lib/ProMotion/push_notification/push_notification.rb +0 -58
- data/resources/WebScreen.html +0 -6
- data/resources/list.png +0 -0
- data/resources/test.png +0 -0
- data/spec/functional/func_image_title_screen.rb +0 -20
- data/spec/functional/func_image_view_title_screen.rb +0 -20
- data/spec/functional/func_map_screen_spec.rb +0 -162
- data/spec/functional/func_searchable_table_spec.rb +0 -56
- data/spec/functional/func_tab_bar_spec.rb +0 -78
- data/spec/functional/func_view_title_screen.rb +0 -21
- data/spec/helpers/basic_screen.rb +0 -3
- data/spec/helpers/custom_title_view.rb +0 -4
- data/spec/helpers/detail_screen.rb +0 -3
- data/spec/helpers/dummy_class.rb +0 -3
- data/spec/helpers/functional_screen.rb +0 -15
- data/spec/helpers/home_screen.rb +0 -19
- data/spec/helpers/image_title_screen.rb +0 -15
- data/spec/helpers/image_view_title_screen.rb +0 -15
- data/spec/helpers/map_screen.rb +0 -53
- data/spec/helpers/master_screen.rb +0 -3
- data/spec/helpers/present_screen.rb +0 -26
- data/spec/helpers/screen_module_view_controller.rb +0 -55
- data/spec/helpers/tab_screen.rb +0 -4
- data/spec/helpers/table_screen.rb +0 -117
- data/spec/helpers/table_screen_indexable.rb +0 -18
- data/spec/helpers/table_screen_refreshable.rb +0 -11
- data/spec/helpers/table_screen_searchable.rb +0 -72
- data/spec/helpers/test_delegate.rb +0 -34
- data/spec/helpers/test_delegate_colors.rb +0 -17
- data/spec/helpers/view_title_screen.rb +0 -15
- data/spec/helpers/web_screen.rb +0 -23
- data/spec/unit/map_spec.rb +0 -71
data/.gitignore
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
|
19
|
-
/build
|
20
|
-
.repl_history
|
21
|
-
.rvmrc
|
22
|
-
.ruby-gemset
|
23
|
-
.ruby-version
|
24
|
-
.DS_Store
|
25
|
-
.dat*
|
26
|
-
.rake_tasks*
|
27
|
-
|
28
|
-
# IDE / editor files
|
29
|
-
.idea/
|
30
|
-
*.tmproj
|
31
|
-
*.tmproject
|
32
|
-
tmtags
|
33
|
-
*.sublime-workspace
|
data/.travis.yml
DELETED
data/CONTRIBUTING.md
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Over 20 developers have contributed to ProMotion. We love it when ProMotion users become ProMotion contributors.
|
2
|
-
|
3
|
-
## Working on New Features
|
4
|
-
|
5
|
-
1. Clone the repo into `<My iOS Projects Folder>/ProMotion`
|
6
|
-
2. Update your `Gemfile`to reference the project as `gem 'ProMotion', :path => "../ProMotion"`
|
7
|
-
3. Run `bundle`
|
8
|
-
4. Run `rake clean` and then `rake`
|
9
|
-
5. Contribute!
|
10
|
-
|
11
|
-
## Submitting a Pull Request
|
12
|
-
|
13
|
-
1. Fork the project
|
14
|
-
2. Create a feature branch
|
15
|
-
3. Code
|
16
|
-
4. Update or create new specs ** NOTE: your PR is far more likely to be merged if you include comprehensive tests! **
|
17
|
-
5. Make sure tests are passing by running `rake spec` *(you can run functional and unit specs separately with `rake spec:func` and `rake spec:unit`, and a single spec with `rake spec:single f=test_file_name`)*
|
18
|
-
6. Submit pull request to `edge` (for new features) or `master` (for bugfixes)
|
19
|
-
7. Make a million little nitpicky changes that @jamonholmgren wants
|
20
|
-
8. Merged, then fame, adoration, kudos everywhere
|
data/Gemfile
DELETED
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Jamon Holmgren
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/ProMotion.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/ProMotion/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Jamon Holmgren", "Silas Matson", "Mark Rickert"]
|
6
|
-
gem.email = ["jamon@clearsightstudio.com", "silas@clearsightstudio.com", "mark@mohawkapps.com"]
|
7
|
-
gem.summary = "ProMotion makes it easy to build RubyMotion iOS screen-based apps."
|
8
|
-
gem.description = "
|
9
|
-
ProMotion is a RubyMotion gem that makes iOS development more like Ruby and less like Objective-C.
|
10
|
-
It introduces a clean, Ruby-style syntax for building screens that is easy to learn and remember and
|
11
|
-
abstracts a ton of boilerplate UIViewController, UINavigationController, and other iOS code into a
|
12
|
-
simple, Ruby-like DSL.
|
13
|
-
"
|
14
|
-
gem.homepage = "https://github.com/clearsightstudio/ProMotion"
|
15
|
-
gem.license = 'MIT'
|
16
|
-
|
17
|
-
gem.files = `git ls-files`.split($\)
|
18
|
-
gem.executables << "promotion"
|
19
|
-
gem.test_files = gem.files.grep(%r{^(spec)/})
|
20
|
-
gem.name = "ProMotion"
|
21
|
-
gem.require_paths = ["lib"]
|
22
|
-
gem.version = ProMotion::VERSION
|
23
|
-
|
24
|
-
gem.add_dependency "motion-require", "~> 0.2"
|
25
|
-
gem.add_runtime_dependency("methadone", "~> 1.3")
|
26
|
-
gem.add_development_dependency("webstub", "~> 1.0")
|
27
|
-
gem.add_development_dependency("motion-stump", "~> 0.3")
|
28
|
-
gem.add_development_dependency("motion-redgreen", "~> 0.1")
|
29
|
-
gem.add_development_dependency("rake", "~> 10.1")
|
30
|
-
end
|
data/Rakefile
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
$:.unshift("/Library/RubyMotion/lib")
|
2
|
-
require 'motion/project/template/ios'
|
3
|
-
require 'bundler'
|
4
|
-
Bundler.require(:development)
|
5
|
-
require 'ProMotion'
|
6
|
-
|
7
|
-
Motion::Project::App.setup do |app|
|
8
|
-
app.name = 'ProMotionTest'
|
9
|
-
app.version = "0.99.0"
|
10
|
-
app.redgreen_style = :full # :focused, :full
|
11
|
-
app.frameworks += %w(CoreLocation MapKit)
|
12
|
-
|
13
|
-
# Devices
|
14
|
-
app.deployment_target = "6.0"
|
15
|
-
app.device_family = [:ipad] # so we can test split screen capability
|
16
|
-
end
|
17
|
-
|
18
|
-
def all_files
|
19
|
-
App.config.spec_files
|
20
|
-
end
|
21
|
-
|
22
|
-
def functional_files
|
23
|
-
Dir.glob('./spec/functional/**/*.rb')
|
24
|
-
end
|
25
|
-
|
26
|
-
def unit_files
|
27
|
-
Dir.glob('./spec/unit/**/*.rb')
|
28
|
-
end
|
29
|
-
|
30
|
-
namespace :spec do
|
31
|
-
task :unit do
|
32
|
-
App.config.spec_mode = true
|
33
|
-
spec_files = all_files
|
34
|
-
spec_files -= functional_files
|
35
|
-
App.config.instance_variable_set("@spec_files", spec_files)
|
36
|
-
Rake::Task["simulator"].invoke
|
37
|
-
end
|
38
|
-
|
39
|
-
task :func do
|
40
|
-
Rake::Task["spec:functional"].invoke
|
41
|
-
end
|
42
|
-
|
43
|
-
task :functional do
|
44
|
-
App.config.spec_mode = true
|
45
|
-
spec_files = all_files
|
46
|
-
spec_files -= unit_files
|
47
|
-
App.config.instance_variable_set("@spec_files", spec_files)
|
48
|
-
Rake::Task["simulator"].invoke
|
49
|
-
end
|
50
|
-
|
51
|
-
task :single do
|
52
|
-
App.config.spec_mode = true
|
53
|
-
spec_files = App.config.spec_files
|
54
|
-
spec_files -= unit_files
|
55
|
-
spec_files -= functional_files
|
56
|
-
spec_files += Dir.glob("./spec/unit/**/#{ENV['f'] || ENV['file']}.rb")
|
57
|
-
spec_files += Dir.glob("./spec/functional/**/#{ENV['f'] || ENV['file']}.rb")
|
58
|
-
App.config.instance_variable_set("@spec_files", spec_files)
|
59
|
-
Rake::Task["simulator"].invoke
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
task :sim_close do
|
65
|
-
sh "osascript -e 'tell application \"iphone simulator\" to quit'"
|
66
|
-
end
|
data/app/app_delegate.rb
DELETED
data/app/screens/basic_screen.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class BasicScreen < PM::Screen
|
2
|
-
title "Basic"
|
3
|
-
|
4
|
-
attr_reader :animation_ts
|
5
|
-
|
6
|
-
def will_appear
|
7
|
-
@will_appear_ts = NSDate.date
|
8
|
-
end
|
9
|
-
|
10
|
-
def on_appear
|
11
|
-
@on_appear_ts = NSDate.date
|
12
|
-
@animation_ts = @on_appear_ts - @will_appear_ts
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module ProMotion
|
2
|
-
module DelegateNotifications
|
3
|
-
|
4
|
-
attr_accessor :aps_notification
|
5
|
-
|
6
|
-
def check_for_push_notification(options)
|
7
|
-
if options && options[UIApplicationLaunchOptionsRemoteNotificationKey]
|
8
|
-
received_push_notification options[UIApplicationLaunchOptionsRemoteNotificationKey], true
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def register_for_push_notifications(*notification_types)
|
13
|
-
notification_types = Array.new(notification_types)
|
14
|
-
notification_types = [ :badge, :sound, :alert, :newsstand ] if notification_types.include?(:all)
|
15
|
-
|
16
|
-
types = UIRemoteNotificationTypeNone
|
17
|
-
notification_types.each { |t| types = types | map_notification_symbol(t) }
|
18
|
-
|
19
|
-
UIApplication.sharedApplication.registerForRemoteNotificationTypes types
|
20
|
-
end
|
21
|
-
|
22
|
-
def unregister_for_push_notifications
|
23
|
-
UIApplication.sharedApplication.unregisterForRemoteNotifications
|
24
|
-
end
|
25
|
-
|
26
|
-
def registered_push_notifications
|
27
|
-
mask = UIApplication.sharedApplication.enabledRemoteNotificationTypes
|
28
|
-
types = []
|
29
|
-
|
30
|
-
types << :badge if mask & UIRemoteNotificationTypeBadge > 0
|
31
|
-
types << :sound if mask & UIRemoteNotificationTypeSound > 0
|
32
|
-
types << :alert if mask & UIRemoteNotificationTypeAlert > 0
|
33
|
-
types << :newsstand if mask & UIRemoteNotificationTypeNewsstandContentAvailability > 0
|
34
|
-
|
35
|
-
types
|
36
|
-
end
|
37
|
-
|
38
|
-
def received_push_notification(notification, was_launched)
|
39
|
-
@aps_notification = PM::PushNotification.new(notification)
|
40
|
-
on_push_notification(@aps_notification, was_launched) if respond_to?(:on_push_notification)
|
41
|
-
end
|
42
|
-
|
43
|
-
# CocoaTouch
|
44
|
-
|
45
|
-
def application(application, didRegisterForRemoteNotificationsWithDeviceToken:device_token)
|
46
|
-
on_push_registration(device_token, nil) if respond_to?(:on_push_registration)
|
47
|
-
end
|
48
|
-
|
49
|
-
def application(application, didFailToRegisterForRemoteNotificationsWithError:error)
|
50
|
-
on_push_registration(nil, error) if respond_to?(:on_push_registration)
|
51
|
-
end
|
52
|
-
|
53
|
-
def application(application, didReceiveRemoteNotification:notification)
|
54
|
-
received_push_notification(notification, application.applicationState != UIApplicationStateActive)
|
55
|
-
end
|
56
|
-
|
57
|
-
protected
|
58
|
-
|
59
|
-
def map_notification_symbol(symbol)
|
60
|
-
{
|
61
|
-
none: UIRemoteNotificationTypeNone,
|
62
|
-
badge: UIRemoteNotificationTypeBadge,
|
63
|
-
sound: UIRemoteNotificationTypeSound,
|
64
|
-
alert: UIRemoteNotificationTypeAlert,
|
65
|
-
newsstand: UIRemoteNotificationTypeNewsstandContentAvailability
|
66
|
-
}[symbol] || UIRemoteNotificationTypeNone
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ProMotion
|
2
|
-
module Conversions
|
3
|
-
|
4
|
-
# For converting, for example, from :contacts to UITabBarSystemItemContacts
|
5
|
-
# Unfortunately, this only works if the symbol is defined in your code.
|
6
|
-
# So, for now, we'll have to do it manually.
|
7
|
-
def convert_symbol(symbol, prefix)
|
8
|
-
Object.const_get("#{prefix}#{camel_case symbol}")
|
9
|
-
end
|
10
|
-
|
11
|
-
def objective_c_method_name(str)
|
12
|
-
str.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
|
13
|
-
end
|
14
|
-
|
15
|
-
def camel_case(str)
|
16
|
-
str.split('_').map(&:capitalize).join
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
motion_require '../cocoatouch/view_controller'
|
2
|
-
motion_require '../screen/screen_module'
|
3
|
-
motion_require 'map_screen_module'
|
4
|
-
|
5
|
-
module ProMotion
|
6
|
-
class MapScreen < ViewController
|
7
|
-
include ProMotion::ScreenModule
|
8
|
-
include ProMotion::MapScreenModule
|
9
|
-
end
|
10
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module ProMotion
|
2
|
-
class MapScreenAnnotation
|
3
|
-
|
4
|
-
#Creates the new crime object
|
5
|
-
def initialize(params = {})
|
6
|
-
@params = params
|
7
|
-
set_defaults
|
8
|
-
|
9
|
-
unless @params[:latitude] && @params[:longitude]
|
10
|
-
PM.logger.error("You are required to specify :latitude and :longitude for annotations.")
|
11
|
-
return nil
|
12
|
-
end
|
13
|
-
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
14
|
-
end
|
15
|
-
|
16
|
-
def set_defaults
|
17
|
-
@params = {
|
18
|
-
title: "Title",
|
19
|
-
pin_color: MKPinAnnotationColorRed,
|
20
|
-
identifier: "Annotation-#{@params[:pin_color] || @params[:image]}",
|
21
|
-
show_callout: true,
|
22
|
-
animates_drop: false
|
23
|
-
}.merge(@params)
|
24
|
-
end
|
25
|
-
|
26
|
-
def title
|
27
|
-
@params[:title]
|
28
|
-
end
|
29
|
-
|
30
|
-
def subtitle
|
31
|
-
@params[:subtitle] ||= nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def coordinate
|
35
|
-
@coordinate
|
36
|
-
end
|
37
|
-
|
38
|
-
def cllocation
|
39
|
-
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
|
40
|
-
end
|
41
|
-
|
42
|
-
def setCoordinate(new_coordinate);
|
43
|
-
if new_coordinate.is_a? Hash
|
44
|
-
@coordinate = CLLocationCoordinate2D.new(new_coordinate[:latitude], new_coordinate[:longitude])
|
45
|
-
else
|
46
|
-
@coordinate = new_coordinate
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Allows for retrieving your own custom values on the annotation
|
51
|
-
def annotation_params
|
52
|
-
@params
|
53
|
-
end
|
54
|
-
|
55
|
-
def method_missing(meth, *args)
|
56
|
-
if @params[meth.to_sym]
|
57
|
-
@params[meth.to_sym]
|
58
|
-
else
|
59
|
-
PM.logger.warn "The annotation parameter \"#{meth}\" does not exist on this pin."
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
@@ -1,212 +0,0 @@
|
|
1
|
-
module ProMotion
|
2
|
-
module MapScreenModule
|
3
|
-
attr_accessor :mapview
|
4
|
-
|
5
|
-
def screen_setup
|
6
|
-
check_mapkit_included
|
7
|
-
self.mapview ||= add MKMapView.new, {
|
8
|
-
frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height),
|
9
|
-
resize: [ :width, :height ],
|
10
|
-
delegate: self
|
11
|
-
}
|
12
|
-
|
13
|
-
check_annotation_data
|
14
|
-
@promotion_annotation_data = []
|
15
|
-
set_up_start_position
|
16
|
-
end
|
17
|
-
|
18
|
-
def view_will_appear(animated)
|
19
|
-
super
|
20
|
-
update_annotation_data
|
21
|
-
end
|
22
|
-
|
23
|
-
def check_mapkit_included
|
24
|
-
PM.logger.error "You must add MapKit and CoreLocation to your project's frameworks in the Rakefile." unless defined?(CLLocationCoordinate2D)
|
25
|
-
end
|
26
|
-
|
27
|
-
def check_annotation_data
|
28
|
-
PM.logger.error "Missing #annotation_data method in MapScreen #{self.class.to_s}." unless self.respond_to?(:annotation_data)
|
29
|
-
end
|
30
|
-
|
31
|
-
def update_annotation_data
|
32
|
-
clear_annotations
|
33
|
-
add_annotations annotation_data
|
34
|
-
end
|
35
|
-
|
36
|
-
def map
|
37
|
-
self.mapview
|
38
|
-
end
|
39
|
-
|
40
|
-
def center
|
41
|
-
self.mapview.centerCoordinate
|
42
|
-
end
|
43
|
-
|
44
|
-
def center=(params={})
|
45
|
-
PM.logger.error "Missing #:latitude property in call to #center=." unless params[:latitude]
|
46
|
-
PM.logger.error "Missing #:longitude property in call to #center=." unless params[:longitude]
|
47
|
-
params[:animated] = true
|
48
|
-
|
49
|
-
# Set the new region
|
50
|
-
self.mapview.setCenterCoordinate(
|
51
|
-
CLLocationCoordinate2D.new(params[:latitude], params[:longitude]),
|
52
|
-
animated:params[:animated]
|
53
|
-
)
|
54
|
-
end
|
55
|
-
|
56
|
-
def annotations
|
57
|
-
@promotion_annotation_data
|
58
|
-
end
|
59
|
-
|
60
|
-
def select_annotation(annotation, animated=true)
|
61
|
-
self.mapview.selectAnnotation(annotation, animated:animated)
|
62
|
-
end
|
63
|
-
|
64
|
-
def select_annotation_at(annotation_index, animated=true)
|
65
|
-
select_annotation(annotations[annotation_index], animated:animated)
|
66
|
-
end
|
67
|
-
|
68
|
-
def selected_annotations
|
69
|
-
self.mapview.selectedAnnotations
|
70
|
-
end
|
71
|
-
|
72
|
-
def deselect_annotations(animated=false)
|
73
|
-
unless selected_annotations.nil?
|
74
|
-
selected_annotations.each do |annotation|
|
75
|
-
self.mapview.deselectAnnotation(annotation, animated:animated)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def add_annotation(annotation)
|
81
|
-
@promotion_annotation_data << MapScreenAnnotation.new(annotation)
|
82
|
-
self.mapview.addAnnotation @promotion_annotation_data.last
|
83
|
-
end
|
84
|
-
|
85
|
-
def add_annotations(annotations)
|
86
|
-
@promotion_annotation_data = Array(annotations).map{|a| MapScreenAnnotation.new(a)}
|
87
|
-
self.mapview.addAnnotations @promotion_annotation_data
|
88
|
-
end
|
89
|
-
|
90
|
-
def clear_annotations
|
91
|
-
@promotion_annotation_data.each do |a|
|
92
|
-
self.mapview.removeAnnotation(a)
|
93
|
-
end
|
94
|
-
@promotion_annotation_data = []
|
95
|
-
end
|
96
|
-
|
97
|
-
def mapView(mapView, viewForAnnotation:annotation)
|
98
|
-
identifier = annotation.annotation_params[:identifier]
|
99
|
-
if view = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
|
100
|
-
view.annotation = annotation
|
101
|
-
else
|
102
|
-
#Set the pin properties
|
103
|
-
if annotation.annotation_params[:image]
|
104
|
-
view = MKAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier:identifier)
|
105
|
-
view.image = annotation.annotation_params[:image]
|
106
|
-
else
|
107
|
-
view = MKPinAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier:identifier)
|
108
|
-
view.animatesDrop = annotation.annotation_params[:animates_drop]
|
109
|
-
view.pinColor = annotation.annotation_params[:pin_color]
|
110
|
-
end
|
111
|
-
view.canShowCallout = annotation.annotation_params[:show_callout]
|
112
|
-
end
|
113
|
-
view
|
114
|
-
end
|
115
|
-
|
116
|
-
def set_start_position(params={})
|
117
|
-
params[:latitude] ||= 37.331789
|
118
|
-
params[:longitude] ||= -122.029620
|
119
|
-
params[:radius] ||= 10
|
120
|
-
|
121
|
-
meters_per_mile = 1609.344
|
122
|
-
|
123
|
-
initialLocation = CLLocationCoordinate2D.new(params[:latitude], params[:longitude])
|
124
|
-
region = MKCoordinateRegionMakeWithDistance(initialLocation, params[:radius] * meters_per_mile, params[:radius] * meters_per_mile)
|
125
|
-
self.mapview.setRegion(region, animated:false)
|
126
|
-
end
|
127
|
-
|
128
|
-
def set_up_start_position
|
129
|
-
if self.class.respond_to?(:get_start_position) && self.class.get_start_position
|
130
|
-
self.set_start_position self.class.get_start_position_params
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# TODO: Why is this so complex?
|
135
|
-
def zoom_to_fit_annotations(animated=true)
|
136
|
-
#Don't attempt the rezoom of there are no pins
|
137
|
-
return if annotations.count == 0
|
138
|
-
|
139
|
-
#Set some crazy boundaries
|
140
|
-
topLeft = CLLocationCoordinate2D.new(-90, 180)
|
141
|
-
bottomRight = CLLocationCoordinate2D.new(90, -180)
|
142
|
-
|
143
|
-
#Find the bounds of the pins
|
144
|
-
annotations.each do |a|
|
145
|
-
topLeft.longitude = [topLeft.longitude, a.coordinate.longitude].min
|
146
|
-
topLeft.latitude = [topLeft.latitude, a.coordinate.latitude].max
|
147
|
-
bottomRight.longitude = [bottomRight.longitude, a.coordinate.longitude].max
|
148
|
-
bottomRight.latitude = [bottomRight.latitude, a.coordinate.latitude].min
|
149
|
-
end
|
150
|
-
|
151
|
-
#Find the bounds of all the pins and set the mapView
|
152
|
-
coord = CLLocationCoordinate2D.new(
|
153
|
-
topLeft.latitude - (topLeft.latitude - bottomRight.latitude) * 0.5,
|
154
|
-
topLeft.longitude + (bottomRight.longitude - topLeft.longitude) * 0.5
|
155
|
-
)
|
156
|
-
|
157
|
-
# Add some padding to the edges
|
158
|
-
span = MKCoordinateSpanMake(
|
159
|
-
((topLeft.latitude - bottomRight.latitude) * 1.075).abs,
|
160
|
-
((bottomRight.longitude - topLeft.longitude) * 1.075).abs
|
161
|
-
)
|
162
|
-
|
163
|
-
region = MKCoordinateRegionMake(coord, span)
|
164
|
-
fits = self.mapview.regionThatFits(region);
|
165
|
-
|
166
|
-
self.mapview.setRegion(fits, animated:animated)
|
167
|
-
end
|
168
|
-
|
169
|
-
def set_region(region, animated=true)
|
170
|
-
self.mapview.setRegion(region, animated:animated)
|
171
|
-
end
|
172
|
-
|
173
|
-
def region(params)
|
174
|
-
return nil unless params.is_a? Hash
|
175
|
-
|
176
|
-
params[:coordinate] = CLLocationCoordinate2D.new(params[:coordinate][:latitude], params[:coordinate][:longitude]) if params[:coordinate].is_a? Hash
|
177
|
-
params[:span] = MKCoordinateSpanMake(params[:span][0], params[:span][1]) if params[:span].is_a? Array
|
178
|
-
|
179
|
-
if params[:coordinate] && params[:span]
|
180
|
-
MKCoordinateRegionMake( params[:coordinate], params[:span] )
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def look_up_address(args={}, &callback)
|
185
|
-
args[:address] = args if args.is_a? String # Assume if a string is passed that they want an address
|
186
|
-
|
187
|
-
geocoder = CLGeocoder.new
|
188
|
-
return geocoder.geocodeAddressDictionary(args[:address], completionHandler: callback) if args[:address].is_a?(Hash)
|
189
|
-
return geocoder.geocodeAddressString(args[:address].to_s, completionHandler: callback) unless args[:region]
|
190
|
-
return geocoder.geocodeAddressString(args[:address].to_s, inRegion:args[:region].to_s, completionHandler: callback) if args[:region]
|
191
|
-
end
|
192
|
-
|
193
|
-
module MapClassMethods
|
194
|
-
def start_position(params={})
|
195
|
-
@start_position_params = params
|
196
|
-
@start_position = true
|
197
|
-
end
|
198
|
-
|
199
|
-
def get_start_position_params
|
200
|
-
@start_position_params ||= nil
|
201
|
-
end
|
202
|
-
|
203
|
-
def get_start_position
|
204
|
-
@start_position ||= false
|
205
|
-
end
|
206
|
-
end
|
207
|
-
def self.included(base)
|
208
|
-
base.extend(MapClassMethods)
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|
212
|
-
end
|