Search in sources :

Example 46 with Vibrator

use of android.os.Vibrator in project android_frameworks_base by crdroidandroid.

the class ShutdownThread method rebootOrShutdown.

/**
     * Do not call this directly. Use {@link #reboot(Context, String, boolean)}
     * or {@link #shutdown(Context, boolean)} instead.
     *
     * @param context Context used to vibrate or null without vibration
     * @param reboot true to reboot or false to shutdown
     * @param reason reason for reboot/shutdown
     */
public static void rebootOrShutdown(final Context context, boolean reboot, String reason) {
    // Call oem shutdown handler
    deviceRebootOrShutdown(reboot, reason);
    if (reboot) {
        Log.i(TAG, "Rebooting, reason: " + reason);
        PowerManagerService.lowLevelReboot(reason);
        Log.e(TAG, "Reboot failed, will attempt shutdown instead");
        reason = null;
    } else if (SHUTDOWN_VIBRATE_MS > 0 && context != null) {
        // vibrate before shutting down
        Vibrator vibrator = new SystemVibrator(context);
        try {
            vibrator.vibrate(SHUTDOWN_VIBRATE_MS, VIBRATION_ATTRIBUTES);
        } catch (Exception e) {
            // Failure to vibrate shouldn't interrupt shutdown.  Just log it.
            Log.w(TAG, "Failed to vibrate during shutdown.", e);
        }
        // vibrator is asynchronous so we need to wait to avoid shutting down too soon.
        try {
            Thread.sleep(SHUTDOWN_VIBRATE_MS);
        } catch (InterruptedException unused) {
        }
    }
    // Shutdown power
    Log.i(TAG, "Performing low-level shutdown...");
    PowerManagerService.lowLevelShutdown(reason);
}
Also used : SystemVibrator(android.os.SystemVibrator) Vibrator(android.os.Vibrator) SystemVibrator(android.os.SystemVibrator) RemoteException(android.os.RemoteException) ErrnoException(android.system.ErrnoException) IOException(java.io.IOException)

Example 47 with Vibrator

use of android.os.Vibrator in project android_frameworks_base by crdroidandroid.

the class VibratorService method updateInputDeviceVibrators.

private void updateInputDeviceVibrators() {
    synchronized (mVibrations) {
        doCancelVibrateLocked();
        synchronized (mInputDeviceVibrators) {
            mVibrateInputDevicesSetting = false;
            try {
                mVibrateInputDevicesSetting = Settings.System.getIntForUser(mContext.getContentResolver(), Settings.System.VIBRATE_INPUT_DEVICES, UserHandle.USER_CURRENT) > 0;
            } catch (SettingNotFoundException snfe) {
            }
            mLowPowerMode = mPowerManagerInternal.getLowPowerModeEnabled();
            if (mVibrateInputDevicesSetting) {
                if (!mInputDeviceListenerRegistered) {
                    mInputDeviceListenerRegistered = true;
                    mIm.registerInputDeviceListener(this, mH);
                }
            } else {
                if (mInputDeviceListenerRegistered) {
                    mInputDeviceListenerRegistered = false;
                    mIm.unregisterInputDeviceListener(this);
                }
            }
            mInputDeviceVibrators.clear();
            if (mVibrateInputDevicesSetting) {
                int[] ids = mIm.getInputDeviceIds();
                for (int i = 0; i < ids.length; i++) {
                    InputDevice device = mIm.getInputDevice(ids[i]);
                    Vibrator vibrator = device.getVibrator();
                    if (vibrator.hasVibrator()) {
                        mInputDeviceVibrators.add(vibrator);
                    }
                }
            }
        }
        startNextVibrationLocked();
    }
}
Also used : InputDevice(android.view.InputDevice) Vibrator(android.os.Vibrator) SettingNotFoundException(android.provider.Settings.SettingNotFoundException)

Example 48 with Vibrator

use of android.os.Vibrator in project android_frameworks_base by AOSPA.

the class BugreportProgressService method takeScreenshot.

/**
     * Takes a screenshot and save it to the given location.
     */
private static boolean takeScreenshot(Context context, String path) {
    final Bitmap bitmap = Screenshooter.takeScreenshot();
    if (bitmap == null) {
        return false;
    }
    boolean status;
    try (final FileOutputStream fos = new FileOutputStream(path)) {
        if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos)) {
            ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(150);
            return true;
        } else {
            Log.e(TAG, "Failed to save screenshot on " + path);
        }
    } catch (IOException e) {
        Log.e(TAG, "Failed to save screenshot on " + path, e);
        return false;
    } finally {
        bitmap.recycle();
    }
    return false;
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Vibrator(android.os.Vibrator) IOException(java.io.IOException)

Example 49 with Vibrator

use of android.os.Vibrator in project Talon-for-Twitter by klinker24.

the class SendQueue method finishedTweetingNotification.

public void finishedTweetingNotification() {
    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext, TALON_SERVICE_CHANNEL_ID).setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false).setTicker(getResources().getString(R.string.tweet_success));
        if (AppSettings.getInstance(this).vibrate) {
            Log.v("talon_vibrate", "vibrate on compose");
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            long[] pattern = { 0, 50, 500 };
            v.vibrate(pattern, -1);
        }
        stopForeground(true);
        NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(6, mBuilder.build());
        // cancel it immediately, the ticker will just go off
        mNotificationManager.cancel(6);
    } catch (Exception e) {
    // not attached to activity
    }
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Vibrator(android.os.Vibrator)

Example 50 with Vibrator

use of android.os.Vibrator in project run-wallet-android by runplay.

the class NotificationHelper method vibrate.

public static void vibrate(Context context) {
    Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(240);
}
Also used : Vibrator(android.os.Vibrator)

Aggregations

Vibrator (android.os.Vibrator)88 IOException (java.io.IOException)10 RemoteException (android.os.RemoteException)8 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)6 InputDevice (android.view.InputDevice)6 NotificationManager (android.app.NotificationManager)5 Intent (android.content.Intent)5 Bitmap (android.graphics.Bitmap)5 SystemVibrator (android.os.SystemVibrator)5 FileOutputStream (java.io.FileOutputStream)5 Activity (android.app.Activity)4 Context (android.content.Context)4 AudioManager (android.media.AudioManager)4 PowerManager (android.os.PowerManager)4 NotificationCompat (android.support.v4.app.NotificationCompat)4 ErrnoException (android.system.ErrnoException)4 Uri (android.net.Uri)3 AlarmManager (android.app.AlarmManager)2 PendingIntent (android.app.PendingIntent)2 SearchManager (android.app.SearchManager)2