motion-egg 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a755311e092feb9bf84952946cd0f3ab3f4d657
4
+ data.tar.gz: 9e055ea10c7e4e60e77c7e67cc629a0eb18b9206
5
+ SHA512:
6
+ metadata.gz: 05f01b628880ad4f2632c75e152e8088163a7a300d30974066b269aadaee9fdb602c97fde787a11772a0b12e5d4add934397648c067e98810b3ce7404ce75464
7
+ data.tar.gz: ee96ec7fee541c74da4b5741aefccfba40ed4d24eefe352bf1ea667599f647e4b79ddea83bbe9b99cc122a9e3a5f249d56518838643d085547819b660499694a
data/lib/motion_egg.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "motion_egg/version"
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_egg/*.rb')).each do |file|
9
+ app.files.unshift(file)
10
+ end
11
+ #app.frameworks += ["Twitter", "Accounts"]
12
+ end
@@ -0,0 +1,92 @@
1
+ class Egg
2
+ attr_accessor :number_touches, :current_code
3
+
4
+ DEFAULT_TOUCHES = 1
5
+ KONAMI = [
6
+ UISwipeGestureRecognizerDirectionUp, UISwipeGestureRecognizerDirectionUp,
7
+ UISwipeGestureRecognizerDirectionDown, UISwipeGestureRecognizerDirectionDown,
8
+ UISwipeGestureRecognizerDirectionLeft, UISwipeGestureRecognizerDirectionRight,
9
+ UISwipeGestureRecognizerDirectionLeft, UISwipeGestureRecognizerDirectionRight
10
+ ]
11
+
12
+ def initialize (opts = {})
13
+ @options = {secret_code: KONAMI, number_touches: DEFAULT_TOUCHES, image_file: "toasty.png"}.merge(opts)
14
+ end
15
+
16
+ def activate
17
+ #p "************* OMG THE CODEZ! *************"
18
+ insert_egg
19
+ show_egg
20
+ NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: 'hide_egg:', userInfo: nil, repeats: false)
21
+ end
22
+
23
+ def show_egg(timing = 0.5)
24
+ # Animate the egg into the view:
25
+ UIView.animateWithDuration(timing,
26
+ delay:0.0,
27
+ options:UIViewAnimationOptionCurveLinear,
28
+ animations: lambda {
29
+ @egg_view.frame = show_frame
30
+ },
31
+ completion:lambda {|finished|
32
+ }
33
+ )
34
+ end
35
+
36
+ def hide_egg(sender)
37
+ # Animate the egg out of the view:
38
+ UIView.animateWithDuration(0.5,
39
+ delay:0.0,
40
+ options:UIViewAnimationOptionCurveLinear,
41
+ animations: lambda {
42
+ @egg_view.frame = hidden_frame
43
+ },
44
+ completion:lambda {|finished|
45
+ #consider removing egg subview here.
46
+ }
47
+ )
48
+ end
49
+
50
+ def insert_egg
51
+ @egg_view ||= begin
52
+ egg_view = UIImageView.alloc.initWithFrame(hidden_frame)
53
+ egg_view.contentMode = UIViewContentModeScaleAspectFit
54
+ egg_view.image = UIImage.imageNamed(@options[:image_file])
55
+ egg_view
56
+ end
57
+
58
+ # We want to add the view to the root view
59
+ UIApplication.sharedApplication.keyWindow.subviews.objectAtIndex(0).nextResponder.view.addSubview(@egg_view)
60
+ end
61
+
62
+ def add_code new_direction
63
+ @current_code ||= Array.new
64
+ @current_code.push(new_direction)
65
+
66
+ # Only keep the last @current_code.size entries
67
+ @current_code = @current_code[-@options[:secret_code].size..-1] if @current_code.size > @options[:secret_code].size
68
+ #p @current_code
69
+ activate if @options[:secret_code] == @current_code
70
+ end
71
+
72
+ def number_touches
73
+ @options[:number_touches]
74
+ end
75
+
76
+ def hidden_frame
77
+ [[0,UIScreen.mainScreen.bounds.size.height + egg_height],[egg_width, egg_height]]
78
+ end
79
+
80
+ def show_frame
81
+ [[0,UIScreen.mainScreen.bounds.size.height - egg_height],[egg_width, egg_height]]
82
+ end
83
+
84
+ def egg_height
85
+ 180
86
+ end
87
+
88
+ def egg_width
89
+ UIScreen.mainScreen.bounds.size.width
90
+ end
91
+
92
+ end
@@ -0,0 +1,38 @@
1
+ class UIWindow
2
+
3
+ def add_egg(options = {})
4
+
5
+ # Easter egg workhorse
6
+ @egg = Egg.new options
7
+
8
+ #left
9
+ @swipe_gesture_left = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
10
+ @swipe_gesture_left.direction = UISwipeGestureRecognizerDirectionLeft
11
+ @swipe_gesture_left.numberOfTouchesRequired = @egg.number_touches
12
+ self.addGestureRecognizer(@swipe_gesture_left)
13
+
14
+ #right
15
+ @swipe_gesture_right = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
16
+ @swipe_gesture_right.direction = UISwipeGestureRecognizerDirectionRight
17
+ @swipe_gesture_right.numberOfTouchesRequired = @egg.number_touches
18
+ self.addGestureRecognizer(@swipe_gesture_right)
19
+
20
+ #up
21
+ @swipe_gesture_up = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
22
+ @swipe_gesture_up.direction = UISwipeGestureRecognizerDirectionUp
23
+ @swipe_gesture_up.numberOfTouchesRequired = @egg.number_touches
24
+ self.addGestureRecognizer(@swipe_gesture_up)
25
+
26
+ #down
27
+ @swipe_gesture_down = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
28
+ @swipe_gesture_down.direction = UISwipeGestureRecognizerDirectionDown
29
+ @swipe_gesture_down.numberOfTouchesRequired = @egg.number_touches
30
+ self.addGestureRecognizer(@swipe_gesture_down)
31
+ end
32
+
33
+ # each recognizer should have a direction, but you can send them all to the same function!
34
+ def handle_swipe(sender)
35
+ @egg.add_code(sender.direction)
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ module MotionEgg
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-egg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gant Laborde
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-01 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: motion-egg lets you perform the Konami code and get a lovely surprise
28
+ in your app
29
+ email: gant@iconoclastlabs.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/motion_egg/egg.rb
35
+ - lib/motion_egg/uiwindow.rb
36
+ - lib/motion_egg/version.rb
37
+ - lib/motion_egg.rb
38
+ homepage: https://github.com/GantMan/motion-egg
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.0.3
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Automatically add an easter egg to your iOS app
62
+ test_files: []
63
+ has_rdoc: