2022-10-26 18:39:04 +02:00
|
|
|
package android.os;
|
|
|
|
|
|
2024-03-15 20:02:18 +01:00
|
|
|
import android.util.Slog;
|
|
|
|
|
|
2022-10-26 18:39:04 +02:00
|
|
|
public class Vibrator {
|
2024-03-22 13:17:09 +01:00
|
|
|
int fd; // vibrator /dev/input/eventX
|
|
|
|
|
|
|
|
|
|
public Vibrator() {
|
|
|
|
|
fd = native_constructor();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-12 14:53:30 +03:00
|
|
|
public boolean hasVibrator(){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 20:02:18 +01:00
|
|
|
public void vibrate(long millis) {
|
2024-03-22 13:17:09 +01:00
|
|
|
if(fd != -1)
|
|
|
|
|
native_vibrate(fd, millis);
|
|
|
|
|
else
|
|
|
|
|
Slog.v("Vibrator", "vibration motor go burrrr for "+millis+"ms");
|
2024-03-15 20:02:18 +01:00
|
|
|
}
|
2024-03-22 13:17:09 +01:00
|
|
|
|
2024-03-15 20:02:18 +01:00
|
|
|
public void vibrate (final long[] pattern, int repeat) {
|
|
|
|
|
Thread t = new Thread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
for(int i = 0; i < pattern.length; i++) {
|
|
|
|
|
if(i%2 == 0)
|
|
|
|
|
try { Thread.sleep(pattern[i]); } catch(InterruptedException e) {}
|
|
|
|
|
else
|
|
|
|
|
vibrate(pattern[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
t.start();
|
|
|
|
|
}
|
2024-03-22 13:17:09 +01:00
|
|
|
|
|
|
|
|
private native void native_vibrate(int fd, long millis);
|
|
|
|
|
private native int native_constructor();
|
2022-10-26 18:39:04 +02:00
|
|
|
}
|