SDL2 Java implementation

This commit is contained in:
Sergii Pylypenko
2022-01-03 02:12:10 +02:00
parent ef8b1d2c7d
commit 094d04a4c2
15 changed files with 253 additions and 109 deletions

View File

@@ -177,7 +177,6 @@ class DataDownloader extends Thread
{
Parent = _Parent;
Status = new StatusWriter( _Status, _Parent );
//Status.setText( "Connecting to " + Globals.DataDownloadUrl );
outFilesDir = Globals.DataDir;
DownloadComplete = false;
this.start();
@@ -193,7 +192,8 @@ class DataDownloader extends Thread
@Override
public void run()
{
Parent.getVideoLayout().setOnKeyListener(new BackKeyListener(Parent));
if (Parent.getVideoLayout() != null)
Parent.getVideoLayout().setOnKeyListener(new BackKeyListener(Parent));
String [] downloadFiles = Globals.DataDownloadUrl;
int total = 0;
@@ -235,7 +235,8 @@ class DataDownloader extends Thread
}
}
DownloadComplete = true;
Parent.getVideoLayout().setOnKeyListener(null);
if (Parent.getVideoLayout() != null)
Parent.getVideoLayout().setOnKeyListener(null);
initParent();
}
@@ -855,7 +856,7 @@ class DataDownloader extends Thread
public MainActivity Parent;
public void run()
{
Parent.initSDL();
Parent.downloadFinishedInitSDL();
}
}
Callback cb = new Callback();

View File

@@ -43,6 +43,7 @@ import android.widget.RelativeLayout;
import android.graphics.drawable.Drawable;
import android.graphics.Color;
import android.content.res.Configuration;
import android.content.pm.ApplicationInfo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -193,7 +194,7 @@ public class MainActivity extends Activity
{
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP )
{
ApplicationInfo info = this.getPackageManager().getApplicationInfo(Parent.getPackageName(), 0);
ApplicationInfo info = this.getPackageManager().getApplicationInfo(this.getPackageName(), 0);
if( info.splitSourceDirs != null )
{
for( String apk: info.splitSourceDirs )
@@ -345,7 +346,7 @@ public class MainActivity extends Activity
this.runOnUiThread(cb);
}
public void initSDL()
public void downloadFinishedInitSDL()
{
setScreenOrientation();
updateScreenOrientation();
@@ -590,7 +591,7 @@ public class MainActivity extends Activity
downloader.setStatusField(_tv);
if( downloader.DownloadComplete )
{
initSDL();
downloadFinishedInitSDL();
}
}
}

56
project/java/Mouse.java Normal file
View File

@@ -0,0 +1,56 @@
/*
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;
class Mouse
{
public static final int LEFT_CLICK_NORMAL = 0;
public static final int LEFT_CLICK_NEAR_CURSOR = 1;
public static final int LEFT_CLICK_WITH_MULTITOUCH = 2;
public static final int LEFT_CLICK_WITH_PRESSURE = 3;
public static final int LEFT_CLICK_WITH_KEY = 4;
public static final int LEFT_CLICK_WITH_TIMEOUT = 5;
public static final int LEFT_CLICK_WITH_TAP = 6;
public static final int LEFT_CLICK_WITH_TAP_OR_TIMEOUT = 7;
public static final int RIGHT_CLICK_NONE = 0;
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
public static final int RIGHT_CLICK_WITH_KEY = 3;
public static final int RIGHT_CLICK_WITH_TIMEOUT = 4;
public static final int SDL_FINGER_DOWN = 0;
public static final int SDL_FINGER_UP = 1;
public static final int SDL_FINGER_MOVE = 2;
public static final int SDL_FINGER_HOVER = 3;
public static final int ZOOM_NONE = 0;
public static final int ZOOM_MAGNIFIER = 1;
public static final int MOUSE_HW_INPUT_FINGER = 0;
public static final int MOUSE_HW_INPUT_STYLUS = 1;
public static final int MOUSE_HW_INPUT_MOUSE = 2;
public static final int MAX_HOVER_DISTANCE = 1024;
public static final int HOVER_REDRAW_SCREEN = 1024 * 10;
public static final float MAX_PRESSURE = 1024.0f;
}

View File

@@ -278,7 +278,7 @@ class SDL_1_2_Keycodes
// Autogenerated by hand with a command:
// grep 'SDL_SCANCODE_' SDL_scancode.h | sed 's/SDL_SCANCODE_\([a-zA-Z0-9_]\+\).*[=] \([0-9]\+\).*/public static final int SDLK_\1 = \2;/' >> Keycodes.java
class SDL_1_3_Keycodes
class SDL_2_Keycodes
{
public static final int SDLK_UNKNOWN = 0;
public static final int SDLK_A = 4;
@@ -519,6 +519,10 @@ class SDL_1_3_Keycodes
public static final int SDLK_KBDILLUMUP = 280;
public static final int SDLK_EJECT = 281;
public static final int SDLK_SLEEP = 282;
public static final int SDLK_APP1 = 283;
public static final int SDLK_APP2 = 284;
public static final int SDLK_AUDIOREWIND = 285;
public static final int SDLK_AUDIOFASTFORWARD = 286;
// Mouse buttons can be mapped to on-screen keys
public static final int SDLK_MOUSE_LEFT = 500;
@@ -558,9 +562,9 @@ class SDL_Keys
ArrayList<String> Names = new ArrayList<String> ();
ArrayList<Integer> Values = new ArrayList<Integer> ();
Field [] fields = SDL_1_2_Keycodes.class.getDeclaredFields();
if( Globals.Using_SDL_1_3 )
if( Globals.UsingSDL2 )
{
fields = SDL_1_3_Keycodes.class.getDeclaredFields();
fields = SDL_2_Keycodes.class.getDeclaredFields();
}
try {

View File

@@ -629,7 +629,7 @@ public class Settings
Globals.TouchscreenKeyboardTransparency,
Globals.FloatingScreenJoystick ? 1 : 0,
Globals.AppTouchscreenKeyboardKeysAmount );
SetupTouchscreenKeyboardGraphics(p);
DemoGLSurfaceView.SetupTouchscreenKeyboardGraphics(p);
for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ )
nativeSetKeymapKeyScreenKb(i, SDL_Keys.values[Globals.RemapScreenKbKeycode[i]]);
if( Globals.TouchscreenKeyboardSize == Globals.TOUCHSCREEN_KEYBOARD_CUSTOM )
@@ -736,63 +736,6 @@ public class Settings
} catch (Exception eeeee) {}
}
static byte [] loadRaw(Activity p, int res)
{
byte [] buf = new byte[65536 * 2];
byte [] a = new byte[1048576 * 5]; // We need 5Mb buffer for Keen theme, and this Java code is inefficient
int written = 0;
try{
InputStream is = new GZIPInputStream(p.getResources().openRawResource(res));
int readed = 0;
while( (readed = is.read(buf)) >= 0 )
{
if( written + readed > a.length )
{
byte [] b = new byte [written + readed];
System.arraycopy(a, 0, b, 0, written);
a = b;
}
System.arraycopy(buf, 0, a, written, readed);
written += readed;
}
} catch(Exception e) {};
byte [] b = new byte [written];
System.arraycopy(a, 0, b, 0, written);
return b;
}
static void SetupTouchscreenKeyboardGraphics(Activity p)
{
if( Globals.UseTouchscreenKeyboard )
{
if(Globals.TouchscreenKeyboardTheme < 0)
Globals.TouchscreenKeyboardTheme = 0;
if(Globals.TouchscreenKeyboardTheme > 9)
Globals.TouchscreenKeyboardTheme = 9;
if( Globals.TouchscreenKeyboardTheme == 0 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.ultimatedroid));
if( Globals.TouchscreenKeyboardTheme == 1 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.simpletheme));
if( Globals.TouchscreenKeyboardTheme == 2 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.sun));
if( Globals.TouchscreenKeyboardTheme == 3 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.keen));
if( Globals.TouchscreenKeyboardTheme == 4 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.retro));
if( Globals.TouchscreenKeyboardTheme == 5 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.gba));
if( Globals.TouchscreenKeyboardTheme == 6 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.psx));
if( Globals.TouchscreenKeyboardTheme == 7 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.snes));
if( Globals.TouchscreenKeyboardTheme == 8 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.dualshock));
if( Globals.TouchscreenKeyboardTheme == 9 )
nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.n64));
}
}
abstract static class SdcardAppPath
{
public static SdcardAppPath get()
@@ -1023,7 +966,7 @@ public class Settings
private static native void nativeSetVideoMultithreaded();
private static native void nativeSetVideoForceSoftwareMode();
public static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int transparency, int floatingScreenJoystick, int buttonAmount);
private static native void nativeSetupScreenKeyboardButtons(byte[] img);
public static native void nativeSetupScreenKeyboardButtons(byte[] img);
private static native void nativeInitKeymap();
private static native int nativeGetKeymapKey(int key);
private static native void nativeSetKeymapKey(int javakey, int key);

View File

@@ -369,7 +369,7 @@ class SettingsMenuMisc extends SettingsMenu
defaults = defaults2;
}
if(Globals.Using_SDL_1_3)
if(Globals.UsingSDL2)
{
CharSequence[] items2 = {
p.getResources().getString(R.string.mouse_keepaspectratio),

View File

@@ -33,11 +33,13 @@ import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
import java.io.File;
import java.io.InputStream;
import java.util.concurrent.locks.ReentrantLock;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.zip.GZIPInputStream;
import android.os.Bundle;
import android.os.Build;
@@ -69,40 +71,6 @@ import android.hardware.input.InputManager;
import android.graphics.Rect;
class Mouse
{
public static final int LEFT_CLICK_NORMAL = 0;
public static final int LEFT_CLICK_NEAR_CURSOR = 1;
public static final int LEFT_CLICK_WITH_MULTITOUCH = 2;
public static final int LEFT_CLICK_WITH_PRESSURE = 3;
public static final int LEFT_CLICK_WITH_KEY = 4;
public static final int LEFT_CLICK_WITH_TIMEOUT = 5;
public static final int LEFT_CLICK_WITH_TAP = 6;
public static final int LEFT_CLICK_WITH_TAP_OR_TIMEOUT = 7;
public static final int RIGHT_CLICK_NONE = 0;
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
public static final int RIGHT_CLICK_WITH_KEY = 3;
public static final int RIGHT_CLICK_WITH_TIMEOUT = 4;
public static final int SDL_FINGER_DOWN = 0;
public static final int SDL_FINGER_UP = 1;
public static final int SDL_FINGER_MOVE = 2;
public static final int SDL_FINGER_HOVER = 3;
public static final int ZOOM_NONE = 0;
public static final int ZOOM_MAGNIFIER = 1;
public static final int MOUSE_HW_INPUT_FINGER = 0;
public static final int MOUSE_HW_INPUT_STYLUS = 1;
public static final int MOUSE_HW_INPUT_MOUSE = 2;
public static final int MAX_HOVER_DISTANCE = 1024;
public static final int HOVER_REDRAW_SCREEN = 1024 * 10;
public static final float MAX_PRESSURE = 1024.0f;
}
abstract class DifferentTouchInput
{
public abstract void process(final MotionEvent event);
@@ -776,7 +744,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
if(mGlContextLost) {
mGlContextLost = false;
Settings.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics
DemoGLSurfaceView.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics
super.SwapBuffers();
}
@@ -1256,6 +1224,63 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
}
}
static byte [] loadRaw(Activity p, int res)
{
byte [] buf = new byte[65536 * 2];
byte [] a = new byte[1048576 * 5]; // We need 5Mb buffer for Keen theme, and this Java code is inefficient
int written = 0;
try{
InputStream is = new GZIPInputStream(p.getResources().openRawResource(res));
int readed = 0;
while( (readed = is.read(buf)) >= 0 )
{
if( written + readed > a.length )
{
byte [] b = new byte [written + readed];
System.arraycopy(a, 0, b, 0, written);
a = b;
}
System.arraycopy(buf, 0, a, written, readed);
written += readed;
}
} catch(Exception e) {};
byte [] b = new byte [written];
System.arraycopy(a, 0, b, 0, written);
return b;
}
static void SetupTouchscreenKeyboardGraphics(Activity p)
{
if( Globals.UseTouchscreenKeyboard )
{
if(Globals.TouchscreenKeyboardTheme < 0)
Globals.TouchscreenKeyboardTheme = 0;
if(Globals.TouchscreenKeyboardTheme > 9)
Globals.TouchscreenKeyboardTheme = 9;
if( Globals.TouchscreenKeyboardTheme == 0 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.ultimatedroid));
if( Globals.TouchscreenKeyboardTheme == 1 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.simpletheme));
if( Globals.TouchscreenKeyboardTheme == 2 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.sun));
if( Globals.TouchscreenKeyboardTheme == 3 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.keen));
if( Globals.TouchscreenKeyboardTheme == 4 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.retro));
if( Globals.TouchscreenKeyboardTheme == 5 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.gba));
if( Globals.TouchscreenKeyboardTheme == 6 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.psx));
if( Globals.TouchscreenKeyboardTheme == 7 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.snes));
if( Globals.TouchscreenKeyboardTheme == 8 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.dualshock));
if( Globals.TouchscreenKeyboardTheme == 9 )
Settings.nativeSetupScreenKeyboardButtons(loadRaw(p, R.raw.n64));
}
}
DemoRenderer mRenderer;
MainActivity mParent;