Search in sources :

Example 81 with Vibrator

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

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 82 with Vibrator

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

the class FingerprintUtils method vibrateFingerprintSuccess.

public static void vibrateFingerprintSuccess(Context context) {
    Vibrator vibrator = context.getSystemService(Vibrator.class);
    boolean FingerprintVib = Settings.System.getIntForUser(context.getContentResolver(), Settings.System.FINGERPRINT_SUCCESS_VIB, 1, UserHandle.USER_CURRENT) == 1;
    if (vibrator != null && FingerprintVib) {
        vibrator.vibrate(FP_SUCCESS_VIBRATE_PATTERN, -1);
    }
}
Also used : Vibrator(android.os.Vibrator)

Example 83 with Vibrator

use of android.os.Vibrator in project weex-example by KalicyZhou.

the class BeepManager method playBeepSoundAndVibrate.

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)

Example 84 with Vibrator

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

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 85 with Vibrator

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

the class Action method processActionWithOptions.

public static void processActionWithOptions(Context context, String action, boolean isLongpress, boolean collapseShade) {
    if (action == null || action.equals(ActionConstants.ACTION_NULL)) {
        return;
    }
    boolean isKeyguardShowing = false;
    try {
        isKeyguardShowing = WindowManagerGlobal.getWindowManagerService().isKeyguardLocked();
    } catch (RemoteException e) {
        Log.w("Action", "Error getting window manager service", e);
    }
    // process the actions
    if (action.equals(ActionConstants.ACTION_HOME)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_HOME, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_BACK)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_BACK, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_SEARCH)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_SEARCH, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_MENU) || action.equals(ActionConstants.ACTION_MENU_BIG)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_MENU, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_LEFT)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_LEFT, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_RIGHT)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_RIGHT, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_UP)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_UP, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_IME_NAVIGATION_DOWN)) {
        triggerVirtualKeypress(KeyEvent.KEYCODE_DPAD_DOWN, isLongpress);
        return;
    } else if (action.equals(ActionConstants.ACTION_POWER)) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        pm.goToSleep(SystemClock.uptimeMillis());
        return;
    } else if (action.equals(ActionConstants.ACTION_IME)) {
        if (isKeyguardShowing) {
            return;
        }
        context.sendBroadcastAsUser(new Intent("android.settings.SHOW_INPUT_METHOD_PICKER"), new UserHandle(UserHandle.USER_CURRENT));
        return;
    } else if (action.equals(ActionConstants.ACTION_VOICE_SEARCH)) {
        // launch the search activity
        Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            // TODO: This only stops the factory-installed search manager.
            // Need to formalize an API to handle others
            SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
            if (searchManager != null) {
                searchManager.stopSearch();
            }
            startActivity(context, intent);
        } catch (ActivityNotFoundException e) {
            Log.e("Actions:", "No activity to handle assist long press action.", e);
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_VIB)) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (am != null && ActivityManagerNative.isSystemReady()) {
            if (am.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) {
                am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                if (vib != null) {
                    vib.vibrate(50);
                }
            } else {
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
                if (tg != null) {
                    tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                }
            }
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_SILENT)) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (am != null && ActivityManagerNative.isSystemReady()) {
            if (am.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
                am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            } else {
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
                if (tg != null) {
                    tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                }
            }
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_VIB_SILENT)) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (am != null && ActivityManagerNative.isSystemReady()) {
            if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
                am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                Vibrator vib = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                if (vib != null) {
                    vib.vibrate(50);
                }
            } else if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
                am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            } else {
                am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, (int) (ToneGenerator.MAX_VOLUME * 0.85));
                if (tg != null) {
                    tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                }
            }
        }
        return;
    } else if (action.equals(ActionConstants.ACTION_CAMERA)) {
        // ToDo: Send for secure keyguard secure camera intent.
        // We need to add support for it first.
        Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA, null);
        startActivity(context, intent);
        return;
    } else if (action.equals(ActionConstants.ACTION_MEDIA_PREVIOUS)) {
        dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PREVIOUS, context);
        return;
    } else if (action.equals(ActionConstants.ACTION_MEDIA_NEXT)) {
        dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_NEXT, context);
        return;
    } else if (action.equals(ActionConstants.ACTION_MEDIA_PLAY_PAUSE)) {
        dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, context);
        return;
    } else if (action.equals(ActionConstants.ACTION_WAKE_DEVICE)) {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (!powerManager.isScreenOn()) {
            powerManager.wakeUp(SystemClock.uptimeMillis());
        }
        return;
    } else {
        // we must have a custom uri
        Intent intent = null;
        try {
            intent = Intent.parseUri(action, 0);
        } catch (URISyntaxException e) {
            Log.e("Actions:", "URISyntaxException: [" + action + "]");
            return;
        }
        startActivity(context, intent);
        return;
    }
}
Also used : PowerManager(android.os.PowerManager) AudioManager(android.media.AudioManager) ToneGenerator(android.media.ToneGenerator) SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) UserHandle(android.os.UserHandle) Intent(android.content.Intent) Vibrator(android.os.Vibrator) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException)

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