Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Neeraj Singh
committed
Feb 22, 2014
1 parent
da7fc54
commit ca1e92a
Showing
26 changed files
with
1,386 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.repl_history | ||
build | ||
tags | ||
app/pixate_code.rb | ||
resources/*.nib | ||
resources/*.momd | ||
resources/*.storyboardc | ||
.DS_Store | ||
nbproject | ||
.redcar | ||
#*# | ||
*~ | ||
*.sw[po] | ||
.eprj | ||
.sass-cache | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rake' | ||
gem 'motion_model' | ||
gem 'ruby_motion_query' | ||
gem 'bubble-wrap' | ||
# Add your dependencies here: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
bubble-wrap (1.3.0) | ||
motion-require (0.0.7) | ||
motion-support (0.2.5) | ||
motion-require (>= 0.0.6) | ||
motion_model (0.4.6) | ||
bubble-wrap (= 1.3.0) | ||
motion-support (>= 0.1.0) | ||
rake (10.1.0) | ||
ruby_motion_query (0.5.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bubble-wrap | ||
motion_model | ||
rake | ||
ruby_motion_query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
$:.unshift("/Library/RubyMotion/lib") | ||
require 'motion/project/template/ios' | ||
|
||
version = `motion --version`; puts "RubyMotion version: #{version}"; puts '' | ||
|
||
begin | ||
require 'bundler' | ||
Bundler.require | ||
rescue LoadError | ||
end | ||
|
||
require 'bubble-wrap/reactor' | ||
|
||
Motion::Project::App.setup do |app| | ||
# Use `rake config' to see complete project settings. | ||
app.name = 'lrm' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class AppDelegate | ||
|
||
attr_reader :language_service | ||
|
||
LOCK_TIME = 10 | ||
|
||
def application(application, didFinishLaunchingWithOptions:launchOptions) | ||
|
||
StandardAppearance.apply | ||
|
||
@window = IdlingWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) | ||
|
||
setup_lock_screen | ||
|
||
@window.rootViewController = build_tabbar | ||
|
||
@language_service = LanguagesService.new | ||
|
||
@window.makeKeyAndVisible | ||
true | ||
end | ||
|
||
def applicationWillEnterForeground app | ||
@screen_lock_controller.lock_the_screen | ||
end | ||
|
||
private | ||
|
||
def setup_lock_screen | ||
@screen_lock_controller = ScreenLockController.alloc.initWithText("Enter code to unlock") | ||
|
||
App.notification_center.observe(IdlingWindow::BECAME_IDLE, @window) do |_| | ||
@screen_lock_controller.lock_the_screen | ||
end | ||
|
||
@window.set_idle_timeout_seconds LOCK_TIME | ||
end | ||
|
||
def build_tabbar | ||
tabbar = UITabBarController.alloc.init | ||
tabbar.viewControllers = [ | ||
UINavigationController.alloc.initWithRootViewController(StaticLanguagesController.alloc.init), | ||
UINavigationController.alloc.initWithRootViewController(DynamicLanguagesController.alloc.init), | ||
UINavigationController.alloc.initWithRootViewController(AllLanguagesController.alloc.init), | ||
UINavigationController.alloc.initWithRootViewController(MoreActionsController.alloc.init) | ||
] | ||
tabbar.selectedIndex = 0 | ||
tabbar.delegate = self | ||
tabbar | ||
end | ||
|
||
|
||
end |
28 changes: 28 additions & 0 deletions
28
episode-20-wip/app/controllers/all_languages_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class AllLanguagesController < BaseLanguagesController | ||
|
||
def init | ||
super | ||
self.tabBarItem = UITabBarItem.alloc.initWithTitle('All', image: rmq.image.resource('bell'), tag: 0) | ||
self.title = 'All' | ||
self | ||
end | ||
|
||
def viewDidLoad | ||
super | ||
|
||
navigationItem.title = 'All languages' | ||
view.dataSource = view.delegate = self | ||
|
||
language_service = rmq.app.delegate.language_service | ||
@data = language_service.all | ||
@keys = @data.map { |r| r.name } | ||
end | ||
|
||
def tableView(tableView, cellForRowAtIndexPath: indexPath) | ||
@reuseIdentifier ||= "CELL_IDENTIFIER_FOR_ALL_LANGUAGES" | ||
super | ||
end | ||
|
||
|
||
end | ||
|
20 changes: 20 additions & 0 deletions
20
episode-20-wip/app/controllers/base_languages_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class BaseLanguagesController < UITableViewController | ||
|
||
def tableView(tableView, numberOfRowsInSection: section) | ||
@data.count | ||
end | ||
|
||
def tableView(tableView, cellForRowAtIndexPath: indexPath) | ||
cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) | ||
|
||
cell ||= UITableViewCell.alloc.initWithStyle( UITableViewCellStyleValue1, reuseIdentifier:@reuseIdentifier) | ||
|
||
row_number = indexPath.row | ||
key = @keys[row_number] | ||
cell.textLabel.text = key | ||
inventor_name = @data[row_number].inventor_name | ||
cell.detailTextLabel.text = inventor_name | ||
cell | ||
end | ||
|
||
end |
27 changes: 27 additions & 0 deletions
27
episode-20-wip/app/controllers/dynamic_languages_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class DynamicLanguagesController < BaseLanguagesController | ||
|
||
def init | ||
super | ||
self.tabBarItem = UITabBarItem.alloc.initWithTitle('Dynamic', image: rmq.image.resource('binocular'), tag: 0) | ||
self.title = 'Dynamic' | ||
self | ||
end | ||
|
||
def viewDidLoad | ||
super | ||
|
||
navigationItem.title = 'Dynamic languages' | ||
view.dataSource = view.delegate = self | ||
|
||
language_service = rmq.app.delegate.language_service | ||
@data = language_service.dynamic | ||
@keys = @data.map { |r| r.name } | ||
end | ||
|
||
def tableView(tableView, cellForRowAtIndexPath: indexPath) | ||
@reuseIdentifier ||= "CELL_IDENTIFIER_FOR_DYNAMIC_LANGUAGES" | ||
super | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# This is how this class works. | ||
# | ||
# A timer is set when application boots and whenver a user event is detected. That timer will invoke method to lock the screen based on LOCK_TIME. | ||
# The only way to cancel that operation is to cancel the timer before the screen is locked. | ||
# | ||
# That timer is cancelled anytime a user event is detected. | ||
# | ||
# So if a user event is not detected within the given LOCK_TIME the screen will be locked. | ||
class IdlingWindow < UIWindow | ||
|
||
BECAME_IDLE = "com.bigbinary.notifications.BecameIdle" | ||
BECAME_ACTIVE = "com.bigbinary.notifications.BecameActive" | ||
|
||
attr_accessor :idle_timer | ||
attr_reader :idle_timeout_seconds | ||
|
||
def initWithFrame(frame) | ||
if super | ||
@idle_timeout_seconds = 0 | ||
end | ||
|
||
self | ||
end | ||
|
||
def sendEvent event | ||
super event | ||
|
||
user_event if user_triggered_event?(event) | ||
end | ||
|
||
def set_idle_timeout_seconds seconds | ||
@idle_timeout_seconds = seconds | ||
|
||
set_timer | ||
end | ||
|
||
def dealloc | ||
if idle_timer | ||
BW::Reactor.cancel_timer(idle_timer) | ||
self.idle_timer = nil | ||
end | ||
|
||
super.dealloc | ||
end | ||
|
||
private | ||
|
||
def user_event | ||
idle_timer ? BW::Reactor.cancel_timer(idle_timer) : became_active_notification | ||
|
||
set_timer | ||
end | ||
|
||
def became_active_notification | ||
App.notification_center.post(BECAME_ACTIVE, self) | ||
end | ||
|
||
def became_idle_notification | ||
App.notification_center.post(BECAME_IDLE, self) | ||
self.idle_timer = nil | ||
end | ||
|
||
def set_timer | ||
BW::Reactor.cancel_timer(idle_timer) if idle_timer | ||
|
||
if (idle_timeout_seconds > 0) | ||
self.idle_timer = BW::Reactor.add_timer(idle_timeout_seconds) do | ||
became_idle_notification | ||
end | ||
end | ||
end | ||
|
||
def user_triggered_event?(event) | ||
all_touches = event.allTouches | ||
if all_touches.count > 0 | ||
phase = all_touches.anyObject.phase | ||
return true if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded) | ||
end | ||
end | ||
|
||
end | ||
|
||
|
69 changes: 69 additions & 0 deletions
69
episode-20-wip/app/controllers/lock_code/manage_lock_code_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
class ManageLockCodeController < UIViewController | ||
|
||
def initAndSetCode | ||
if init | ||
@text = "Enter a new code" | ||
@action = -> (code) do | ||
controller = ManageLockCodeController.alloc.initAndConfirmCode code | ||
self.navigationController.pushViewController(controller, animated: true) | ||
end | ||
end | ||
|
||
self | ||
end | ||
|
||
def initAndConfirmCode input_code | ||
if init | ||
@text = "Confirm your new code" | ||
end | ||
|
||
@action = -> (confirmation_code) do | ||
stack = self.navigationController.viewControllers | ||
if input_code == confirmation_code | ||
LockCode.set(input_code) | ||
outer_controller = stack.reverse.detect { |controller| controller.class != ManageLockCodeController } | ||
self.navigationController.popToViewController(outer_controller, animated: false) | ||
else | ||
App.alert("Your codes do not match. Please try again.") | ||
controller = stack[stack.size - 2] | ||
self.navigationController.popToViewController(controller, animated: true) | ||
end | ||
end | ||
|
||
self | ||
end | ||
|
||
def initAndChangeCode | ||
if init | ||
@text = "Enter your current code" | ||
@action = -> (code) do | ||
if LockCode.matches?(code) | ||
self.navigationController.pushViewController(ManageLockCodeController.alloc.initAndSetCode, animated: true) | ||
@lock_screen.reset_screen | ||
else | ||
@lock_screen.label.get.text = "Please try again" | ||
@lock_screen.flash_background | ||
@lock_screen.reset_screen | ||
end | ||
end | ||
end | ||
|
||
self | ||
end | ||
|
||
def viewDidAppear(animated) | ||
@lock_screen.reset_screen | ||
end | ||
|
||
def viewDidLoad | ||
super | ||
rmq.stylesheet = ManageLockCodeStylesheet | ||
|
||
@lock_screen = rmq.append(LockScreen, :lock_screen).get | ||
@lock_screen.text = @text | ||
@lock_screen.style_for_controller(self) | ||
@lock_screen.action_on_last_button = @action | ||
end | ||
|
||
end | ||
|
Oops, something went wrong.