From 2ef2016c39172f12ce1072fad879d7bd999c549a Mon Sep 17 00:00:00 2001 From: jianglong0156 Date: Wed, 1 Jul 2015 10:41:24 +0800 Subject: [PATCH] add call reflection with bool test case --- .../js-tests/project/proj.ios/NativeOcClass.h | 1 + .../js-tests/project/proj.ios/NativeOcClass.m | 32 +++++++++++++++++++ .../src/ReflectionTest/ReflectionTest.js | 17 +++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/js-tests/project/proj.ios/NativeOcClass.h b/tests/js-tests/project/proj.ios/NativeOcClass.h index f8664c6d63..64e92cc0ab 100644 --- a/tests/js-tests/project/proj.ios/NativeOcClass.h +++ b/tests/js-tests/project/proj.ios/NativeOcClass.h @@ -29,5 +29,6 @@ +(void) callNativeWithParam:(NSString *)str; +(NSString *)callNativeWithReturnString; +(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content; ++(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content addBool:(BOOL)logicSwitch; +(int)callNativeWithAdd:(NSNumber *)num1 and:(NSNumber *)num2; @end diff --git a/tests/js-tests/project/proj.ios/NativeOcClass.m b/tests/js-tests/project/proj.ios/NativeOcClass.m index 8591fee98a..0bcfd9c355 100644 --- a/tests/js-tests/project/proj.ios/NativeOcClass.m +++ b/tests/js-tests/project/proj.ios/NativeOcClass.m @@ -50,6 +50,19 @@ [alertView show]; return true; } ++(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content addBool:(BOOL)logicSwitch{ + if (logicSwitch) + { + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:content delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"it's true", nil]; + [alertView show]; + } + else + { + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:content delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"it's false", nil]; + [alertView show]; + } + return true; +} #elif TARGET_OS_MAC +(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content{ @@ -63,5 +76,24 @@ return true; } ++(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content addBool:(BOOL)logicSwitch{ + NSAlert *alert = [[NSAlert alloc] init]; + if (logicSwitch) + { + [alert addButtonWithTitle:@"it's true"]; + [alert addButtonWithTitle:@"Cancel"]; + } + else + { + [alert addButtonWithTitle:@"it's false"]; + [alert addButtonWithTitle:@"Cancel"]; + } + + [alert setMessageText:title]; + [alert setInformativeText:content]; + [alert setAlertStyle:NSWarningAlertStyle]; + [alert runModal]; + return true; +} #endif @end diff --git a/tests/js-tests/src/ReflectionTest/ReflectionTest.js b/tests/js-tests/src/ReflectionTest/ReflectionTest.js index 6b3c7b3a35..14509c1a01 100644 --- a/tests/js-tests/src/ReflectionTest/ReflectionTest.js +++ b/tests/js-tests/src/ReflectionTest/ReflectionTest.js @@ -41,12 +41,19 @@ var ReflectionTestLayer = BaseTestLayer.extend({ cc.log("ret val is "+ret); } }, this); - menuItem.x = winSize.width / 2; - menuItem.y = winSize.height / 2; - var menu = new cc.Menu(menuItem); - menu.x = 0; - menu.y = 0; + var label2 = new cc.LabelTTF("CallReflectionWithBool", "Arial", 35); + var menuItem2 = new cc.MenuItemLabel(label2, function(){ + if(cc.sys.os == cc.sys.OS_ANDROID){ + jsb.reflection.callStaticMethod("org/cocos2dx/js_tests/AppActivity", "showAlertDialog", "(Ljava/lang/String;Ljava/lang/String;)V", "How are you ?", "I'm great !"); + }else if(cc.sys.os == cc.sys.OS_IOS || cc.sys.os == cc.sys.OS_OSX){ + var ret = jsb.reflection.callStaticMethod("NativeOcClass","callNativeUIWithTitle:andContent:addBool:","cocos2d-js","Yes! you call a Native UI from Reflection", true); + cc.log("ret val is "+ret); + } + }, this); + + var menu = new cc.Menu(menuItem, menuItem2); + menu.alignItemsVerticallyWithPadding(4); this.addChild(menu); }