Merge pull request #3047 from natural-law/develop

Add user login/logout plugin UC.
This commit is contained in:
James Chen 2013-07-03 18:47:16 -07:00
commit 31540768eb
16 changed files with 480 additions and 1 deletions

View File

@ -0,0 +1,10 @@
<?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="sdk/alipay_msp.jar"/>
<classpathentry exported="true" kind="lib" path="sdk/UCGameSDK.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libPluginUC</name>
<comment></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>
</projectDescription>

View File

@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.plugin"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
</manifest>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifestConfig xmlns:android="http://schemas.android.com/apk/res/android">
<applicationCfg keyword="cn.uc.gamesdk.view.SdkWebActivity">
<activity
android:name="cn.uc.gamesdk.view.SdkWebActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="cn.uc.gamesdk.sdkweb" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</applicationCfg>
<permissionCfg>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET" />
<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" />
</permissionCfg>
</manifestConfig>

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="libPluginUC" default="plugin-publish">
<!-- 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" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- 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 the ANDROID_HOME environment variable."
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="${plugin.dir}/tools/android/build_common.xml" />
</project>

View File

@ -0,0 +1,16 @@
# 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 edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library=true
android.library.reference.1=../../../protocols/proj.android

View File

View File

@ -0,0 +1 @@
ba5cc5fb902013d53136f6b198055643d5d8a045

Binary file not shown.

View File

@ -0,0 +1,232 @@
/****************************************************************************
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.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
import cn.uc.gamesdk.UCCallbackListener;
import cn.uc.gamesdk.UCGameSDK;
import cn.uc.gamesdk.UCGameSDKStatusCode;
import cn.uc.gamesdk.UCLogLevel;
import cn.uc.gamesdk.UCOrientation;
import cn.uc.gamesdk.info.GameParamInfo;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.util.Log;
public class UserUC implements InterfaceUser {
private static Context mContext = null;
protected static String TAG = "UserUC";
private static InterfaceUser mAdapter = null;
private boolean mLogined = false;
protected static void LogE(String msg, Exception e) {
Log.e(TAG, msg, e);
e.printStackTrace();
}
private static boolean isDebug = false;
private boolean isInited = false;
protected static void LogD(String msg) {
if (isDebug) {
Log.d(TAG, msg);
}
}
public UserUC(Context context) {
mContext = context;
mAdapter = this;
}
@Override
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
final Hashtable<String, String> curInfo = cpInfo;
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
String strCpId = curInfo.get("UCCpId");
String strGameId = curInfo.get("UCGameId");
String strServerId = curInfo.get("UCServerId");
int cpId = Integer.parseInt(strCpId);
int gameId = Integer.parseInt(strGameId);
int serverId = Integer.parseInt(strServerId);
GameParamInfo gpi = new GameParamInfo();
gpi.setCpId(cpId);
gpi.setGameId(gameId);
gpi.setServerId(serverId);
UCGameSDK.defaultSDK().setLogoutNotifyListener(new UCCallbackListener<String>() {
@Override
public void callback(int statuscode, String data) {
switch (statuscode) {
case UCGameSDKStatusCode.SUCCESS:
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGOUT_SUCCEED, "User Logout!");
mLogined = false;
break;
default:
break;
}
}
});
if (isLandscape()) {
UCGameSDK.defaultSDK().setOrientation(UCOrientation.LANDSCAPE);
}
UCGameSDK.defaultSDK().initSDK(mContext, UCLogLevel.ERROR, isDebug, gpi, new UCCallbackListener<String>() {
@Override
public void callback(int code, String msg) {
System.out.println("msg:" + msg);
switch (code) {
case UCGameSDKStatusCode.SUCCESS:
isInited = true;
break;
case UCGameSDKStatusCode.INIT_FAIL:
default:
isInited = false;
break;
}
}
});
} catch(Exception e) {
isInited = false;
LogE("Init SDK failed", e);
}
}
});
}
private static boolean waitHandle = true;
@Override
public void login() {
if (! isInited) {
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_FAILED, "SDK init failed");
return;
}
if (isLogined()) {
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, "Already logined!");
return;
}
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
waitHandle = true;
UCGameSDK.defaultSDK().login(mContext, new UCCallbackListener<String>() {
@Override
public void callback(int code, String msg) {
LogD("login ret : " + code + " , msg : " + msg);
if (! waitHandle) {
return;
}
switch(code) {
case UCGameSDKStatusCode.SUCCESS:
mLogined = true;
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_SUCCEED, msg);
break;
default:
mLogined = false;
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_FAILED, msg);
break;
}
waitHandle = false;
}
});
} catch (Exception e) {
mLogined = false;
LogE("Login failed", e);
UserWrapper.onActionResult(mAdapter, UserWrapper.ACTION_RET_LOGIN_FAILED, "Login Failed!");
}
}
});
}
@Override
public void logout() {
if (! isLogined()) {
LogD("User not logined!");
return;
}
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
UCGameSDK.defaultSDK().logout();
} catch (Exception e) {
LogE("User logout failed", e);
}
}
});
}
@Override
public boolean isLogined() {
return mLogined;
}
@Override
public String getSessionID() {
LogD("getSessionID() invoked!");
return UCGameSDK.defaultSDK().getSid();
}
@Override
public void setDebugMode(boolean debug) {
isDebug = debug;
}
@Override
public String getPluginVersion() {
return "0.2.0";
}
@Override
public String getSDKVersion() {
return "2.3.4";
}
private static boolean isLandscape()
{
Configuration config = mContext.getResources().getConfiguration();
int orientation = config.orientation;
if (orientation != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ||
orientation != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)
{
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
return (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}

View File

@ -34,6 +34,7 @@ MyUserManager::MyUserManager()
: _retListener(NULL) : _retListener(NULL)
, _qh360(NULL) , _qh360(NULL)
, _nd91(NULL) , _nd91(NULL)
, _uc(NULL)
{ {
} }
@ -101,6 +102,27 @@ void MyUserManager::loadPlugin()
_nd91->setActionListener(_retListener); _nd91->setActionListener(_retListener);
} }
} }
#if TEST_UC
{
_uc = dynamic_cast<ProtocolUser*>(PluginManager::getInstance()->loadPlugin("UserUC"));
if (NULL != _uc)
{
TUserDeveloperInfo pUCInfo;
pUCInfo["UCCpId"] = "20087";
pUCInfo["UCGameId"] = "119474";
pUCInfo["UCServerId"] = "1333";
if (pUCInfo.empty()) {
char msg[256] = { 0 };
sprintf(msg, "Developer info is empty. PLZ fill your UC info in %s(nearby line %d)", __FILE__, __LINE__);
MessageBox(msg, "UC Warning");
}
_uc->setDebugMode(true);
_uc->configDeveloperInfo(pUCInfo);
_uc->setActionListener(_retListener);
}
}
#endif
} }
void MyUserManager::unloadPlugin() void MyUserManager::unloadPlugin()
@ -116,6 +138,12 @@ void MyUserManager::unloadPlugin()
PluginManager::getInstance()->unloadPlugin("UserNd91"); PluginManager::getInstance()->unloadPlugin("UserNd91");
_nd91 = NULL; _nd91 = NULL;
} }
if (_uc)
{
PluginManager::getInstance()->unloadPlugin("UserUC");
_uc = NULL;
}
} }
void MyUserManager::loginByMode(MyUserMode mode) void MyUserManager::loginByMode(MyUserMode mode)
@ -129,6 +157,11 @@ void MyUserManager::loginByMode(MyUserMode mode)
case kND91: case kND91:
pUser = _nd91; pUser = _nd91;
break; break;
#if TEST_UC
case kUC:
pUser = _uc;
break;
#endif
default: default:
break; break;
} }
@ -149,6 +182,11 @@ void MyUserManager::logoutByMode(MyUserMode mode)
case kND91: case kND91:
pUser = _nd91; pUser = _nd91;
break; break;
#if TEST_UC
case kUC:
pUser = _uc;
break;
#endif
default: default:
break; break;
} }

View File

@ -26,6 +26,13 @@ THE SOFTWARE.
#include "ProtocolUser.h" #include "ProtocolUser.h"
/** @warning
* The file UCGameSDK.jar conflicts with weiboSDK.jar
* if you want test the login/logout of UC,
* modify the android project config: remove the weiboSDK.jar, and add UCGameSDK.jar
*/
#define TEST_UC 0
class MyUserActionResult : public cocos2d::plugin::UserActionListener class MyUserActionResult : public cocos2d::plugin::UserActionListener
{ {
public: public:
@ -42,6 +49,9 @@ public:
kNoneMode = 0, kNoneMode = 0,
kQH360, kQH360,
kND91, kND91,
#if TEST_UC
kUC,
#endif
} MyUserMode; } MyUserMode;
void unloadPlugin(); void unloadPlugin();
@ -57,6 +67,7 @@ private:
cocos2d::plugin::ProtocolUser* _qh360; cocos2d::plugin::ProtocolUser* _qh360;
cocos2d::plugin::ProtocolUser* _nd91; cocos2d::plugin::ProtocolUser* _nd91;
cocos2d::plugin::ProtocolUser* _uc;
MyUserActionResult* _retListener; MyUserActionResult* _retListener;
}; };

View File

@ -7,6 +7,9 @@ USING_NS_CC;
const std::string s_aTestCases[] = { const std::string s_aTestCases[] = {
"QH360", "QH360",
"ND91", "ND91",
#if TEST_UC
"UC",
#endif
}; };
Scene* TestUser::scene() Scene* TestUser::scene()

View File

@ -24,5 +24,6 @@
<classpathentry exported="true" kind="lib" path="plugin-x/plugins/weibo/android/weibosdk.jar"/> <classpathentry exported="true" kind="lib" path="plugin-x/plugins/weibo/android/weibosdk.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/360SDK.jar"/>
<classpathentry exported="true" kind="lib" path="plugin-x/plugins/qh360/android/libPluginQH360.jar"/> <classpathentry exported="true" kind="lib" path="plugin-x/plugins/qh360/android/libPluginQH360.jar"/>
<classpathentry exported="true" kind="lib" path="plugin-x/plugins/uc/android/libPluginUC.jar"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -36,6 +36,16 @@
<meta-data android:name="QHOPENSDK_APPKEY" android:value="Your app_key" /> <meta-data android:name="QHOPENSDK_APPKEY" android:value="Your app_key" />
<meta-data android:name="QHOPENSDK_PRIVATEKEY" android:value="Your app_private_key" /> <meta-data android:name="QHOPENSDK_PRIVATEKEY" android:value="Your app_private_key" />
<meta-data android:name="QHOPENSDK_CHANNEL" android:value="Your channel or delete this line" /> <meta-data android:name="QHOPENSDK_CHANNEL" android:value="Your channel or delete this line" />
<activity
android:name="cn.uc.gamesdk.view.SdkWebActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="cn.uc.gamesdk.sdkweb" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application> </application>
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" /> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" />

View File

@ -3,7 +3,7 @@ export ALL_PLUGINS=("flurry" "umeng" \
"alipay" "nd91" \ "alipay" "nd91" \
"admob" \ "admob" \
"twitter" "weibo" \ "twitter" "weibo" \
"qh360") "qh360" "uc")
# define the plugin root directory & publish target directory # define the plugin root directory & publish target directory
export TARGET_DIR_NAME="publish" export TARGET_DIR_NAME="publish"