mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Android: Convert DolphinVibratorManagerCompat to Kotlin
This commit is contained in:
parent
1ff6a3788e
commit
29adbb4394
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user