예제 #1
0
/*
 * 创建一个UMShareButton对象
 * @param  normalImage  按钮正常情况下显示的图片
 * @param  selectedImage 按钮选中情况下显示的图片
 * @param  umAppKey 友盟AppKey
 * @param callback 分享回调函数
 */
UMShareButton* UMShareButton::create(const char *normalImage,
		const char *selectedImage, const char* umAppKey,
		ShareEventHandler callback) {

	UMShareButton* shareButton = new UMShareButton(normalImage, selectedImage,
			umAppKey);
	shareButton->setShareCallback(callback);
	return shareButton;
}
// on "init" you need to initialize your instance
bool HelloWorld::init() {
    //////////////////////////////
    // 1. super init first
    if (!CCLayer::init()) {
        return false;
    }

    // ********************  设置友盟的app key以及相关的信息  ***********************************
    // 获取CCUMSocialSDK对象, 如果使用的UMShareButton, 则通过UMShareButton对象的getSocialSDK()方法获取.
    CCUMSocialSDK *sdk = CCUMSocialSDK::create("4eaee02c527015373b000003");
    sdk->setTargetUrl("http://www.umeng.com/social");
    //    // 设置友盟app key
    //    sdk->setAppKey("507fcab25270157b37000010");
    sdk->setQQAppIdAndAppKey("100424468", "c7394704798a158208a74ab60104f0ba");
    sdk->setWeiXinAppId("wx485ab7ca6a7e02d1");
    sdk->setYiXinAppKey("yx52dd5c14bbb3430b93e6f2dafcbcc68d");
    sdk->setLaiwangAppInfo("设置来往和来往动态的app id", "设置来往和来往动态的app key", "我的应用名");
    sdk->setFacebookAppId("567261760019884");
    sdk->openTwitterForiOS();
    // 设置用户点击一条图文分享时用户跳转到的目标页面, 一般为app主页或者下载页面


    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    // 打开分享面板
    CCMenuItemFont *shareTextButton = CCMenuItemFont::create("打开分享面板", this,
                                      menu_selector(HelloWorld::menuShareCallback));
    shareTextButton->setPosition(ccp(150, 480));

    // 底层API分享
    CCMenuItemFont *directTextButton = CCMenuItemFont::create("底层分享", this,
                                       menu_selector(HelloWorld::directShareCallback));
    directTextButton->setPosition(ccp(150, 400));

    // 授权某平台
    CCMenuItemFont *authTextButton = CCMenuItemFont::create("授权某平台", this,
                                     menu_selector(HelloWorld::authorizeCallback));
    authTextButton->setPosition(ccp(150, 320));

    // 删除某平台授权
    CCMenuItemFont *delAuthTextButton = CCMenuItemFont::create("删除某平台删除", this,
                                        menu_selector(HelloWorld::deleteAuthorizeCallback));
    delAuthTextButton->setPosition(ccp(150, 240));

    // 判断某平台是否授权
    CCMenuItemFont *isAuthTextButton = CCMenuItemFont::create("判断某平台是否授权", this,
                                       menu_selector(HelloWorld::isAuthorizedShareCallback));
    isAuthTextButton->setPosition(ccp(150, 160));


    // ********************************************************************************

    // 打开或者关闭log
    sdk->setLogEnable(true);

    // 关闭按钮
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png",
                                  "CloseSelected.png", this,
                                  menu_selector(HelloWorld::menuCloseCallback));

    pCloseItem->setPosition(
        ccp(
            origin.x + visibleSize.width
            - pCloseItem->getContentSize().width / 2,
            origin.y + pCloseItem->getContentSize().height / 2));

    // 友盟share button, 参数1为正常情况下的图片, 参数2为用户点击后的图片, 参数3为友盟app key, 参数四为分享回调.
    UMShareButton *shareButton = UMShareButton::create("share.png",
                                 "CloseSelected.png", "4eaee02c527015373b000003",
                                 share_selector(shareCallback));
    vector<int>* platforms = new vector<int>();
    platforms->push_back(SINA);
    platforms->push_back(FACEBOOK);
//	platforms->push_back(INSTAGRAM);
    platforms->push_back(QZONE);
    platforms->push_back(QQ);
    platforms->push_back(YIXIN_CIRCLE);
    platforms->push_back(YIXIN);
    platforms->push_back(WEIXIN);
    shareButton->setPlatforms(platforms) ;
    shareButton->setShareContent("这是很长的文字内容是个撒刚好是法国是大家给老师发给了对方两个");

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

    shareButton->setShareImage(NULL);

#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

    shareButton->setShareImage("share.png");

#endif

    // 设置分享回调
    shareButton->setShareCallback(share_selector(shareCallback));
    shareButton->setPosition(ccp(480, 150));

    CCMenuItemFont *umshareTextButton = CCMenuItemFont::create("友盟ShareButton");
    umshareTextButton->setPosition(ccp(480, 60));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create();
    pMenu->addChild(pCloseItem, 1);
    // 友盟share button
    pMenu->addChild(shareButton, 1);
    pMenu->addChild(umshareTextButton, 1);

    // 文字按钮
    pMenu->addChild(shareTextButton, 1);
    pMenu->addChild(directTextButton, 1);
    pMenu->addChild(authTextButton, 1);
    pMenu->addChild(delAuthTextButton, 1);
    pMenu->addChild(isAuthTextButton, 1);

    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label

    CCLabelTTF* pLabel = CCLabelTTF::create("Umeng Social Cocos2d-x SDK",
                                            "Arial", 34);
    pLabel->setTag(labelTag);
    // position the label on the center of the screen
    pLabel->setPosition(
        ccp(origin.x + visibleSize.width / 2,
            origin.y + visibleSize.height
            - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(
        ccp(visibleSize.width / 2 + origin.x,
            visibleSize.height / 2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);

    return true;
}