Skip to content

Commit db34312

Browse files
committed
Enabled CCSliders for Android. Fixed a bug that was causing touches to get cancelled because android gesture detectors were not being removed.
1 parent 7c06c44 commit db34312

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

cocos2d-ui/CCScrollView.m

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ - (id) initWithContentNode:(CCNode*)contentNode
214214
_listener = [[CCGestureListener alloc] init];
215215
_listener.delegate = (id<CCGestureListenerDelegate>)self;
216216
_detector = [[AndroidGestureDetector alloc] initWithContext:[CCActivity currentActivity] listener:_listener];
217-
[[[CCDirector sharedDirector] view] addGestureDetector:_detector];
218217
});
219218
#elif __CC_PLATFORM_MAC
220219

@@ -752,8 +751,11 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
752751
return (otherGestureRecognizer == _panRecognizer || otherGestureRecognizer == _tapRecognizer);
753752
}
754753

754+
#elif __CC_PLATFORM_ANDROID
755+
755756
- (void) onEnterTransitionDidFinish
756757
{
758+
#if __CC_PLATFORM_IOS
757759
// Add recognizers to view
758760
UIView* view = [CCDirector sharedDirector].view;
759761

@@ -763,12 +765,22 @@ - (void) onEnterTransitionDidFinish
763765
[recognizers insertObject:_tapRecognizer atIndex:0];
764766

765767
view.gestureRecognizers = recognizers;
766-
768+
#elif __CC_PLATFORM_ANDROID
769+
dispatch_async(dispatch_get_main_queue(), ^{
770+
if(_detector)
771+
{
772+
[[[CCDirector sharedDirector] view] addGestureDetector:_detector];
773+
}
774+
});
775+
#endif
767776
[super onEnterTransitionDidFinish];
768777
}
769778

779+
780+
770781
- (void) onExitTransitionDidStart
771782
{
783+
#if __CC_PLATFORM_IOS
772784
// Remove recognizers from view
773785
UIView* view = [CCDirector sharedDirector].view;
774786

@@ -777,11 +789,19 @@ - (void) onExitTransitionDidStart
777789
[recognizers removeObject:_tapRecognizer];
778790

779791
view.gestureRecognizers = recognizers;
792+
#elif __CC_PLATFORM_ANDROID
793+
dispatch_async(dispatch_get_main_queue(), ^{
794+
if(_detector)
795+
{
796+
[[[CCDirector sharedDirector] view] removeGestureDetector:_detector];
797+
}
798+
});
799+
#endif
780800

781801
[super onExitTransitionDidStart];
782802
}
783803

784-
#elif __CC_PLATFORM_ANDROID
804+
785805

786806
- (CCTouchPhase)handleGestureEvent:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end
787807
{
@@ -930,9 +950,6 @@ - (BOOL)onFling:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end veloci
930950
CCDirector* dir = [CCDirector sharedDirector];
931951
[[CCActivity currentActivity] runOnGameThread:^{
932952

933-
CCResponderManager *mgr = [[CCDirector sharedDirector] responderManager];
934-
[mgr removeAllResponders];
935-
936953
CGPoint translation = [dir convertToGL:rawTranslationFling];
937954
translation = [self convertToNodeSpace:translation];
938955

cocos2d-ui/CCSlider.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ - (void) updateSliderPositionFromValue
7171
_handle.position = ccp(size.width * _sliderValue, size.height/2.0f);
7272
}
7373

74-
#if __CC_PLATFORM_IOS
74+
#if __CC_PLATFORM_IOS || __CC_PLATFORM_ANDROID
7575

7676
#pragma mark Handle touches
7777

cocos2d/Platforms/Android/CCGLView.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ - (BOOL)onTouchEvent:(AndroidMotionEvent *)event
101101
}
102102

103103
if(cancelTouch)
104+
{
104105
phase = CCTouchPhaseCancelled;
106+
}
105107

106108
NSTimeInterval timestamp = event.eventTime * 1000.0;
107109
currentEvent.timestamp = timestamp;

0 commit comments

Comments
 (0)