motion-launchimages 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a011eb95f543bac37beccf3bf70cf10c5668df0
4
+ data.tar.gz: efabfc1d2b75fd98d9535021240052d2cd89ca24
5
+ SHA512:
6
+ metadata.gz: f571a451be42262a1bb6319095b20d958fab480965caa97fa41e909be84780d1f1573e3acb234cfe9fe0d5f4f14d6adf9c5b02db02bc0ab4743cb0ea7c3e3f4a
7
+ data.tar.gz: dbc5e4804244f82e52afad693b8a738d67d363c4bd878fcd79a65590feca913b155de8befc2ea12eacd6bd84d4550274192e46c9760c53eab7bdd7d14dddaabf
@@ -0,0 +1,52 @@
1
+ # motion-launchimages
2
+
3
+ Automate taking your iPhone and/or iPad launch images (i.e. `Default-568h@2x.png`) with `rake launchimages`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'motion-launchimages'
10
+
11
+ And then execute:
12
+
13
+ bundle
14
+
15
+ ## Usage
16
+
17
+ After your app has launched, let motion-launchimages know to take the screenshots:
18
+
19
+ ```ruby
20
+ class AppDelegate
21
+
22
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
23
+ # ...
24
+
25
+ Motion::LaunchImages.take!
26
+ true
27
+ end
28
+ end
29
+ ```
30
+
31
+ This method does nothing if it's not taking screenshots, so it's safe to leave in your code.
32
+
33
+ If you need to do some processing to get your app ready for the screenshot, you can use `Motion::LaunchImages.taking?` to check whether the app is being screenshoted. For example, if you have a table in your main view, you might want to empty it out like this:
34
+
35
+ ```ruby
36
+ class MainViewController
37
+ def tableView(table, numberOfRowsInSection:section)
38
+ return 0 if Motion::LaunchImages.taking?
39
+ # ...
40
+ end
41
+ end
42
+ ```
43
+
44
+ ## Running
45
+
46
+ Just run `rake launchimages`! The task will launch your app in the simulator several times with different screen sizes and save the screenshots in your resources directory with the correct names. It detects whether it's being run on an iPhone or iPad (or both) app and only takes the screenshots it needs to.
47
+
48
+ If you want to just take the screenshot at one resolution, you can run `rake take_launchimages=true device_name="iPhone 6 Plus"` (for example). Any of the iPhone or iPad devices should work. You can get a full list of what's available by opening the simulator, going to the `Hardware` menu and looking under `Device`.
49
+
50
+ ## Contact
51
+
52
+ [Brendan J. Caffrey](http://brendan.jcaffrey.com/)
@@ -0,0 +1,37 @@
1
+ require 'open3'
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise 'This file must be required within a RubyMotion project Rakefile.'
5
+ end
6
+
7
+ Motion::Project::App.setup do |app|
8
+ Dir.glob(File.join(File.dirname(__FILE__), 'motion/*.rb')).each do |file|
9
+ app.files.unshift(file)
10
+
11
+ if ENV.has_key?('take_launchimages')
12
+ app.info_plist['screenshot_path'] = Dir.pwd + '/resources/'
13
+ end
14
+ end
15
+ end
16
+
17
+ desc 'Take launch images of your app at all display resolutions'
18
+ task :launchimages do
19
+ devices = []
20
+ family = Motion::Project::App.config.device_family
21
+ family = [family] if family.is_a?(Symbol)
22
+
23
+ if family.index(:iphone) != nil
24
+ devices << 'iPhone 4s' << 'iPhone 5s' << 'iPhone 6' << 'iPhone 6 Plus'
25
+ end
26
+
27
+ if family.index(:ipad) != nil
28
+ devices << 'iPad 2' << 'iPad Air'
29
+ end
30
+
31
+ devices.each do |device|
32
+ puts "Taking screenshot on #{device}"
33
+ Open3.popen3({'take_launchimages' => 'true', 'device_name' => device}, 'rake') do |i, o, e, s|
34
+ o.read
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,125 @@
1
+ module Motion
2
+ class LaunchImages
3
+ def self.screenshot_path
4
+ NSBundle.mainBundle.objectForInfoDictionaryKey('screenshot_path')
5
+ end
6
+
7
+ def self.taking?
8
+ screenshot_path != nil
9
+ end
10
+
11
+ def self.take!(orientation = :portrait)
12
+ return unless taking?
13
+
14
+ Dispatch::Queue.main.async do
15
+ if needs_rotation?(orientation)
16
+ rotate(orientation)
17
+ sleep 1.0
18
+ end
19
+
20
+ Dispatch::Queue.main.async { capture! }
21
+ end
22
+ end
23
+
24
+ def self.capture!
25
+ screen = UIScreen.mainScreen
26
+ height = screen.bounds.size.height
27
+ scale = begin
28
+ if !screen.respondsToSelector('displayLinkWithTarget:selector:')
29
+ ''
30
+ elsif screen.scale == 1.0
31
+ ''
32
+ elsif screen.scale == 2.0
33
+ '@2x'
34
+ elsif screen.scale == 3.0
35
+ '@3x'
36
+ else
37
+ puts 'Error: Unable to determine screen scale'
38
+ exit
39
+ end
40
+ end
41
+ filename = generate_filename(height, scale)
42
+
43
+ if scale != ''
44
+ UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, screen.scale)
45
+ else
46
+ UIGraphicsBeginImageContext(window.bounds.size)
47
+ end
48
+
49
+ window.layer.renderInContext(UIGraphicsGetCurrentContext())
50
+ image = UIGraphicsGetImageFromCurrentImageContext()
51
+ UIGraphicsEndImageContext()
52
+ data = UIImagePNGRepresentation(image)
53
+ data.writeToFile(filename, atomically:true)
54
+ puts "Wrote to #{filename}"
55
+
56
+ if should_rotate_and_take_again?(height)
57
+ take!(:landscape)
58
+ else
59
+ exit
60
+ end
61
+ end
62
+
63
+ def self.generate_filename(height, scale)
64
+ filename = screenshot_path + 'Default'
65
+
66
+ case height
67
+ when 480 # iPhone 4s
68
+ when 568 # iPhone 5s
69
+ filename << '-568h'
70
+ when 667 # iPhone 6
71
+ filename << '-667h'
72
+ when 736 # iPhone 6 Plus
73
+ filename << '-736h'
74
+ when 768 # iPad (Landscape)
75
+ filename << '-Landscape'
76
+ when 1024 # iPad (Portrait)
77
+ filename << '-Portrait'
78
+ else
79
+ puts "Error: Invalid screen height #{height}"
80
+ exit
81
+ end
82
+
83
+ filename << scale << '.png'
84
+ end
85
+
86
+ # ported from BubbleWrap to reduce dependencies
87
+ def self.window
88
+ normal_windows = UIApplication.sharedApplication.windows.select { |w|
89
+ w.windowLevel == UIWindowLevelNormal
90
+ }
91
+
92
+ key_window = normal_windows.select { |w|
93
+ w == UIApplication.sharedApplication.keyWindow
94
+ }.first
95
+
96
+ key_window || normal_windows.first
97
+ end
98
+
99
+ def self.should_rotate_and_take_again?(height)
100
+ height == 1024 # iPad (Portrait)
101
+ end
102
+
103
+ def self.rotate(to)
104
+ if to == :portrait
105
+ value = NSNumber.numberWithInt(UIInterfaceOrientationPortrait)
106
+ else
107
+ value = NSNumber.numberWithInt(UIInterfaceOrientationLandscapeLeft)
108
+ end
109
+
110
+ UIDevice.currentDevice.setValue(value, forKey:'orientation')
111
+ end
112
+
113
+ def self.needs_rotation?(orientation)
114
+ status = UIApplication.sharedApplication.statusBarOrientation
115
+ if orientation == :portrait && status == UIInterfaceOrientationPortrait
116
+ false
117
+ elsif orientation == :landscape && (status == UIInterfaceOrientationLandscapeLeft ||
118
+ status == UIInterfaceOrientationLandscapeRight)
119
+ false
120
+ else
121
+ true
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'motion-launchimages'
3
+ s.version = '1.0.0'
4
+ s.summary = 'Automate RubyMotion launch images'
5
+ s.description = 'Automate RubyMotion launch images'
6
+ s.homepage = 'https://github.com/brendanjcaffrey/motion-launchimages'
7
+ s.authors = ['Brendan J. Caffrey']
8
+ s.email = ['brendan@jcaffrey.com']
9
+ s.license = 'MIT'
10
+
11
+ files = ['README.md', 'motion-launchimages.gemspec']
12
+ files.concat(Dir.glob('lib/**/*.rb'))
13
+ s.files = files
14
+ s.require_paths = ['lib']
15
+ s.add_development_dependency 'rake'
16
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-launchimages
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brendan J. Caffrey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Automate RubyMotion launch images
28
+ email:
29
+ - brendan@jcaffrey.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/motion-launchimages.rb
36
+ - lib/motion/launch_images.rb
37
+ - motion-launchimages.gemspec
38
+ homepage: https://github.com/brendanjcaffrey/motion-launchimages
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.5
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Automate RubyMotion launch images
62
+ test_files: []