-
Notifications
You must be signed in to change notification settings - Fork 0
/
WLMainFrameController+RemoteControl.m
160 lines (146 loc) · 4.51 KB
/
WLMainFrameController+RemoteControl.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// WLMainFrameController+RemoteControl.m
// Welly
//
// Created by K.O.ed on 10-4-30.
// Copyright 2010 Welly Group. All rights reserved.
//
#import "WLMainFrameController+RemoteControl.h"
#import "WLMainFrameController+TabControl.h"
#import "WLTabView.h"
#import "WLConnection.h"
#import "CommonType.h"
// for remote control
#import "AppleRemote.h"
#import "KeyspanFrontRowControl.h"
#import "RemoteControlContainer.h"
#import "MultiClickRemoteBehavior.h"
@implementation WLMainFrameController (RemoteControl)
const NSTimeInterval DEFAULT_CLICK_TIME_DIFFERENCE = 0.25; // for remote control
#pragma mark -
#pragma mark Remote Control
- (void)initializeRemoteControl {
// set remote control
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RemoteSupport"]) {
// 1. instantiate the desired behavior for the remote control device
_remoteControlBehavior = [[MultiClickRemoteBehavior alloc] init];
// 2. configure the behavior
[_remoteControlBehavior setDelegate:self];
[_remoteControlBehavior setClickCountingEnabled:YES];
[_remoteControlBehavior setSimulateHoldEvent:YES];
[_remoteControlBehavior setMaximumClickCountTimeDifference:DEFAULT_CLICK_TIME_DIFFERENCE];
// 3. a Remote Control Container manages a number of devices and conforms to the RemoteControl interface
// Therefore you can enable or disable all the devices of the container with a single "startListening:" call.
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
RemoteControlContainer *container = [[RemoteControlContainer alloc] initWithDelegate:_remoteControlBehavior];
[container instantiateAndAddRemoteControlDeviceWithClass:[AppleRemote class]];
[container instantiateAndAddRemoteControlDeviceWithClass:[KeyspanFrontRowControl class]];
// to give the binding mechanism a chance to see the change of the attribute
[self setValue:container forKey:@"remoteControl"];
[container startListening:self];
_remoteControl = container;
[pool release];
}
}
/* Remote Control */
- (void)remoteButton:(RemoteControlEventIdentifier)buttonIdentifier
pressedDown:(BOOL)pressedDown
clickCount:(unsigned int)clickCount {
NSString *cmd = nil;
if (!pressedDown) { // release
switch(buttonIdentifier) {
case kRemoteButtonPlus: // up
if (clickCount == 1)
cmd = termKeyUp;
else
cmd = termKeyPageUp;
break;
case kRemoteButtonMinus: // down
if (clickCount == 1)
cmd = termKeyDown;
else
cmd = termKeyPageDown;
break;
case kRemoteButtonMenu:
break;
case kRemoteButtonPlay:
cmd = termKeyEnter;
break;
case kRemoteButtonRight: // right
if (clickCount == 1)
cmd = termKeyRight;
else
cmd = termKeyEnd;
break;
case kRemoteButtonLeft: // left
if (clickCount == 1)
cmd = termKeyLeft;
else
cmd = termKeyHome;
break;
case kRemoteButtonPlus_Hold:
[self disableTimer];
break;
case kRemoteButtonMinus_Hold:
[self disableTimer];
break;
case kRemoteButtonPlay_Hold:
break;
}
}
else { // Key Press
switch(buttonIdentifier) {
case kRemoteButtonRight_Hold: // Right Tab
[self selectNextTab:self];
break;
case kRemoteButtonLeft_Hold: // Left Tab
[self selectPrevTab:self];
break;
case kRemoteButtonPlus_Hold:
// Enable timer!
[self disableTimer];
_scrollTimer = [NSTimer scheduledTimerWithTimeInterval:scrollTimerInterval
target:self
selector:@selector(doScrollUp:)
userInfo:nil
repeats:YES];
break;
case kRemoteButtonMinus_Hold:
// Enable timer!
[self disableTimer];
_scrollTimer = [NSTimer scheduledTimerWithTimeInterval:scrollTimerInterval
target:self
selector:@selector(doScrollDown:)
userInfo:nil
repeats:YES];
break;
case kRemoteButtonMenu_Hold:
[self fullScreenMode:nil];
break;
}
}
if (cmd != nil) {
[[_tabView frontMostConnection] sendText:cmd];
}
}
// TODO: use responder instead of finding the connection!!
// for timer
- (void)doScrollDown:(NSTimer*)timer {
[[_tabView frontMostConnection] sendText:termKeyDown];
}
- (void)doScrollUp:(NSTimer*)timer {
[[_tabView frontMostConnection] sendText:termKeyUp];
}
- (void)disableTimer {
[_scrollTimer invalidate];
[_scrollTimer release];
_scrollTimer = nil;
}
// for bindings access
- (RemoteControl*)remoteControl {
return _remoteControl;
}
- (MultiClickRemoteBehavior*)remoteBehavior {
return _remoteControlBehavior;
}
@end