Updated Java settings dialog, added Java-C callbacks, tested on device - it doesn't work properly yet

This commit is contained in:
pelya
2010-08-18 15:47:25 +03:00
parent a88843354c
commit c0d8427795
7 changed files with 72 additions and 93 deletions

View File

@@ -30,26 +30,6 @@
#include "SDL_config.h"
#include "SDL_version.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "SDL_events.h"
#if (SDL_VERSION_ATLEAST(1,3,0))
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "SDL_scancode.h"
#include "SDL_compat.h"
#else
#include "SDL_keysym.h"
#include "../../events/SDL_events_c.h"
#endif
#include "SDL_joystick.h"
#include "../../joystick/SDL_sysjoystick.h"
#include "../../joystick/SDL_joystick_c.h"
#include "SDL_androidvideo.h"
#include "SDL_androidinput.h"

View File

@@ -171,8 +171,6 @@ enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
enum { MAX_MULTITOUCH_POINTERS = 5 };
extern int SDL_android_drawTouchscreenKeyboard();
extern int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointerId);
#ifndef SDL_ANDROID_KEYCODE_0

View File

@@ -19,11 +19,13 @@
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_androidvideo_h
#define _SDL_androidvideo_h
#include "SDL_config.h"
#include "SDL_video.h"
#include "../SDL_sysvideo.h"
extern void ANDROID_InitOSKeymap();
extern int SDL_ANDROID_sWindowWidth;
@@ -31,7 +33,7 @@ extern int SDL_ANDROID_sWindowHeight;
extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only
extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only
extern int SDL_ANDROID_CallJavaSwapBuffers();
// typedef struct SDL_VideoDevice SDL_VideoDevice;
extern int SDL_android_drawTouchscreenKeyboard();
extern SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex);
// Keycodes ripped from Java SDK

View File

@@ -26,30 +26,11 @@
#include <stdint.h>
#include <math.h>
#include <string.h> // for memset()
#include <GLES/gl.h>
#include "SDL_config.h"
#include "SDL_version.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_mutex.h"
#include "SDL_thread.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "SDL_events.h"
#if (SDL_VERSION_ATLEAST(1,3,0))
#include "../../events/SDL_events_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
#include "SDL_scancode.h"
#include "SDL_compat.h"
#else
#include "SDL_keysym.h"
#include "../../events/SDL_events_c.h"
#endif
#include "SDL_joystick.h"
#include "../../joystick/SDL_sysjoystick.h"
#include "../../joystick/SDL_joystick_c.h"
#include "SDL_androidvideo.h"
#include "SDL_androidinput.h"
@@ -122,7 +103,7 @@ static inline void drawChar(int idx, Uint16 x, Uint16 y, Uint8 r, Uint8 g, Uint8
glPushMatrix();
glTranslatex( x, y, 0 );
glVertexPointer(2, GL_SHORT, 0, vertices);
glVertexPointer(2, GL_SHORT, 0, fontGL[idx]);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINE_STRIP, 0, fontGL[idx][FONT_CHAR_LINES_COUNT]);
glDisableClientState(GL_VERTEX_ARRAY);
@@ -198,7 +179,7 @@ int SDL_android_drawTouchscreenKeyboard()
static inline int ArrowKeysPressed(int x, int y)
{
itn ret = 0, dx, dy;
int ret = 0, dx, dy;
/*
if( !InsideRect( &arrows, x, y ) )
return 0;
@@ -261,7 +242,7 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer
return 1;
}
for( int i = 0; i < nbuttons; i++ )
for( i = 0; i < nbuttons; i++ )
{
if( InsideRect( &buttons[i], x, y) )
{
@@ -289,12 +270,12 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer
oldArrows = 0;
return 1;
}
for( int i = 0; i < nbuttons; i++ )
for( i = 0; i < nbuttons; i++ )
{
if( OldCoords[pointerId] == &buttons[i] )
{
if( ! ( i == 0 && Button1AutoFire ) )
SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i]) ,&keysym) );
SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) );
OldCoords[pointerId] = NULL;
return 1;
}
@@ -344,3 +325,10 @@ int SDL_android_processTouchscreenKeyboard(int x, int y, int action, int pointer
return 0;
};
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenKeyboardUsed) ( JNIEnv* env, jobject thiz)
{
isTouchscreenKeyboardUsed = 1;
}

View File

@@ -25,7 +25,7 @@ class AccelerometerReader implements SensorEventListener {
_manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
if( _manager != null )
{
if( Globals.AppNeedsArrowKeys )
if( Globals.UseAccelerometerAsArrowKeys )
{
_manager.registerListener(this, _manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_GAME);
}

View File

@@ -10,12 +10,6 @@ class Globals {
// Should be zip file
public static String DataDownloadUrl = "http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0%26d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"; // This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
// Set DownloadToSdcard to true if your app data is bigger than 5 megabytes.
// It will download app data to /sdcard/alienblaster then,
// otherwise it will download it to /data/data/de.schwardtnet.alienblaster/files -
// set this dir in jni/Android.mk in SDL_CURDIR_PATH
public static boolean DownloadToSdcard = false;
// Set this value to true if you're planning to render 3D using OpenGL - it eats some GFX resources, so disabled for 2D
public static boolean NeedDepthBuffer = false;
@@ -27,14 +21,20 @@ class Globals {
public static boolean AppUsesMouse = false;
// We have to use accelerometer as arrow keys
public static boolean AppNeedsArrowKeys = true;
public static boolean AppUsesJoystick = false;
public static boolean AppUsesMultitouch = false;
// Phone-specific config
// It will download app data to /sdcard/alienblaster if set to true,
// otherwise it will download it to /data/data/de.schwardtnet.alienblaster/files
public static boolean DownloadToSdcard = false;
public static boolean PhoneHasTrackball = false;
public static boolean PhoneHasArrowKeys = false;
public static boolean UseAccelerometerAsArrowKeys = false;
public static boolean UseTouchscreenKeyboard = false;
}
class LoadLibrary {

View File

@@ -20,13 +20,31 @@ import android.os.StatFs;
class Settings
{
static String SettingsFileName = "libsdl-settings.cfg";
static void Save(final MainActivity p)
{
try {
ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE ));
out.writeBoolean(Globals.DownloadToSdcard);
out.writeBoolean(Globals.PhoneHasArrowKeys);
out.writeBoolean(Globals.PhoneHasTrackball);
out.writeBoolean(Globals.UseAccelerometerAsArrowKeys);
out.writeBoolean(Globals.UseTouchscreenKeyboard);
out.close();
} catch( FileNotFoundException e ) {
} catch( SecurityException e ) {
} catch ( IOException e ) {};
}
static void Load( final MainActivity p )
{
try {
ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName ));
Globals.DownloadToSdcard = settingsFile.readBoolean();
Globals.AppNeedsArrowKeys = settingsFile.readBoolean();
Globals.PhoneHasArrowKeys = settingsFile.readBoolean();
Globals.PhoneHasTrackball = settingsFile.readBoolean();
Globals.UseAccelerometerAsArrowKeys = settingsFile.readBoolean();
Globals.UseTouchscreenKeyboard = settingsFile.readBoolean();
startDownloader(p);
return;
@@ -86,7 +104,7 @@ class Settings
static void showKeyboardConfig(final MainActivity p)
{
if( ! Globals.AppNeedsArrowKeys )
if( ! Globals.AppNeedsArrowKeys )
{
Save(p);
startDownloader(p);
@@ -101,11 +119,11 @@ class Settings
{
public void onClick(DialogInterface dialog, int item)
{
Globals.AppNeedsArrowKeys = (item == 2);
Globals.PhoneHasArrowKeys = (item == 0);
Globals.PhoneHasTrackball = (item == 1);
dialog.dismiss();
showAccelermoeterConfig(p);
showAdditionalInputConfig(p);
}
});
AlertDialog alert = builder.create();
@@ -113,24 +131,23 @@ class Settings
alert.show();
}
static void showAccelermoeterConfig(final MainActivity p)
static void showAdditionalInputConfig(final MainActivity p)
{
if( Globals.AppNeedsArrowKeys || Globals.AppUsesJoystick )
{
Save(p);
startDownloader(p);
return;
}
final CharSequence[] items = {"Do not use accelerometer", "Use accelerometer as navigation keys"};
final CharSequence[] items = {
"On-screen keyboard" + ( Globals.AppUsesMouse ? " (disables mouse input)" : ""),
"Accelerometer as navigation keys" + ( Globals.AppUsesJoystick ? " (disables joystick input)" : "" ),
"Both accelerometer and on-screen keyboard",
"No additional controls" + ( Globals.AppNeedsArrowKeys ? " (you won't be able to play without arrow keys)" : " (only if your phone has enough buttons)")
};
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle("You may optionally use accelerometer as another navigation keys");
builder.setTitle("Additional controls to use");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
Globals.AppNeedsArrowKeys = (item == 1);
Globals.UseTouchscreenKeyboard = (item == 0 || item == 2);
Globals.UseAccelerometerAsArrowKeys = (item == 1 || item == 2);
Save(p);
dialog.dismiss();
@@ -142,19 +159,6 @@ class Settings
alert.show();
}
static void Save(final MainActivity p)
{
try {
ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE ));
out.writeBoolean(Globals.DownloadToSdcard);
out.writeBoolean(Globals.AppNeedsArrowKeys);
out.writeBoolean(Globals.PhoneHasTrackball);
out.close();
} catch( FileNotFoundException e ) {
} catch( SecurityException e ) {
} catch ( IOException e ) {};
}
static void Apply()
{
@@ -164,10 +168,15 @@ class Settings
nativeSetTrackballUsed();
if( Globals.AppUsesMouse )
nativeSetMouseUsed();
if( Globals.AppUsesJoystick && !Globals.AppNeedsArrowKeys )
if( Globals.AppUsesJoystick && !Globals.UseAccelerometerAsArrowKeys )
nativeSetJoystickUsed();
if( Globals.AppUsesMultitouch )
nativeSetMultitouchUsed();
if( Globals.UseTouchscreenKeyboard )
{
nativeSetTouchscreenKeyboardUsed();
nativeSetupScreenKeyboard(0, 4);
}
}
static void startDownloader(MainActivity p)
@@ -186,10 +195,12 @@ class Settings
};
private static native int nativeIsSdcardUsed(int flag);
private static native int nativeSetTrackballUsed();
private static native int nativeSetMouseUsed();
private static native int nativeSetJoystickUsed();
private static native int nativeSetMultitouchUsed();
private static native void nativeIsSdcardUsed(int flag);
private static native void nativeSetTrackballUsed();
private static native void nativeSetMouseUsed();
private static native void nativeSetJoystickUsed();
private static native void nativeSetMultitouchUsed();
private static native void nativeSetTouchscreenKeyboardUsed();
private static native void nativeSetupScreenKeyboard(int size, int nbuttons);
}