Add SDL2 to android
This commit is contained in:
@@ -176,7 +176,6 @@ LOCAL_MODULE := irrlicht
|
||||
LOCAL_PATH := .
|
||||
LOCAL_CPP_FEATURES += rtti
|
||||
LOCAL_SRC_FILES := $(wildcard ../lib/irrlicht/source/Irrlicht/*.cpp) \
|
||||
$(wildcard ../lib/irrlicht/source/Irrlicht/Android/*.cpp) \
|
||||
../lib/irrlicht/source/Irrlicht/stk_android_native_app_glue.c
|
||||
LOCAL_CFLAGS := -I../lib/irrlicht/source/Irrlicht/ \
|
||||
-I../lib/irrlicht/include/ \
|
||||
@@ -184,12 +183,58 @@ LOCAL_CFLAGS := -I../lib/irrlicht/source/Irrlicht/ \
|
||||
-Iobj/jpeglib/ \
|
||||
-Iobj/libpng/ \
|
||||
-Iobj/zlib/ \
|
||||
-I../lib/sdl2/include/ \
|
||||
-DANDROID_PACKAGE_CALLBACK_NAME=$(PACKAGE_CALLBACK_NAME)
|
||||
LOCAL_CPPFLAGS := -std=gnu++0x
|
||||
LOCAL_STATIC_LIBRARIES := jpeglib png zlib
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
# SDL2
|
||||
LOCAL_MODULE := SDL2
|
||||
LOCAL_PATH := .
|
||||
LOCAL_CPP_FEATURES += rtti
|
||||
LOCAL_SRC_FILES := $(wildcard ../lib/sdl2/src/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/audio/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/audio/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/audio/dummy/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/audio/openslES/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/core/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/cpuinfo/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/dynapi/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/events/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/file/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/haptic/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/haptic/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/joystick/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/joystick/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/joystick/hidapi/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/joystick/virtual/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/loadso/dlopen/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/power/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/power/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/filesystem/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/sensor/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/sensor/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/render/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/render/*/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/stdlib/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/thread/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/thread/pthread/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/timer/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/timer/unix/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/video/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/video/android/*.c) \
|
||||
$(wildcard ../lib/sdl2/src/video/yuv2rgb/*.c) \
|
||||
../lib/sdl2/src/atomic/SDL_atomic.c.arm \
|
||||
../lib/sdl2/src/atomic/SDL_spinlock.c.arm \
|
||||
../lib/sdl2/src/hidapi/android/hid.cpp
|
||||
LOCAL_CFLAGS := -I../lib/sdl2/include/ -DGL_GLEXT_PROTOTYPES
|
||||
LOCAL_CPPFLAGS := -std=gnu++0x
|
||||
LOCAL_STATIC_LIBRARIES := cpufeatures
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
# STK
|
||||
LOCAL_MODULE := main
|
||||
@@ -198,7 +243,7 @@ LOCAL_CPP_FEATURES += rtti exceptions
|
||||
LOCAL_SRC_FILES := $(wildcard ../src/*.cpp) \
|
||||
$(wildcard ../src/*/*.cpp) \
|
||||
$(wildcard ../src/*/*/*.cpp)
|
||||
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv3 -lOpenSLES
|
||||
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM -lGLESv3 -lOpenSLES -ldl
|
||||
LOCAL_CFLAGS := -I../lib/angelscript/include \
|
||||
-I../lib/bullet/src \
|
||||
-I../lib/libraqm \
|
||||
@@ -208,6 +253,7 @@ LOCAL_CFLAGS := -I../lib/angelscript/include \
|
||||
-I../lib/irrlicht/source/Irrlicht \
|
||||
-I../lib/graphics_utils \
|
||||
-I../lib/mcpp \
|
||||
-I../lib/sdl2/include \
|
||||
-I../src \
|
||||
-Iobj/curl/include \
|
||||
-Iobj/fribidi/include \
|
||||
@@ -229,9 +275,10 @@ LOCAL_CFLAGS := -I../lib/angelscript/include \
|
||||
-DANDROID_PACKAGE_CALLBACK_NAME=$(PACKAGE_CALLBACK_NAME)
|
||||
LOCAL_CPPFLAGS := -std=gnu++0x
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := irrlicht bullet enet ifaddrs angelscript mcpp \
|
||||
LOCAL_STATIC_LIBRARIES := irrlicht bullet enet ifaddrs angelscript mcpp SDL2 \
|
||||
vorbisfile vorbis ogg openal curl libssl libcrypto \
|
||||
c++_static raqm fribidi harfbuzz freetype graphics_utils
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
include $(CLEAR_VARS)
|
||||
$(call import-module, android/cpufeatures)
|
||||
|
||||
@@ -38,8 +38,12 @@
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
<uses-feature android:name="android.software.input_methods" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.gamepad" android:required="false"/>
|
||||
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
</manifest>
|
||||
|
||||
@@ -559,6 +559,20 @@ sed -i "s/versionName=\".*\"/versionName=\"$PROJECT_VERSION\"/g" \
|
||||
sed -i "s/versionCode=\".*\"/versionCode=\"$PROJECT_CODE\"/g" \
|
||||
"$DIRNAME/AndroidManifest.xml"
|
||||
|
||||
cp -f "$DIRNAME/../lib/sdl2/android-project/app/src/main/java/org/libsdl/app/HIDDevice.java" \
|
||||
"$DIRNAME/src/main/java/"
|
||||
cp -f "$DIRNAME/../lib/sdl2/android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java" \
|
||||
"$DIRNAME/src/main/java/"
|
||||
cp -f "$DIRNAME/../lib/sdl2/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java" \
|
||||
"$DIRNAME/src/main/java/"
|
||||
cp -f "$DIRNAME/../lib/sdl2/android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java" \
|
||||
"$DIRNAME/src/main/java/"
|
||||
cp -f "$DIRNAME/../lib/sdl2/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java" \
|
||||
"$DIRNAME/src/main/java/"
|
||||
|
||||
sed -i "s/import org.supertuxkart.*.SuperTuxKartActivity;/import $PACKAGE_NAME.SuperTuxKartActivity;/g" \
|
||||
"$DIRNAME/src/main/java/SDLControllerManager.java"
|
||||
|
||||
cp "banner.png" "$DIRNAME/res/drawable/banner.png"
|
||||
cp "$APP_ICON" "$DIRNAME/res/drawable/icon.png"
|
||||
convert -scale 48x48 "$APP_ICON" "$DIRNAME/res/drawable-mdpi/icon.png"
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.supertuxkart.stk_dbg;
|
||||
|
||||
import org.supertuxkart.stk_dbg.STKEditText;
|
||||
|
||||
import org.libsdl.app.SDLControllerManager;
|
||||
import org.libsdl.app.HIDDeviceManager;
|
||||
|
||||
import android.app.NativeActivity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
@@ -16,6 +19,8 @@ import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewGroup.MarginLayoutParams;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -30,10 +35,14 @@ import org.minidns.record.TXT;
|
||||
public class SuperTuxKartActivity extends NativeActivity
|
||||
{
|
||||
private STKEditText m_stk_edittext;
|
||||
private static Context m_context;
|
||||
private static HIDDeviceManager m_hid_device_manager;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
private native void saveKeyboardHeight(int height);
|
||||
// ------------------------------------------------------------------------
|
||||
private native void startSTK();
|
||||
// ------------------------------------------------------------------------
|
||||
private void hideKeyboardNative(final boolean clear_text)
|
||||
{
|
||||
if (m_stk_edittext == null)
|
||||
@@ -95,6 +104,7 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
{
|
||||
super.onCreate(instance);
|
||||
System.loadLibrary("main");
|
||||
m_context = this;
|
||||
m_stk_edittext = null;
|
||||
|
||||
final View root = getWindow().getDecorView().findViewById(
|
||||
@@ -124,6 +134,12 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
hideNavBar(decor_view);
|
||||
}
|
||||
});
|
||||
SDLControllerManager.nativeSetupJNI();
|
||||
SDLControllerManager.initialize();
|
||||
m_hid_device_manager = HIDDeviceManager.acquire(this);
|
||||
// We only start stk main thread after JNI_OnLoad (for initializing the
|
||||
// java environment)
|
||||
startSTK();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
@@ -131,7 +147,29 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
{
|
||||
super.onPause();
|
||||
hideKeyboardNative(false/*clear_text*/);
|
||||
if (m_hid_device_manager != null)
|
||||
m_hid_device_manager.setFrozen(true);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if (m_hid_device_manager != null)
|
||||
m_hid_device_manager.setFrozen(false);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
if (m_hid_device_manager != null)
|
||||
{
|
||||
HIDDeviceManager.release(m_hid_device_manager);
|
||||
m_hid_device_manager = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean has_focus)
|
||||
@@ -144,6 +182,31 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event)
|
||||
{
|
||||
int device_id = event.getDeviceId();
|
||||
int source = event.getSource();
|
||||
|
||||
// Dispatch the different events depending on where they come from
|
||||
// Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
|
||||
// So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
|
||||
//
|
||||
// Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
|
||||
// SOURCE_JOYSTICK, while its key events arrive from the keyboard source
|
||||
// So, retrieve the device itself and check all of its sources
|
||||
if (SDLControllerManager.isDeviceSDLJoystick(device_id))
|
||||
{
|
||||
// Note that we process events with specific key codes here
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
{
|
||||
if (SDLControllerManager.onNativePadDown(device_id, event.getKeyCode()) == 0)
|
||||
return true;
|
||||
}
|
||||
else if (event.getAction() == KeyEvent.ACTION_UP)
|
||||
{
|
||||
if (SDLControllerManager.onNativePadUp(device_id, event.getKeyCode()) == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Called when user change cursor / select all text in native android
|
||||
// keyboard
|
||||
boolean ret = super.dispatchKeyEvent(event);
|
||||
@@ -152,6 +215,14 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
return ret;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent(MotionEvent ev)
|
||||
{
|
||||
if (SDLControllerManager.useGenericMotionListener(ev))
|
||||
return true;
|
||||
return super.dispatchGenericMotionEvent(ev);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
public void showKeyboard(final int type)
|
||||
{
|
||||
final Context context = this;
|
||||
@@ -272,4 +343,6 @@ public class SuperTuxKartActivity extends NativeActivity
|
||||
return getResources().getConfiguration()
|
||||
.keyboard == Configuration.KEYBOARD_QWERTY;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
public static Context getContext() { return m_context; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user