From 29adbb439457c83d63fdfd217f4f7edeba20579f Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 10 Jun 2023 05:14:20 -0400 Subject: [PATCH] Android: Convert DolphinVibratorManagerCompat to Kotlin --- .../model/DolphinVibratorManagerCompat.java | 35 ------------------- .../model/DolphinVibratorManagerCompat.kt | 24 +++++++++++++ 2 files changed, 24 insertions(+), 35 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.java deleted file mode 100644 index 40c4fa95d1..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.java +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.input.model; - -import android.os.Vibrator; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public final class DolphinVibratorManagerCompat implements DolphinVibratorManager -{ - private final Vibrator mVibrator; - private final int[] mIds; - - public DolphinVibratorManagerCompat(@Nullable Vibrator vibrator) - { - mVibrator = vibrator; - mIds = vibrator != null && vibrator.hasVibrator() ? new int[]{0} : new int[]{}; - } - - @Override @NonNull - public Vibrator getVibrator(int vibratorId) - { - if (vibratorId > mIds.length) - throw new IndexOutOfBoundsException(); - - return mVibrator; - } - - @Override @NonNull - public int[] getVibratorIds() - { - return mIds; - } -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.kt new file mode 100644 index 0000000000..039f0ecb6b --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/DolphinVibratorManagerCompat.kt @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.input.model + +import android.os.Vibrator + +class DolphinVibratorManagerCompat(vibrator: Vibrator) : DolphinVibratorManager { + private val vibrator: Vibrator + private val vibratorIds: IntArray + + init { + this.vibrator = vibrator + vibratorIds = if (vibrator.hasVibrator()) intArrayOf(0) else intArrayOf() + } + + override fun getVibrator(vibratorId: Int): Vibrator { + if (vibratorId > vibratorIds.size) + throw IndexOutOfBoundsException() + + return vibrator + } + + override fun getVibratorIds(): IntArray = vibratorIds +}