motion-gyro-image-controller 1.0 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmY3ZGM0NDAzNTVkMzIwOGZkZGU1ZDhlMTU4OGFkODk5YTY5ODUyNQ==
4
+ NmZlYjNkYTJmODY5MGVkNTQwMjE3YTk4MDVlMTMzMTExN2EwZWNlYw==
5
5
  data.tar.gz: !binary |-
6
- YTI5OGNjZjlhNTMzOGY4ODE5ZWQ4NTVkMzdjZjdlNDI4NzVlZDMwZg==
6
+ NzlhOTFhNTc3NjE1ZGY1MGQwMWJkZjQ5YjcwMjYxZGE2NTBjNzhhNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2ViMTBiYzFjM2VjMzc3OGI1MzlmNzg0ODM2N2FjZDU5N2VhODA0YjQwODA2
10
- OWM5YmVjN2Y2ZGY2NmE5NzQyMWQ2N2JiNGZhMjQ2OTliZjk2MDBjNTJlMDM5
11
- MzQzZWY0NTI4Y2UyYjQyNDNkMDU4ZGE1NTEzODlmYmU2ZmNlMGQ=
9
+ Njc5NjBkZWYzNWZjZTU0ZDEwNTE3ZmQ0ZjRjOTNhYWRhZDBiOWQ2ZTFkNWVl
10
+ ZWU4Nzk0ZDYwZDAyMjYwY2MxZTQyNmFlMjdhMzlhMmI4YmNhMmM2NmNlYTg0
11
+ YWYyOGU2MDI5ZTlhMGFjOGFiODY1OTQ0NzI0ODE3OTNhZDczOWI=
12
12
  data.tar.gz: !binary |-
13
- ZmUxOGUwMzE4ODlhYmMzODViYTUzOTE4YWFhODg0N2UzOWIzNjNhZGI2ZTAw
14
- YWQyYTRiZDBlNzExZTQ5MTg1ODQwYTlkZDdhM2VjMWYwYzFhMWRmNmIyZGFm
15
- YWIwNDQ1MzQ2NmVkMzYzYTIyNjMyMDBmYzhjMGQ4YmMzMDc3MzM=
13
+ NzlkM2VjNzIxZGYzNjNiNmI1ZWExNTVmMTE4MGM2ZTY4NjkxMDBjMzE4MzIy
14
+ Y2Y3OTQ0NjAzMDRjOTAyMjM1Njc2ODhlYTI3YTg2NjliZWVlMDU5MDc1MTUy
15
+ YmU5MGEzNjEwMWU0NjRlYTY4OTY2ZmJlYTUyNjAxMTY5NjYwMGY=
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor/
19
+ build/
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in motion-gyro-image-controller.gemspec
4
- gemspec
3
+ gem 'rake'
4
+ # Add your dependencies here:
5
+ gem 'bubble-wrap'
6
+ gem 'afmotion'
7
+ gem 'alerter'
8
+ gem 'motion-gyro-image-controller'
9
+ gem 'motion-facon'
data/Rakefile CHANGED
@@ -1 +1,16 @@
1
- require "bundler/gem_tasks"
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project/template/ios'
4
+
5
+ begin
6
+ require 'bundler'
7
+ Bundler.require
8
+ rescue LoadError
9
+ end
10
+
11
+ Motion::Project::App.setup do |app|
12
+ # Use `rake config' to see complete project settings.
13
+ app.name = 'gyro_gallery_sample_app'
14
+ app.interface_orientations = [:portrait]
15
+ app.frameworks << "CoreMotion"
16
+ end
Binary file
@@ -0,0 +1,10 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
4
+ @window.makeKeyAndVisible
5
+ @window.rootViewController = PagedImageController.alloc.initWithTransitionStyle(UIPageViewControllerTransitionStyleScroll, navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal, options: {
6
+ "UIPageViewControllerOptionInterPageSpacingKey" => 5.0
7
+ })
8
+ true
9
+ end
10
+ end
@@ -0,0 +1,73 @@
1
+ class PagedImageController < UIPageViewController
2
+ attr_accessor :items_list, :index
3
+
4
+ def viewDidLoad
5
+ super
6
+ set_page_controller_attributes
7
+ set_up_sample_data
8
+ self.index = 0
9
+ @image_controller = set_up_image_controller
10
+ self.setViewControllers([@image_controller], direction: UIPageViewControllerNavigationDirectionForward, animated: true, completion: nil)
11
+ end
12
+
13
+ def set_page_controller_attributes
14
+ self.dataSource = self
15
+ self.delegate = self
16
+ self.doubleSided = false
17
+ end
18
+
19
+ def set_up_sample_data
20
+ self.items_list = []
21
+ 5.times do |n|
22
+ self.items_list << "http://lorempixel.com/620/568/transport/#{n}"
23
+ end
24
+ end
25
+
26
+ def pageViewController(page_view_controller, viewControllerBeforeViewController: view_controller)
27
+ self.index = view_controller.index - 1
28
+ if self.index < 0
29
+ self.index = 0
30
+ return nil
31
+ end
32
+ @prev_image_controller = set_up_image_controller
33
+ end
34
+
35
+ def pageViewController(page_view_controller, viewControllerAfterViewController: view_controller)
36
+ self.index = view_controller.index + 1
37
+ if self.index >= self.items_list.count
38
+ self.index = self.items_list.count - 1
39
+ return nil
40
+ end
41
+ @next_image_controller = set_up_image_controller
42
+ end
43
+
44
+ def set_up_image_controller
45
+ image_controller = GyroDrivenImageViewController.new
46
+ screen_size = get_screen_size
47
+ image_controller.set_up_view(20, 20, screen_size.width - 40, screen_size.height - 40)
48
+ set_control_variables image_controller
49
+ image_controller.index = self.index
50
+ set_image_with_url image_controller, self.items_list[self.index], "placeholder.jpeg"
51
+ image_controller
52
+ end
53
+
54
+ def set_control_variables image_controller
55
+ image_controller.update_interval = 1.0/120.0
56
+ image_controller.motion_rate = 3.1415926/180.0
57
+ image_controller.shake_threshold = 0.1
58
+ end
59
+
60
+ def set_image_with_url controller, image_url, placeholder
61
+ image_view = UIImageView.alloc.initWithFrame(CGRectZero)
62
+ completed_block = Proc.new do |request, response, image|
63
+ controller.set_image image
64
+ end
65
+ placeholder = UIImage.imageNamed placeholder
66
+ controller.set_image placeholder
67
+ image_view.setImageWithURLRequest(NSURLRequest.requestWithURL(NSURL.URLWithString(image_url)), placeholderImage: placeholder, success: completed_block, failure: nil)
68
+ end
69
+
70
+ def get_screen_size
71
+ UIScreen.mainScreen.bounds.size
72
+ end
73
+ end
@@ -1,7 +1,9 @@
1
1
  class ScrollingImageViewController < UIViewController
2
- attr_accessor :index, :width, :height
2
+ attr_accessor :index, :x, :y, :width, :height
3
3
 
4
- def set_up_view(width, height)
4
+ def set_up_view(x, y, width, height)
5
+ self.x = x
6
+ self.y = y
5
7
  self.width = width
6
8
  self.height = height
7
9
  @scroll_view = set_up_scroll_view
@@ -11,7 +13,7 @@ class ScrollingImageViewController < UIViewController
11
13
  end
12
14
 
13
15
  def set_up_scroll_view
14
- scroll_view = UIScrollView.alloc.initWithFrame(CGRectMake(0, 0, self.width, self.height))
16
+ scroll_view = UIScrollView.alloc.initWithFrame(CGRectMake(self.x, self.y, self.width, self.height))
15
17
  scroll_view.showsHorizontalScrollIndicator = false
16
18
  scroll_view.showsVerticalScrollIndicator = false
17
19
  scroll_view.delegate = self
@@ -31,9 +33,9 @@ class ScrollingImageViewController < UIViewController
31
33
  end
32
34
 
33
35
  def fit_image_to_height
34
- final_height = self.view.size.height
36
+ final_height = self.height
35
37
  final_width = (@image_view.image.size.width / @image_view.image.size.height) * final_height
36
- scroll_offset = (final_width - self.width) / 2
38
+ scroll_offset = ((final_width - self.width) / 2).abs
37
39
  @image_view.frame = CGRectMake(0, 0, final_width, final_height)
38
40
  @scroll_view.contentSize = CGSizeMake(final_width, final_height)
39
41
  @scroll_view.setContentOffset(CGPointMake(scroll_offset, 0), animated: false)
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "motion-gyro-image-controller"
7
- spec.version = "1.0"
7
+ spec.version = "1.1"
8
8
  spec.authors = ["Multunus"]
9
9
  spec.email = ["info@multunus.com"]
10
10
  spec.summary = %q{A controller that lets you control images using gyro}
Binary file
@@ -0,0 +1,9 @@
1
+ describe "Application 'gyro_gallery_sample_app'" do
2
+ before do
3
+ @app = UIApplication.sharedApplication
4
+ end
5
+
6
+ it "has one window" do
7
+ @app.windows.size.should == 1
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ describe PagedImageController do
2
+ extend Facon::SpecHelpers
3
+
4
+ before do
5
+ @paged_image_controller = PagedImageController.alloc.initWithTransitionStyle(UIPageViewControllerTransitionStyleScroll, navigationOrientation: UIPageViewControllerNavigationOrientationHorizontal, options: {
6
+ "UIPageViewControllerOptionInterPageSpacingKey" => 5.0
7
+ })
8
+ @paged_image_controller.index = 0
9
+ @paged_image_controller.items_list = ["http://sample.image.url"]
10
+ end
11
+
12
+ it "should setup the image controller" do
13
+ @paged_image_controller.should.receive(:set_image_with_url)
14
+ image_controller = @paged_image_controller.set_up_image_controller
15
+ image_controller.class.should == GyroDrivenImageViewController
16
+ end
17
+
18
+ it "should set the right control variables" do
19
+ image_controller = GyroDrivenImageViewController.new
20
+ @paged_image_controller.set_control_variables image_controller
21
+ image_controller.shake_threshold.should == 0.1
22
+ end
23
+
24
+ it "should set up sample data" do
25
+ @paged_image_controller.set_up_sample_data
26
+ @paged_image_controller.items_list.count.should == 5
27
+ end
28
+ end
@@ -0,0 +1,63 @@
1
+ describe ScrollingImageViewController do
2
+ before do
3
+ @scrolling_image_view_controller = ScrollingImageViewController.new
4
+ end
5
+
6
+ it "should set up the main view" do
7
+ @scrolling_image_view_controller.set_up_view(0, 0, 20, 30)
8
+ @scrolling_image_view_controller.width.should == 20
9
+ @scrolling_image_view_controller.height.should == 30
10
+ @scrolling_image_view_controller.view.subviews.count.should == 1
11
+ end
12
+
13
+ it "should set up the scroll view" do
14
+ @scrolling_image_view_controller.width = 20
15
+ @scrolling_image_view_controller.height = 20
16
+ @scrolling_image_view_controller.x = 20
17
+ @scrolling_image_view_controller.y = 20
18
+ scroll_view = @scrolling_image_view_controller.set_up_scroll_view
19
+ scroll_view.class.should == UIScrollView
20
+ scroll_view.isScrollEnabled.should == false
21
+ end
22
+
23
+ it "should set up the image view" do
24
+ @scrolling_image_view_controller.width = 20
25
+ @scrolling_image_view_controller.height = 20
26
+ image_view = @scrolling_image_view_controller.set_up_image_view
27
+ image_view.class.should == UIImageView
28
+ end
29
+
30
+ it "should set an image to the image view" do
31
+ image = UIImage.new
32
+ image_view = UIImageView.alloc.initWithFrame(CGRectMake(0, 0, 20, 20))
33
+ @scrolling_image_view_controller.instance_variable_set(:@image_view, image_view)
34
+ @scrolling_image_view_controller.should.receive(:fit_image_to_height)
35
+ @scrolling_image_view_controller.set_image image
36
+ @scrolling_image_view_controller.instance_variable_get(:@image_view).image.should == image
37
+ end
38
+
39
+
40
+ describe "image and scroll view adjustments" do
41
+ before do
42
+ image_view = UIImageView.alloc.initWithImage(UIImage.imageNamed('sample_spec_image.jpeg'))
43
+ @scrolling_image_view_controller.instance_variable_set(:@image_view, image_view)
44
+ scroll_view = UIScrollView.new
45
+ @scrolling_image_view_controller.instance_variable_set(:@scroll_view, scroll_view)
46
+ @scrolling_image_view_controller.width = 20
47
+ @scrolling_image_view_controller.height = 20
48
+ @final_width = (20.0/30.0 * 20)
49
+ @scrolling_image_view_controller.fit_image_to_height
50
+ end
51
+
52
+ it "should fit an image to the available height" do
53
+ scroll_view = @scrolling_image_view_controller.instance_variable_get(:@scroll_view)
54
+ scroll_view.contentSize.height.should == 20
55
+ scroll_view.contentSize.width.should == @final_width
56
+ end
57
+
58
+ it "should set the content offset" do
59
+ scroll_offset = ((@final_width - 20) / 2).abs.round
60
+ @scrolling_image_view_controller.instance_variable_get(:@scroll_view).contentOffset.x.should == scroll_offset
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-gyro-image-controller
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Multunus
@@ -51,10 +51,20 @@ files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
+ - app/.DS_Store
55
+ - app/app_delegate.rb
56
+ - app/paged_image_controller.rb
54
57
  - lib/motion-gyro-image-controller.rb
55
58
  - lib/motion-gyro-image-controller/gyro_driven_image_view_controller.rb
56
59
  - lib/motion-gyro-image-controller/scrolling_image_view_controller.rb
57
60
  - motion-gyro-image-controller.gemspec
61
+ - resources/.DS_Store
62
+ - resources/Default-568h@2x.png
63
+ - resources/placeholder.jpeg
64
+ - resources/sample_spec_image.jpeg
65
+ - spec/main_spec.rb
66
+ - spec/paged_image_controller_spec.rb
67
+ - spec/scrolling_image_view_controller_spec.rb
58
68
  homepage: ''
59
69
  licenses:
60
70
  - MIT
@@ -79,4 +89,7 @@ rubygems_version: 2.2.2
79
89
  signing_key:
80
90
  specification_version: 4
81
91
  summary: A controller that lets you control images using gyro
82
- test_files: []
92
+ test_files:
93
+ - spec/main_spec.rb
94
+ - spec/paged_image_controller_spec.rb
95
+ - spec/scrolling_image_view_controller_spec.rb