mirror of https://github.com/axmolengine/axmol.git
closed #2317, Add sample project HelloUser.
This commit is contained in:
parent
1a6bfc0bf6
commit
f8a22bb134
|
@ -0,0 +1,54 @@
|
|||
#include "AppDelegate.h"
|
||||
#include "HelloWorldScene.h"
|
||||
#include "MyUserManager.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
AppDelegate::AppDelegate() {
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching() {
|
||||
MyUserManager::sharedManager()->loadPlugin();
|
||||
|
||||
// initialize director
|
||||
Director* pDirector = Director::sharedDirector();
|
||||
EGLView* pEGLView = EGLView::sharedOpenGLView();
|
||||
|
||||
pDirector->setOpenGLView(pEGLView);
|
||||
|
||||
pEGLView->setDesignResolutionSize(960.0f, 640.0f, kResolutionNoBorder);
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
Scene *pScene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
pDirector->runWithScene(pScene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground() {
|
||||
Director::sharedDirector()->stopAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground() {
|
||||
Director::sharedDirector()->startAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
#include "HelloWorldScene.h"
|
||||
#include "MyUserManager.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
const std::string s_aTestCases[] = {
|
||||
"QH360",
|
||||
};
|
||||
|
||||
Scene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object
|
||||
Scene *scene = Scene::create();
|
||||
|
||||
// 'layer' is an autorelease object
|
||||
HelloWorld *layer = HelloWorld::create();
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
// on "init" you need to initialize your instance
|
||||
bool HelloWorld::init()
|
||||
{
|
||||
//////////////////////////////
|
||||
// 1. super init first
|
||||
if ( !Layer::init() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Size visibleSize = Director::sharedDirector()->getVisibleSize();
|
||||
Point origin = Director::sharedDirector()->getVisibleOrigin();
|
||||
Point posMid = ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
|
||||
|
||||
/////////////////////////////
|
||||
// 2. add a menu item with "X" image, which is clicked to quit the program
|
||||
// you may modify it.
|
||||
|
||||
// add a "close" icon to exit the progress. it's an autorelease object
|
||||
MenuItemImage *pCloseItem = MenuItemImage::create(
|
||||
"CloseNormal.png",
|
||||
"CloseSelected.png",
|
||||
CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
|
||||
|
||||
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
|
||||
origin.y + pCloseItem->getContentSize().height/2));
|
||||
|
||||
// create menu, it's an autorelease object
|
||||
Menu* pMenu = Menu::create(pCloseItem, NULL);
|
||||
pMenu->setPosition(PointZero);
|
||||
|
||||
LabelTTF* label1 = LabelTTF::create("Login", "Arial", 32);
|
||||
MenuItemLabel* pItemLogin = MenuItemLabel::create(label1, CC_CALLBACK_1(HelloWorld::testLogin, this));
|
||||
pItemLogin->setAnchorPoint(ccp(0.5f, 0));
|
||||
pMenu->addChild(pItemLogin, 0);
|
||||
pItemLogin->setPosition(ccpAdd(posMid, ccp(-100, -120)));
|
||||
|
||||
LabelTTF* label2 = LabelTTF::create("Logout", "Arial", 32);
|
||||
MenuItemLabel* pItemLogout = MenuItemLabel::create(label2, CC_CALLBACK_1(HelloWorld::testLogout, this));
|
||||
pItemLogout->setAnchorPoint(ccp(0.5f, 0));
|
||||
pMenu->addChild(pItemLogout, 0);
|
||||
pItemLogout->setPosition(ccpAdd(posMid, ccp(100, -120)));
|
||||
|
||||
// create optional menu
|
||||
// cases item
|
||||
_caseItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(HelloWorld::caseChanged, this),
|
||||
MenuItemFont::create( s_aTestCases[0].c_str() ),
|
||||
NULL );
|
||||
int caseLen = sizeof(s_aTestCases) / sizeof(std::string);
|
||||
for (int i = 1; i < caseLen; ++i)
|
||||
{
|
||||
_caseItem->getSubItems()->addObject( MenuItemFont::create( s_aTestCases[i].c_str() ) );
|
||||
}
|
||||
_caseItem->setPosition(ccpAdd(posMid, ccp(0, 120)));
|
||||
pMenu->addChild(_caseItem);
|
||||
|
||||
_selectedCase = 0;
|
||||
|
||||
this->addChild(pMenu, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HelloWorld::caseChanged(Object* pSender)
|
||||
{
|
||||
_selectedCase = _caseItem->getSelectedIndex();
|
||||
}
|
||||
|
||||
void HelloWorld::testLogin(Object* pSender)
|
||||
{
|
||||
MyUserManager::sharedManager()->loginByMode((MyUserManager::MyUserMode) (_selectedCase + 1));
|
||||
}
|
||||
|
||||
void HelloWorld::testLogout(Object* pSender)
|
||||
{
|
||||
MyUserManager::sharedManager()->logoutByMode((MyUserManager::MyUserMode) (_selectedCase + 1));
|
||||
}
|
||||
|
||||
void HelloWorld::menuCloseCallback(Object* pSender)
|
||||
{
|
||||
Director::sharedDirector()->end();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
exit(0);
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef __HELLOWORLD_SCENE_H__
|
||||
#define __HELLOWORLD_SCENE_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
class HelloWorld : public cocos2d::Layer
|
||||
{
|
||||
public:
|
||||
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
|
||||
virtual bool init();
|
||||
|
||||
// there's no 'id' in cpp, so we recommend returning the class instance pointer
|
||||
static cocos2d::Scene* scene();
|
||||
|
||||
// a selector callback
|
||||
void menuCloseCallback(Object* pSender);
|
||||
void testLogin(Object* pSender);
|
||||
void testLogout(Object* pSender);
|
||||
|
||||
void caseChanged(Object* pSender);
|
||||
|
||||
// implement the "static node()" method manually
|
||||
CREATE_FUNC(HelloWorld);
|
||||
|
||||
private:
|
||||
cocos2d::MenuItemToggle* _caseItem;
|
||||
int _selectedCase;
|
||||
};
|
||||
|
||||
#endif // __HELLOWORLD_SCENE_H__
|
|
@ -0,0 +1,149 @@
|
|||
/****************************************************************************
|
||||
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 "MyUserManager.h"
|
||||
#include "PluginManager.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
using namespace cocos2d::plugin;
|
||||
using namespace cocos2d;
|
||||
|
||||
MyUserManager* MyUserManager::s_pManager = NULL;
|
||||
|
||||
MyUserManager::MyUserManager()
|
||||
: _retListener(NULL)
|
||||
, _qh360(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MyUserManager::~MyUserManager()
|
||||
{
|
||||
unloadPlugin();
|
||||
if (_retListener)
|
||||
{
|
||||
delete _retListener;
|
||||
_retListener = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
MyUserManager* MyUserManager::sharedManager()
|
||||
{
|
||||
if (s_pManager == NULL) {
|
||||
s_pManager = new MyUserManager();
|
||||
}
|
||||
return s_pManager;
|
||||
}
|
||||
|
||||
void MyUserManager::purgeManager()
|
||||
{
|
||||
if (s_pManager)
|
||||
{
|
||||
delete s_pManager;
|
||||
s_pManager = NULL;
|
||||
}
|
||||
PluginManager::end();
|
||||
}
|
||||
|
||||
void MyUserManager::loadPlugin()
|
||||
{
|
||||
if (_retListener == NULL)
|
||||
{
|
||||
_retListener = new MyUserActionResult();
|
||||
}
|
||||
|
||||
{
|
||||
// init qh360 plugin
|
||||
_qh360 = dynamic_cast<ProtocolUser*>(PluginManager::getInstance()->loadPlugin("UserQH360"));
|
||||
if (NULL != _qh360)
|
||||
{
|
||||
_qh360->setDebugMode(true);
|
||||
_qh360->setActionListener(_retListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MyUserManager::unloadPlugin()
|
||||
{
|
||||
if (_qh360)
|
||||
{
|
||||
PluginManager::getInstance()->unloadPlugin("UserQH360");
|
||||
_qh360 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void MyUserManager::loginByMode(MyUserMode mode)
|
||||
{
|
||||
ProtocolUser* pUser = NULL;
|
||||
switch(mode)
|
||||
{
|
||||
case kQH360:
|
||||
pUser = _qh360;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pUser) {
|
||||
pUser->login();
|
||||
}
|
||||
}
|
||||
|
||||
void MyUserManager::logoutByMode(MyUserMode mode)
|
||||
{
|
||||
ProtocolUser* pUser = NULL;
|
||||
switch(mode)
|
||||
{
|
||||
case kQH360:
|
||||
pUser = _qh360;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pUser) {
|
||||
pUser->logout();
|
||||
}
|
||||
}
|
||||
|
||||
void MyUserActionResult::onActionResult(ProtocolUser* pPlugin, UserActionResultCode code, const char* msg)
|
||||
{
|
||||
char userStatus[1024] = { 0 };
|
||||
switch (code)
|
||||
{
|
||||
case kLoginSucceed:
|
||||
case kLoginFailed:
|
||||
sprintf(userStatus, "User of \"%s\" login %s", pPlugin->getPluginName(), (code == kLoginSucceed)? "Successed" : "Failed");
|
||||
break;
|
||||
case kLogoutSucceed:
|
||||
sprintf(userStatus, "User of \"%s\" logout", pPlugin->getPluginName());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
MessageBox(msg, userStatus);
|
||||
|
||||
// get session ID
|
||||
std::string sessionID = pPlugin->getSessionID();
|
||||
CCLog("User Session ID of plugin %s is : %s", pPlugin->getPluginName(), sessionID.c_str());
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/****************************************************************************
|
||||
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 __MY_USER_MANAGER_H__
|
||||
#define __MY_USER_MANAGER_H__
|
||||
|
||||
#include "ProtocolUser.h"
|
||||
|
||||
class MyUserActionResult : public cocos2d::plugin::UserActionListener
|
||||
{
|
||||
public:
|
||||
virtual void onActionResult(cocos2d::plugin::ProtocolUser* pPlugin, cocos2d::plugin::UserActionResultCode code, const char* msg);
|
||||
};
|
||||
|
||||
class MyUserManager
|
||||
{
|
||||
public:
|
||||
static MyUserManager* sharedManager();
|
||||
static void purgeManager();
|
||||
|
||||
typedef enum {
|
||||
kNoneMode = 0,
|
||||
kQH360,
|
||||
} MyUserMode;
|
||||
|
||||
void unloadPlugin();
|
||||
void loadPlugin();
|
||||
void loginByMode(MyUserMode mode);
|
||||
void logoutByMode(MyUserMode mode);
|
||||
|
||||
private:
|
||||
MyUserManager();
|
||||
virtual ~MyUserManager();
|
||||
|
||||
static MyUserManager* s_pManager;
|
||||
|
||||
cocos2d::plugin::ProtocolUser* _qh360;
|
||||
MyUserActionResult* _retListener;
|
||||
};
|
||||
|
||||
#endif // __MY_USER_MANAGER_H__
|
|
@ -0,0 +1 @@
|
|||
761ab0ca76abcdc06890e579f77fcdea6afa83c6
|
|
@ -0,0 +1 @@
|
|||
0cb89ef70f9172baa023fcbae9b87da09af2e776
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="lib" path="plugin-x/protocols/android/libPluginProtocol.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="plugin-x/plugins/qh360/android/360SDK.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="plugin-x/plugins/qh360/android/libPluginQH360.jar"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<projectDescription>
|
||||
<name>HelloUser</name>
|
||||
<comment />
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>Classes</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-1-PROJECT_LOC/Classes</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>plugin-x</name>
|
||||
<type>2</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/publish</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.cocos2dx.HelloUser" android:versionCode="1" android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
<uses-feature android:glEsVersion="0x00020000" />
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
|
||||
<activity android:configChanges="orientation" android:label="@string/app_name" android:name=".HelloUser" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:configChanges="orientation|keyboardHidden|navigation" android:name="com.qihoopay.insdk.activity.ContainerActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
||||
</activity>
|
||||
<activity android:configChanges="orientation|keyboardHidden|navigation|screenSize" android:name="com.qihoopay.insdk.activity.RemoteContainerActivity" android:process=":remote" android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
||||
</activity>
|
||||
|
||||
<meta-data android:name="QHOPENSDK_APPID" android:value="102094835" />
|
||||
<meta-data android:name="QHOPENSDK_APPKEY" android:value="8689e00460eabb1e66277eb4232fde6f" />
|
||||
<meta-data android:name="QHOPENSDK_PRIVATEKEY" android:value="4e04fe9ac8e2a73cbb27ba52ac076eb9" />
|
||||
<meta-data android:name="QHOPENSDK_CHANNEL" android:value="360PayDebug" />
|
||||
</application>
|
||||
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.GET_TASKS" />
|
||||
<uses-permission android:name="android.permission.READ_SMS" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
</manifest>
|
|
@ -0,0 +1,87 @@
|
|||
## Prerequisites:
|
||||
|
||||
* Android NDK
|
||||
* Android SDK **OR** Eclipse ADT Bundle
|
||||
* Android AVD target installed
|
||||
|
||||
## Building project
|
||||
|
||||
There are two ways of building Android projects.
|
||||
|
||||
1. Eclipse
|
||||
2. Command Line
|
||||
|
||||
### Import Project in Eclipse
|
||||
|
||||
#### Features:
|
||||
|
||||
1. Complete workflow from Eclipse, including:
|
||||
* Build C++.
|
||||
* Clean C++.
|
||||
* Build and Run whole project.
|
||||
* Logcat view.
|
||||
* Debug Java code.
|
||||
* Javascript editor.
|
||||
* Project management.
|
||||
2. True C++ editing, including:
|
||||
* Code completion.
|
||||
* Jump to definition.
|
||||
* Refactoring tools etc.
|
||||
* Quick open C++ files.
|
||||
|
||||
|
||||
#### Setup Eclipse Environment (only once)
|
||||
|
||||
|
||||
**NOTE:** This step needs to be done only once to setup the Eclipse environment for cocos2d-x projects. Skip this section if you've done this before.
|
||||
|
||||
1. Download Eclipse ADT bundle from [Google ADT homepage](http://developer.android.com/sdk/index.html)
|
||||
|
||||
**OR**
|
||||
|
||||
Install Eclipse with Java. Add ADT and CDT plugins.
|
||||
|
||||
2. Only for Windows
|
||||
1. Install [Cygwin](http://www.cygwin.com/) with make (select make package from the list during the install).
|
||||
2. Add `Cygwin\bin` directory to system PATH variable.
|
||||
3. Add this line `none /cygdrive cygdrive binary,noacl,posix=0,user 0 0` to `Cygwin\etc\fstab` file.
|
||||
|
||||
3. Set up Variables:
|
||||
1. Path Variable `COCOS2DX`:
|
||||
* Eclipse->Preferences->General->Workspace->**Linked Resources**
|
||||
* Click **New** button to add a Path Variable `COCOS2DX` pointing to the root cocos2d-x directory.
|
||||
![Example](https://lh5.googleusercontent.com/-oPpk9kg3e5w/UUOYlq8n7aI/AAAAAAAAsdQ/zLA4eghBH9U/s400/cocos2d-x-eclipse-vars.png)
|
||||
|
||||
2. C/C++ Environment Variable `NDK_ROOT`:
|
||||
* Eclipse->Preferences->C/C++->Build->**Environment**.
|
||||
* Click **Add** button and add a new variable `NDK_ROOT` pointing to the root NDK directory.
|
||||
![Example](https://lh3.googleusercontent.com/-AVcY8IAT0_g/UUOYltoRobI/AAAAAAAAsdM/22D2J9u3sig/s400/cocos2d-x-eclipse-ndk.png)
|
||||
* Only for Windows: Add new variables **CYGWIN** with value `nodosfilewarning` and **SHELLOPTS** with value `igncr`
|
||||
|
||||
4. Import libcocos2dx library project:
|
||||
1. File->New->Project->Android Project From Existing Code.
|
||||
2. Click **Browse** button and open `cocos2d-x/cocos2dx/platform/android/java` directory.
|
||||
3. Click **Finish** to add project.
|
||||
|
||||
#### Adding and running from Eclipse
|
||||
|
||||
![Example](https://lh3.googleusercontent.com/-SLBOu6e3QbE/UUOcOXYaGqI/AAAAAAAAsdo/tYBY2SylOSM/s288/cocos2d-x-eclipse-project-from-code.png) ![Import](https://lh5.googleusercontent.com/-XzC9Pn65USc/UUOcOTAwizI/AAAAAAAAsdk/4b6YM-oim9Y/s400/cocos2d-x-eclipse-import-project.png)
|
||||
|
||||
1. File->New->Project->Android Project From Existing Code
|
||||
2. **Browse** to your project directory. eg: `cocos2d-x/cocos2dx/samples/Cpp/TestCpp/proj.android/`
|
||||
3. Add the project
|
||||
4. Click **Run** or **Debug** to compile C++ followed by Java and to run on connected device or emulator.
|
||||
|
||||
|
||||
### Running project from Command Line
|
||||
|
||||
$ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/
|
||||
$ export NDK_ROOT=/path/to/ndk
|
||||
$ ./build_native.sh
|
||||
$ ant debug install
|
||||
|
||||
If the last command results in sdk.dir missing error then do:
|
||||
|
||||
$ android list target
|
||||
$ android update project -p . -t (id from step 6)
|
||||
$ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6)
|
|
@ -0,0 +1,17 @@
|
|||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="HelloUser" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
|
@ -0,0 +1,78 @@
|
|||
APPNAME="HelloUser"
|
||||
|
||||
# options
|
||||
|
||||
buildexternalsfromsource=
|
||||
|
||||
usage(){
|
||||
cat << EOF
|
||||
usage: $0 [options]
|
||||
|
||||
Build C/C++ code for $APPNAME using Android NDK
|
||||
|
||||
OPTIONS:
|
||||
-s Build externals from source
|
||||
-h this help
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts "sh" OPTION; do
|
||||
case "$OPTION" in
|
||||
s)
|
||||
buildexternalsfromsource=1
|
||||
;;
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# paths
|
||||
|
||||
if [ -z "${NDK_ROOT+aaa}" ];then
|
||||
echo "please define NDK_ROOT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
# ... use paths relative to current directory
|
||||
PLUGIN_ROOT="$DIR/../../.."
|
||||
COCOS2DX_ROOT="$DIR/../../../.."
|
||||
APP_ROOT="$DIR/.."
|
||||
APP_ANDROID_ROOT="$DIR"
|
||||
|
||||
echo "NDK_ROOT = $NDK_ROOT"
|
||||
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
|
||||
echo "APP_ROOT = $APP_ROOT"
|
||||
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
|
||||
|
||||
# make sure assets is exist
|
||||
if [ -d "$APP_ANDROID_ROOT"/assets ]; then
|
||||
rm -rf "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
|
||||
mkdir "$APP_ANDROID_ROOT"/assets
|
||||
|
||||
# copy resources
|
||||
for file in "$APP_ROOT"/Resources/*
|
||||
do
|
||||
if [ -d "$file" ]; then
|
||||
cp -rf "$file" "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
cp "$file" "$APP_ANDROID_ROOT"/assets
|
||||
fi
|
||||
done
|
||||
|
||||
# run ndk-build
|
||||
if [[ "$buildexternalsfromsource" ]]; then
|
||||
echo "Building external dependencies from source"
|
||||
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
|
||||
"NDK_MODULE_PATH=${PLUGIN_ROOT}/publish:${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
|
||||
else
|
||||
echo "Using prebuilt externals"
|
||||
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
|
||||
"NDK_MODULE_PATH=${PLUGIN_ROOT}/publish:${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
|
||||
fi
|
|
@ -0,0 +1,23 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := cocos2dcpp_shared
|
||||
|
||||
LOCAL_MODULE_FILENAME := libcocos2dcpp
|
||||
|
||||
LOCAL_SRC_FILES := hellocpp/main.cpp \
|
||||
../../Classes/AppDelegate.cpp \
|
||||
../../Classes/HelloWorldScene.cpp \
|
||||
../../Classes/MyUserManager.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
|
||||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static \
|
||||
PluginProtocolStatic
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
$(call import-module,cocos2dx)
|
||||
|
||||
$(call import-module,protocols/android)
|
|
@ -0,0 +1,3 @@
|
|||
APP_STL := gnustl_static
|
||||
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1 -std=c++11
|
||||
NDK_TOOLCHAIN_VERSION=4.7
|
|
@ -0,0 +1,48 @@
|
|||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
#include "CCEventType.h"
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include "PluginJniHelper.h"
|
||||
|
||||
#define LOG_TAG "main"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
JniHelper::setJavaVM(vm);
|
||||
PluginJniHelper::setJavaVM(vm);
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
|
||||
{
|
||||
if (!Director::sharedDirector()->getOpenGLView())
|
||||
{
|
||||
EGLView *view = EGLView::sharedOpenGLView();
|
||||
view->setFrameSize(w, h);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
Application::sharedApplication()->run();
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
ccDrawInit();
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
ShaderCache::sharedShaderCache()->reloadDefaultShaders();
|
||||
TextureCache::reloadAllTextures();
|
||||
NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
Director::sharedDirector()->setGLDefaultValues();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
|
@ -0,0 +1,13 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-17
|
||||
|
||||
android.library.reference.1=../../../../cocos2dx/platform/android/java
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">HelloUser</string>
|
||||
</resources>
|
|
@ -0,0 +1,52 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 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.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.HelloUser;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
|
||||
import org.cocos2dx.plugin.PluginWrapper;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class HelloUser extends Cocos2dxActivity{
|
||||
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
PluginWrapper.init(this);
|
||||
PluginWrapper.setGLSurfaceView(Cocos2dxGLSurfaceView.getInstance());
|
||||
}
|
||||
|
||||
public Cocos2dxGLSurfaceView onCreateView() {
|
||||
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
|
||||
// HelloUser should create stencil buffer
|
||||
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8);
|
||||
|
||||
return glSurfaceView;
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("cocos2dcpp");
|
||||
}
|
||||
}
|
|
@ -2,7 +2,8 @@
|
|||
export ALL_PLUGINS=("flurry" "umeng" \
|
||||
"alipay" "nd91" \
|
||||
"admob" \
|
||||
"twitter" "weibo")
|
||||
"twitter" "weibo" \
|
||||
"qh360")
|
||||
|
||||
# define the plugin root directory & publish target directory
|
||||
export TARGET_DIR_NAME="publish"
|
||||
|
|
Loading…
Reference in New Issue