android: reduce visiblity as much as possible

This commit is contained in:
Anonymous Maarten
2025-03-15 23:13:27 +01:00
committed by Anonymous Maarten
parent c696e93180
commit 9820f655dd
11 changed files with 134 additions and 124 deletions

View File

@@ -44,9 +44,9 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
private static final int CHROMEBOOK_CONNECTION_CHECK_INTERVAL = 10000; private static final int CHROMEBOOK_CONNECTION_CHECK_INTERVAL = 10000;
static public final UUID steamControllerService = UUID.fromString("100F6C32-1735-4313-B402-38567131E5F3"); static final UUID steamControllerService = UUID.fromString("100F6C32-1735-4313-B402-38567131E5F3");
static public final UUID inputCharacteristic = UUID.fromString("100F6C33-1735-4313-B402-38567131E5F3"); static final UUID inputCharacteristic = UUID.fromString("100F6C33-1735-4313-B402-38567131E5F3");
static public final UUID reportCharacteristic = UUID.fromString("100F6C34-1735-4313-B402-38567131E5F3"); static final UUID reportCharacteristic = UUID.fromString("100F6C34-1735-4313-B402-38567131E5F3");
static private final byte[] enterValveMode = new byte[] { (byte)0xC0, (byte)0x87, 0x03, 0x08, 0x07, 0x00 }; static private final byte[] enterValveMode = new byte[] { (byte)0xC0, (byte)0x87, 0x03, 0x08, 0x07, 0x00 };
static class GattOperation { static class GattOperation {
@@ -156,7 +156,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
} }
} }
public HIDDeviceBLESteamController(HIDDeviceManager manager, BluetoothDevice device) { HIDDeviceBLESteamController(HIDDeviceManager manager, BluetoothDevice device) {
mManager = manager; mManager = manager;
mDevice = device; mDevice = device;
mDeviceId = mManager.getDeviceIDForIdentifier(getIdentifier()); mDeviceId = mManager.getDeviceIDForIdentifier(getIdentifier());
@@ -169,17 +169,17 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
// final HIDDeviceBLESteamController finalThis = this; // final HIDDeviceBLESteamController finalThis = this;
// mHandler.postDelayed(new Runnable() { // mHandler.postDelayed(new Runnable() {
// @Override // @Override
// public void run() { // void run() {
// finalThis.checkConnectionForChromebookIssue(); // finalThis.checkConnectionForChromebookIssue();
// } // }
// }, CHROMEBOOK_CONNECTION_CHECK_INTERVAL); // }, CHROMEBOOK_CONNECTION_CHECK_INTERVAL);
} }
public String getIdentifier() { String getIdentifier() {
return String.format("SteamController.%s", mDevice.getAddress()); return String.format("SteamController.%s", mDevice.getAddress());
} }
public BluetoothGatt getGatt() { BluetoothGatt getGatt() {
return mGatt; return mGatt;
} }
@@ -219,7 +219,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
return btManager.getConnectionState(mDevice, BluetoothProfile.GATT); return btManager.getConnectionState(mDevice, BluetoothProfile.GATT);
} }
public void reconnect() { void reconnect() {
if (getConnectionState() != BluetoothProfile.STATE_CONNECTED) { if (getConnectionState() != BluetoothProfile.STATE_CONNECTED) {
mGatt.disconnect(); mGatt.disconnect();
@@ -401,12 +401,12 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
queueGattOperation(op); queueGattOperation(op);
} }
public void writeCharacteristic(UUID uuid, byte[] value) { void writeCharacteristic(UUID uuid, byte[] value) {
GattOperation op = HIDDeviceBLESteamController.GattOperation.writeCharacteristic(mGatt, uuid, value); GattOperation op = HIDDeviceBLESteamController.GattOperation.writeCharacteristic(mGatt, uuid, value);
queueGattOperation(op); queueGattOperation(op);
} }
public void readCharacteristic(UUID uuid) { void readCharacteristic(UUID uuid) {
GattOperation op = HIDDeviceBLESteamController.GattOperation.readCharacteristic(mGatt, uuid); GattOperation op = HIDDeviceBLESteamController.GattOperation.readCharacteristic(mGatt, uuid);
queueGattOperation(op); queueGattOperation(op);
} }
@@ -415,6 +415,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
////////////// BluetoothGattCallback overridden methods ////////////// BluetoothGattCallback overridden methods
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onConnectionStateChange(BluetoothGatt g, int status, int newState) { public void onConnectionStateChange(BluetoothGatt g, int status, int newState) {
//Log.v(TAG, "onConnectionStateChange status=" + status + " newState=" + newState); //Log.v(TAG, "onConnectionStateChange status=" + status + " newState=" + newState);
mIsReconnecting = false; mIsReconnecting = false;
@@ -437,6 +438,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
// Disconnection is handled in SteamLink using the ACTION_ACL_DISCONNECTED Intent. // Disconnection is handled in SteamLink using the ACTION_ACL_DISCONNECTED Intent.
} }
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) { public void onServicesDiscovered(BluetoothGatt gatt, int status) {
//Log.v(TAG, "onServicesDiscovered status=" + status); //Log.v(TAG, "onServicesDiscovered status=" + status);
if (status == 0) { if (status == 0) {
@@ -453,6 +455,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
} }
} }
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
//Log.v(TAG, "onCharacteristicRead status=" + status + " uuid=" + characteristic.getUuid()); //Log.v(TAG, "onCharacteristicRead status=" + status + " uuid=" + characteristic.getUuid());
@@ -463,6 +466,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
finishCurrentGattOperation(); finishCurrentGattOperation();
} }
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
//Log.v(TAG, "onCharacteristicWrite status=" + status + " uuid=" + characteristic.getUuid()); //Log.v(TAG, "onCharacteristicWrite status=" + status + " uuid=" + characteristic.getUuid());
@@ -478,6 +482,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
finishCurrentGattOperation(); finishCurrentGattOperation();
} }
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
// Enable this for verbose logging of controller input reports // Enable this for verbose logging of controller input reports
//Log.v(TAG, "onCharacteristicChanged uuid=" + characteristic.getUuid() + " data=" + HexDump.dumpHexString(characteristic.getValue())); //Log.v(TAG, "onCharacteristicChanged uuid=" + characteristic.getUuid() + " data=" + HexDump.dumpHexString(characteristic.getValue()));
@@ -487,10 +492,12 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
} }
} }
@Override
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
//Log.v(TAG, "onDescriptorRead status=" + status); //Log.v(TAG, "onDescriptorRead status=" + status);
} }
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
BluetoothGattCharacteristic chr = descriptor.getCharacteristic(); BluetoothGattCharacteristic chr = descriptor.getCharacteristic();
//Log.v(TAG, "onDescriptorWrite status=" + status + " uuid=" + chr.getUuid() + " descriptor=" + descriptor.getUuid()); //Log.v(TAG, "onDescriptorWrite status=" + status + " uuid=" + chr.getUuid() + " descriptor=" + descriptor.getUuid());
@@ -508,14 +515,17 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
finishCurrentGattOperation(); finishCurrentGattOperation();
} }
@Override
public void onReliableWriteCompleted(BluetoothGatt gatt, int status) { public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
//Log.v(TAG, "onReliableWriteCompleted status=" + status); //Log.v(TAG, "onReliableWriteCompleted status=" + status);
} }
@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
//Log.v(TAG, "onReadRemoteRssi status=" + status); //Log.v(TAG, "onReadRemoteRssi status=" + status);
} }
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
//Log.v(TAG, "onMtuChanged status=" + status); //Log.v(TAG, "onMtuChanged status=" + status);
} }

View File

@@ -25,14 +25,14 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
public class HIDDeviceManager { class HIDDeviceManager {
private static final String TAG = "hidapi"; private static final String TAG = "hidapi";
private static final String ACTION_USB_PERMISSION = "org.libsdl.app.USB_PERMISSION"; private static final String ACTION_USB_PERMISSION = "org.libsdl.app.USB_PERMISSION";
private static HIDDeviceManager sManager; private static HIDDeviceManager sManager;
private static int sManagerRefCount = 0; private static int sManagerRefCount = 0;
public static HIDDeviceManager acquire(Context context) { static HIDDeviceManager acquire(Context context) {
if (sManagerRefCount == 0) { if (sManagerRefCount == 0) {
sManager = new HIDDeviceManager(context); sManager = new HIDDeviceManager(context);
} }
@@ -40,7 +40,7 @@ public class HIDDeviceManager {
return sManager; return sManager;
} }
public static void release(HIDDeviceManager manager) { static void release(HIDDeviceManager manager) {
if (manager == sManager) { if (manager == sManager) {
--sManagerRefCount; --sManagerRefCount;
if (sManagerRefCount == 0) { if (sManagerRefCount == 0) {
@@ -121,11 +121,11 @@ public class HIDDeviceManager {
} }
} }
public Context getContext() { Context getContext() {
return mContext; return mContext;
} }
public int getDeviceIDForIdentifier(String identifier) { int getDeviceIDForIdentifier(String identifier) {
SharedPreferences.Editor spedit = mSharedPreferences.edit(); SharedPreferences.Editor spedit = mSharedPreferences.edit();
int result = mSharedPreferences.getInt(identifier, 0); int result = mSharedPreferences.getInt(identifier, 0);
@@ -439,7 +439,7 @@ public class HIDDeviceManager {
// Chromebooks do not pass along ACTION_ACL_CONNECTED / ACTION_ACL_DISCONNECTED properly. // Chromebooks do not pass along ACTION_ACL_CONNECTED / ACTION_ACL_DISCONNECTED properly.
// This function provides a sort of dummy version of that, watching for changes in the // This function provides a sort of dummy version of that, watching for changes in the
// connected devices and attempting to add controllers as things change. // connected devices and attempting to add controllers as things change.
public void chromebookConnectionHandler() { void chromebookConnectionHandler() {
if (!mIsChromebook) { if (!mIsChromebook) {
return; return;
} }
@@ -478,7 +478,7 @@ public class HIDDeviceManager {
}, 10000); }, 10000);
} }
public boolean connectBluetoothDevice(BluetoothDevice bluetoothDevice) { boolean connectBluetoothDevice(BluetoothDevice bluetoothDevice) {
Log.v(TAG, "connectBluetoothDevice device=" + bluetoothDevice); Log.v(TAG, "connectBluetoothDevice device=" + bluetoothDevice);
synchronized (this) { synchronized (this) {
if (mBluetoothDevices.containsKey(bluetoothDevice)) { if (mBluetoothDevices.containsKey(bluetoothDevice)) {
@@ -499,7 +499,7 @@ public class HIDDeviceManager {
return true; return true;
} }
public void disconnectBluetoothDevice(BluetoothDevice bluetoothDevice) { void disconnectBluetoothDevice(BluetoothDevice bluetoothDevice) {
synchronized (this) { synchronized (this) {
HIDDeviceBLESteamController device = mBluetoothDevices.get(bluetoothDevice); HIDDeviceBLESteamController device = mBluetoothDevices.get(bluetoothDevice);
if (device == null) if (device == null)
@@ -513,7 +513,7 @@ public class HIDDeviceManager {
} }
} }
public boolean isSteamController(BluetoothDevice bluetoothDevice) { boolean isSteamController(BluetoothDevice bluetoothDevice) {
// Sanity check. If you pass in a null device, by definition it is never a Steam Controller. // Sanity check. If you pass in a null device, by definition it is never a Steam Controller.
if (bluetoothDevice == null) { if (bluetoothDevice == null) {
return false; return false;
@@ -540,7 +540,7 @@ public class HIDDeviceManager {
} }
} }
public void setFrozen(boolean frozen) { void setFrozen(boolean frozen) {
synchronized (this) { synchronized (this) {
for (HIDDevice device : mDevicesById.values()) { for (HIDDevice device : mDevicesById.values()) {
device.setFrozen(frozen); device.setFrozen(frozen);
@@ -567,7 +567,7 @@ public class HIDDeviceManager {
////////// JNI interface functions ////////// JNI interface functions
////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////
public boolean initialize(boolean usb, boolean bluetooth) { boolean initialize(boolean usb, boolean bluetooth) {
Log.v(TAG, "initialize(" + usb + ", " + bluetooth + ")"); Log.v(TAG, "initialize(" + usb + ", " + bluetooth + ")");
if (usb) { if (usb) {
@@ -579,7 +579,7 @@ public class HIDDeviceManager {
return true; return true;
} }
public boolean openDevice(int deviceID) { boolean openDevice(int deviceID) {
Log.v(TAG, "openDevice deviceID=" + deviceID); Log.v(TAG, "openDevice deviceID=" + deviceID);
HIDDevice device = getDevice(deviceID); HIDDevice device = getDevice(deviceID);
if (device == null) { if (device == null) {
@@ -621,7 +621,7 @@ public class HIDDeviceManager {
return false; return false;
} }
public int writeReport(int deviceID, byte[] report, boolean feature) { int writeReport(int deviceID, byte[] report, boolean feature) {
try { try {
//Log.v(TAG, "writeReport deviceID=" + deviceID + " length=" + report.length); //Log.v(TAG, "writeReport deviceID=" + deviceID + " length=" + report.length);
HIDDevice device; HIDDevice device;
@@ -638,7 +638,7 @@ public class HIDDeviceManager {
return -1; return -1;
} }
public boolean readReport(int deviceID, byte[] report, boolean feature) { boolean readReport(int deviceID, byte[] report, boolean feature) {
try { try {
//Log.v(TAG, "readReport deviceID=" + deviceID); //Log.v(TAG, "readReport deviceID=" + deviceID);
HIDDevice device; HIDDevice device;
@@ -655,7 +655,7 @@ public class HIDDeviceManager {
return false; return false;
} }
public void closeDevice(int deviceID) { void closeDevice(int deviceID) {
try { try {
Log.v(TAG, "closeDevice deviceID=" + deviceID); Log.v(TAG, "closeDevice deviceID=" + deviceID);
HIDDevice device; HIDDevice device;

View File

@@ -30,7 +30,7 @@ class HIDDeviceUSB implements HIDDevice {
mRunning = false; mRunning = false;
} }
public String getIdentifier() { String getIdentifier() {
return String.format("%s/%x/%x/%d", mDevice.getDeviceName(), mDevice.getVendorId(), mDevice.getProductId(), mInterfaceIndex); return String.format("%s/%x/%x/%d", mDevice.getDeviceName(), mDevice.getVendorId(), mDevice.getProductId(), mInterfaceIndex);
} }
@@ -100,7 +100,7 @@ class HIDDeviceUSB implements HIDDevice {
return mDevice; return mDevice;
} }
public String getDeviceName() { String getDeviceName() {
return getManufacturerName() + " " + getProductName() + "(0x" + String.format("%x", getVendorId()) + "/0x" + String.format("%x", getProductId()) + ")"; return getManufacturerName() + " " + getProductName() + "(0x" + String.format("%x", getVendorId()) + "/0x" + String.format("%x", getProductId()) + ")";
} }

View File

@@ -8,18 +8,18 @@ import java.lang.reflect.Method;
/** /**
SDL library initialization SDL library initialization
*/ */
public class SDL { class SDL {
// This function should be called first and sets up the native code // This function should be called first and sets up the native code
// so it can call into the Java classes // so it can call into the Java classes
public static void setupJNI() { static void setupJNI() {
SDLActivity.nativeSetupJNI(); SDLActivity.nativeSetupJNI();
SDLAudioManager.nativeSetupJNI(); SDLAudioManager.nativeSetupJNI();
SDLControllerManager.nativeSetupJNI(); SDLControllerManager.nativeSetupJNI();
} }
// This function should be called each time the activity is started // This function should be called each time the activity is started
public static void initialize() { static void initialize() {
setContext(null); setContext(null);
SDLActivity.initialize(); SDLActivity.initialize();
@@ -28,20 +28,20 @@ public class SDL {
} }
// This function stores the current activity (SDL or not) // This function stores the current activity (SDL or not)
public static void setContext(Context context) { static void setContext(Context context) {
SDLAudioManager.setContext(context); SDLAudioManager.setContext(context);
mContext = context; mContext = context;
} }
public static Context getContext() { static Context getContext() {
return mContext; return mContext;
} }
public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException { static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
loadLibrary(libraryName, mContext); loadLibrary(libraryName, mContext);
} }
public static void loadLibrary(String libraryName, Context context) throws UnsatisfiedLinkError, SecurityException, NullPointerException { static void loadLibrary(String libraryName, Context context) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
if (libraryName == null) { if (libraryName == null) {
throw new NullPointerException("No library name provided."); throw new NullPointerException("No library name provided.");

View File

@@ -10,14 +10,14 @@ import android.util.Log;
import java.util.Arrays; import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
public class SDLAudioManager { class SDLAudioManager {
protected static final String TAG = "SDLAudio"; protected static final String TAG = "SDLAudio";
protected static Context mContext; protected static Context mContext;
private static AudioDeviceCallback mAudioDeviceCallback; private static AudioDeviceCallback mAudioDeviceCallback;
public static void initialize() { static void initialize() {
mAudioDeviceCallback = null; mAudioDeviceCallback = null;
if(Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) if(Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */)
@@ -40,11 +40,11 @@ public class SDLAudioManager {
} }
} }
public static void setContext(Context context) { static void setContext(Context context) {
mContext = context; mContext = context;
} }
public static void release(Context context) { static void release(Context context) {
// no-op atm // no-op atm
} }
@@ -74,7 +74,7 @@ public class SDLAudioManager {
return null; return null;
} }
public static void registerAudioDeviceCallback() { static void registerAudioDeviceCallback() {
if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
// get an initial list now, before hotplug callbacks fire. // get an initial list now, before hotplug callbacks fire.
@@ -91,7 +91,7 @@ public class SDLAudioManager {
} }
} }
public static void unregisterAudioDeviceCallback() { static void unregisterAudioDeviceCallback() {
if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback); audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback);
@@ -99,7 +99,7 @@ public class SDLAudioManager {
} }
/** This method is called by SDL using JNI. */ /** This method is called by SDL using JNI. */
public static void audioSetThreadPriority(boolean recording, int device_id) { static void audioSetThreadPriority(boolean recording, int device_id) {
try { try {
/* Set thread name */ /* Set thread name */
@@ -117,10 +117,10 @@ public class SDLAudioManager {
} }
} }
public static native int nativeSetupJNI(); static native int nativeSetupJNI();
public static native void removeAudioDevice(boolean recording, int deviceId); static native void removeAudioDevice(boolean recording, int deviceId);
public static native void addAudioDevice(boolean recording, String name, int deviceId); static native void addAudioDevice(boolean recording, String name, int deviceId);
} }

View File

@@ -17,23 +17,23 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
public class SDLControllerManager class SDLControllerManager
{ {
public static native int nativeSetupJNI(); static native int nativeSetupJNI();
public static native void nativeAddJoystick(int device_id, String name, String desc, static native void nativeAddJoystick(int device_id, String name, String desc,
int vendor_id, int product_id, int vendor_id, int product_id,
int button_mask, int button_mask,
int naxes, int axis_mask, int nhats, boolean can_rumble); int naxes, int axis_mask, int nhats, boolean can_rumble);
public static native void nativeRemoveJoystick(int device_id); static native void nativeRemoveJoystick(int device_id);
public static native void nativeAddHaptic(int device_id, String name); static native void nativeAddHaptic(int device_id, String name);
public static native void nativeRemoveHaptic(int device_id); static native void nativeRemoveHaptic(int device_id);
public static native boolean onNativePadDown(int device_id, int keycode); static native boolean onNativePadDown(int device_id, int keycode);
public static native boolean onNativePadUp(int device_id, int keycode); static native boolean onNativePadUp(int device_id, int keycode);
public static native void onNativeJoy(int device_id, int axis, static native void onNativeJoy(int device_id, int axis,
float value); float value);
public static native void onNativeHat(int device_id, int hat_id, static native void onNativeHat(int device_id, int hat_id,
int x, int y); int x, int y);
protected static SDLJoystickHandler mJoystickHandler; protected static SDLJoystickHandler mJoystickHandler;
@@ -41,7 +41,7 @@ public class SDLControllerManager
private static final String TAG = "SDLControllerManager"; private static final String TAG = "SDLControllerManager";
public static void initialize() { static void initialize() {
if (mJoystickHandler == null) { if (mJoystickHandler == null) {
if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) { if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
mJoystickHandler = new SDLJoystickHandler_API19(); mJoystickHandler = new SDLJoystickHandler_API19();
@@ -62,48 +62,48 @@ public class SDLControllerManager
} }
// Joystick glue code, just a series of stubs that redirect to the SDLJoystickHandler instance // Joystick glue code, just a series of stubs that redirect to the SDLJoystickHandler instance
public static boolean handleJoystickMotionEvent(MotionEvent event) { static boolean handleJoystickMotionEvent(MotionEvent event) {
return mJoystickHandler.handleMotionEvent(event); return mJoystickHandler.handleMotionEvent(event);
} }
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void pollInputDevices() { static void pollInputDevices() {
mJoystickHandler.pollInputDevices(); mJoystickHandler.pollInputDevices();
} }
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void pollHapticDevices() { static void pollHapticDevices() {
mHapticHandler.pollHapticDevices(); mHapticHandler.pollHapticDevices();
} }
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void hapticRun(int device_id, float intensity, int length) { static void hapticRun(int device_id, float intensity, int length) {
mHapticHandler.run(device_id, intensity, length); mHapticHandler.run(device_id, intensity, length);
} }
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void hapticRumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length) { static void hapticRumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length) {
mHapticHandler.rumble(device_id, low_frequency_intensity, high_frequency_intensity, length); mHapticHandler.rumble(device_id, low_frequency_intensity, high_frequency_intensity, length);
} }
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void hapticStop(int device_id) static void hapticStop(int device_id)
{ {
mHapticHandler.stop(device_id); mHapticHandler.stop(device_id);
} }
// Check if a given device is considered a possible SDL joystick // Check if a given device is considered a possible SDL joystick
public static boolean isDeviceSDLJoystick(int deviceId) { static boolean isDeviceSDLJoystick(int deviceId) {
InputDevice device = InputDevice.getDevice(deviceId); InputDevice device = InputDevice.getDevice(deviceId);
// We cannot use InputDevice.isVirtual before API 16, so let's accept // We cannot use InputDevice.isVirtual before API 16, so let's accept
// only nonnegative device ids (VIRTUAL_KEYBOARD equals -1) // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
@@ -140,14 +140,14 @@ class SDLJoystickHandler {
* @param event the event to be handled. * @param event the event to be handled.
* @return if given event was processed. * @return if given event was processed.
*/ */
public boolean handleMotionEvent(MotionEvent event) { boolean handleMotionEvent(MotionEvent event) {
return false; return false;
} }
/** /**
* Handles adding and removing of input devices. * Handles adding and removing of input devices.
*/ */
public void pollInputDevices() { void pollInputDevices() {
} }
} }
@@ -155,11 +155,11 @@ class SDLJoystickHandler {
class SDLJoystickHandler_API16 extends SDLJoystickHandler { class SDLJoystickHandler_API16 extends SDLJoystickHandler {
static class SDLJoystick { static class SDLJoystick {
public int device_id; int device_id;
public String name; String name;
public String desc; String desc;
public ArrayList<InputDevice.MotionRange> axes; ArrayList<InputDevice.MotionRange> axes;
public ArrayList<InputDevice.MotionRange> hats; ArrayList<InputDevice.MotionRange> hats;
} }
static class RangeComparator implements Comparator<InputDevice.MotionRange> { static class RangeComparator implements Comparator<InputDevice.MotionRange> {
@Override @Override
@@ -210,13 +210,13 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
private final ArrayList<SDLJoystick> mJoysticks; private final ArrayList<SDLJoystick> mJoysticks;
public SDLJoystickHandler_API16() { SDLJoystickHandler_API16() {
mJoysticks = new ArrayList<SDLJoystick>(); mJoysticks = new ArrayList<SDLJoystick>();
} }
@Override @Override
public void pollInputDevices() { void pollInputDevices() {
int[] deviceIds = InputDevice.getDeviceIds(); int[] deviceIds = InputDevice.getDeviceIds();
for (int device_id : deviceIds) { for (int device_id : deviceIds) {
@@ -299,7 +299,7 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
} }
@Override @Override
public boolean handleMotionEvent(MotionEvent event) { boolean handleMotionEvent(MotionEvent event) {
int actionPointerIndex = event.getActionIndex(); int actionPointerIndex = event.getActionIndex();
int action = event.getActionMasked(); int action = event.getActionMasked();
if (action == MotionEvent.ACTION_MOVE) { if (action == MotionEvent.ACTION_MOVE) {
@@ -321,7 +321,7 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
return true; return true;
} }
public String getJoystickDescriptor(InputDevice joystickDevice) { String getJoystickDescriptor(InputDevice joystickDevice) {
String desc = joystickDevice.getDescriptor(); String desc = joystickDevice.getDescriptor();
if (desc != null && !desc.isEmpty()) { if (desc != null && !desc.isEmpty()) {
@@ -330,16 +330,16 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
return joystickDevice.getName(); return joystickDevice.getName();
} }
public int getProductId(InputDevice joystickDevice) { int getProductId(InputDevice joystickDevice) {
return 0; return 0;
} }
public int getVendorId(InputDevice joystickDevice) { int getVendorId(InputDevice joystickDevice) {
return 0; return 0;
} }
public int getAxisMask(List<InputDevice.MotionRange> ranges) { int getAxisMask(List<InputDevice.MotionRange> ranges) {
return -1; return -1;
} }
public int getButtonMask(InputDevice joystickDevice) { int getButtonMask(InputDevice joystickDevice) {
return -1; return -1;
} }
} }
@@ -347,17 +347,17 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 { class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 {
@Override @Override
public int getProductId(InputDevice joystickDevice) { int getProductId(InputDevice joystickDevice) {
return joystickDevice.getProductId(); return joystickDevice.getProductId();
} }
@Override @Override
public int getVendorId(InputDevice joystickDevice) { int getVendorId(InputDevice joystickDevice) {
return joystickDevice.getVendorId(); return joystickDevice.getVendorId();
} }
@Override @Override
public int getAxisMask(List<InputDevice.MotionRange> ranges) { int getAxisMask(List<InputDevice.MotionRange> ranges) {
// For compatibility, keep computing the axis mask like before, // For compatibility, keep computing the axis mask like before,
// only really distinguishing 2, 4 and 6 axes. // only really distinguishing 2, 4 and 6 axes.
int axis_mask = 0; int axis_mask = 0;
@@ -394,7 +394,7 @@ class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 {
} }
@Override @Override
public int getButtonMask(InputDevice joystickDevice) { int getButtonMask(InputDevice joystickDevice) {
int button_mask = 0; int button_mask = 0;
int[] keys = new int[] { int[] keys = new int[] {
KeyEvent.KEYCODE_BUTTON_A, KeyEvent.KEYCODE_BUTTON_A,
@@ -491,7 +491,7 @@ class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 {
class SDLHapticHandler_API31 extends SDLHapticHandler { class SDLHapticHandler_API31 extends SDLHapticHandler {
@Override @Override
public void run(int device_id, float intensity, int length) { void run(int device_id, float intensity, int length) {
SDLHaptic haptic = getHaptic(device_id); SDLHaptic haptic = getHaptic(device_id);
if (haptic != null) { if (haptic != null) {
vibrate(haptic.vib, intensity, length); vibrate(haptic.vib, intensity, length);
@@ -499,7 +499,7 @@ class SDLHapticHandler_API31 extends SDLHapticHandler {
} }
@Override @Override
public void rumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length) { void rumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length) {
InputDevice device = InputDevice.getDevice(device_id); InputDevice device = InputDevice.getDevice(device_id);
if (device == null) { if (device == null) {
return; return;
@@ -543,7 +543,7 @@ class SDLHapticHandler_API31 extends SDLHapticHandler {
class SDLHapticHandler_API26 extends SDLHapticHandler { class SDLHapticHandler_API26 extends SDLHapticHandler {
@Override @Override
public void run(int device_id, float intensity, int length) { void run(int device_id, float intensity, int length) {
SDLHaptic haptic = getHaptic(device_id); SDLHaptic haptic = getHaptic(device_id);
if (haptic != null) { if (haptic != null) {
if (intensity == 0.0f) { if (intensity == 0.0f) {
@@ -575,36 +575,36 @@ class SDLHapticHandler_API26 extends SDLHapticHandler {
class SDLHapticHandler { class SDLHapticHandler {
static class SDLHaptic { static class SDLHaptic {
public int device_id; int device_id;
public String name; String name;
public Vibrator vib; Vibrator vib;
} }
private final ArrayList<SDLHaptic> mHaptics; private final ArrayList<SDLHaptic> mHaptics;
public SDLHapticHandler() { SDLHapticHandler() {
mHaptics = new ArrayList<SDLHaptic>(); mHaptics = new ArrayList<SDLHaptic>();
} }
public void run(int device_id, float intensity, int length) { void run(int device_id, float intensity, int length) {
SDLHaptic haptic = getHaptic(device_id); SDLHaptic haptic = getHaptic(device_id);
if (haptic != null) { if (haptic != null) {
haptic.vib.vibrate(length); haptic.vib.vibrate(length);
} }
} }
public void rumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length) { void rumble(int device_id, float low_frequency_intensity, float high_frequency_intensity, int length) {
// Not supported in older APIs // Not supported in older APIs
} }
public void stop(int device_id) { void stop(int device_id) {
SDLHaptic haptic = getHaptic(device_id); SDLHaptic haptic = getHaptic(device_id);
if (haptic != null) { if (haptic != null) {
haptic.vib.cancel(); haptic.vib.cancel();
} }
} }
public void pollHapticDevices() { void pollHapticDevices() {
final int deviceId_VIBRATOR_SERVICE = 999999; final int deviceId_VIBRATOR_SERVICE = 999999;
boolean hasVibratorService = false; boolean hasVibratorService = false;
@@ -724,31 +724,31 @@ class SDLGenericMotionListener_API14 implements View.OnGenericMotionListener {
return consumed; return consumed;
} }
public boolean supportsRelativeMouse() { boolean supportsRelativeMouse() {
return false; return false;
} }
public boolean inRelativeMode() { boolean inRelativeMode() {
return false; return false;
} }
public boolean setRelativeMouseEnabled(boolean enabled) { boolean setRelativeMouseEnabled(boolean enabled) {
return false; return false;
} }
public void reclaimRelativeMouseModeIfNeeded() { void reclaimRelativeMouseModeIfNeeded() {
} }
public boolean checkRelativeEvent(MotionEvent event) { boolean checkRelativeEvent(MotionEvent event) {
return inRelativeMode(); return inRelativeMode();
} }
public float getEventX(MotionEvent event, int pointerIndex) { float getEventX(MotionEvent event, int pointerIndex) {
return event.getX(pointerIndex); return event.getX(pointerIndex);
} }
public float getEventY(MotionEvent event, int pointerIndex) { float getEventY(MotionEvent event, int pointerIndex) {
return event.getY(pointerIndex); return event.getY(pointerIndex);
} }
@@ -760,23 +760,23 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API14 {
private boolean mRelativeModeEnabled; private boolean mRelativeModeEnabled;
@Override @Override
public boolean supportsRelativeMouse() { boolean supportsRelativeMouse() {
return true; return true;
} }
@Override @Override
public boolean inRelativeMode() { boolean inRelativeMode() {
return mRelativeModeEnabled; return mRelativeModeEnabled;
} }
@Override @Override
public boolean setRelativeMouseEnabled(boolean enabled) { boolean setRelativeMouseEnabled(boolean enabled) {
mRelativeModeEnabled = enabled; mRelativeModeEnabled = enabled;
return true; return true;
} }
@Override @Override
public float getEventX(MotionEvent event, int pointerIndex) { float getEventX(MotionEvent event, int pointerIndex) {
if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) { if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) {
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_X, pointerIndex); return event.getAxisValue(MotionEvent.AXIS_RELATIVE_X, pointerIndex);
} else { } else {
@@ -785,7 +785,7 @@ class SDLGenericMotionListener_API24 extends SDLGenericMotionListener_API14 {
} }
@Override @Override
public float getEventY(MotionEvent event, int pointerIndex) { float getEventY(MotionEvent event, int pointerIndex) {
if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) { if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) {
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y, pointerIndex); return event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y, pointerIndex);
} else { } else {
@@ -799,17 +799,17 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
private boolean mRelativeModeEnabled; private boolean mRelativeModeEnabled;
@Override @Override
public boolean supportsRelativeMouse() { boolean supportsRelativeMouse() {
return (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */); return (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */);
} }
@Override @Override
public boolean inRelativeMode() { boolean inRelativeMode() {
return mRelativeModeEnabled; return mRelativeModeEnabled;
} }
@Override @Override
public boolean setRelativeMouseEnabled(boolean enabled) { boolean setRelativeMouseEnabled(boolean enabled) {
if (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */) { if (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */) {
if (enabled) { if (enabled) {
SDLActivity.getContentView().requestPointerCapture(); SDLActivity.getContentView().requestPointerCapture();
@@ -824,25 +824,25 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
} }
@Override @Override
public void reclaimRelativeMouseModeIfNeeded() { void reclaimRelativeMouseModeIfNeeded() {
if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) { if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) {
SDLActivity.getContentView().requestPointerCapture(); SDLActivity.getContentView().requestPointerCapture();
} }
} }
@Override @Override
public boolean checkRelativeEvent(MotionEvent event) { boolean checkRelativeEvent(MotionEvent event) {
return event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE; return event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE;
} }
@Override @Override
public float getEventX(MotionEvent event, int pointerIndex) { float getEventX(MotionEvent event, int pointerIndex) {
// Relative mouse in capture mode will only have relative for X/Y // Relative mouse in capture mode will only have relative for X/Y
return event.getX(pointerIndex); return event.getX(pointerIndex);
} }
@Override @Override
public float getEventY(MotionEvent event, int pointerIndex) { float getEventY(MotionEvent event, int pointerIndex) {
// Relative mouse in capture mode will only have relative for X/Y // Relative mouse in capture mode will only have relative for X/Y
return event.getY(pointerIndex); return event.getY(pointerIndex);
} }

View File

@@ -14,14 +14,14 @@ public class SDLDummyEdit extends View implements View.OnKeyListener
InputConnection ic; InputConnection ic;
int input_type; int input_type;
public SDLDummyEdit(Context context) { SDLDummyEdit(Context context) {
super(context); super(context);
setFocusableInTouchMode(true); setFocusableInTouchMode(true);
setFocusable(true); setFocusable(true);
setOnKeyListener(this); setOnKeyListener(this);
} }
public void setInputType(int input_type) { void setInputType(int input_type) {
this.input_type = input_type; this.input_type = input_type;
} }

View File

@@ -7,12 +7,12 @@ import android.view.*;
import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.BaseInputConnection;
import android.widget.EditText; import android.widget.EditText;
public class SDLInputConnection extends BaseInputConnection class SDLInputConnection extends BaseInputConnection
{ {
protected EditText mEditText; protected EditText mEditText;
protected String mCommittedText = ""; protected String mCommittedText = "";
public SDLInputConnection(View targetView, boolean fullEditor) { SDLInputConnection(View targetView, boolean fullEditor) {
super(targetView, fullEditor); super(targetView, fullEditor);
mEditText = new EditText(SDL.getContext()); mEditText = new EditText(SDL.getContext());
} }

View File

@@ -40,10 +40,10 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
protected float mWidth, mHeight; protected float mWidth, mHeight;
// Is SurfaceView ready for rendering // Is SurfaceView ready for rendering
public boolean mIsSurfaceReady; protected boolean mIsSurfaceReady;
// Startup // Startup
public SDLSurface(Context context) { protected SDLSurface(Context context) {
super(context); super(context);
getHolder().addCallback(this); getHolder().addCallback(this);
@@ -66,11 +66,11 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
mIsSurfaceReady = false; mIsSurfaceReady = false;
} }
public void handlePause() { protected void handlePause() {
enableSensor(Sensor.TYPE_ACCELEROMETER, false); enableSensor(Sensor.TYPE_ACCELEROMETER, false);
} }
public void handleResume() { protected void handleResume() {
setFocusable(true); setFocusable(true);
setFocusableInTouchMode(true); setFocusableInTouchMode(true);
requestFocus(); requestFocus();
@@ -80,7 +80,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
enableSensor(Sensor.TYPE_ACCELEROMETER, true); enableSensor(Sensor.TYPE_ACCELEROMETER, true);
} }
public Surface getNativeSurface() { protected Surface getNativeSurface() {
return getHolder().getSurface(); return getHolder().getSurface();
} }
@@ -299,7 +299,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
} }
// Sensor events // Sensor events
public void enableSensor(int sensortype, boolean enabled) { protected void enableSensor(int sensortype, boolean enabled) {
// TODO: This uses getDefaultSensor - what if we have >1 accels? // TODO: This uses getDefaultSensor - what if we have >1 accels?
if (enabled) { if (enabled) {
mSensorManager.registerListener(this, mSensorManager.registerListener(this,
@@ -363,6 +363,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
} }
// Captured pointer events for API 26. // Captured pointer events for API 26.
@Override
public boolean onCapturedPointerEvent(MotionEvent event) public boolean onCapturedPointerEvent(MotionEvent event)
{ {
int action = event.getActionMasked(); int action = event.getActionMasked();

View File

@@ -1459,7 +1459,7 @@ The following symbols have been removed:
* SDL_RENDERER_PRESENTVSYNC - replaced with SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER during renderer creation and SDL_PROP_RENDERER_VSYNC_NUMBER after renderer creation * SDL_RENDERER_PRESENTVSYNC - replaced with SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER during renderer creation and SDL_PROP_RENDERER_VSYNC_NUMBER after renderer creation
* SDL_RENDERER_SOFTWARE - you can check whether the name of the renderer is `SDL_SOFTWARE_RENDERER` * SDL_RENDERER_SOFTWARE - you can check whether the name of the renderer is `SDL_SOFTWARE_RENDERER`
* SDL_RENDERER_TARGETTEXTURE - all renderers support target texture functionality * SDL_RENDERER_TARGETTEXTURE - all renderers support target texture functionality
* SDL_ScaleModeBest = use SDL_SCALEMODE_LINEAR instead * SDL_ScaleModeBest - use SDL_SCALEMODE_LINEAR instead
## SDL_rwops.h ## SDL_rwops.h

View File

@@ -8,7 +8,6 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import org.libsdl.app.SDL;
import org.libsdl.app.SDLActivity; import org.libsdl.app.SDLActivity;
import android.widget.Button; import android.widget.Button;