Skip to content

Commit 25a0927

Browse files
author
minggo
committed
Merge pull request #2419 from natural-law/master
Add protocol Ads & plugin Admob
2 parents ec43617 + 155064e commit 25a0927

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1887
-41
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef __CCX_ADS_ADMOB_H__
2+
#define __CCX_ADS_ADMOB_H__
3+
4+
#include "ProtocolAds.h"
5+
#include <map>
6+
#include <string>
7+
8+
namespace cocos2d { namespace plugin {
9+
10+
class AdsAdmob : public ProtocolAds
11+
{
12+
PLUGIN_REGISTER_DECL(AdsAdmob)
13+
public:
14+
15+
typedef enum {
16+
eSizeBanner = 0,
17+
eSizeIABMRect,
18+
eSizeIABBanner,
19+
eSizeIABLeaderboard,
20+
} ESizeAdmobBanner;
21+
22+
/**
23+
@brief plugin initialization
24+
*/
25+
virtual bool init();
26+
27+
/**
28+
@brief initialize the application info
29+
@param appInfo This parameter is the info of application, must contains:
30+
AdmobID The publisher ID of admob.
31+
@warning Must invoke this interface before other interfaces.
32+
And invoked only once.
33+
*/
34+
virtual void initAppInfo(TAppInfo appInfo);
35+
36+
/**
37+
@brief show banner ads at specified position
38+
@param pos The position where the banner view be shown
39+
@param sizeEnum The size of the banner view. Use the value in ESizeAdmobBanner
40+
*/
41+
virtual void showBannerAd(EBannerPos pos, int sizeEnum);
42+
43+
/**
44+
@brief hide the banner ads view
45+
*/
46+
virtual void hideBannerAd();
47+
48+
/**
49+
@brief Set whether needs to output logs to console.
50+
@param debug if true debug mode enabled, or debug mode disabled.
51+
*/
52+
virtual void setDebugMode(bool debug);
53+
54+
/**
55+
@brief Add the test device ID
56+
@param deviceID The device ID
57+
*/
58+
void addTestDevice(const char* deviceID);
59+
60+
virtual const char* getPluginVersion() { return "v0.1.01"; };
61+
virtual const char* getSDKVersion();
62+
63+
virtual ~AdsAdmob();
64+
};
65+
66+
}} // namespace cocos2d { namespace plugin {
67+
68+
#endif /* __CCX_ADS_ADMOB_H__ */

plugin/plugins/admob/jsb_admob.ini

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[admob]
2+
# the prefix to be added to the generated functions. You might or might not use this in your own
3+
# templates
4+
prefix = pluginx_admob
5+
6+
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
7+
# all classes will be embedded in that namespace
8+
target_namespace = plugin
9+
10+
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
11+
android_flags = -D_SIZE_T_DEFINED_
12+
13+
clang_headers = -I%(clangllvmdir)s/lib/clang/3.1/include
14+
clang_flags = -nostdinc -x c++
15+
16+
cocos_headers = -I%(pluginxdir)s/protocols/include -I%(pluginxdir)s/plugins/admob/include
17+
18+
cocos_flags = -DANDROID
19+
20+
cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
21+
22+
# extra arguments for clang
23+
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
24+
25+
# what headers to parse
26+
headers = %(pluginxdir)s/plugins/admob/include/IAPAlipay.h
27+
28+
# what classes to produce code for. You can use regular expressions here. When testing the regular
29+
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
30+
classes = IAPAlipay
31+
32+
# what should we skip? in the format ClassName::[function function]
33+
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
34+
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
35+
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
36+
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
37+
# functions from all classes.
38+
39+
skip = *::[createPlugin]
40+
41+
rename_functions =
42+
43+
rename_classes =
44+
45+
# for all class names, should we remove something when registering in the target VM?
46+
remove_prefix =
47+
48+
# classes for which there will be no "parent" lookup
49+
classes_have_no_parents =
50+
51+
# base classes which will be skipped when their sub-classes found them.
52+
base_classes_to_skip =
53+
54+
# classes that create no constructor
55+
# CCSet is special and we will use a hand-written constructor
56+
abstract_classes = IAPAlipay
57+
58+
# 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'.
59+
script_control_cpp = yes
60+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "AdsAdmob.h"
2+
#include "PluginUtils.h"
3+
4+
namespace cocos2d { namespace plugin {
5+
6+
PLUGIN_REGISTER_IMPL(AdsAdmob)
7+
8+
AdsAdmob::~AdsAdmob()
9+
{
10+
}
11+
12+
bool AdsAdmob::init()
13+
{
14+
return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.AdsAdmob");
15+
}
16+
17+
void AdsAdmob::initAppInfo(TAppInfo appInfo)
18+
{
19+
ProtocolAds::initAppInfo(appInfo);
20+
}
21+
22+
void AdsAdmob::showBannerAd(EBannerPos pos, int sizeEnum)
23+
{
24+
ProtocolAds::showBannerAd(pos, sizeEnum);
25+
}
26+
27+
void AdsAdmob::hideBannerAd()
28+
{
29+
ProtocolAds::hideBannerAd();
30+
}
31+
32+
const char* AdsAdmob::getSDKVersion()
33+
{
34+
return ProtocolAds::getSDKVersion();
35+
}
36+
37+
void AdsAdmob::setDebugMode(bool debug)
38+
{
39+
ProtocolAds::setDebugMode(debug);
40+
}
41+
42+
void AdsAdmob::addTestDevice(const char* deviceID)
43+
{
44+
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
45+
PluginJniMethodInfo t;
46+
if (PluginJniHelper::getMethodInfo(t
47+
, pData->jclassName.c_str()
48+
, "addTestDevice"
49+
, "(Ljava/lang/String;)V"))
50+
{
51+
jstring strDeviceID = t.env->NewStringUTF(deviceID);
52+
t.env->CallVoidMethod(pData->jobj, t.methodID, strDeviceID);
53+
t.env->DeleteLocalRef(strDeviceID);
54+
t.env->DeleteLocalRef(t.classID);
55+
}
56+
}
57+
58+
}} // namespace cocos2d { namespace plugin {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry exported="true" kind="lib" path="sdk/GoogleAdMobAdsSdk.jar"/>
8+
<classpathentry kind="output" path="bin/classes"/>
9+
</classpath>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>libPluginAdmob</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
<linkedResources>
34+
<link>
35+
<name>android</name>
36+
<type>2</type>
37+
<locationURI>PARENT-1-PROJECT_LOC/platform/android</locationURI>
38+
</link>
39+
<link>
40+
<name>include</name>
41+
<type>2</type>
42+
<locationURI>PARENT-1-PROJECT_LOC/include</locationURI>
43+
</link>
44+
</linkedResources>
45+
</projectDescription>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="org.cocos2dx.libAdsAdmob"
3+
android:versionCode="1"
4+
android:versionName="1.0">
5+
6+
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
7+
8+
9+
</manifest>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifestConfig xmlns:android="http://schemas.android.com/apk/res/android">
3+
<applicationCfg keyword="com.google.ads.AdActivity">
4+
<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
5+
</applicationCfg>
6+
7+
<permissionCfg>
8+
<uses-permission android:name="android.permission.INTERNET"/>
9+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
10+
</permissionCfg>
11+
</manifestConfig>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="libPluginAdmob" default="plugin-publish">
3+
4+
<!-- The local.properties file is created and updated by the 'android' tool.
5+
It contains the path to the SDK. It should *NOT* be checked into
6+
Version Control Systems. -->
7+
<property file="local.properties" />
8+
9+
<!-- The ant.properties file can be created by you. It is only edited by the
10+
'android' tool to add properties to it.
11+
This is the place to change some Ant specific build properties.
12+
Here are some properties you may want to change/update:
13+
14+
source.dir
15+
The name of the source directory. Default is 'src'.
16+
out.dir
17+
The name of the output directory. Default is 'bin'.
18+
19+
For other overridable properties, look at the beginning of the rules
20+
files in the SDK, at tools/ant/build.xml
21+
22+
Properties related to the SDK location or the project target should
23+
be updated using the 'android' tool with the 'update' action.
24+
25+
This file is an integral part of the build system for your
26+
application and should be checked into Version Control Systems.
27+
28+
-->
29+
<property file="ant.properties" />
30+
31+
<!-- if sdk.dir was not set from one of the property file, then
32+
get it from the ANDROID_HOME env var.
33+
This must be done before we load project.properties since
34+
the proguard config can use sdk.dir -->
35+
<property environment="env" />
36+
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
37+
<isset property="env.ANDROID_HOME" />
38+
</condition>
39+
40+
<!-- The project.properties file is created and updated by the 'android'
41+
tool, as well as ADT.
42+
43+
This contains project specific properties such as project target, and library
44+
dependencies. Lower level build properties are stored in ant.properties
45+
(or in .classpath for Eclipse projects).
46+
47+
This file is an integral part of the build system for your
48+
application and should be checked into Version Control Systems. -->
49+
<loadproperties srcFile="project.properties" />
50+
51+
<!-- quick check on sdk.dir -->
52+
<fail
53+
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
54+
unless="sdk.dir"
55+
/>
56+
57+
<!--
58+
Import per project custom build rules if present at the root of the project.
59+
This is the place to put custom intermediary targets such as:
60+
-pre-build
61+
-pre-compile
62+
-post-compile (This is typically used for code obfuscation.
63+
Compiled code location: ${out.classes.absolute.dir}
64+
If this is not done in place, override ${out.dex.input.absolute.dir})
65+
-post-package
66+
-post-build
67+
-pre-clean
68+
-->
69+
<import file="custom_rules.xml" optional="true" />
70+
71+
<!-- Import the actual build file.
72+
73+
To customize existing targets, there are two options:
74+
- Customize only one target:
75+
- copy/paste the target into this file, *before* the
76+
<import> task.
77+
- customize it to your needs.
78+
- Customize the whole content of build.xml
79+
- copy/paste the content of the rules files (minus the top node)
80+
into this file, replacing the <import> task.
81+
- customize to your needs.
82+
83+
***********************
84+
****** IMPORTANT ******
85+
***********************
86+
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
87+
in order to avoid having your file be overridden by tools such as "android update project"
88+
-->
89+
<!-- version-tag: 1 -->
90+
<import file="${plugin.dir}/tools/android/build_common.xml" />
91+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# set params
2+
PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd)
3+
4+
if [ ! "${PLUGIN_ROOT}" ]; then
5+
PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../..
6+
fi
7+
8+
# build
9+
"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \
10+
NDK_MODULE_PATH="$PLUGIN_ROOT"
11+
12+
echo
13+
if [ "0" != "$?" ]; then
14+
echo "Build error occoured!!!"
15+
exit 1
16+
fi
17+
18+
echo
19+
echo "Native build action success."
20+
exit 0

0 commit comments

Comments
 (0)