mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2024-11-26 17:23:17 +01:00
73267d68fb
This reverts commitsef03dfed5c
andff01678ba6
. The "vibration duration" slider is bought back. The "vibration enabled" option is replaced by "custom vibration", which switch between the system haptic feedback or the custom vibration. The slider is greyed when "custom vibration" is unchecked and is allowed to have a value of 0 to disable vibrations within the app. The intermediate values "light", "medium" and "strong" are removed and no migration of the setting is made.
49 lines
1.1 KiB
Java
49 lines
1.1 KiB
Java
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
|
|
{
|
|
public static void vibrate(View v, Config config)
|
|
{
|
|
if (config.vibrate_custom)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
/** Use the older [Vibrator] when the newer API is not available or the user
|
|
wants more control. */
|
|
static void vibrator_vibrate(View v, long duration)
|
|
{
|
|
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;
|
|
}
|
|
}
|