Skip to content

Commit 143f65c

Browse files
1bsylslouken
authored andcommitted
Android: silence false Lint warnings (the class are instantiated only at correct API level)
1 parent fb0a542 commit 143f65c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ void rumble(int device_id, float low_frequency_intensity, float high_frequency_i
471471
return;
472472
}
473473

474+
if (Build.VERSION.SDK_INT < 31 /* Android 12.0 (S) */) {
475+
/* Silence 'lint' warning */
476+
return;
477+
}
478+
474479
VibratorManager manager = device.getVibratorManager();
475480
int[] vibrators = manager.getVibratorIds();
476481
if (vibrators.length >= 2) {
@@ -483,6 +488,12 @@ void rumble(int device_id, float low_frequency_intensity, float high_frequency_i
483488
}
484489

485490
private void vibrate(Vibrator vibrator, float intensity, int length) {
491+
492+
if (Build.VERSION.SDK_INT < 31 /* Android 12.0 (S) */) {
493+
/* Silence 'lint' warning */
494+
return;
495+
}
496+
486497
if (intensity == 0.0f) {
487498
vibrator.cancel();
488499
return;
@@ -510,6 +521,12 @@ private void vibrate(Vibrator vibrator, float intensity, int length) {
510521
class SDLHapticHandler_API26 extends SDLHapticHandler {
511522
@Override
512523
void run(int device_id, float intensity, int length) {
524+
525+
if (Build.VERSION.SDK_INT < 26 /* Android 8.0 (O) */) {
526+
/* Silence 'lint' warning */
527+
return;
528+
}
529+
513530
SDLHaptic haptic = getHaptic(device_id);
514531
if (haptic != null) {
515532
if (intensity == 0.0f) {
@@ -743,6 +760,11 @@ boolean setRelativeMouseEnabled(boolean enabled) {
743760

744761
@Override
745762
float getEventX(MotionEvent event, int pointerIndex) {
763+
if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) {
764+
/* Silence 'lint' warning */
765+
return 0;
766+
}
767+
746768
if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) {
747769
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_X, pointerIndex);
748770
} else {
@@ -752,6 +774,11 @@ float getEventX(MotionEvent event, int pointerIndex) {
752774

753775
@Override
754776
float getEventY(MotionEvent event, int pointerIndex) {
777+
if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) {
778+
/* Silence 'lint' warning */
779+
return 0;
780+
}
781+
755782
if (mRelativeModeEnabled && event.getToolType(pointerIndex) == MotionEvent.TOOL_TYPE_MOUSE) {
756783
return event.getAxisValue(MotionEvent.AXIS_RELATIVE_Y, pointerIndex);
757784
} else {
@@ -776,6 +803,12 @@ boolean inRelativeMode() {
776803

777804
@Override
778805
boolean setRelativeMouseEnabled(boolean enabled) {
806+
807+
if (Build.VERSION.SDK_INT < 26 /* Android 8.0 (O) */) {
808+
/* Silence 'lint' warning */
809+
return false;
810+
}
811+
779812
if (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */) {
780813
if (enabled) {
781814
SDLActivity.getContentView().requestPointerCapture();
@@ -791,13 +824,23 @@ boolean setRelativeMouseEnabled(boolean enabled) {
791824

792825
@Override
793826
void reclaimRelativeMouseModeIfNeeded() {
827+
828+
if (Build.VERSION.SDK_INT < 26 /* Android 8.0 (O) */) {
829+
/* Silence 'lint' warning */
830+
return;
831+
}
832+
794833
if (mRelativeModeEnabled && !SDLActivity.isDeXMode()) {
795834
SDLActivity.getContentView().requestPointerCapture();
796835
}
797836
}
798837

799838
@Override
800839
boolean checkRelativeEvent(MotionEvent event) {
840+
if (Build.VERSION.SDK_INT < 26 /* Android 8.0 (O) */) {
841+
/* Silence 'lint' warning */
842+
return false;
843+
}
801844
return event.getSource() == InputDevice.SOURCE_MOUSE_RELATIVE;
802845
}
803846

0 commit comments

Comments
 (0)