SDL2: custom activity that overrides SDLActivity

This commit is contained in:
Sergii Pylypenko
2022-01-02 00:11:31 +02:00
parent a235249f57
commit 919bf9a378
16 changed files with 179 additions and 100 deletions

View File

@@ -14,7 +14,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
<activity android:name=".MainActivity"
<activity android:name="MainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleTask"
@@ -50,7 +50,7 @@
<!-- ==GOOGLEPLAYGAMESERVICES== --> <meta-data android:name="com.google.android.gms.appstate.APP_ID" android:value="@string/google_play_game_services_app_id" />
<!-- ==GOOGLEPLAYGAMESERVICES== --> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" /> <!-- Samsung's multiwindow -->
<activity android:name=".RestartMainActivity"
<activity android:name="RestartMainActivity"
android:label="@string/app_name"
android:alwaysRetainTaskState="true"
android:launchMode="singleTask"

View File

@@ -338,54 +338,6 @@ class DataDownloader extends Thread
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.connecting_to, url) );
if( url.equals("assetpack") )
{
Log.i("SDL", "Checking for asset pack");
/*
try
{
AssetPackManager assetPackManager = AssetPackManagerFactory.getInstance(Parent.getApplicationContext());
Log.i("SDL", "Parent.getApplicationContext(): " + Parent.getApplicationContext() + " assetPackManager " + assetPackManager);
if( assetPackManager != null )
{
Log.i("SDL", "assetPackManager.getPackLocation(): " + assetPackManager.getPackLocation("assetpack"));
if( assetPackManager.getPackLocation("assetpack") != null )
{
String assetPackPath = assetPackManager.getPackLocation("assetpack").assetsPath();
Parent.assetPackPath = assetPackPath;
if( assetPackPath != null )
{
Log.i("SDL", "Asset pack is installed at: " + assetPackPath);
return true;
}
}
}
}
catch( Exception e )
{
Log.i("SDL", "Asset pack exception: " + e);
}
*/
try
{
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP )
{
ApplicationInfo info = Parent.getPackageManager().getApplicationInfo(Parent.getPackageName(), 0);
if( info.splitSourceDirs != null )
{
for( String apk: info.splitSourceDirs )
{
Log.i("SDL", "Package apk: " + apk);
if( apk.endsWith("assetpack.apk") )
{
Parent.assetPackPath = apk;
}
}
}
}
}
catch( Exception e )
{
Log.i("SDL", "Asset pack exception: " + e);
}
if( Parent.assetPackPath != null )
{
Log.i("SDL", "Found asset pack: " + Parent.assetPackPath);

View File

@@ -39,8 +39,7 @@ class Globals
{ "expat", "expat-sdl" },
{ "sqlite3", "sqlite3-sdl" },
}; // Because some libraries are named differently to not clash with system libs
public static final boolean Using_SDL_1_3 = false;
public static final boolean Using_SDL_2_0 = false;
public static final boolean UsingSDL2 = false;
public static String[] DataDownloadUrl = { "Data files are 2 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-data.zip/download", "High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp.zip/download" };
public static boolean SwVideoMode = false;
public static boolean NeedDepthBuffer = false;

View File

@@ -188,6 +188,31 @@ public class MainActivity extends Activity
_videoLayout.requestFocus();
DimSystemStatusBar.dim(_videoLayout, getWindow());
Log.i("SDL", "Checking for asset pack");
try
{
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP )
{
ApplicationInfo info = this.getPackageManager().getApplicationInfo(Parent.getPackageName(), 0);
if( info.splitSourceDirs != null )
{
for( String apk: info.splitSourceDirs )
{
Log.i("SDL", "Package apk: " + apk);
if( apk.endsWith("assetpack.apk") )
{
this.assetPackPath = apk;
Log.i("SDL", "Found asset pack: " + this.assetPackPath);
}
}
}
}
}
catch( Exception eee )
{
Log.i("SDL", "Asset pack exception: " + eee);
}
class Callback implements Runnable
{
MainActivity p;

View File

@@ -1001,6 +1001,7 @@ public class Settings
Save(MainActivity.instance);
}
// libsdl-1.2.so, does not exist in SDL2
private static native void nativeSetAccelerometerSettings(int sensitivity, int centerPos);
private static native void nativeSetMouseUsed(int RightClickMethod, int ShowScreenUnderFinger, int LeftClickMethod,
int MoveMouseWithJoystick, int ClickMouseWithDpad, int MaxForce, int MaxRadius,
@@ -1035,6 +1036,7 @@ public class Settings
private static native void nativeSetKeymapKeyMultitouchGesture(int keynum, int key);
private static native void nativeSetMultitouchGestureSensitivity(int sensitivity);
public static native void nativeSetTouchscreenCalibration(int x1, int y1, int x2, int y2);
// libsdl_native_helpers.so, exists in both versions
public static native void nativeSetEnv(final String name, final String value);
public static native int nativeChmod(final String name, int mode);
public static native void nativeChdir(final String dir);

View File

@@ -0,0 +1 @@
../java/Globals.java

View File

@@ -0,0 +1,87 @@
/*
Simple DirectMedia Layer
Java source code (C) 2009-2014 Sergii Pylypenko
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
package net.sourceforge.clonekeenplus;
import android.app.Activity;
import java.util.ArrayList;
public class MainActivity extends org.libsdl.app.SDLActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Globals.DataDir = this.getFilesDir().getAbsolutePath();
Settings.LoadConfig(this); // Load Globals.DataDir from SDL 1.2 installation, we never save config file
Log.i("SDL", "Checking for asset pack");
try
{
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP )
{
ApplicationInfo info = this.getPackageManager().getApplicationInfo(Parent.getPackageName(), 0);
if( info.splitSourceDirs != null )
{
for( String apk: info.splitSourceDirs )
{
Log.i("SDL", "Package apk: " + apk);
if( apk.endsWith("assetpack.apk") )
{
this.assetPackPath = apk;
Log.i("SDL", "Found asset pack: " + this.assetPackPath);
}
}
}
}
}
catch( Exception eee )
{
Log.i("SDL", "Asset pack exception: " + eee);
}
Settings.setEnvVars(this);
}
@Override
protected String[] getLibraries() {
ArrayList<String> ret = new ArrayList<String>();
for (String l: Globals.AppLibraries) {
ret.add(GetMappedLibraryName(l));
}
return ret.toArray(new String[0]);
}
@Override
protected String[] getArguments() {
return new String[0];
}
private static String GetMappedLibraryName(final String s) {
for (int i = 0; i < Globals.LibraryNamesMap.length; i++) {
if (Globals.LibraryNamesMap[i][0].equals(s))
return Globals.LibraryNamesMap[i][1];
}
return s;
}
public String ObbMountPath = null; // Deprecated, always empty
public String assetPackPath = null; // Not saved to the config file
}

View File

@@ -0,0 +1 @@
../java/Settings.java

View File

@@ -0,0 +1 @@
../java/translations

1
project/jni/SDL2/include Symbolic link
View File

@@ -0,0 +1 @@
../sdl2/include

View File

@@ -6,7 +6,9 @@ LOCAL_MODULE := application
APPDIR := $(shell readlink $(LOCAL_PATH)/src)
LOCAL_SHARED_LIBRARIES := sdl-$(SDL_VERSION) $(filter-out $(APP_AVAILABLE_STATIC_LIBS), $(COMPILED_LIBRARIES))
SDL_LIB := $(if $(filter 1.2, $(SDL_VERSION)), sdl-1.2, SDL2)
LOCAL_SHARED_LIBRARIES := $(SDL_LIB_NAME) $(filter-out $(APP_AVAILABLE_STATIC_LIBS), $(COMPILED_LIBRARIES))
LOCAL_STATIC_LIBRARIES := $(filter $(APP_AVAILABLE_STATIC_LIBS), $(COMPILED_LIBRARIES))
@@ -45,7 +47,7 @@ LOCAL_CFLAGS += $(foreach D, $(LOCAL_C_INCLUDES), -iquote$(D))
LOCAL_C_INCLUDES :=
endif
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../sdl-$(SDL_VERSION)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../$(SDL_LIB_NAME)/include
LOCAL_C_INCLUDES += $(foreach L, $(COMPILED_LIBRARIES), $(LOCAL_PATH)/../$(L)/include)
LOCAL_CFLAGS += $(APPLICATION_ADDITIONAL_CFLAGS)

View File

@@ -36,21 +36,21 @@ AppDataDownloadUrl="!!SSL certificates|:ca-certificates.crt:ca-certificates.crt"
ResetSdlConfigForThisVersion=y
# Delete application data files when upgrading (specify file/dir paths separated by spaces)
DeleteFilesOnUpgrade="libsdl-DownloadFinished-0.flag"
DeleteFilesOnUpgrade=""
# Here you may type readme text, which will be shown during startup. Format is:
# Text in English, use \\\\n to separate lines (that's four backslashes)^de:Text in Deutsch^ru:Text in Russian^button:Button that will open some URL:http://url-to-open/
ReadmeText='^You may press "Home" now - the data will be downloaded in background'
# libSDL version to use (1.2/1.3/2.0)
LibSdlVersion=1.2
# libSDL version to use (1.2/2)
LibSdlVersion=2
# Specify screen orientation: (v)ertical/(p)ortrait or (h)orizontal/(l)andscape
ScreenOrientation=h
# Video color depth - 16 BPP is the fastest and supported for all modes, 24 bpp is supported only
# with SwVideoMode=y, SDL_OPENGL mode supports everything. (16)/(24)/(32)
VideoDepthBpp=16
VideoDepthBpp=24
# Enable OpenGL depth buffer (needed only for 3-d applications, small speed decrease) (y) or (n)
NeedDepthBuffer=n
@@ -60,14 +60,14 @@ NeedStencilBuffer=n
# Use GLES 2.x context
# you need this option only if you're developing 3-d app (y) or (n)
NeedGles2=n
NeedGles2=y
# Use GLES 3.x context
# you need this option only if you're developing 3-d app (y) or (n)
NeedGles3=
NeedGles3=n
# Use gl4es library for provide OpenGL 1.x functionality to OpenGL ES accelerated cards (y) or (n)
UseGl4es=
UseGl4es=n
# Application uses software video buffer - you're calling SDL_SetVideoMode() without SDL_HWSURFACE and without SDL_OPENGL,
# this will allow small speed optimization. Enable this even when you're using SDL_HWSURFACE. (y) or (n)
@@ -91,7 +91,7 @@ CompatibilityHacksForceScreenUpdate=n
# Application does not call SDL_Flip() or SDL_UpdateRects() after mouse click (ScummVM and all Amiga emulators do that) -
# force screen update by moving mouse cursor a little after each click (y) or (n)
CompatibilityHacksForceScreenUpdateMouseClick=y
CompatibilityHacksForceScreenUpdateMouseClick=n
# Application initializes SDL audio/video inside static constructors (which is bad, you won't be able to run ndk-gdb) (y)/(n)
CompatibilityHacksStaticInit=n
@@ -285,13 +285,12 @@ APP_PLATFORM=
# Specify architectures to compile, 'all' or 'y' to compile for all architectures.
# Available architectures: armeabi-v7a arm64-v8a x86 x86_64
MultiABI='armeabi-v7a x86 x86_64 arm64-v8a'
MultiABI=arm64-v8a
MultiABI='arm64-v8a'
# Optional shared libraries to compile - removing some of them will save space
# MP3 patents are expired, but libmad license is GPL, not LGPL
# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2
CompiledLibraries="c++_shared sdl_image sdl_ttf glm boost_filesystem boost_system boost_date_time boost_locale icuuc icudata iconv charset crypto ssl curl openal vorbis ogg"
CompiledLibraries="c++_shared SDL2_image glm boost_filesystem boost_system boost_date_time boost_locale icuuc icudata iconv charset crypto ssl curl openal vorbis ogg"
# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n)
CustomBuildScript=n

View File

@@ -1 +0,0 @@
include include/Android.mk

View File

@@ -1 +0,0 @@
include include/Android.mk

View File

@@ -0,0 +1 @@
../drawable/icon.png