Search in sources :

Example 41 with Vibrator

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));
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Vibrator(android.os.Vibrator) Date(java.util.Date)

Example 42 with Vibrator

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");
    }
}
Also used : Vibrator(android.os.Vibrator)

Example 43 with Vibrator

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);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Vibrator(android.os.Vibrator)

Example 44 with Vibrator

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;
        }
    }
}
Also used : Vibrator(android.os.Vibrator)

Example 45 with Vibrator

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);
    }
}
Also used : Vibrator(android.os.Vibrator) SuppressLint(android.annotation.SuppressLint)

Aggregations

Vibrator (android.os.Vibrator)159 Intent (android.content.Intent)15 IOException (java.io.IOException)14 Uri (android.net.Uri)12 Context (android.content.Context)10 Handler (android.os.Handler)10 View (android.view.View)10 NotificationManager (android.app.NotificationManager)8 RemoteException (android.os.RemoteException)8 ImageView (android.widget.ImageView)8 AudioManager (android.media.AudioManager)7 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 InputDevice (android.view.InputDevice)6 TextView (android.widget.TextView)6 Activity (android.app.Activity)5 Bitmap (android.graphics.Bitmap)5 FileOutputStream (java.io.FileOutputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ListenableFuture (org.thoughtcrime.securesms.util.concurrent.ListenableFuture)5 SuppressLint (android.annotation.SuppressLint)4