Search in sources :

Example 66 with Vibrator

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

the class SearchPanelView method vibrate.

private void vibrate() {
    Context context = getContext();
    if (Settings.System.getIntForUser(context.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 1, UserHandle.USER_CURRENT) != 0) {
        Resources res = context.getResources();
        Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(res.getInteger(R.integer.config_search_panel_view_vibration_duration));
    }
}
Also used : Context(android.content.Context) Resources(android.content.res.Resources) Vibrator(android.os.Vibrator)

Example 67 with Vibrator

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

the class ShutdownThread method rebootOrShutdown.

/**
     * Do not call this directly. Use {@link #reboot(Context, String, boolean)}
     * or {@link #shutdown(Context, boolean)} instead.
     *
     * @param reboot true to reboot or false to shutdown
     * @param reason reason for reboot
     */
public static void rebootOrShutdown(boolean reboot, String reason) {
    if (reboot) {
        Log.i(TAG, "Rebooting, reason: " + reason);
        try {
            PowerManagerService.lowLevelReboot(reason);
        } catch (Exception e) {
            Log.e(TAG, "Reboot failed, will attempt shutdown instead", e);
        }
    } else if (SHUTDOWN_VIBRATE_MS > 0) {
        // vibrate before shutting down
        Vibrator vibrator = new SystemVibrator();
        try {
            vibrator.vibrate(SHUTDOWN_VIBRATE_MS);
        } 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();
}
Also used : SystemVibrator(android.os.SystemVibrator) Vibrator(android.os.Vibrator) SystemVibrator(android.os.SystemVibrator) RemoteException(android.os.RemoteException)

Example 68 with Vibrator

use of android.os.Vibrator in project qksms by moezbhatti.

the class DeliveredReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    switch(getResultCode()) {
        case Activity.RESULT_OK:
            if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SettingsFragment.DELIVERY_TOAST, true)) {
                Toast.makeText(context, R.string.message_delivered, Toast.LENGTH_LONG).show();
            }
            if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SettingsFragment.DELIVERY_VIBRATE, true)) {
                Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                vibrator.vibrate(100);
            }
            break;
        case Activity.RESULT_CANCELED:
            Toast.makeText(context, R.string.message_not_delivered, Toast.LENGTH_LONG).show();
            break;
    }
}
Also used : Vibrator(android.os.Vibrator)

Example 69 with Vibrator

use of android.os.Vibrator in project qksms by moezbhatti.

the class MessageListFragment method vibrateOnConversationStateChanged.

private void vibrateOnConversationStateChanged(final boolean notificationMuted) {
    final int vibrateTime = 70;
    Toast.makeText(getActivity(), notificationMuted ? R.string.notification_mute_off : R.string.notification_mute_on, Toast.LENGTH_SHORT).show();
    Vibrator v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(vibrateTime);
}
Also used : Vibrator(android.os.Vibrator)

Example 70 with Vibrator

use of android.os.Vibrator in project platform_frameworks_base by android.

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)

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