2023-06-03 11:08:22 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Build.VERSION;
|
|
|
|
import android.os.Vibrator;
|
|
|
|
import android.view.HapticFeedbackConstants;
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
public final class VibratorCompat
|
|
|
|
{
|
2024-01-09 00:43:28 +01:00
|
|
|
public static void vibrate(View v, Config config)
|
2023-06-03 11:08:22 +02:00
|
|
|
{
|
2024-01-09 00:43:28 +01:00
|
|
|
if (config.vibrate_custom)
|
2023-06-03 11:08:22 +02:00
|
|
|
{
|
2024-01-09 00:43:28 +01:00
|
|
|
if (config.vibrate_duration > 0)
|
|
|
|
vibrator_vibrate(v, config.vibrate_duration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (VERSION.SDK_INT >= 8)
|
|
|
|
v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP,
|
|
|
|
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
|
2023-06-03 11:08:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Use the older [Vibrator] when the newer API is not available or the user
|
|
|
|
wants more control. */
|
2024-01-09 00:43:28 +01:00
|
|
|
static void vibrator_vibrate(View v, long duration)
|
2023-06-03 11:08:22 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
get_vibrator(v).vibrate(duration);
|
|
|
|
}
|
|
|
|
catch (Exception e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Vibrator vibrator_service = null;
|
|
|
|
|
|
|
|
static Vibrator get_vibrator(View v)
|
|
|
|
{
|
|
|
|
if (vibrator_service == null)
|
|
|
|
{
|
|
|
|
vibrator_service =
|
|
|
|
(Vibrator)v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
|
|
|
}
|
|
|
|
return vibrator_service;
|
|
|
|
}
|
|
|
|
}
|