use of android.os.Vibrator in project NetGuard by M66B.
the class WidgetAdmin method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.i(TAG, "Received " + intent);
Util.logExtras(intent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// Cancel set alarm
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(INTENT_ON);
i.setPackage(context.getPackageName());
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction()))
am.cancel(pi);
// Vibrate
Vibrator vs = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
if (vs.hasVibrator())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
vs.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
else
vs.vibrate(50);
try {
if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction())) {
boolean enabled = INTENT_ON.equals(intent.getAction());
prefs.edit().putBoolean("enabled", enabled).apply();
if (enabled)
ServiceSinkhole.start("widget", context);
else
ServiceSinkhole.stop("widget", context, false);
// Auto enable
int auto = Integer.parseInt(prefs.getString("auto_enable", "0"));
if (!enabled && auto > 0) {
Log.i(TAG, "Scheduling enabled after minutes=" + auto);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
else
am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi);
}
} else if (INTENT_LOCKDOWN_ON.equals(intent.getAction()) || INTENT_LOCKDOWN_OFF.equals(intent.getAction())) {
boolean lockdown = INTENT_LOCKDOWN_ON.equals(intent.getAction());
prefs.edit().putBoolean("lockdown", lockdown).apply();
ServiceSinkhole.reload("widget", context, false);
WidgetLockdown.updateWidgets(context);
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
}
use of android.os.Vibrator in project matrix-android-sdk by matrix-org.
the class CallSoundsManager method enableVibrating.
/**
* Enable the vibrate mode.
*
* @param aIsVibrateEnabled true to force vibrate, false to stop vibrate.
*/
private void enableVibrating(boolean aIsVibrateEnabled) {
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
if ((null != vibrator) && vibrator.hasVibrator()) {
if (aIsVibrateEnabled) {
vibrator.vibrate(VIBRATE_PATTERN, 0);
Log.d(LOG_TAG, "## startVibrating(): Vibrate started");
} else {
vibrator.cancel();
Log.d(LOG_TAG, "## startVibrating(): Vibrate canceled");
}
} else {
Log.w(LOG_TAG, "## startVibrating(): vibrator access failed");
}
}
use of android.os.Vibrator in project Bilal by cdjalel.
the class AlarmReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Timber.i("=============== Athan alarm is ON");
if (UserSettings.isVibrateEnabled(context)) {
// this is independent of notification setVibrate
Vibrator vibrator = (Vibrator) context.getSystemService(VIBRATOR_SERVICE);
if (vibrator != null) {
vibrator.vibrate(new long[] { 1000, 1000, 1000 }, -1);
}
}
if (UserSettings.isAthanEnabled(context)) {
WakeLocker.acquire(context);
Intent audioIntent = new Intent(context, AthanAudioService.class);
audioIntent.putExtra(AthanAudioService.EXTRA_MUEZZIN, UserSettings.getMuezzin(context));
context.startService(audioIntent);
}
if (UserSettings.isNotificationEnabled(context)) {
showNotification(context);
}
// Broadcast to MainActivity so it updates its screen if on
Intent updateIntent = new Intent(MainActivity.UPDATE_VIEWS);
context.sendBroadcast(updateIntent);
// Re-arm alarm.
PrayerTimesManager.updatePrayerTimes(context, false);
}
use of android.os.Vibrator in project Osmand by osmandapp.
the class NavigationInfo method updateTargetDirection.
public synchronized void updateTargetDirection(final Location point, float heading) {
if ((currentLocation != null) && (point != null)) {
RelativeDirection direction = new RelativeDirection(point, heading);
Integer inclination = direction.getInclination();
if (targetDirectionFlag && ((inclination == null) || (inclination != 0))) {
targetDirectionFlag = false;
if (settings.DIRECTION_AUDIO_FEEDBACK.get()) {
AccessibilityPlugin accessibilityPlugin = OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class);
if (accessibilityPlugin != null) {
if (inclination == null) {
accessibilityPlugin.playSoundIcon(AccessibilityPlugin.DIRECTION_NOTIFICATION);
} else if (inclination > 0) {
accessibilityPlugin.playSoundIcon(AccessibilityPlugin.INCLINATION_LEFT);
} else {
accessibilityPlugin.playSoundIcon(AccessibilityPlugin.INCLINATION_RIGHT);
}
}
}
if (settings.DIRECTION_HAPTIC_FEEDBACK.get()) {
Vibrator haptic = (Vibrator) app.getSystemService(Context.VIBRATOR_SERVICE);
if ((haptic != null) && haptic.hasVibrator()) {
if (inclination == null) {
haptic.vibrate(200);
} else if (inclination > 0) {
haptic.vibrate(HAPTIC_INCLINATION_LEFT, -1);
} else {
haptic.vibrate(HAPTIC_INCLINATION_RIGHT, -1);
}
}
}
} else if ((!targetDirectionFlag) && (direction.getValue() == 0)) {
targetDirectionFlag = true;
}
}
}
use of android.os.Vibrator in project zxing by yuzhiqiang1993.
the class BeepManager method playBeepSoundAndVibrate.
/**
* 开启响铃和震动
*/
@SuppressLint("MissingPermission")
public synchronized void playBeepSoundAndVibrate() {
if (playBeep && mediaPlayer != null) {
mediaPlayer.start();
}
if (vibrate) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_DURATION);
}
}
Aggregations