issue #2224 : Modify the implementation of plugin twitter & weibo on android for the new framework of plugin.

This commit is contained in:
zhangbin 2013-05-27 13:58:31 +08:00
parent c89bf0f1a8
commit 9f61f92017
32 changed files with 147 additions and 639 deletions

View File

@ -1,76 +0,0 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_SOCIAL_TWITTER_H__
#define __CCX_SOCIAL_TWITTER_H__
#include "ProtocolSocial.h"
#include <map>
#include <string>
namespace cocos2d { namespace plugin {
class SocialTwitter : public ProtocolSocial
{
PLUGIN_REGISTER_DECL(SocialTwitter)
public:
/**
@brief plugin initialization
*/
virtual bool init();
/**
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
TwitterKey The consumerkey of twitter account
TwitterSecret The consumersecret of twitter account
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief pay for product
@param info The info of product, can contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
@warning For different plugin, the parameter should have other keys to pay.
Look at the manual of plugins.
*/
virtual void share(TShareInfo info);
/**
@brief Set whether needs to output logs to console.
@param debug if true debug mode enabled, or debug mode disabled.
*/
virtual void setDebugMode(bool debug);
virtual const char* getPluginVersion() { return "v0.1.01"; };
virtual const char* getSDKVersion();
virtual ~SocialTwitter();
};
}} // namespace cocos2d { namespace plugin {
#endif /* __CCX_SOCIAL_TWITTER_H__ */

View File

@ -1,60 +0,0 @@
[twitter]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = pluginx_twitter
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = plugin
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include
android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include
clang_flags = -nostdinc -x c++
cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/twitter/include
cocos_flags = -DANDROID
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
# what headers to parse
headers = %(pluginxdir)s/plugins/twitter/include/SocialTwitter.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
classes = SocialTwitter
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = *::[createPlugin]
rename_functions =
rename_classes =
# for all class names, should we remove something when registering in the target VM?
remove_prefix =
# classes for which there will be no "parent" lookup
classes_have_no_parents =
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip =
# classes that create no constructor
# CCSet is special and we will use a hand-written constructor
abstract_classes = SocialTwitter
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = yes

View File

@ -1,78 +0,0 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "SocialTwitter.h"
#include "PluginUtils.h"
namespace cocos2d { namespace plugin {
PLUGIN_REGISTER_IMPL(SocialTwitter)
SocialTwitter::~SocialTwitter()
{
}
/**
@brief plugin initialization
*/
bool SocialTwitter::init()
{
return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.SocialTwitter");
}
/**
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
TwitterKey The consumerkey of twitter account
TwitterSecret The consumersecret of twitter account
More: https://dev.twitter.com
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void SocialTwitter::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
ProtocolSocial::configDeveloperInfo(devInfo);
}
/**
@brief pay for product
@param info The info of product, must contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
*/
void SocialTwitter::share(TShareInfo info)
{
ProtocolSocial::share(info);
}
const char* SocialTwitter::getSDKVersion()
{
return ProtocolSocial::getSDKVersion();
}
void SocialTwitter::setDebugMode(bool debug)
{
ProtocolSocial::setDebugMode(debug);
}
}} // namespace cocos2d { namespace plugin {

View File

@ -1,20 +0,0 @@
# set params
PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd)
if [ ! "${PLUGIN_ROOT}" ]; then
PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../..
fi
# build
"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \
NDK_MODULE_PATH="$PLUGIN_ROOT"
echo
if [ "0" != "$?" ]; then
echo "Build error occoured!!!"
exit 1
fi
echo
echo "Native build action success."
exit 0

View File

@ -1,29 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := PluginTwitterStatic
LOCAL_MODULE_FILENAME := libPluginTwitterStatic
LOCAL_SRC_FILES := \
$(addprefix ../../platform/android/, \
SocialTwitter.cpp \
) \
LOCAL_CFLAGS :=
LOCAL_EXPORT_CFLAGS :=
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic
LOCAL_LDLIBS := -landroid
LOCAL_LDLIBS += -llog
include $(BUILD_STATIC_LIBRARY)
$(call import-module, protocols/proj.android/jni)

View File

@ -1,7 +0,0 @@
# it is needed for ndk-r5
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_MODULES := PluginTwitterStatic
APP_ABI :=armeabi
#APP_ABI :=x86
#APP_ABI :=mips mips-r2 mips-r2-sf armeabi

View File

@ -25,7 +25,6 @@ package org.cocos2dx.plugin;
import java.util.Hashtable;
import org.cocos2dx.plugin.InterfaceSocial.ShareAdapter;
import org.cocos2dx.plugin.TwitterApp.TwDialogListener;
import android.app.Activity;
@ -34,11 +33,11 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
public class SocialTwitter implements ShareAdapter {
public class SocialTwitter implements InterfaceSocial {
private static final String LOG_TAG = "SocialTwitter";
private static Activity mContext = null;
private static ShareAdapter mSocialAdapter = null;
private static InterfaceSocial mSocialAdapter = null;
protected static boolean bDebug = false;
private static String CONSUMER_KEY="";
private static String CONSUMER_SECRET="";
@ -98,12 +97,12 @@ public class SocialTwitter implements ShareAdapter {
LogD("share invoked " + info.toString());
mShareInfo = info;
if (! networkReachable()) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Network error!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "Network error!");
return;
}
if (! isInitialized) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Initialize failed!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "Initialize failed!");
return;
}
@ -153,7 +152,7 @@ public class SocialTwitter implements ShareAdapter {
}
private static void shareResult(int ret, String msg) {
InterfaceSocial.onShareResult(mSocialAdapter, ret, msg);
SocialWrapper.onShareResult(mSocialAdapter, ret, msg);
LogD("SocialTwitter result : " + ret + " msg : " + msg);
}
@ -162,7 +161,7 @@ public class SocialTwitter implements ShareAdapter {
@Override
public void onError(int flag, String value) {
LogD("Twitter connection failed!");
shareResult(InterfaceSocial.SHARERESULT_FAIL, value);
shareResult(SocialWrapper.SHARERESULT_FAIL, value);
}
@Override
@ -181,11 +180,16 @@ public class SocialTwitter implements ShareAdapter {
mTwitter.updateStatus(text);
}
LogD("Posted to Twitter!");
shareResult(InterfaceSocial.SHARERESULT_SUCCESS, "Share succeed!");
shareResult(SocialWrapper.SHARERESULT_SUCCESS, "Share succeed!");
} catch (Exception e) {
LogD("Post to Twitter failed!");
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Unknown error!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "Unknown error!");
e.printStackTrace();
}
}
@Override
public String getPluginVersion() {
return "0.2.0";
}
}

View File

@ -1,74 +0,0 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_SOCIAL_WEIBO_H__
#define __CCX_SOCIAL_WEIBO_H__
#include "ProtocolSocial.h"
namespace cocos2d { namespace plugin {
class SocialWeibo : public ProtocolSocial
{
PLUGIN_REGISTER_DECL(SocialWeibo)
public:
/**
@brief plugin initialization
*/
virtual bool init();
/**
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
WeiboAppKey The app key of weibo account
WeiboRedirectUrl The redirect url of weibo account
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief pay for product
@param info The info of product, can contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
@warning For different plugin, the parameter should have other keys to pay.
Look at the manual of plugins.
*/
virtual void share(TShareInfo info);
/**
@brief Set whether needs to output logs to console.
@param debug if true debug mode enabled, or debug mode disabled.
*/
virtual void setDebugMode(bool debug);
virtual const char* getPluginVersion() { return "v0.1.01"; };
virtual const char* getSDKVersion();
virtual ~SocialWeibo();
};
}} // namespace cocos2d { namespace plugin {
#endif /* __CCX_SOCIAL_WEIBO_H__ */

View File

@ -1,60 +0,0 @@
[weibo]
# the prefix to be added to the generated functions. You might or might not use this in your own
# templates
prefix = pluginx_weibo
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
# all classes will be embedded in that namespace
target_namespace = plugin
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include/linux -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.6/include -I%(androidndkdir)s/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/lib/gcc/arm-linux-androideabi/4.6/include
android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include
clang_flags = -nostdinc -x c++
cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/weibo/include
cocos_flags = -DANDROID
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
# extra arguments for clang
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
# what headers to parse
headers = %(pluginxdir)s/plugins/weibo/include/SocialWeibo.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
classes = SocialWeibo
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = *::[createPlugin]
rename_functions =
rename_classes =
# for all class names, should we remove something when registering in the target VM?
remove_prefix =
# classes for which there will be no "parent" lookup
classes_have_no_parents =
# base classes which will be skipped when their sub-classes found them.
base_classes_to_skip =
# classes that create no constructor
# CCSet is special and we will use a hand-written constructor
abstract_classes = SocialWeibo
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = yes

View File

@ -1,77 +0,0 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "SocialWeibo.h"
#include "PluginUtils.h"
namespace cocos2d { namespace plugin {
PLUGIN_REGISTER_IMPL(SocialWeibo)
SocialWeibo::~SocialWeibo()
{
}
/**
@brief plugin initialization
*/
bool SocialWeibo::init()
{
return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.SocialWeibo");
}
/**
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
WeiboAppKey The app key of weibo account
WeiboRedirectUrl The redirect url of weibo account
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void SocialWeibo::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
ProtocolSocial::configDeveloperInfo(devInfo);
}
/**
@brief pay for product
@param info The info of product, must contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
*/
void SocialWeibo::share(TShareInfo info)
{
ProtocolSocial::share(info);
}
const char* SocialWeibo::getSDKVersion()
{
return ProtocolSocial::getSDKVersion();
}
void SocialWeibo::setDebugMode(bool debug)
{
ProtocolSocial::setDebugMode(debug);
}
}} // namespace cocos2d { namespace plugin {

View File

@ -1,20 +0,0 @@
# set params
PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd)
if [ ! "${PLUGIN_ROOT}" ]; then
PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../..
fi
# build
"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \
NDK_MODULE_PATH="$PLUGIN_ROOT"
echo
if [ "0" != "$?" ]; then
echo "Build error occoured!!!"
exit 1
fi
echo
echo "Native build action success."
exit 0

View File

@ -1,29 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := PluginWeiboStatic
LOCAL_MODULE_FILENAME := libPluginWeiboStatic
LOCAL_SRC_FILES := \
$(addprefix ../../platform/android/, \
SocialWeibo.cpp \
) \
LOCAL_CFLAGS :=
LOCAL_EXPORT_CFLAGS :=
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic
LOCAL_LDLIBS := -landroid
LOCAL_LDLIBS += -llog
include $(BUILD_STATIC_LIBRARY)
$(call import-module, protocols/proj.android/jni)

View File

@ -1,7 +0,0 @@
# it is needed for ndk-r5
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_MODULES := PluginWeiboStatic
APP_ABI :=armeabi
#APP_ABI :=x86
#APP_ABI :=mips mips-r2 mips-r2-sf armeabi

View File

@ -26,7 +26,6 @@ package org.cocos2dx.plugin;
import java.io.IOException;
import java.util.Hashtable;
import org.cocos2dx.plugin.InterfaceSocial.ShareAdapter;
import com.weibo.sdk.android.Oauth2AccessToken;
import com.weibo.sdk.android.Weibo;
@ -43,7 +42,7 @@ import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
public class SocialWeibo implements ShareAdapter {
public class SocialWeibo implements InterfaceSocial {
private static final String LOG_TAG = "SocialWeibo";
private static Activity mContext = null;
@ -109,12 +108,12 @@ public class SocialWeibo implements ShareAdapter {
LogD("share invoked " + info.toString());
mShareInfo = info;
if (! networkReachable()) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Network error!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "Network error!");
return;
}
if (! isInitialized) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Initialize failed!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "Initialize failed!");
return;
}
@ -154,7 +153,7 @@ public class SocialWeibo implements ShareAdapter {
}
public static void shareResult(int ret, String msg) {
InterfaceSocial.onShareResult(mSocialAdapter, ret, msg);
SocialWrapper.onShareResult(mSocialAdapter, ret, msg);
LogD("SocialWeibo result : " + ret + " msg : " + msg);
}
@ -170,24 +169,24 @@ public class SocialWeibo implements ShareAdapter {
mSocialAdapter.shareToWeibo();
} catch (Exception e) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "认证失败!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "认证失败!");
LogE("anthorize failed", e);
}
}
@Override
public void onError(WeiboDialogError e) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, e.getMessage());
shareResult(SocialWrapper.SHARERESULT_FAIL, e.getMessage());
}
@Override
public void onCancel() {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "取消认证!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "取消认证!");
}
@Override
public void onWeiboException(WeiboException e) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, e.getMessage());
shareResult(SocialWrapper.SHARERESULT_FAIL, e.getMessage());
}
}
@ -206,19 +205,24 @@ public class SocialWeibo implements ShareAdapter {
@Override
public void onComplete(String arg0) {
shareResult(InterfaceSocial.SHARERESULT_SUCCESS, "分享成功!");
shareResult(SocialWrapper.SHARERESULT_SUCCESS, "分享成功!");
}
@Override
public void onError(WeiboException arg0) {
LogE("Share onError", arg0);
shareResult(InterfaceSocial.SHARERESULT_FAIL, "分享失败!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "分享失败!");
}
@Override
public void onIOException(IOException arg0) {
LogE("Share onIOException", arg0);
shareResult(InterfaceSocial.SHARERESULT_FAIL, "分享失败!");
shareResult(SocialWrapper.SHARERESULT_FAIL, "分享失败!");
}
}
@Override
public String getPluginVersion() {
return "0.2.0";
}
}

View File

@ -77,6 +77,10 @@ PluginProtocol* PluginManager::loadPlugin(const char* name)
it->second = PluginFactory::getInstance()->createPlugin(name);
}
pRet = it->second;
} else
{
pRet = PluginFactory::getInstance()->createPlugin(name);
m_pluginsMap["name"] = pRet;
}
} while (false);

View File

@ -38,9 +38,7 @@ enum {
kPluginSocial,
};
#define ANDROID_PLUGIN_TYPE_FIELD "PluginType"
#define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugins/"
#define BREAK_IF(cond) if(cond) break
#define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugin/"
static PluginFactory* s_pFactory = NULL;
@ -91,6 +89,7 @@ PluginProtocol* PluginFactory::createPlugin(const char* name)
, "initPlugin"
, "(Ljava/lang/String;)Ljava/lang/Object;"))
{
PluginUtils::outputLog("PluginFactory", "Can't find method initPlugin in class org.cocos2dx.plugin.PluginWrapper");
break;
}
@ -98,13 +97,22 @@ PluginProtocol* PluginFactory::createPlugin(const char* name)
jobject jObj = t.env->CallStaticObjectMethod(t.classID, t.methodID, clsName);
t.env->DeleteLocalRef(clsName);
t.env->DeleteLocalRef(t.classID);
BREAK_IF(jObj == NULL);
if (jObj == NULL)
{
PluginUtils::outputLog("PluginFactory", "Can't find java class %s", jClassName.c_str());
break;
}
jclass jcls = t.env->FindClass(jClassName.c_str());
jfieldID fid_Type = t.env->GetFieldID(jcls, ANDROID_PLUGIN_TYPE_FIELD, "I");
BREAK_IF(fid_Type == NULL);
int curType = t.env->GetIntField(jObj, fid_Type);
if (! PluginJniHelper::getStaticMethodInfo(t
, "org/cocos2dx/plugin/PluginWrapper"
, "getPluginType"
, "(Ljava/lang/Object;)I"))
{
PluginUtils::outputLog("PluginFactory", "Can't find method getPluginType in class org.cocos2dx.plugin.PluginWrapper");
break;
}
int curType = t.env->CallStaticIntMethod(t.classID, t.methodID, jObj);
t.env->DeleteLocalRef(t.classID);
PluginUtils::outputLog("PluginFactory", "The type of plugin %s is : %d", name, curType);
switch (curType)

View File

@ -115,5 +115,3 @@ void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param)
}
}} //namespace cocos2d { namespace plugin {
#endif /* __CCX_IPLUGIN_H__ */

View File

@ -98,6 +98,10 @@ PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj)
ret = it->second;
}
if (NULL != ret)
{
outputLog("PluginUtils", "get plugin java data : %s, %p", ret->jclassName.c_str(), ret->jobj);
}
return ret;
}

View File

@ -56,6 +56,8 @@ public:
return_if_fails(funcName != NULL && strlen(funcName) > 0);
return_if_fails(paramCode != NULL && strlen(paramCode) > 0);
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz);
return_if_fails(pData != NULL);
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
@ -71,6 +73,8 @@ public:
{
return_if_fails(funcName != NULL && strlen(funcName) > 0);
PluginJavaData* pData = PluginUtils::getPluginJavaData(thiz);
return_if_fails(pData != NULL);
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()

View File

@ -30,7 +30,7 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsWrapper_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) {
std::string strMsg = PluginJniHelper::jstring2string(msg);
std::string strClassName = PluginJniHelper::jstring2string(className);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
@ -46,7 +46,7 @@ extern "C" {
}
}
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsWrapper_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) {
std::string strClassName = PluginJniHelper::jstring2string(className);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin);

View File

@ -30,7 +30,7 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg)
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_IAPWrapper_nativeOnPayResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg)
{
std::string strMsg = PluginJniHelper::jstring2string(msg);
std::string strClassName = PluginJniHelper::jstring2string(className);

View File

@ -30,7 +30,7 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg)
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_SocialWrapper_nativeOnShareResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg)
{
std::string strMsg = PluginJniHelper::jstring2string(msg);
std::string strClassName = PluginJniHelper::jstring2string(className);

View File

@ -11,6 +11,7 @@ $(addprefix ../../platform/android/, \
PluginFactory.cpp \
PluginJniHelper.cpp \
PluginUtils.cpp \
PluginProtocol.cpp \
ProtocolAnalytics.cpp \
ProtocolIAP.cpp \
ProtocolAds.cpp \

View File

@ -23,8 +23,6 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

View File

@ -23,8 +23,6 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
public class IAPWrapper {
public static final int PAYRESULT_SUCCESS = 0;
public static final int PAYRESULT_FAIL = 1;

View File

@ -23,6 +23,8 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.lang.reflect.Field;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Handler;
@ -75,6 +77,20 @@ public class PluginWrapper {
return null;
}
protected static int getPluginType(Object obj) {
int nRet = -1;
try
{
Field filedID = obj.getClass().getField("PluginType");
Integer nObj = (Integer) filedID.get(obj);
nRet = nObj.intValue();
} catch (Exception e) {
e.printStackTrace();
}
return nRet;
}
public static Context getContext() {
return sContext;
}

View File

@ -23,8 +23,6 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
public class SocialWrapper {
public static final int SHARERESULT_SUCCESS = 0;
public static final int SHARERESULT_FAIL = 1;

View File

@ -75,40 +75,46 @@ void MySocialManager::loadSocialPlugin()
{
// init twitter plugin
s_pTwitter = dynamic_cast<SocialTwitter*>(PluginManager::getInstance()->loadPlugin("SocialTwitter"));
TSocialDeveloperInfo pTwitterInfo;
/* Warning: must set your twiiter dev info here */
// pTwitterInfo["TwitterKey"] = "your consumerkey";
// pTwitterInfo["TwitterSecret"] = "your consumersecret";
if (pTwitterInfo.empty())
s_pTwitter = dynamic_cast<ProtocolSocial*>(PluginManager::getInstance()->loadPlugin("SocialTwitter"));
if (NULL != s_pTwitter)
{
char msg[256] = { 0 };
sprintf(msg, "Developer info is empty. PLZ fill your twitter info in %s(nearby line %d)", __FILE__, __LINE__);
CCMessageBox(msg, "Twitter Warning");
TSocialDeveloperInfo pTwitterInfo;
/* Warning: must set your twiiter dev info here */
// pTwitterInfo["TwitterKey"] = "your consumerkey";
// pTwitterInfo["TwitterSecret"] = "your consumersecret";
if (pTwitterInfo.empty())
{
char msg[256] = { 0 };
sprintf(msg, "Developer info is empty. PLZ fill your twitter info in %s(nearby line %d)", __FILE__, __LINE__);
CCMessageBox(msg, "Twitter Warning");
}
s_pTwitter->setDebugMode(true);
s_pTwitter->configDeveloperInfo(pTwitterInfo);
s_pTwitter->setResultListener(s_pRetListener);
}
s_pTwitter->setDebugMode(true);
s_pTwitter->configDeveloperInfo(pTwitterInfo);
s_pTwitter->setResultListener(s_pRetListener);
}
{
s_pWeibo = dynamic_cast<SocialWeibo*>(PluginManager::getInstance()->loadPlugin("SocialWeibo"));
TSocialDeveloperInfo pWeiboInfo;
// pWeiboInfo["WeiboAppKey"] = "your app key";
// pWeiboInfo["WeiboRedirectUrl"] = "your redirect url";
if (pWeiboInfo.empty())
s_pWeibo = dynamic_cast<ProtocolSocial*>(PluginManager::getInstance()->loadPlugin("SocialWeibo"));
if (NULL != s_pWeibo)
{
char msg[256] = { 0 };
sprintf(msg, "Developer info is empty. PLZ fill your weibo info in %s(nearby line %d)", __FILE__, __LINE__);
CCMessageBox(msg, "Weibo Warning");
}
TSocialDeveloperInfo pWeiboInfo;
// pWeiboInfo["WeiboAppKey"] = "your app key";
// pWeiboInfo["WeiboRedirectUrl"] = "your redirect url";
s_pWeibo->setDebugMode(true);
s_pWeibo->configDeveloperInfo(pWeiboInfo);
s_pWeibo->setResultListener(s_pRetListener);
if (pWeiboInfo.empty())
{
char msg[256] = { 0 };
sprintf(msg, "Developer info is empty. PLZ fill your weibo info in %s(nearby line %d)", __FILE__, __LINE__);
CCMessageBox(msg, "Weibo Warning");
}
s_pWeibo->setDebugMode(true);
s_pWeibo->configDeveloperInfo(pWeiboInfo);
s_pWeibo->setResultListener(s_pRetListener);
}
}
}

View File

@ -24,8 +24,7 @@ THE SOFTWARE.
#ifndef __MY_SOCIAL_MANAGER_H__
#define __MY_SOCIAL_MANAGER_H__
#include "SocialTwitter.h"
#include "SocialWeibo.h"
#include "ProtocolSocial.h"
class MyShareResult : public cocos2d::plugin::ShareResultListener
{
@ -55,8 +54,8 @@ private:
static MySocialManager* s_pManager;
cocos2d::plugin::SocialTwitter* s_pTwitter;
cocos2d::plugin::SocialWeibo* s_pWeibo;
cocos2d::plugin::ProtocolSocial* s_pTwitter;
cocos2d::plugin::ProtocolSocial* s_pWeibo;
MyShareResult* s_pRetListener;
};

View File

@ -14,13 +14,9 @@ LOCAL_SRC_FILES := hellocpp/main.cpp \
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static \
PluginTwitterStatic \
PluginProtocolStatic \
PluginWeiboStatic
PluginProtocolStatic
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,plugins/twitter/android)
$(call import-module,plugins/weibo/android)
$(call import-module,protocols/android)

View File

@ -29,7 +29,7 @@ echo
echo
echo Now publish protocols
echo ---------------------------------
./toolsForPublish/publishPlugin.sh "protocols" ${TARGET_ROOT} ${PLUGIN_ROOT}
./toolsForPublish/publishPlugin.sh "protocols" ${TARGET_ROOT} ${PLUGIN_ROOT} 1
echo ---------------------------------
#publish plugins

View File

@ -9,10 +9,6 @@ echo android project dir is ${ANDROID_PROJ_DIR}
#create directory for plugin
mkdir -p ${TARGET_DIR}
#create include directory
mkdir -p ${TARGET_DIR}/include
cp -rf ${PLUGIN_ROOT}/${plugin_name}/include/* ${TARGET_DIR}/include
###############################
# functions used
###############################
@ -84,25 +80,6 @@ if [ -d ${ANDROID_PROJ_DIR}/sdk ]; then
cp -rf ${ANDROID_PROJ_DIR}/sdk/*.jar ${TARGET_DIR}/android
fi
#copy android include files
ADNROID_SOURCE_DIR=${PLUGIN_ROOT}/${plugin_name}/platform/android
if [ -d ${ADNROID_SOURCE_DIR} ]; then
HAVE_HEADER_FILE=`find ${ADNROID_SOURCE_DIR} -name "*.h"`
if [ -n "${HAVE_HEADER_FILE}" ]; then
cp -rf ${ADNROID_SOURCE_DIR}/*.h "${TARGET_DIR}/android"
fi
fi
#invoke ndk build for plugin project
if [ -f "${ANDROID_PROJ_DIR}/build_native.sh" ]; then
./build_native.sh
LIB_FILE="$(getLibraryFileName)"
cp -rf "${ANDROID_PROJ_DIR}/obj/local/armeabi/${LIB_FILE}" "${TARGET_DIR}/android"
fi
#generate mk file for prebuild
${PLUGIN_ROOT}/tools/toolsForPublish/genPrebuildMK.sh ${ANDROID_PROJ_DIR}/jni/Android.mk ${TARGET_DIR}/android/Android.mk
#copy android depend on project to publish directory
if [ -d "${ADNROID_SOURCE_DIR}/DependProject" ]; then
cp -rf "${ADNROID_SOURCE_DIR}/DependProject" "${TARGET_DIR}/android"
@ -123,4 +100,34 @@ if [ -d "${ANDROID_PROJ_DIR}/ForAssets" ]; then
cp -rf "${ANDROID_PROJ_DIR}/ForAssets" "${TARGET_DIR}/android"
fi
#Build C++ code
BUILD_CPLUSPLUS=$4
if [ $BUILD_CPLUSPLUS ]; then
echo "Build C++ code"
#create include directory
mkdir -p ${TARGET_DIR}/include
cp -rf ${PLUGIN_ROOT}/${plugin_name}/include/* ${TARGET_DIR}/include
#copy android include files
ADNROID_SOURCE_DIR=${PLUGIN_ROOT}/${plugin_name}/platform/android
if [ -d ${ADNROID_SOURCE_DIR} ]; then
HAVE_HEADER_FILE=`find ${ADNROID_SOURCE_DIR} -name "*.h"`
if [ -n "${HAVE_HEADER_FILE}" ]; then
cp -rf ${ADNROID_SOURCE_DIR}/*.h "${TARGET_DIR}/android"
fi
fi
#invoke ndk build for plugin project
if [ -f "${ANDROID_PROJ_DIR}/build_native.sh" ]; then
./build_native.sh
LIB_FILE="$(getLibraryFileName)"
cp -rf "${ANDROID_PROJ_DIR}/obj/local/armeabi/${LIB_FILE}" "${TARGET_DIR}/android"
fi
#generate mk file for prebuild
${PLUGIN_ROOT}/tools/toolsForPublish/genPrebuildMK.sh ${ANDROID_PROJ_DIR}/jni/Android.mk ${TARGET_DIR}/android/Android.mk
fi
popd