mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3-animation-getCurrentFrame
This commit is contained in:
commit
c95283f563
|
@ -584,7 +584,6 @@ bool FileUtils::writeStringToFile(std::string dataStr, const std::string& fullPa
|
|||
|
||||
bool FileUtils::writeDataToFile(Data retData, const std::string& fullPath)
|
||||
{
|
||||
unsigned char* buffer = nullptr;
|
||||
size_t size = 0;
|
||||
const char* mode = "wb";
|
||||
|
||||
|
@ -1038,36 +1037,6 @@ bool FileUtils::isAbsolutePath(const std::string& path) const
|
|||
return (path[0] == '/');
|
||||
}
|
||||
|
||||
bool FileUtils::isDirectoryExistInternal(const std::string& dirPath) const
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
std::wstring wdirPath(dirPath.begin(), dirPath.end());
|
||||
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
unsigned long fAttrib = GetFileAttributesA(dirPath.c_str());
|
||||
if (fAttrib != INVALID_FILE_ATTRIBUTES &&
|
||||
(fAttrib & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
struct stat st;
|
||||
if (stat(dirPath.c_str(), &st) == 0)
|
||||
{
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool FileUtils::isDirectoryExist(const std::string& dirPath) const
|
||||
{
|
||||
CCASSERT(!dirPath.empty(), "Invalid path");
|
||||
|
@ -1098,7 +1067,6 @@ bool FileUtils::isDirectoryExist(const std::string& dirPath) const
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ protected:
|
|||
* @param dirPath The directory (with absolute path) to look up for
|
||||
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
||||
*/
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const;
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const = 0;
|
||||
|
||||
/**
|
||||
* Gets full path for filename, resolution directory and search path.
|
||||
|
|
|
@ -33,6 +33,7 @@ THE SOFTWARE.
|
|||
#include "android/asset_manager_jni.h"
|
||||
#include "jni/CocosPlayClient.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define LOG_TAG "CCFileUtils-android.cpp"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
@ -187,6 +188,59 @@ bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
|
|||
return bFound;
|
||||
}
|
||||
|
||||
bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) const
|
||||
{
|
||||
if (dirPath.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* s = dirPath.c_str();
|
||||
bool startWithAssets = (dirPath.find("assets/") == 0);
|
||||
int lenOfAssets = 7;
|
||||
|
||||
std::string tmpStr;
|
||||
if (cocosplay::isEnabled() && !cocosplay::isDemo())
|
||||
{
|
||||
// redirect assets/*** path to cocosplay resource dir
|
||||
tmpStr.append(_defaultResRootPath);
|
||||
if ('/' != tmpStr[tmpStr.length() - 1])
|
||||
{
|
||||
tmpStr += '/';
|
||||
}
|
||||
tmpStr.append(s + lenOfAssets);
|
||||
}
|
||||
|
||||
// find absolute path in flash memory
|
||||
if (s[0] == '/')
|
||||
{
|
||||
CCLOG("find in flash memory dirPath(%s)", s);
|
||||
struct stat st;
|
||||
if (stat(s, &st) == 0)
|
||||
{
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
}
|
||||
|
||||
// find it in apk's assets dir
|
||||
// Found "assets/" at the beginning of the path and we don't want it
|
||||
CCLOG("find in apk dirPath(%s)", s);
|
||||
if (startWithAssets)
|
||||
{
|
||||
s += lenOfAssets;
|
||||
}
|
||||
if (FileUtilsAndroid::assetmanager)
|
||||
{
|
||||
AAssetDir* aa = AAssetManager_openDir(FileUtilsAndroid::assetmanager, s);
|
||||
if (aa && AAssetDir_getNextFileName(aa))
|
||||
{
|
||||
AAssetDir_close(aa);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
|
||||
{
|
||||
// On Android, there are two situations for full path.
|
||||
|
|
|
@ -81,7 +81,8 @@ public:
|
|||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
||||
|
||||
private:
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||
Data getData(const std::string& filename, bool forString);
|
||||
|
||||
static AAssetManager* assetmanager;
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -36,271 +36,271 @@ import android.view.MotionEvent;
|
|||
import android.util.Log;
|
||||
|
||||
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
// ===========================================================
|
||||
// Constants
|
||||
// ===========================================================
|
||||
|
||||
private final static String TAG = GameControllerActivity.class.getSimpleName();
|
||||
private final static String TAG = GameControllerActivity.class.getSimpleName();
|
||||
|
||||
public static final int DRIVERTYPE_NIBIRU = 0;
|
||||
public static final int DRIVERTYPE_MOGA = 1;
|
||||
public static final int DRIVERTYPE_OUYA = 2;
|
||||
public static final int DRIVERTYPE_STANDARD = 3;
|
||||
public static final int DRIVERTYPE_UNKNOWN = 4;
|
||||
|
||||
// ===========================================================
|
||||
// Fields
|
||||
// ===========================================================
|
||||
private static GameControllerActivity sGameControllerActivity;
|
||||
private InputManagerCompat mInputManager = null;
|
||||
|
||||
protected GameControllerHelper mControllerHelper = null;
|
||||
|
||||
protected GameControllerDelegate mControllerNibiru = null;
|
||||
protected GameControllerDelegate mControllerMoga = null;
|
||||
protected GameControllerDelegate mControllerOuya = null;
|
||||
|
||||
public void connectController(int driveType){
|
||||
try {
|
||||
|
||||
ClassLoader loader = sGameControllerActivity.getClassLoader();
|
||||
Class<?> controllerDelegate = null;
|
||||
if (driveType == DRIVERTYPE_MOGA) {
|
||||
if (mControllerMoga != null) {
|
||||
return;
|
||||
}
|
||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga");
|
||||
} else if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onCreate(sGameControllerActivity);
|
||||
mControllerNibiru.onResume();
|
||||
return;
|
||||
}
|
||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
|
||||
} else if (driveType == DRIVERTYPE_OUYA) {
|
||||
if (mControllerOuya != null) {
|
||||
return;
|
||||
}
|
||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya");
|
||||
}
|
||||
|
||||
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
|
||||
sGameControllerActivity.setGameControllerInstance(instance, driveType);
|
||||
|
||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
Method method = controllerDelegate.getDeclaredMethod("onResume");
|
||||
method.invoke(instance);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) {
|
||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
mControllerNibiru = controllerDelegate;
|
||||
}else if (driveType == DRIVERTYPE_MOGA) {
|
||||
mControllerMoga = controllerDelegate;
|
||||
}
|
||||
else if (driveType == DRIVERTYPE_OUYA) {
|
||||
mControllerOuya = controllerDelegate;
|
||||
}
|
||||
controllerDelegate.setControllerEventListener(mControllerEventListener);
|
||||
controllerDelegate.onCreate(sGameControllerActivity);
|
||||
}
|
||||
|
||||
public GameControllerDelegate getGameControllerDelegate(int driveType){
|
||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
return mControllerNibiru;
|
||||
}else if (driveType == DRIVERTYPE_MOGA) {
|
||||
return mControllerMoga;
|
||||
}
|
||||
else if (driveType == DRIVERTYPE_OUYA) {
|
||||
return mControllerOuya;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
|
||||
|
||||
@Override
|
||||
public void onButtonEvent(String vendorName, int controller, int button,
|
||||
boolean isPressed, float value, boolean isAnalog) {
|
||||
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAxisEvent(String vendorName, int controller, int axisID,
|
||||
float value, boolean isAnalog) {
|
||||
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
|
||||
}
|
||||
public static final int DRIVERTYPE_NIBIRU = 0;
|
||||
public static final int DRIVERTYPE_MOGA = 1;
|
||||
public static final int DRIVERTYPE_OUYA = 2;
|
||||
public static final int DRIVERTYPE_STANDARD = 3;
|
||||
public static final int DRIVERTYPE_UNKNOWN = 4;
|
||||
|
||||
// ===========================================================
|
||||
// Fields
|
||||
// ===========================================================
|
||||
private static GameControllerActivity sGameControllerActivity;
|
||||
private InputManagerCompat mInputManager = null;
|
||||
|
||||
protected GameControllerHelper mControllerHelper = null;
|
||||
|
||||
protected GameControllerDelegate mControllerNibiru = null;
|
||||
protected GameControllerDelegate mControllerMoga = null;
|
||||
protected GameControllerDelegate mControllerOuya = null;
|
||||
|
||||
public void connectController(int driveType){
|
||||
try {
|
||||
|
||||
ClassLoader loader = sGameControllerActivity.getClassLoader();
|
||||
Class<?> controllerDelegate = null;
|
||||
if (driveType == DRIVERTYPE_MOGA) {
|
||||
if (mControllerMoga != null) {
|
||||
return;
|
||||
}
|
||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga");
|
||||
} else if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onCreate(sGameControllerActivity);
|
||||
mControllerNibiru.onResume();
|
||||
return;
|
||||
}
|
||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
|
||||
} else if (driveType == DRIVERTYPE_OUYA) {
|
||||
if (mControllerOuya != null) {
|
||||
return;
|
||||
}
|
||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya");
|
||||
}
|
||||
|
||||
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
|
||||
sGameControllerActivity.setGameControllerInstance(instance, driveType);
|
||||
|
||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
Method method = controllerDelegate.getDeclaredMethod("onResume");
|
||||
method.invoke(instance);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) {
|
||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
mControllerNibiru = controllerDelegate;
|
||||
}else if (driveType == DRIVERTYPE_MOGA) {
|
||||
mControllerMoga = controllerDelegate;
|
||||
}
|
||||
else if (driveType == DRIVERTYPE_OUYA) {
|
||||
mControllerOuya = controllerDelegate;
|
||||
}
|
||||
controllerDelegate.setControllerEventListener(mControllerEventListener);
|
||||
controllerDelegate.onCreate(sGameControllerActivity);
|
||||
}
|
||||
|
||||
public GameControllerDelegate getGameControllerDelegate(int driveType){
|
||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||
return mControllerNibiru;
|
||||
}else if (driveType == DRIVERTYPE_MOGA) {
|
||||
return mControllerMoga;
|
||||
}
|
||||
else if (driveType == DRIVERTYPE_OUYA) {
|
||||
return mControllerOuya;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
|
||||
|
||||
@Override
|
||||
public void onButtonEvent(String vendorName, int controller, int button,
|
||||
boolean isPressed, float value, boolean isAnalog) {
|
||||
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAxisEvent(String vendorName, int controller, int axisID,
|
||||
float value, boolean isAnalog) {
|
||||
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(String vendorName, int controller) {
|
||||
GameControllerAdapter.onConnected(vendorName, controller);
|
||||
}
|
||||
@Override
|
||||
public void onConnected(String vendorName, int controller) {
|
||||
GameControllerAdapter.onConnected(vendorName, controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(String vendorName, int controller) {
|
||||
GameControllerAdapter.onDisconnected(vendorName, controller);
|
||||
}
|
||||
};
|
||||
|
||||
// ===========================================================
|
||||
// Constructors
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
sGameControllerActivity = this;
|
||||
mInputManager = InputManagerCompat.Factory.getInputManager(this);
|
||||
mInputManager.registerInputDeviceListener(this, null);
|
||||
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onCreate(this);
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onCreate(this);
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onCreate(this);
|
||||
}
|
||||
if (mControllerHelper == null) {
|
||||
mControllerHelper = new GameControllerHelper(this);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Getter & Setter
|
||||
// ===========================================================
|
||||
@Override
|
||||
public void onDisconnected(String vendorName, int controller) {
|
||||
GameControllerAdapter.onDisconnected(vendorName, controller);
|
||||
}
|
||||
};
|
||||
|
||||
// ===========================================================
|
||||
// Constructors
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
sGameControllerActivity = this;
|
||||
mInputManager = InputManagerCompat.Factory.getInputManager(this);
|
||||
mInputManager.registerInputDeviceListener(this, null);
|
||||
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onCreate(this);
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onCreate(this);
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onCreate(this);
|
||||
}
|
||||
if (mControllerHelper == null) {
|
||||
mControllerHelper = new GameControllerHelper(this);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================
|
||||
// Getter & Setter
|
||||
// ===========================================================
|
||||
|
||||
// ===========================================================
|
||||
// Methods for/from SuperClass/Interfaces
|
||||
// ===========================================================
|
||||
// ===========================================================
|
||||
// Methods for/from SuperClass/Interfaces
|
||||
// ===========================================================
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchKeyEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchKeyEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
if (handled == false) {
|
||||
handled |= mControllerHelper.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
return handled || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
if (handled == false) {
|
||||
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
return handled || super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
||||
|
||||
mControllerHelper.onInputDeviceAdded(deviceId);
|
||||
}
|
||||
/*
|
||||
* This is an unusual case. Input devices don't typically change, but they
|
||||
* certainly can --- for example a device may have different modes. We use
|
||||
* this to make sure that the ship has an up-to-date InputDevice.
|
||||
*
|
||||
* @see
|
||||
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
||||
* #onInputDeviceChanged(int)
|
||||
*/
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
Log.w(TAG,"onInputDeviceChanged:" + deviceId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove any ship associated with the ID.
|
||||
*
|
||||
* @see
|
||||
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
||||
* #onInputDeviceRemoved(int)
|
||||
*/
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
|
||||
|
||||
mControllerHelper.onInputDeviceRemoved(deviceId);
|
||||
}
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchKeyEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchKeyEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
if (handled == false) {
|
||||
handled |= mControllerHelper.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
return handled || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = false;
|
||||
if (mControllerNibiru != null) {
|
||||
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerMoga != null) {
|
||||
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
if (handled == false && mControllerOuya != null) {
|
||||
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
if (handled == false) {
|
||||
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
return handled || super.dispatchGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
||||
|
||||
mControllerHelper.onInputDeviceAdded(deviceId);
|
||||
}
|
||||
/*
|
||||
* This is an unusual case. Input devices don't typically change, but they
|
||||
* certainly can --- for example a device may have different modes. We use
|
||||
* this to make sure that the ship has an up-to-date InputDevice.
|
||||
*
|
||||
* @see
|
||||
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
||||
* #onInputDeviceChanged(int)
|
||||
*/
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
Log.w(TAG,"onInputDeviceChanged:" + deviceId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove any ship associated with the ID.
|
||||
*
|
||||
* @see
|
||||
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
||||
* #onInputDeviceRemoved(int)
|
||||
*/
|
||||
@Override
|
||||
public void onInputDeviceRemoved(int deviceId) {
|
||||
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
|
||||
|
||||
mControllerHelper.onInputDeviceRemoved(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onResume();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onResume();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onResume();
|
||||
}
|
||||
|
||||
GameControllerHelper.gatherControllers(mControllerHelper.mGameController);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onPause();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onPause();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onPause();
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onDestroy();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onDestroy();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onDestroy();
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onResume();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onResume();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onResume();
|
||||
}
|
||||
|
||||
GameControllerHelper.gatherControllers(mControllerHelper.mGameController);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onPause();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onPause();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onPause();
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mControllerNibiru != null) {
|
||||
mControllerNibiru.onDestroy();
|
||||
}
|
||||
if (mControllerMoga != null) {
|
||||
mControllerMoga.onDestroy();
|
||||
}
|
||||
if (mControllerOuya != null) {
|
||||
mControllerOuya.onDestroy();
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
}
|
|
@ -10,248 +10,248 @@ import android.view.MotionEvent;
|
|||
|
||||
public class GameControllerHelper {
|
||||
|
||||
public static final String StandardControllerName = "Standard";
|
||||
|
||||
SparseIntArray ControllerKeyMap;
|
||||
|
||||
private static final int AXIS_X = 0;
|
||||
private static final int AXIS_Y = 1;
|
||||
private static final int AXIS_Z = 11;
|
||||
private static final int AXIS_RZ = 14;
|
||||
private static final int AXIS_LTRIGGER = 17;
|
||||
private static final int AXIS_RTRIGGER = 18;
|
||||
public static final int AXIS_GAS = 22;
|
||||
private static final int AXIS_BRAKE = 23;
|
||||
private static final int AXIS_THROTTLE = 19;
|
||||
|
||||
public GameControllerHelper(GameControllerActivity activity){
|
||||
|
||||
ControllerKeyMap = new SparseIntArray(25);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||
|
||||
ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
|
||||
ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
|
||||
ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
|
||||
ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
|
||||
}
|
||||
|
||||
private float mOldLeftThumbstickX = 0.0f;
|
||||
private float mOldLeftThumbstickY = 0.0f;
|
||||
private float mOldRightThumbstickX = 0.0f;
|
||||
private float mOldRightThumbstickY = 0.0f;
|
||||
|
||||
private float mOldLeftTrigger = 0.0f;
|
||||
private float mOldRightTrigger = 0.0f;
|
||||
private float mOldThrottle = 0.0f;
|
||||
private float mOldBrake = 0.0f;
|
||||
private float mOldGas = 0.0f;
|
||||
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = false;
|
||||
|
||||
int eventSource = event.getSource();
|
||||
|
||||
public static final String StandardControllerName = "Standard";
|
||||
|
||||
SparseIntArray ControllerKeyMap;
|
||||
|
||||
private static final int AXIS_X = 0;
|
||||
private static final int AXIS_Y = 1;
|
||||
private static final int AXIS_Z = 11;
|
||||
private static final int AXIS_RZ = 14;
|
||||
private static final int AXIS_LTRIGGER = 17;
|
||||
private static final int AXIS_RTRIGGER = 18;
|
||||
public static final int AXIS_GAS = 22;
|
||||
private static final int AXIS_BRAKE = 23;
|
||||
private static final int AXIS_THROTTLE = 19;
|
||||
|
||||
public GameControllerHelper(GameControllerActivity activity){
|
||||
|
||||
ControllerKeyMap = new SparseIntArray(25);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||
|
||||
ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
|
||||
ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
|
||||
ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
|
||||
ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
|
||||
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
|
||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
|
||||
}
|
||||
|
||||
private float mOldLeftThumbstickX = 0.0f;
|
||||
private float mOldLeftThumbstickY = 0.0f;
|
||||
private float mOldRightThumbstickX = 0.0f;
|
||||
private float mOldRightThumbstickY = 0.0f;
|
||||
|
||||
private float mOldLeftTrigger = 0.0f;
|
||||
private float mOldRightTrigger = 0.0f;
|
||||
private float mOldThrottle = 0.0f;
|
||||
private float mOldBrake = 0.0f;
|
||||
private float mOldGas = 0.0f;
|
||||
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = false;
|
||||
|
||||
int eventSource = event.getSource();
|
||||
|
||||
if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
if(mGameController.get(deviceId) == null){
|
||||
gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
|
||||
float newAXIS_LX = event.getAxisValue(AXIS_X);
|
||||
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
|
||||
mOldLeftThumbstickX = newAXIS_LX;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_LY = event.getAxisValue(AXIS_Y);
|
||||
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
|
||||
mOldLeftThumbstickY = newAXIS_LY;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RX = event.getAxisValue(AXIS_Z);
|
||||
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
|
||||
mOldRightThumbstickX = newAXIS_RX;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
|
||||
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
|
||||
mOldRightThumbstickY = newAXIS_RY;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
|
||||
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true);
|
||||
mOldLeftTrigger = newAXIS_LTRIGGER;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
|
||||
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true);
|
||||
mOldRightTrigger = newAXIS_RTRIGGER;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
|
||||
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true);
|
||||
mOldBrake = newAXIS_BRAKE;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
|
||||
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true);
|
||||
mOldThrottle = newAXIS_THROTTLE;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
|
||||
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true);
|
||||
mOldGas = newAXIS_GAS;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
if(mGameController.get(deviceId) == null){
|
||||
gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
|
||||
float newAXIS_LX = event.getAxisValue(AXIS_X);
|
||||
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
|
||||
mOldLeftThumbstickX = newAXIS_LX;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_LY = event.getAxisValue(AXIS_Y);
|
||||
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
|
||||
mOldLeftThumbstickY = newAXIS_LY;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RX = event.getAxisValue(AXIS_Z);
|
||||
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
|
||||
mOldRightThumbstickX = newAXIS_RX;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
|
||||
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
|
||||
mOldRightThumbstickY = newAXIS_RY;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
|
||||
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true);
|
||||
mOldLeftTrigger = newAXIS_LTRIGGER;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
|
||||
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true);
|
||||
mOldRightTrigger = newAXIS_RTRIGGER;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
|
||||
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true);
|
||||
mOldBrake = newAXIS_BRAKE;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
|
||||
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true);
|
||||
mOldThrottle = newAXIS_THROTTLE;
|
||||
handled = true;
|
||||
}
|
||||
|
||||
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
|
||||
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
|
||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true);
|
||||
mOldGas = newAXIS_GAS;
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
private static SparseArray<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
|
||||
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
|
||||
int eventSource = event.getSource();
|
||||
int keyCode = event.getKeyCode();
|
||||
int controllerKey = ControllerKeyMap.get(keyCode);
|
||||
|
||||
if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
|
||||
if(mGameController.get(deviceId) == null){
|
||||
gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
|
||||
if (controllerKey == 0) {
|
||||
if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) {
|
||||
controllerKey = keyCode;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int action = event.getAction();
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
handled = true;
|
||||
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false);
|
||||
}else if (action == KeyEvent.ACTION_UP) {
|
||||
handled = true;
|
||||
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false);
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
return handled;
|
||||
}
|
||||
|
||||
private static SparseArray<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
|
||||
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
|
||||
int eventSource = event.getSource();
|
||||
int keyCode = event.getKeyCode();
|
||||
int controllerKey = ControllerKeyMap.get(keyCode);
|
||||
|
||||
if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
|
||||
if(mGameController.get(deviceId) == null){
|
||||
gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
|
||||
if (controllerKey == 0) {
|
||||
if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) {
|
||||
controllerKey = keyCode;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int action = event.getAction();
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
handled = true;
|
||||
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false);
|
||||
}else if (action == KeyEvent.ACTION_UP) {
|
||||
handled = true;
|
||||
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false);
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) {
|
||||
if (receive) {
|
||||
if (mControllerExtendKey.get(deviceId) == null) {
|
||||
mControllerExtendKey.put(deviceId, new ArrayList<Integer>());
|
||||
}
|
||||
mControllerExtendKey.get(deviceId).add(externalKeyCode);
|
||||
} else {
|
||||
if (mControllerExtendKey.get(deviceId) != null) {
|
||||
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
void onInputDeviceAdded(int deviceId){
|
||||
try {
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
String deviceName = device.getName();
|
||||
mGameController.append(deviceId, deviceName);
|
||||
GameControllerAdapter.onConnected(deviceName, deviceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void onInputDeviceChanged(int deviceId){
|
||||
gatherControllers(mGameController);
|
||||
}
|
||||
|
||||
void onInputDeviceRemoved(int deviceId) {
|
||||
if (mGameController.get(deviceId) != null) {
|
||||
GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId);
|
||||
mGameController.delete(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
static void gatherControllers(SparseArray<String> controllers){
|
||||
int controllerCount = controllers.size();
|
||||
for (int i = 0; i < controllerCount; i++) {
|
||||
try {
|
||||
int controllerDeveceId = controllers.keyAt(i);
|
||||
InputDevice device = InputDevice.getDevice(controllerDeveceId);
|
||||
if (device == null) {
|
||||
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
||||
controllers.delete(controllerDeveceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
int controllerDeveceId = controllers.keyAt(i);
|
||||
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
||||
controllers.delete(controllerDeveceId);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) {
|
||||
if (receive) {
|
||||
if (mControllerExtendKey.get(deviceId) == null) {
|
||||
mControllerExtendKey.put(deviceId, new ArrayList<Integer>());
|
||||
}
|
||||
mControllerExtendKey.get(deviceId).add(externalKeyCode);
|
||||
} else {
|
||||
if (mControllerExtendKey.get(deviceId) != null) {
|
||||
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
void onInputDeviceAdded(int deviceId){
|
||||
try {
|
||||
InputDevice device = InputDevice.getDevice(deviceId);
|
||||
int deviceSource = device.getSources();
|
||||
|
||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||
{
|
||||
String deviceName = device.getName();
|
||||
mGameController.append(deviceId, deviceName);
|
||||
GameControllerAdapter.onConnected(deviceName, deviceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void onInputDeviceChanged(int deviceId){
|
||||
gatherControllers(mGameController);
|
||||
}
|
||||
|
||||
void onInputDeviceRemoved(int deviceId) {
|
||||
if (mGameController.get(deviceId) != null) {
|
||||
GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId);
|
||||
mGameController.delete(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
static void gatherControllers(SparseArray<String> controllers){
|
||||
int controllerCount = controllers.size();
|
||||
for (int i = 0; i < controllerCount; i++) {
|
||||
try {
|
||||
int controllerDeveceId = controllers.keyAt(i);
|
||||
InputDevice device = InputDevice.getDevice(controllerDeveceId);
|
||||
if (device == null) {
|
||||
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
||||
controllers.delete(controllerDeveceId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
int controllerDeveceId = controllers.keyAt(i);
|
||||
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
||||
controllers.delete(controllerDeveceId);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,205 +14,205 @@ import com.bda.controller.StateEvent;
|
|||
|
||||
public class GameControllerMoga implements ControllerListener, GameControllerDelegate {
|
||||
|
||||
private static final String mVendorName = "Moga";
|
||||
|
||||
private float mOldLeftThumbstickX = 0.0f;
|
||||
private float mOldLeftThumbstickY = 0.0f;
|
||||
private float mOldRightThumbstickX = 0.0f;
|
||||
private float mOldRightThumbstickY = 0.0f;
|
||||
|
||||
private float mOldLeftTrigger = 0.0f;
|
||||
private float mOldRightTrigger = 0.0f;
|
||||
private static final String mVendorName = "Moga";
|
||||
|
||||
private float mOldLeftThumbstickX = 0.0f;
|
||||
private float mOldLeftThumbstickY = 0.0f;
|
||||
private float mOldRightThumbstickX = 0.0f;
|
||||
private float mOldRightThumbstickY = 0.0f;
|
||||
|
||||
private float mOldLeftTrigger = 0.0f;
|
||||
private float mOldRightTrigger = 0.0f;
|
||||
|
||||
private SparseIntArray mKeyMap = null;
|
||||
private SparseIntArray mKeyMap = null;
|
||||
|
||||
public GameControllerMoga() {
|
||||
mKeyMap = new SparseIntArray(20);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1,
|
||||
GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1,
|
||||
GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2,
|
||||
GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2,
|
||||
GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP,
|
||||
GameControllerDelegate.BUTTON_DPAD_UP);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT,
|
||||
GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||
GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
||||
GameControllerDelegate.BUTTON_START);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT,
|
||||
GameControllerDelegate.BUTTON_SELECT);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
||||
GameControllerDelegate.BUTTON_START);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL,
|
||||
GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR,
|
||||
GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||
}
|
||||
|
||||
public void onKeyEvent(KeyEvent event) {
|
||||
int keycode = event.getKeyCode();
|
||||
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|
||||
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
|
||||
return;
|
||||
}
|
||||
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
|
||||
boolean isAnalog = false;
|
||||
public GameControllerMoga() {
|
||||
mKeyMap = new SparseIntArray(20);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1,
|
||||
GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1,
|
||||
GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2,
|
||||
GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2,
|
||||
GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP,
|
||||
GameControllerDelegate.BUTTON_DPAD_UP);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN,
|
||||
GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT,
|
||||
GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||
GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
||||
GameControllerDelegate.BUTTON_START);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT,
|
||||
GameControllerDelegate.BUTTON_SELECT);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
||||
GameControllerDelegate.BUTTON_START);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL,
|
||||
GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR,
|
||||
GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||
}
|
||||
|
||||
public void onKeyEvent(KeyEvent event) {
|
||||
int keycode = event.getKeyCode();
|
||||
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|
||||
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
|
||||
return;
|
||||
}
|
||||
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
|
||||
boolean isAnalog = false;
|
||||
|
||||
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
|
||||
|| keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
|
||||
isAnalog = true;
|
||||
}
|
||||
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
|
||||
|| keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
|
||||
isAnalog = true;
|
||||
}
|
||||
|
||||
if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) {
|
||||
mControllerEventListener.onButtonEvent(mVendorName,
|
||||
event.getControllerId(), mKeyMap.get(keycode), isPressed,
|
||||
isPressed ? 1.0f : 0.0f, isAnalog);
|
||||
}
|
||||
}
|
||||
if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) {
|
||||
mControllerEventListener.onButtonEvent(mVendorName,
|
||||
event.getControllerId(), mKeyMap.get(keycode), isPressed,
|
||||
isPressed ? 1.0f : 0.0f, isAnalog);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMotionEvent(MotionEvent event) {
|
||||
if (mControllerEventListener == null) {
|
||||
return;
|
||||
}
|
||||
int controllerId = event.getControllerId();
|
||||
|
||||
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
|
||||
if (newLeftThumbstickX != mOldLeftThumbstickX) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_X,
|
||||
newLeftThumbstickX, true);
|
||||
mOldLeftThumbstickX = newLeftThumbstickX;
|
||||
}
|
||||
@Override
|
||||
public void onMotionEvent(MotionEvent event) {
|
||||
if (mControllerEventListener == null) {
|
||||
return;
|
||||
}
|
||||
int controllerId = event.getControllerId();
|
||||
|
||||
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
|
||||
if (newLeftThumbstickX != mOldLeftThumbstickX) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_X,
|
||||
newLeftThumbstickX, true);
|
||||
mOldLeftThumbstickX = newLeftThumbstickX;
|
||||
}
|
||||
|
||||
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
|
||||
if (newLeftThumbstickY != mOldLeftThumbstickY) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_Y,
|
||||
newLeftThumbstickY, true);
|
||||
mOldLeftThumbstickY = newLeftThumbstickY;
|
||||
}
|
||||
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
|
||||
if (newLeftThumbstickY != mOldLeftThumbstickY) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_Y,
|
||||
newLeftThumbstickY, true);
|
||||
mOldLeftThumbstickY = newLeftThumbstickY;
|
||||
}
|
||||
|
||||
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
|
||||
if (newRightThumbstickX != mOldRightThumbstickX) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_X,
|
||||
newRightThumbstickX, true);
|
||||
mOldRightThumbstickX = newRightThumbstickX;
|
||||
}
|
||||
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
|
||||
if (newRightThumbstickX != mOldRightThumbstickX) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_X,
|
||||
newRightThumbstickX, true);
|
||||
mOldRightThumbstickX = newRightThumbstickX;
|
||||
}
|
||||
|
||||
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
|
||||
if (newRightThumbstickY != mOldRightThumbstickY) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_Y,
|
||||
newRightThumbstickY, true);
|
||||
mOldRightThumbstickY = newRightThumbstickY;
|
||||
}
|
||||
|
||||
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
||||
if (newLeftTrigger != mOldLeftTrigger) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
|
||||
newLeftTrigger, true);
|
||||
mOldLeftTrigger = newLeftTrigger;
|
||||
}
|
||||
|
||||
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
||||
if (newRightTrigger != mOldRightTrigger) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
|
||||
newRightTrigger, true);
|
||||
mOldRightTrigger = newRightTrigger;
|
||||
}
|
||||
}
|
||||
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
|
||||
if (newRightThumbstickY != mOldRightThumbstickY) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_Y,
|
||||
newRightThumbstickY, true);
|
||||
mOldRightThumbstickY = newRightThumbstickY;
|
||||
}
|
||||
|
||||
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
||||
if (newLeftTrigger != mOldLeftTrigger) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
|
||||
newLeftTrigger, true);
|
||||
mOldLeftTrigger = newLeftTrigger;
|
||||
}
|
||||
|
||||
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
||||
if (newRightTrigger != mOldRightTrigger) {
|
||||
mControllerEventListener.onAxisEvent(mVendorName,
|
||||
controllerId,
|
||||
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
|
||||
newRightTrigger, true);
|
||||
mOldRightTrigger = newRightTrigger;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateEvent(StateEvent event) {
|
||||
if (mControllerEventListener != null) {
|
||||
switch (event.getState()) {
|
||||
case StateEvent.STATE_CONNECTION:
|
||||
switch (event.getAction()) {
|
||||
case StateEvent.ACTION_DISCONNECTED:
|
||||
// disconnected from controller
|
||||
mControllerEventListener.onDisconnected(mVendorName,
|
||||
event.getControllerId());
|
||||
break;
|
||||
case StateEvent.ACTION_CONNECTED:
|
||||
// connected to controller
|
||||
mControllerEventListener.onConnected(mVendorName,
|
||||
event.getControllerId());
|
||||
break;
|
||||
case StateEvent.ACTION_CONNECTING:
|
||||
// attempting to connect to controller
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case StateEvent.STATE_POWER_LOW:
|
||||
if (event.getAction() == StateEvent.ACTION_TRUE) {
|
||||
// controller has entered low power state
|
||||
} else {
|
||||
// controller has entered normal power state
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onStateEvent(StateEvent event) {
|
||||
if (mControllerEventListener != null) {
|
||||
switch (event.getState()) {
|
||||
case StateEvent.STATE_CONNECTION:
|
||||
switch (event.getAction()) {
|
||||
case StateEvent.ACTION_DISCONNECTED:
|
||||
// disconnected from controller
|
||||
mControllerEventListener.onDisconnected(mVendorName,
|
||||
event.getControllerId());
|
||||
break;
|
||||
case StateEvent.ACTION_CONNECTED:
|
||||
// connected to controller
|
||||
mControllerEventListener.onConnected(mVendorName,
|
||||
event.getControllerId());
|
||||
break;
|
||||
case StateEvent.ACTION_CONNECTING:
|
||||
// attempting to connect to controller
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case StateEvent.STATE_POWER_LOW:
|
||||
if (event.getAction() == StateEvent.ACTION_TRUE) {
|
||||
// controller has entered low power state
|
||||
} else {
|
||||
// controller has entered normal power state
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Controller mController = null;
|
||||
private Controller mController = null;
|
||||
|
||||
public void onCreate(Context context) {
|
||||
mController = Controller.getInstance(context);
|
||||
|
||||
mController.init();
|
||||
mController.setListener(this, new Handler());
|
||||
}
|
||||
public void onCreate(Context context) {
|
||||
mController = Controller.getInstance(context);
|
||||
|
||||
mController.init();
|
||||
mController.setListener(this, new Handler());
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
mController.onPause();
|
||||
}
|
||||
public void onPause() {
|
||||
mController.onPause();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
mController.onResume();
|
||||
}
|
||||
public void onResume() {
|
||||
mController.onResume();
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
mController.exit();
|
||||
}
|
||||
|
||||
private ControllerEventListener mControllerEventListener;
|
||||
@Override
|
||||
public void setControllerEventListener(ControllerEventListener listener) {
|
||||
mControllerEventListener = listener;
|
||||
}
|
||||
public void onDestroy() {
|
||||
mController.exit();
|
||||
}
|
||||
|
||||
private ControllerEventListener mControllerEventListener;
|
||||
@Override
|
||||
public void setControllerEventListener(ControllerEventListener listener) {
|
||||
mControllerEventListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,16 +26,16 @@ import android.view.MotionEvent;
|
|||
public class GameControllerNibiru implements OnControllerSeviceListener, OnKeyListener,
|
||||
OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameControllerDelegate {
|
||||
|
||||
private static final String TAG = "NibiruTag";
|
||||
|
||||
private Context mContext;
|
||||
private SparseIntArray mKeyMap;
|
||||
private ControllerEventListener mControllerEventListener = null;
|
||||
private ControllerService mControllerService = null;
|
||||
|
||||
public GameControllerNibiru() {
|
||||
mKeyMap = new SparseIntArray(20);
|
||||
|
||||
private static final String TAG = "NibiruTag";
|
||||
|
||||
private Context mContext;
|
||||
private SparseIntArray mKeyMap;
|
||||
private ControllerEventListener mControllerEventListener = null;
|
||||
private ControllerService mControllerService = null;
|
||||
|
||||
public GameControllerNibiru() {
|
||||
mKeyMap = new SparseIntArray(20);
|
||||
|
||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_A , GameControllerDelegate.BUTTON_A);
|
||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_B , GameControllerDelegate.BUTTON_B);
|
||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_X , GameControllerDelegate.BUTTON_X);
|
||||
|
@ -52,188 +52,188 @@ OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameContr
|
|||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_SELECT , GameControllerDelegate.BUTTON_SELECT);
|
||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBL , GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBR , GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControllerEventListener(ControllerEventListener listener) {
|
||||
mControllerEventListener = listener;
|
||||
}
|
||||
|
||||
public void onCreate(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mControllerService = Controller.getControllerService();
|
||||
if (mControllerService != null) {
|
||||
mControllerService.setControllerServiceListener(this);
|
||||
mControllerService.setStateListener(this);
|
||||
mControllerService.setKeyListener(this);
|
||||
mControllerService.setSimpleStickListener(this);
|
||||
//mControllerService.setAccListener(this);
|
||||
//mControllerService.setGyroListener(this);
|
||||
mControllerService.setEnableLR2(true);
|
||||
mControllerService.setAutoKeyUpMode(false);
|
||||
|
||||
mControllerService.checkNibiruInstall(mContext, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
if (mControllerService != null) {
|
||||
mControllerService.setEnable(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
if (mControllerService != null) {
|
||||
if (mControllerService.isServiceEnable()) {
|
||||
//onControllerServiceReady(true);
|
||||
} else {
|
||||
if (mControllerService.checkNibiruInstall(mContext, false)) {
|
||||
try {
|
||||
mControllerService.register(mContext);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mControllerService.setEnable(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
if( mControllerService != null ){
|
||||
mControllerService.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControllerEventListener(ControllerEventListener listener) {
|
||||
mControllerEventListener = listener;
|
||||
}
|
||||
|
||||
public void onCreate(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mControllerService = Controller.getControllerService(context);
|
||||
if (mControllerService != null) {
|
||||
mControllerService.setControllerServiceListener(this);
|
||||
mControllerService.setStateListener(this);
|
||||
mControllerService.setKeyListener(this);
|
||||
mControllerService.setSimpleStickListener(this);
|
||||
//mControllerService.setAccListener(this);
|
||||
//mControllerService.setGyroListener(this);
|
||||
mControllerService.setEnableL2R2(true);
|
||||
mControllerService.setAutoKeyUpMode(false);
|
||||
|
||||
mControllerService.checkNibiruInstall(mContext, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
if (mControllerService != null) {
|
||||
mControllerService.setEnable(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
if (mControllerService != null) {
|
||||
if (mControllerService.isServiceEnable()) {
|
||||
//onControllerServiceReady(true);
|
||||
} else {
|
||||
if (mControllerService.checkNibiruInstall(mContext, false)) {
|
||||
try {
|
||||
mControllerService.register(mContext);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mControllerService.setEnable(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
if( mControllerService != null ){
|
||||
mControllerService.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerServiceReady(boolean isSucc) {
|
||||
if( isSucc )
|
||||
{
|
||||
if( !mControllerService.hasDeviceConnected() ){
|
||||
Bundle bun = new Bundle();
|
||||
bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false);
|
||||
try {
|
||||
mControllerService.showDeviceManagerUI(mContext, bun);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onControllerServiceReady(boolean isSucc) {
|
||||
if( isSucc )
|
||||
{
|
||||
if( !mControllerService.hasDeviceConnected() ){
|
||||
Bundle bun = new Bundle();
|
||||
bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false);
|
||||
/*try {
|
||||
mControllerService.showDeviceManagerUI(mContext, bun);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
||||
if (mKeyMap.get(keyCode) == 0) {
|
||||
Log.e(TAG, "Didn't map the key: " + keyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
||||
mKeyMap.get(keyCode), true, 1.0f, false);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
||||
if (mKeyMap.get(keyCode) == 0) {
|
||||
Log.e(TAG, "Didn't map the key: " + keyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
||||
mKeyMap.get(keyCode), true, 1.0f, false);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
||||
if (mKeyMap.get(keyCode) == 0) {
|
||||
Log.e(TAG, "Didn't map the key: " + keyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
||||
mKeyMap.get(keyCode), false, 0.0f, false);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
||||
if (mKeyMap.get(keyCode) == 0) {
|
||||
Log.e(TAG, "Didn't map the key: " + keyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
||||
mKeyMap.get(keyCode), false, 0.0f, false);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeftStickChanged(int playerOrder, float x, float y) {
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
String deviceName = controllerDevice.getDeviceName();
|
||||
int deviceId = controllerDevice.getDeviceId();
|
||||
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_X, x, true);
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onLeftStickChanged(int playerOrder, float x, float y) {
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
String deviceName = controllerDevice.getDeviceName();
|
||||
int deviceId = controllerDevice.getDeviceId();
|
||||
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_X, x, true);
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightStickChanged(int playerOrder, float x, float y) {
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
String deviceName = controllerDevice.getDeviceName();
|
||||
int deviceId = controllerDevice.getDeviceId();
|
||||
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true);
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) {
|
||||
if (mControllerEventListener != null) {
|
||||
if (state == ControllerDevice.STATE_CONN)
|
||||
{
|
||||
mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId());
|
||||
}
|
||||
else if (state == ControllerDevice.STATE_DISCONN)
|
||||
{
|
||||
mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onRightStickChanged(int playerOrder, float x, float y) {
|
||||
if (mControllerEventListener != null) {
|
||||
try {
|
||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||
|
||||
String deviceName = controllerDevice.getDeviceName();
|
||||
int deviceId = controllerDevice.getDeviceId();
|
||||
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true);
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||
GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true);
|
||||
} catch (ControllerServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) {
|
||||
if (mControllerEventListener != null) {
|
||||
if (state == ControllerDevice.STATE_CONN)
|
||||
{
|
||||
mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId());
|
||||
}
|
||||
else if (state == ControllerDevice.STATE_DISCONN)
|
||||
{
|
||||
mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event){
|
||||
return mControllerService.handleExternalInput(event);
|
||||
}
|
||||
|
||||
public boolean dispatchKeyEvent(KeyEvent event){
|
||||
return mControllerService.handleExternalInput(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerAccEvent(int playerOrder, AccEvent event) {
|
||||
|
||||
}
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event){
|
||||
return mControllerService.handleExternalInput(event);
|
||||
}
|
||||
|
||||
public boolean dispatchKeyEvent(KeyEvent event){
|
||||
return mControllerService.handleExternalInput(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerAccEvent(int playerOrder, AccEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerGyroEvent(int playerOrder, GyroEvent event) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onControllerGyroEvent(int playerOrder, GyroEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBluetoothStateChanged(int state) {
|
||||
Log.d(TAG, "onBluetoothStateChanged:"+state);
|
||||
}
|
||||
@Override
|
||||
public void onBluetoothStateChanged(int state) {
|
||||
Log.d(TAG, "onBluetoothStateChanged:"+state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,17 +11,17 @@ import android.view.KeyEvent;
|
|||
import android.view.MotionEvent;
|
||||
|
||||
public class GameControllerOuya implements GameControllerDelegate{
|
||||
|
||||
private SparseIntArray mKeyMap;
|
||||
|
||||
private SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
public GameControllerOuya(){
|
||||
mKeyMap = new SparseIntArray(20);
|
||||
mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B);
|
||||
mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A);
|
||||
mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X);
|
||||
mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||
private SparseIntArray mKeyMap;
|
||||
|
||||
private SparseArray<String> mGameController = new SparseArray<String>();
|
||||
|
||||
public GameControllerOuya(){
|
||||
mKeyMap = new SparseIntArray(20);
|
||||
mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B);
|
||||
mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A);
|
||||
mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X);
|
||||
mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||
mKeyMap.put(OuyaController.BUTTON_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||
mKeyMap.put(OuyaController.BUTTON_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||
mKeyMap.put(OuyaController.BUTTON_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||
|
@ -34,150 +34,142 @@ public class GameControllerOuya implements GameControllerDelegate{
|
|||
}
|
||||
|
||||
public void onCreate(Context context) {
|
||||
OuyaController.init(context);
|
||||
/*GameControllerAdapter.addRunnableToFrameStartList(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
OuyaController.startOfFrame();
|
||||
}
|
||||
|
||||
});*/
|
||||
OuyaController.init(context);
|
||||
}
|
||||
|
||||
private float mOldLeftThumbstickX = 0.0f;
|
||||
private float mOldLeftThumbstickY = 0.0f;
|
||||
private float mOldRightThumbstickX = 0.0f;
|
||||
private float mOldRightThumbstickY = 0.0f;
|
||||
|
||||
private float mOldLeftThumbstickY = 0.0f;
|
||||
private float mOldRightThumbstickX = 0.0f;
|
||||
private float mOldRightThumbstickY = 0.0f;
|
||||
|
||||
private float mOldLeftTrigger = 0.0f;
|
||||
private float mOldRightTrigger = 0.0f;
|
||||
|
||||
private float mOldRightTrigger = 0.0f;
|
||||
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||
boolean handled = OuyaController.onGenericMotionEvent(event);
|
||||
|
||||
if (handled && mControllerEventListener != null)
|
||||
{
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
OuyaController c = OuyaController.getControllerByDeviceId(deviceId);
|
||||
if (mGameController.get(deviceId) == null) {
|
||||
GameControllerHelper.gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
|
||||
float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2);
|
||||
if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true);
|
||||
mOldLeftTrigger = newLeftTrigger;
|
||||
}
|
||||
|
||||
float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2);
|
||||
if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true);
|
||||
mOldRightTrigger = newRightTrigger;
|
||||
}
|
||||
|
||||
float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X);
|
||||
if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) {
|
||||
if (Float.compare(newLeftThumbstickX, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true);
|
||||
}
|
||||
mOldLeftThumbstickX = newLeftThumbstickX;
|
||||
}
|
||||
|
||||
float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y);
|
||||
if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) {
|
||||
if (Float.compare(newLeftThumbstickY, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true);
|
||||
}
|
||||
mOldLeftThumbstickY = newLeftThumbstickY;
|
||||
}
|
||||
|
||||
float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X);
|
||||
if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) {
|
||||
if (Float.compare(newRightThumbstickX, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true);
|
||||
}
|
||||
mOldRightThumbstickX = newRightThumbstickX;
|
||||
}
|
||||
|
||||
float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y);
|
||||
if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) {
|
||||
if (Float.compare(newRightThumbstickY, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true);
|
||||
}
|
||||
mOldRightThumbstickY = newRightThumbstickY;
|
||||
}
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
OuyaController c = OuyaController.getControllerByDeviceId(deviceId);
|
||||
if (mGameController.get(deviceId) == null) {
|
||||
GameControllerHelper.gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
|
||||
float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2);
|
||||
if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true);
|
||||
mOldLeftTrigger = newLeftTrigger;
|
||||
}
|
||||
|
||||
float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2);
|
||||
if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true);
|
||||
mOldRightTrigger = newRightTrigger;
|
||||
}
|
||||
|
||||
float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X);
|
||||
if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) {
|
||||
if (Float.compare(newLeftThumbstickX, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true);
|
||||
}
|
||||
mOldLeftThumbstickX = newLeftThumbstickX;
|
||||
}
|
||||
|
||||
float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y);
|
||||
if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) {
|
||||
if (Float.compare(newLeftThumbstickY, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true);
|
||||
}
|
||||
mOldLeftThumbstickY = newLeftThumbstickY;
|
||||
}
|
||||
|
||||
float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X);
|
||||
if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) {
|
||||
if (Float.compare(newRightThumbstickX, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true);
|
||||
}
|
||||
mOldRightThumbstickX = newRightThumbstickX;
|
||||
}
|
||||
|
||||
float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y);
|
||||
if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) {
|
||||
if (Float.compare(newRightThumbstickY, 0.0f) == 0) {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true);
|
||||
}else {
|
||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true);
|
||||
}
|
||||
mOldRightThumbstickY = newRightThumbstickY;
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
|
||||
int action = event.getAction();
|
||||
int keyCode = event.getKeyCode();
|
||||
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
handled = OuyaController.onKeyDown(keyCode, event);
|
||||
}
|
||||
else if (action == KeyEvent.ACTION_UP) {
|
||||
handled = OuyaController.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
if (handled && mControllerEventListener != null) {
|
||||
boolean isAnalog = false;
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){
|
||||
isAnalog = true;
|
||||
}
|
||||
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
|
||||
if (mGameController.get(deviceId) == null) {
|
||||
GameControllerHelper.gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog);
|
||||
}else {
|
||||
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog);
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
boolean handled = false;
|
||||
|
||||
int action = event.getAction();
|
||||
int keyCode = event.getKeyCode();
|
||||
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
handled = OuyaController.onKeyDown(keyCode, event);
|
||||
}
|
||||
else if (action == KeyEvent.ACTION_UP) {
|
||||
handled = OuyaController.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
if (handled && mControllerEventListener != null) {
|
||||
boolean isAnalog = false;
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){
|
||||
isAnalog = true;
|
||||
}
|
||||
|
||||
int deviceId = event.getDeviceId();
|
||||
String deviceName = event.getDevice().getName();
|
||||
|
||||
if (mGameController.get(deviceId) == null) {
|
||||
GameControllerHelper.gatherControllers(mGameController);
|
||||
mGameController.append(deviceId, deviceName);
|
||||
}
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog);
|
||||
}else {
|
||||
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog);
|
||||
}
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
public void onPause() {
|
||||
// show the mouse cursor
|
||||
OuyaController.showCursor(true);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
// hide the mouse cursor
|
||||
OuyaController.showCursor(false);
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
|
||||
private ControllerEventListener mControllerEventListener;
|
||||
|
||||
@Override
|
||||
public void setControllerEventListener(ControllerEventListener listener) {
|
||||
mControllerEventListener = listener;
|
||||
}
|
||||
|
||||
private ControllerEventListener mControllerEventListener;
|
||||
|
||||
@Override
|
||||
public void setControllerEventListener(ControllerEventListener listener) {
|
||||
mControllerEventListener = listener;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
|||
// ===========================================================
|
||||
// Constructors
|
||||
// ===========================================================
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
@ -49,7 +49,7 @@ import android.util.DisplayMetrics;
|
|||
import android.util.Log; //Enhance API modification
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.content.ServiceConnection; //Enhance API modification
|
||||
import android.content.ServiceConnection; //Enhance API modification
|
||||
|
||||
import com.enhance.gameservice.IGameTuningService; //Enhance API modification
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ public class Cocos2dxHttpURLConnection
|
|||
}
|
||||
}
|
||||
|
||||
//Add header
|
||||
//Add header
|
||||
static void addRequestHeader(HttpURLConnection urlConnection, String key, String value) {
|
||||
urlConnection.setRequestProperty(key, value);
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ public class Cocos2dxHttpURLConnection
|
|||
}
|
||||
|
||||
static String getResponseHeaders(HttpURLConnection http) {
|
||||
Map<String, List<String>> headers = http.getHeaderFields();
|
||||
Map<String, List<String>> headers = http.getHeaderFields();
|
||||
if (null == headers) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -23,5 +23,5 @@
|
|||
package org.cocos2dx.lib;
|
||||
|
||||
public class Cocos2dxJavascriptJavaBridge {
|
||||
public static native int evalString(String value);
|
||||
public static native int evalString(String value);
|
||||
}
|
||||
|
|
|
@ -147,12 +147,12 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
|
|||
}
|
||||
|
||||
public void handleOnPause() {
|
||||
/**
|
||||
* onPause may be invoked before onSurfaceCreated,
|
||||
* and engine will be initialized correctly after
|
||||
* onSurfaceCreated is invoked. Can not invoke any
|
||||
* native method before onSurfaceCreated is invoked
|
||||
*/
|
||||
/**
|
||||
* onPause may be invoked before onSurfaceCreated,
|
||||
* and engine will be initialized correctly after
|
||||
* onSurfaceCreated is invoked. Can not invoke any
|
||||
* native method before onSurfaceCreated is invoked
|
||||
*/
|
||||
if (! mNativeInitCompleted)
|
||||
return;
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ public class Cocos2dxWebViewHelper {
|
|||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
|
||||
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -138,7 +138,7 @@ public class Cocos2dxWebViewHelper {
|
|||
public void run() {
|
||||
Cocos2dxWebView webView = webViews.get(index);
|
||||
if (webView != null) {
|
||||
webView.loadDataWithBaseURL(baseUrl, data, null, null, null);
|
||||
webView.loadDataWithBaseURL(baseUrl, data, null, null, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
void setBundle(NSBundle* bundle);
|
||||
private:
|
||||
virtual bool isFileExistInternal(const std::string& filePath) const override;
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||
NSBundle* getBundle() const;
|
||||
NSBundle* _bundle;
|
||||
};
|
||||
|
|
|
@ -27,6 +27,8 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCFileUtils-apple.h"
|
||||
|
||||
#include <ftw.h>
|
||||
|
||||
#include <string>
|
||||
#include <stack>
|
||||
|
||||
|
@ -392,6 +394,16 @@ bool FileUtilsApple::isFileExistInternal(const std::string& filePath) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool FileUtilsApple::isDirectoryExistInternal(const std::string& dirPath) const
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(dirPath.c_str(), &st) == 0)
|
||||
{
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string FileUtilsApple::getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const
|
||||
{
|
||||
if (directory[0] != '/')
|
||||
|
|
|
@ -35,6 +35,7 @@ THE SOFTWARE.
|
|||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifndef CC_RESOURCE_FOLDER_LINUX
|
||||
#define CC_RESOURCE_FOLDER_LINUX ("/Resources/")
|
||||
|
@ -121,6 +122,16 @@ bool FileUtilsLinux::isFileExistInternal(const std::string& strFilePath) const
|
|||
return (stat(strPath.c_str(), &sts) != -1) ? true : false;
|
||||
}
|
||||
|
||||
bool FileUtilsLinux::isDirectoryExistInternal(const std::string& dirPath) const
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(dirPath.c_str(), &st) == 0)
|
||||
{
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
|
||||
|
|
|
@ -52,7 +52,8 @@ public:
|
|||
bool init();
|
||||
virtual std::string getWritablePath() const;
|
||||
private:
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||
};
|
||||
|
||||
// end of platform group
|
||||
|
|
|
@ -121,6 +121,17 @@ bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileUtilsWin32::isDirectoryExistInternal(const std::string& dirPath) const
|
||||
{
|
||||
unsigned long fAttrib = GetFileAttributesA(dirPath.c_str());
|
||||
if (fAttrib != INVALID_FILE_ATTRIBUTES &&
|
||||
(fAttrib & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
|
||||
{
|
||||
if ( (strPath.length() > 2
|
||||
|
|
|
@ -53,8 +53,8 @@ public:
|
|||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
||||
protected:
|
||||
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
||||
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||
/**
|
||||
* Gets resource file data
|
||||
*
|
||||
|
|
|
@ -121,6 +121,17 @@ bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool CCFileUtilsWinRT::isDirectoryExistInternal(const std::string& dirPath) const
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||
std::wstring wdirPath(dirPath.begin(), dirPath.end());
|
||||
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
||||
{
|
||||
if ( strPath.length() > 2
|
||||
|
|
|
@ -55,7 +55,8 @@ public:
|
|||
static std::string getAppPath();
|
||||
|
||||
private:
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
||||
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||
};
|
||||
|
||||
// end of platform group
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
support_lr2=1
|
||||
sdk=nibiru
|
|
@ -9,15 +9,17 @@
|
|||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<activity
|
||||
android:name=".AppActivity"
|
||||
android:screenOrientation="landscape"
|
||||
|
@ -30,6 +32,16 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.nibiru.lib.controller.InfoActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
|
||||
<service android:name="com.nibiru.lib.utils.NibiruControllerService" android:process=":controller" >
|
||||
<intent-filter>
|
||||
<action android:name="com.nibiru.controller.service" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -29,16 +29,17 @@ import org.cocos2dx.lib.GameControllerActivity;
|
|||
import android.os.Bundle;
|
||||
|
||||
public class AppActivity extends GameControllerActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
||||
|
||||
//Manually specify an adapter.
|
||||
this.connectController(DRIVERTYPE_NIBIRU);
|
||||
this.connectController(DRIVERTYPE_MOGA);
|
||||
this.connectController(DRIVERTYPE_OUYA);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
||||
|
||||
//Manually specify an adapter.
|
||||
this.connectController(DRIVERTYPE_NIBIRU);
|
||||
//Nibiru SDK have already integrated with MOGA service.
|
||||
//this.connectController(DRIVERTYPE_MOGA);
|
||||
this.connectController(DRIVERTYPE_OUYA);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,15 @@
|
|||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/icon">
|
||||
android:icon="@drawable/icon">
|
||||
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<activity android:name=".AppActivity"
|
||||
android:label="@string/app_name"
|
||||
|
@ -31,6 +33,16 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.nibiru.lib.controller.InfoActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
|
||||
<service android:name="com.nibiru.lib.utils.NibiruControllerService" android:process=":controller" >
|
||||
<intent-filter>
|
||||
<action android:name="com.nibiru.controller.service" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
<supports-screens android:anyDensity="true"
|
||||
android:smallScreens="true"
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
append_str=' \'
|
||||
|
||||
list_alldir()
|
||||
{
|
||||
for file in $1/*
|
||||
do
|
||||
if [ -f $file ]; then
|
||||
echo $file$append_str | grep .cpp
|
||||
fi
|
||||
|
||||
if [ -d $file ]; then
|
||||
list_alldir $file
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
list_alldir "$1"
|
||||
else
|
||||
list_alldir "."
|
||||
fi
|
|
@ -29,16 +29,17 @@ import org.cocos2dx.lib.GameControllerActivity;
|
|||
import android.os.Bundle;
|
||||
|
||||
public class AppActivity extends GameControllerActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
||||
|
||||
//Manually specify an adapter.
|
||||
this.connectController(DRIVERTYPE_NIBIRU);
|
||||
this.connectController(DRIVERTYPE_MOGA);
|
||||
this.connectController(DRIVERTYPE_OUYA);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
||||
|
||||
//Manually specify an adapter.
|
||||
this.connectController(DRIVERTYPE_NIBIRU);
|
||||
//Nibiru SDK have already integrated with MOGA service.
|
||||
//this.connectController(DRIVERTYPE_MOGA);
|
||||
this.connectController(DRIVERTYPE_OUYA);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue