Some rudimentary support for hardware mouse

This commit is contained in:
pelya
2012-01-31 18:48:16 +02:00
parent 66c66a59d9
commit c6489923f7
17 changed files with 75 additions and 26 deletions

View File

@@ -33,7 +33,6 @@ import android.media.AudioTrack;
import android.media.AudioManager;
import android.media.AudioFormat;
import java.io.*;
import java.nio.ByteBuffer;
import android.util.Log;
import java.lang.Thread;

View File

@@ -471,7 +471,7 @@ class DataDownloader extends Thread
try {
CheckedInputStream check = new CheckedInputStream( new FileInputStream(path), new CRC32() );
while( check.read(buf, 0, buf.length) > 0 ) {};
while( check.read(buf, 0, buf.length) >= 0 ) {};
check.close();
if( check.getChecksum().getValue() != entry.getCrc() )
{
@@ -525,19 +525,26 @@ class DataDownloader extends Thread
}
try {
long count = 0, ret = 0;
CheckedInputStream check = new CheckedInputStream( new FileInputStream(path), new CRC32() );
while( check.read(buf, 0, buf.length) > 0 ) {};
while( ret >= 0 )
{
count += ret;
ret = check.read(buf, 0, buf.length);
}
check.close();
if( check.getChecksum().getValue() != entry.getCrc() )
if( check.getChecksum().getValue() != entry.getCrc() || count != entry.getSize() )
{
File ff = new File(path);
ff.delete();
System.out.println("Saving file '" + path + "' - CRC check failed, ZIP: " +
String.format("%x", entry.getCrc()) + " actual file: " + String.format("%x", check.getChecksum().getValue()) +
" file size in ZIP: " + entry.getSize() + " actual size " + count );
throw new Exception();
}
} catch( Exception e )
{
Status.setText( res.getString(R.string.error_write, path) );
System.out.println("Saving file '" + path + "' - CRC check failed");
return false;
}
System.out.println("Saving file '" + path + "' done");

View File

@@ -70,6 +70,7 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance = this;
// fullscreen mode
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
@@ -697,5 +698,5 @@ public class MainActivity extends Activity {
private InputMethodManager _inputManager = null;
public LinkedList<Integer> textInput = new LinkedList<Integer> ();
public static MainActivity instance = null;
}

View File

@@ -2553,6 +2553,7 @@ class Settings
int leftClickTimeout, int rightClickTimeout,
int relativeMovement, int relativeMovementSpeed,
int relativeMovementAccel, int showMouseCursor);
public static native void nativeSetExternalMouseDetected();
private static native void nativeSetJoystickUsed();
private static native void nativeSetMultitouchUsed();
private static native void nativeSetTouchscreenKeyboardUsed();

View File

@@ -45,6 +45,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.content.res.Resources;
import android.content.res.AssetManager;
import android.widget.Toast;
import android.widget.TextView;
import java.lang.Thread;
@@ -87,6 +88,8 @@ class Mouse
abstract class DifferentTouchInput
{
public static boolean ExternalMouseDetected = true;
public static DifferentTouchInput getInstance()
{
boolean multiTouchAvailable1 = false;
@@ -223,8 +226,8 @@ abstract class DifferentTouchInput
if( touchEvents[id].down )
action = Mouse.SDL_FINGER_MOVE;
else
action = Mouse.SDL_FINGER_DOWN;
touchEvents[id].down = true;
action = Mouse.SDL_FINGER_HOVER; //action = Mouse.SDL_FINGER_DOWN;
//touchEvents[id].down = true;
touchEvents[id].x = (int)event.getX(ii);
touchEvents[id].y = (int)event.getY(ii);
touchEvents[id].pressure = (int)(event.getPressure(ii) * 1000.0);
@@ -247,6 +250,12 @@ abstract class DifferentTouchInput
touchEvents[0].size = 0;
DemoGLSurfaceView.nativeMouse( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
}
if( action == Mouse.SDL_FINGER_HOVER && !ExternalMouseDetected )
{
ExternalMouseDetected = true;
Settings.nativeSetExternalMouseDetected();
Toast.makeText(MainActivity.instance, R.string.hardware_mouse_detected, Toast.LENGTH_SHORT).show();
}
}
}
}
@@ -325,6 +334,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
}
Settings.Apply(context);
DifferentTouchInput.ExternalMouseDetected = false;
accelerometer = new AccelerometerReader(context);
// Tweak video thread priority, if user selected big audio buffer
if(Globals.AudioBufferConfig >= 2)
@@ -400,7 +410,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
int width = bmp.getBitmap().getWidth();
int height = bmp.getBitmap().getHeight();
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * width * height);
byteBuffer.order(ByteOrder.BIG_ENDIAN);
//byteBuffer.order(ByteOrder.BIG_ENDIAN);
bmp.getBitmap().copyPixelsToBuffer(byteBuffer);
byteBuffer.position(0);

View File

@@ -131,4 +131,6 @@
<string name="controls_screenkb_drawsize">Размер изображения кнопок</string>
<string name="display_size_small_touchpad">Маленький, режим тачпада</string>
<string name="display_size_tiny_touchpad">Крохотный, режим тачпада</string>
<string name="hardware_mouse_detected">Обнаружена внешняя мышь, эмуляция мыши выключена</string>
</resources>

View File

@@ -129,4 +129,6 @@
<string name="controls_screenkb_drawsize">Розмір зображення кнопок</string>
<string name="display_size_small_touchpad">Маленький, режим тачпаду</string>
<string name="display_size_tiny_touchpad">Крихiтний, режим тачпаду</string>
<string name="hardware_mouse_detected">Виявлена зовнiшня миша, емуляція миші вимкнена</string>
</resources>

View File

@@ -159,4 +159,6 @@
<string name="broken_libc_title">Broken OS detected</string>
<string name="broken_libc_text">Your device has broken system libraries, this application will most probably crash. Please install a system update, or flash a custom ROM, or copy file /system/lib/libc.so from another device (experts only!)</string>
<string name="hardware_mouse_detected">Hardware mouse detected, disabling mouse emulation</string>
</resources>